private void btnDel_Click(object sender, EventArgs e) { if (listBox1.SelectedItems.Count != 1) { MessageBox.Show("抱歉!请先选择一行!"); return; } FrmSetClock dlg = new FrmSetClock(); dlg.operType = "Edit"; //获取项目ID string row = listBox1.SelectedItem.ToString(); ControledClock temp = ControledClock.GetCtrlClockFromRowString(row); int removeIndex = listControlClock.Count; for (int i = 0; i < listControlClock.Count; i++) { if (temp.ID == listControlClock[i].ID) { removeIndex = i; } } if (removeIndex != listControlClock.Count) { listControlClock.RemoveAt(removeIndex); } BindListBox(); }
private void btnAddClock_Click(object sender, EventArgs e) { FrmSetClock dlg = new FrmSetClock(); if (DialogResult.OK == dlg.ShowDialog()) { ControledClock operedClock = new ControledClock() { RingTime = dlg.OperedClock.RingTime, TaskContent = dlg.OperedClock.TaskContent.Trim(), Interval = dlg.OperedClock.Interval, Status = dlg.OperedClock.Status.Trim(), ID = dlg.OperedClock.ID.Trim() }; listControlClock.Add(operedClock); //将闹钟添加进闹钟集合 if (operedClock.Status != "Stop") { BeginRingClock(operedClock); } //将添加闹钟事件记录在闹钟历史信息中 FileHelper.AddControledClockInfoToHistoryFile(operedClock, "新增"); BindListBox(); } }
private void btnEditClock_Click(object sender, EventArgs e) { if (listBox1.SelectedItems.Count != 1) { MessageBox.Show("抱歉!请先选择一行!"); return; } FrmSetClock dlg = new FrmSetClock(); dlg.operType = "Edit"; //获取项目ID string row = listBox1.SelectedItem.ToString(); ControledClock temp = ControledClock.GetCtrlClockFromRowString(row); dlg.OperedClock.RingTime = temp.RingTime; dlg.OperedClock.TaskContent = temp.TaskContent; dlg.OperedClock.Interval = temp.Interval; dlg.OperedClock.Status = temp.Status.Trim(); dlg.OperedClock.ID = temp.ID.Trim(); if (DialogResult.OK == dlg.ShowDialog()) { ControledClock operedClock = new ControledClock() { RingTime = dlg.OperedClock.RingTime, TaskContent = dlg.OperedClock.TaskContent, Interval = dlg.OperedClock.Interval, Status = dlg.OperedClock.Status, ID = dlg.OperedClock.ID }; for (int i = 0; i < listControlClock.Count(); i++) { if (listControlClock[i].ID.Equals(operedClock.ID)) { listControlClock[i] = operedClock; if ("Stop" == temp.Status) { //原先是暂停状态就不会存在于闹钟集里 //如果新闹钟又是启动状态,则可以添加,反之无需添加 if ("Start" == operedClock.Status) { BeginRingClock(operedClock); } } else { //原先是开始状态 if ("Start" == operedClock.Status) { BeginRingClock(operedClock); } } FileHelper.AddControledClockInfoToHistoryFile(operedClock, "编辑:"); break; } } BindListBox(); } }