//奖项设置 private void button3_Click(object sender, EventArgs e) { Form3 child = new Form3(); child.ShowDialog(); MySqliteCategory.WriteCategoryToSQL(); ShowNextLuck(GetNextLuckIndex()); }
//开始抽奖过程 private void StartLuck() { if (!CheckSetting()) { MessageBox.Show("未设定人员或奖项"); return; } //开始抽奖 if (button1.Text == "开始抽奖") { button1.Text = "停"; panel3.Visible = true; panel4.Visible = true; label10.Visible = false; //获取正在抽奖的项目; int index = GetNextLuckIndex(); //更新该项目状态为已抽奖 List <String> luck = LuckCatagroyList[index]; luck[2] = "已抽取"; MySqliteCategory.WriteCategoryToSQL(); label2.Text = "正在抽取 " + luck[0]; label3.Text = luck[1]; //抽取过程禁止按其他按钮 DisabledAllButton(); timer1.Interval = 50;// 设置每次刷新抽奖人员时间间隔为50ms timer1.Start(); } else //停止抽奖 { button1.Text = "开始抽奖"; label2.Text = label2.Text.Replace("正在抽取 ", ""); timer1.Stop(); //保存中奖人名单 SaveLuckPerson(); //中奖人移出抽奖名单 RemoveLuckPerson(); int index = GetNextLuckIndex(); ShowNextLuck(index); EnabledAllButton(); } }
//放弃奖励,人员退回抽奖列表,奖项设为未抽取 private void button2_Click(object sender, EventArgs e) { DialogResult result = MessageBox.Show("放弃奖项", "确认放弃吗", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); //取消弃奖 if (result == DialogResult.Cancel) { return; } int index = GetFocusedItemIndex(); if (index == -1) { //没有选中任何项 return; } List <String> luck = new List <String>(); String state = listView1.FocusedItem.SubItems[3].Text; //奖项状态 if (state == "已弃奖") { MessageBox.Show("懒得理你"); return; } String level = listView1.FocusedItem.SubItems[1].Text; //奖项名 String goods = listView1.FocusedItem.SubItems[2].Text; //奖品名称 String id = listView1.FocusedItem.SubItems[4].Text; //中奖人工号 String department = listView1.FocusedItem.SubItems[5].Text; //中奖人部门 String name = listView1.FocusedItem.SubItems[6].Text; //中奖人名字 //添加到抽奖人员数据库 MySqlitePersons.AddOnePersonFormTable(id, department, name); MySqlitePersons.ReadPersonsFormSQL(); //已弃奖的奖项重置为未抽取状态 for (int i = 0; i < Form1.LuckCatagroyList.Count; i++) { List <String> catagroy = Form1.LuckCatagroyList[i]; String luckedLevel = catagroy[0]; //奖项名 String luckedGoods = catagroy[1]; //奖品名称 String luckedState = catagroy[2]; //奖项状态 if (luckedState != "已抽取") { continue; } if (level == luckedLevel && goods == luckedGoods) { catagroy[2] = "未抽取"; break; } } //保存新的奖项列表 MySqliteCategory.WriteCategoryToSQL(); //已弃奖的中奖结果重置为已弃奖状态 for (int i = 0; i < Form1.LuckedPerson.Count; i++) { List <String> lucked = Form1.LuckedPerson[i]; String luckedLevel = lucked[0]; String luckedGoods = lucked[1]; String luckedState = lucked[2]; String luckedId = lucked[3]; String luckedDepartment = lucked[4]; String luckedName = lucked[5]; if (luckedState != "已抽取") //|| luckedState != "已弃奖") { continue; } if (level == luckedLevel && goods == luckedGoods && id == luckedId && department == luckedDepartment && name == luckedName) { lucked[2] = "已弃奖"; break; } } MySqliteLuckedPerson.WriteLuckedToSQL(); //刷新列表,不然出BUG AddDataToListView(); }