Mr_Xing 通过本文主要向大家介绍了马桶c的个人空间,c站,欲情 c max,维生素c,奔驰c200等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
我写代码一直是这个风格,废话不多,直接给大家贴代码,现在还是老规矩,具体代码如下所示:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Drawing.Imaging; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Data.SqlClient; using System.Collections; using System.IO; namespace Check_Ticket { public partial class Btn_UpLoadFile : Form { string conn = "server=WIN-OUDREHCH;database=Xtf;uid=sa;pwd="; string sql = ""; int CurNum = ;//奖项人数 int second = ;//防止二次被抽取 Hashtable hashtable = new Hashtable();//存储编号 Hashtable hashtable = new Hashtable();//存储获奖名单 Hashtable hashtable = new Hashtable();//避免二次抽奖 Dictionary<int, string> dict = new Dictionary<int, string>();//词典存储所有参赛者 Random rd = new Random(); int time = ; Label[] label = new Label[]; int index = ;//词典key键值 int total = ;//label个数 int num = ;//获奖总数 string s = ""; int End = ;//抽奖结束 public Btn_UpLoadFile() { InitializeComponent(); } private void Form_Load(object sender, EventArgs e) { dataGridView.ForeColor = Color.Blue; menu.Visible = false; comboBox.SelectedIndex = ; this.timer.Interval = ; this.timer.Interval = ; this.timer.Enabled = true; this.WindowState = FormWindowState.Maximized; } private void getNumber(string s) { SqlConnection myconn = new SqlConnection(conn); myconn.Open(); sql = "select *from SumPrize"; SqlDataAdapter da = new SqlDataAdapter(sql, myconn); DataSet ds = new DataSet(); da.Fill(ds); switch (s) { case "一等奖": second = ; CurNum = Convert.ToInt(ds.Tables[].Rows[]["PrizeNum"].ToString()); break; case "二等奖": second = ; CurNum = Convert.ToInt(ds.Tables[].Rows[]["PrizeNum"].ToString()); break; case "三等奖": second = ; CurNum = Convert.ToInt(ds.Tables[].Rows[]["PrizeNum"].ToString()); break; case "四等奖": second = ; CurNum = Convert.ToInt(ds.Tables[].Rows[]["PrizeNum"].ToString()); break; case "五等奖": second = ; CurNum = Convert.ToInt(ds.Tables[].Rows[]["PrizeNum"].ToString()); break; case "六等奖": second = ; CurNum = Convert.ToInt(ds.Tables[].Rows[]["PrizeNum"].ToString()); break; case "请选择": CurNum = ; break; default: break; } } private void button_Click(object sender, EventArgs e) { SqlConnection myconn = new SqlConnection(conn); myconn.Open(); //未选择抽奖项 if (CurNum == ) { MessageBox.Show("未设置该奖项或未选择奖项,抽奖没有意义!!!"); return; } //处理已经被抽奖项 if (!hashtable.ContainsValue(second)) { comboBox.Enabled = true; hashtable.Add(second, second); } else { MessageBox.Show("此奖项已经被抽过,换个奖项吧?"); return; } string prize = comboBox.Text.ToString(); string sqlCount = "Select sum(PrizeNum) as num from SumPrize"; SqlDataAdapter sda = new SqlDataAdapter(sqlCount, myconn); DataSet ds = new DataSet(); sda.Fill(ds); //设置有奖总人数 num = Convert.ToInt(ds.Tables[].Rows[]["num"].ToString()); for (int i = ; i < dataGridView.RowCount-; i++) { dict.Add(index, dataGridView.Rows[i].Cells["WorkerID"].Value.ToString() + " " + dataGridView.Rows[i].Cells["Name"].Value.ToString()); index++; } myconn.Close(); timer.Start(); clearLabel(); bornLabel(); timer.Enabled = true; comboBox.Enabled = false; } private void button_Click(object sender, EventArgs e) { End = ; menu.Text = ""; hashtable.Clear(); clearLabel(); button.Enabled = true; button.Enabled = true; button.Enabled = false; menu.Visible = false; btnAdd.Visible = false; tbNum.Visible = false; ge.Visible = false; addEnd.Visible = false; lab.Text = "中奖名单"; dataGridView.Visible = false; string sqlChecked = "delete from Checked"; sql = "select *from Ticket"; SqlConnection myconn = new SqlConnection(conn); myconn.Open(); SqlDataAdapter sda = new SqlDataAdapter(sql, myconn); DataSet ds = new DataSet(); sda.Fill(ds, "Ticket"); dataGridView.DataSource = ds; dataGridView.DataMember = "Ticket"; SqlCommand mycomm = new SqlCommand(sqlChecked, myconn); mycomm.ExecuteNonQuery(); myconn.Close(); } private void button_Click(object sender, EventArgs e) { menu.Visible = false; clearLabel(); sql = "select WorkerIDAndName,Prize from Checked order by PrizeID"; SqlConnection myconn = new SqlConnection(conn); myconn.Open(); SqlDataAdapter sda = new SqlDataAdapter(sql, myconn); DataSet ds = new DataSet(); sda.Fill(ds, "Checked"); dataGridView.DataSource = ds; dataGridView.DataMember = "Checked"; dataGridView.Visible = true; menu.Text += "恭喜:\n"; for(int i=;i<dataGridView.RowCount-;i++) { menu.Text += dataGridView.Rows[i].Cells["WorkerIDAndName"].Value.ToString() +" 获得"+ dataGridView.Rows[i].Cells["Prize"].Value.ToString() + "\n"; } menu.Visible = true; timer.Start(); myconn.Close(); } private void button_Click(object sender, EventArgs e) { new SetPeople().ShowDialog(); } private void comboBox_SelectedValueChanged(object sender, EventArgs e) { getNumber(comboBox.Text.ToString()); } private void timer_Tick(object sender, EventArgs e) { lab.Left = lab.Left - ; if (lab.Right < ) { lab.Left = this.Width; } } //创建labels private void bornLabel() { int i = ; for (i = ; i < CurNum; i++) { label[i] = new Label(); label[i].ForeColor = Color.Blue; label[i].Location = new System.Drawing.Point(, + (i * )); label[i].Size = new System.Drawing.Size(, ); label[i].BackColor = Color.Transparent; label[i].Anchor = (AnchorStyles.Top); label[i].Font = new System.Drawing.Font("SimSun", , FontStyle.Bold); this.Controls.Add(label[i]); } total = i; } //清除labels private void clearLabel() { for (int i = ; i < total; i++) { this.Controls.Remove(label[i]); } } private void timer_Tick(object sender, EventArgs e) { hashtable.Clear(); hashtable.Clear(); SqlConnection con = new SqlConnection(conn); string sql = "select count(*) from Ticket"; SqlCommand com = new SqlCommand(sql, con); con.Open(); int emcount = Convert.ToInt(com.ExecuteScalar()); con.Close(); timer.Enabled = true; timer.Interval = time; int i; for (i = ; i < CurNum; i++) { int random = Convert.ToInt(rd.Next(, emcount)); if (dataGridView.Rows[random].Cells["Checked"].Value.ToString().Trim()=="" && !hashtable.ContainsValue(dict[random])) { hashtable.Add(random,random); hashtable.Add(dict[random], dict[random]); label[i].Text = dict[random]; } else { i--; } } } private void button_Click(object sender, EventArgs e) { comboBox.Enabled = true; SqlConnection con = new SqlConnection(conn); con.Open(); string sql = ""; s = ""; timer.Stop(); foreach (DictionaryEntry de in hashtable) { sql = string.Format("insert into Checked(WorkerIDAndName,Prize,PrizeID) values('{}','{}','{}')", de.Value.ToString(), comboBox.Text.ToString(),second.ToString()); SqlCommand com = new SqlCommand(sql, con); com.ExecuteNonQuery(); s += de.Value.ToString() +" "; } foreach (DictionaryEntry de in hashtable) { dataGridView.Rows[Convert.ToInt(de.Key)].Cells["Checked"].Value = ""; } lab.Text = "恭喜: " + s + "获得" + comboBox.Text.ToString(); //判断抽奖结束 End = End + CurNum; if (End == num) { button.Enabled = false; //button.Enabled = false; button.Enabled = true; if (MessageBox.Show("抽奖结束,是否进行补抽,点击确定进行补抽,取消结束此次抽奖!", "温馨提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { btnAdd.Visible = true; tbNum.Visible = true; ge.Visible = true; addEnd.Visible = true; } } } private void timer_Tick(object sender, EventArgs e) { menu.Top = menu.Top - ; if (menu.Bottom < ) { menu.Top = this.Height-; } } private void 关闭窗口ToolStripMenuItem_Click(object sender, EventArgs e) { this.Close(); } private void btnAdd_Click(object sender, EventArgs e) { CurNum = Convert.ToInt(tbNum.Text.ToString()); if (CurNum