public bool Cmp(cmsDayNightAlert DNA) { if ( DNA.IpPortNum == this.IpPortNum && DNA.Status == this.Status ) { return(true); } return(false); }
private void but_confirm1_Click(object sender, EventArgs e) { if (rbtn_daynight_on.Checked) { if (comboBox_StaName.Text != "" && comboBox_DeviceAdd.Text != "" && textBox_dayTime.Text != "" && textBox_nightTime.Text != "") { try { string dt0, dt1; if (checkDateString()) { dt0 = "20000101" + textBox_dayTime.Text.Remove(2, 1) + "00"; dt1 = "20000101" + textBox_nightTime.Text.Remove(2, 1) + "00"; DateTime day = DateTime.ParseExact(dt0, "yyyyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture); DateTime night = DateTime.ParseExact(dt1, "yyyyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture); int dayvol = comboBox_dayVol.SelectedIndex; int nightvol = comboBox_nightVol.SelectedIndex; FormMain.DayNightBuff[lb_thisip.Text + "," + comboBox_DeviceAdd.Text] = new FormMain.DayNightBuffCLS(day, night, dayvol, nightvol); string cmd = "insert into tb_DayNightAlert (IpPortNum,Status) values("; cmd += "'" + lb_thisip.Text + "," + comboBox_DeviceAdd.Text + "',"; cmd += "'" + textBox_dayTime.Text + "-" + dayvol + "-" + textBox_nightTime.Text + "-" + nightvol + "'"; cmd += ")"; cmsDayNightAlert addDNA = new cmsDayNightAlert(); addDNA.IpPortNum = lb_thisip.Text + "," + comboBox_DeviceAdd.Text; addDNA.Status = textBox_dayTime.Text + "-" + dayvol + "-" + textBox_nightTime.Text + "-" + nightvol; FormMain.DataModel.DayNightAlert.Add(addDNA); } else { MessageBox.Show("date format error", "WARN"); } } catch (Exception exp) { Console.WriteLine(exp.Message.Length); if (exp.Message.Length == 30 || exp.Message.Length == 64) { MessageBox.Show("date format error", "WARN"); } else { string cmd = "update tb_DayNightAlert set Status = "; cmd += "'" + textBox_dayTime.Text + "-" + comboBox_dayVol.SelectedIndex + "-" + textBox_nightTime.Text + "-" + comboBox_nightVol.SelectedIndex + "'"; cmd += " where IpPortNum = "; cmd += "'" + lb_thisip.Text + "," + comboBox_DeviceAdd.Text + "'"; for (int i = 0; i < FormMain.DataModel.Content.Count; i++) { cmsDayNightAlert updDNA = FormMain.DataModel.DayNightAlert[i]; if (updDNA.IpPortNum == lb_thisip.Text + "," + comboBox_DeviceAdd.Text) { updDNA.Status = textBox_dayTime.Text + "-" + comboBox_dayVol.SelectedIndex + "-" + textBox_nightTime.Text + "-" + comboBox_nightVol.SelectedIndex; FormMain.DataModel.DayNightAlert[i] = updDNA; } } } } } else { MessageBox.Show("Please complete the filling"); } } else { if (comboBox_StaName.Text != "" && comboBox_DeviceAdd.Text != "") { try { FormMain.DayNightBuff.Remove(lb_thisip.Text + "," + comboBox_DeviceAdd.Text); string cmd = "delete * from tb_DayNightAlert Where IpPortNum ="; cmd += "'" + lb_thisip.Text + "," + comboBox_DeviceAdd.Text + "'"; List <cmsDayNightAlert> RemoveListDNA = new List <cmsDayNightAlert>(); foreach (cmsDayNightAlert cmsDNA in FormMain.DataModel.DayNightAlert) { if (cmsDNA.IpPortNum == lb_thisip.Text + "," + comboBox_DeviceAdd.Text) { RemoveListDNA.Add(cmsDNA); } } foreach (cmsDayNightAlert rmDNA in RemoveListDNA) { FormMain.DataModel.DayNightAlert.Remove(rmDNA); } } catch { MessageBox.Show("delete failed"); } } else { MessageBox.Show("Please complete the filling"); } } }