private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { if (comboBox1.SelectedIndex > -1) { AlertType alertType = comboBox1.SelectedItem as AlertType; if (alertType != null) { textBox1.Text = alertType.方式; textBox2.Text = alertType.备注; checkBox1.Checked = alertType.Flag; } } }
private int GetIndexByAlertType(AlertType alertType, ComboBox comboBox3) { if (alertType != null && comboBox3 != null) { for (int i = 0; i < comboBox3.Items.Count; i++) { AlertType at = comboBox3.Items[i] as AlertType; if (at != null && alertType.ID == at.ID) { return(i); } } } return(-1); }
public int AddAlertType(AlertType element) { string sql = "insert into TF_AlertType (方式, Flag, 备注) values ('" + element.方式 + "', " + (element.Flag ? "1" : "0") + ", '" + element.备注 + "'); select SCOPE_IDENTITY()"; object obj = sqlHelper.ExecuteSqlReturn(sql); int R; if (obj != null && obj != DBNull.Value && int.TryParse(obj.ToString(), out R)) { return(R); } else { return(0); } }
public AlertType GetAlertType(int id) { string sql = "select * from TF_AlertType where ID=" + id; DataTable dt = sqlHelper.Query(sql); if (dt != null && dt.Rows.Count > 0) { AlertType element = new AlertType(); element.ID = id; element.方式 = dt.Rows[0]["方式"].ToString(); element.Flag = Convert.ToBoolean(dt.Rows[0]["Flag"]); element.备注 = dt.Rows[0]["备注"].ToString(); return(element); } return(null); }
private void button3_Click(object sender, EventArgs e) { if (comboBox1.SelectedIndex > -1) { if (MessageBox.Show("确定要删除该提醒方式?", "删除提醒", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.OK) { AlertType alertType = (AlertType)comboBox1.SelectedItem; if (AlertTypeLogic.GetInstance().DeleteAlertType(alertType)) { LoadAlertTypes(); } } } else { MessageBox.Show("先选定要删除的提醒方式!"); } }
public List <AlertType> GetAllAlertTypes() { List <AlertType> elements = new List <AlertType>(); string sql = "select * from TF_AlertType"; DataTable dt = sqlHelper.Query(sql); if (dt != null && dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { AlertType element = new AlertType(); element.ID = Convert.ToInt32(dt.Rows[i]["ID"]); element.方式 = dt.Rows[i]["方式"].ToString(); element.Flag = Convert.ToBoolean(dt.Rows[i]["Flag"]); element.备注 = dt.Rows[i]["备注"].ToString(); elements.Add(element); } } return(elements); }
private void button2_Click(object sender, EventArgs e) { if (comboBox1.SelectedIndex > -1) { AlertType alertType = new AlertType(); alertType.ID = ((AlertType)comboBox1.SelectedItem).ID; alertType.方式 = textBox1.Text.Trim(); alertType.备注 = textBox2.Text.Trim(); alertType.Flag = checkBox1.Checked; AlertTypeLogic al = AlertTypeLogic.GetInstance(); if (al.ExistsNameOther(alertType.方式, alertType.ID)) { if (MessageBox.Show("系统中已经存在该提醒方式,确定还要继续保存么?", "重名提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.OK) { if (al.UpdateAlertType(alertType)) { LoadAlertTypes(); MessageBox.Show("修改成功!"); } } else { textBox1.Focus(); textBox1.SelectAll(); } } else { if (al.UpdateAlertType(alertType)) { LoadAlertTypes(); MessageBox.Show("修改成功!"); } } } else { MessageBox.Show("先选定要修改的提醒方式!"); } }
private void button1_Click(object sender, EventArgs e) { AlertType alertType = new AlertType(); alertType.方式 = textBox1.Text.Trim(); alertType.备注 = textBox2.Text.Trim(); alertType.Flag = checkBox1.Checked; AlertTypeLogic al = AlertTypeLogic.GetInstance(); if (al.ExistsName(alertType.方式)) { if (MessageBox.Show("系统中已经存在该提醒方式,确定还要继续保存么?", "重名提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.OK) { int id = al.AddAlertType(alertType); if (id > 0) { alertType.ID = id; LoadAlertTypes(); MessageBox.Show("添加成功!"); } } else { textBox1.Focus(); textBox1.SelectAll(); } } else { int id = al.AddAlertType(alertType); if (id > 0) { alertType.ID = id; LoadAlertTypes(); MessageBox.Show("添加成功!"); } } }
private DataTable Search(string name = null, string subject = null, AlertType alertType = null) { string nm = ""; if (!string.IsNullOrEmpty(name) && name.Trim() != "") { nm = " and 提醒项目 like '%" + name + "%'"; } string sb = ""; if (!string.IsNullOrEmpty(subject) && subject.Trim() != "") { sb = " and 提醒对象 like '%" + subject + "%'"; } string at = ""; if (alertType != null) { at = " and 提醒方式=" + alertType.ID; } string where = "(1=1)" + nm + sb + at + " order by ID desc"; return(AlertLogic.GetInstance().GetAlerts(where)); }