程序博客网 > 局域网 域名访问
来源:互联网 发布:局域网 域名访问 编辑:程序博客网 时间:2024/05/02 10:37
public partial class month2 : Form { public month2() { InitializeComponent(); } private void button2_Click(object sender, EventArgs e) { button2.Visible = false; button2.Enabled = false; button1.Visible = true; button1.Enabled = true; mydel1 = new myDel1(showNum1); thread1 = new Thread(MyEvent1); thread1.IsBackground = true; thread1.Start(); // MessageBox.Show(DBstore.Rlist.Count.ToString()); } private void button1_Click(object sender, EventArgs e) { button1.Visible = false; button1.Enabled = false; button2.Visible = true; button2.Enabled = true; thread1.Suspend(); int i = weekDBstore.Rlist.Count / 8; MessageBox.Show("抽取第" + i.ToString() + "位幸运用户"); string phone = label1.Text; thread1.Suspend(); label2.Text += "第" + i.ToString() + "位:"+phone + "/n"; int index = weekDBstore.Uphone.IndexOf(phone);// weekDBstore.Rlist.Add(weekDBstore.Uphone[index]); weekDBstore.Rlist.Add(weekDBstore.Usorce[index]); weekDBstore.Rlist.Add(weekDBstore.Upid[index]); weekDBstore.Rlist.Add(weekDBstore.Ucity[index]); weekDBstore.Rlist.Add(weekDBstore.Utype[index]); weekDBstore.Rlist.Add("幸运奖"); weekDBstore.Rlist.Add("500"); weekDBstore.Rlist.Add("现金"); weekDBstore.Uphone.RemoveAt(index); weekDBstore.Usorce.RemoveAt(index); weekDBstore.Upid.RemoveAt(index); weekDBstore.Ucity.RemoveAt(index); weekDBstore.Utype.RemoveAt(index); //MessageBox.Show(weekDBstore.Rlist.Count.ToString()); if (weekDBstore.Rlist.Count == 88) { MessageBox.Show("月幸运奖抽取完毕!"); button1.Enabled = false; button2.Enabled = false; button1.Visible = false; button7.Visible = true; } } delegate void myDel1(string i);//委托 将方法当成参数传递 myDel1 mydel1 = null; Thread thread1; public void showNum1(string i) { label1.Text = i; } public void MyEvent1() { bool t = true; int count100 = 0; int k = weekDBstore.Usorce.Count; for (int i = 0; i < k; i++) { int sorce = Convert.ToInt32(weekDBstore.Usorce[i]); if (sorce >= 400) { count100++;//取得大于100分的用户数 } else { k = 0; } } while (t) { Random r = new Random(); int index = r.Next(0, count100 - 1);//产生一个随机数 及抽中者的下标 string phone = weekDBstore.Uphone[index].ToString(); Thread.Sleep(10); this.BeginInvoke(mydel1, new object[] { phone });//异步 } } private void button7_Click(object sender, EventArgs e) { this.Close(); } }