private DataTable Search(string name, int sex = 0, Department dep = null, StaffCondition condition = null, string mobile = null) { string nm = ""; if (!string.IsNullOrEmpty(name)) { nm = " and 姓名 like '%" + name + "%'"; } string sx = ""; if (sex > 0) { sx = " and 性别='" + (性别)Enum.ToObject(typeof(性别), (sex - 1)) + "'"; } string dp = ""; if (dep != null) { dp = " and 部门='" + dep.Name + "'"; } string cd = ""; if (condition != null) { cd = " and 状态='" + condition.状态 + "'"; } string mb = ""; if (!string.IsNullOrEmpty(mb) && mb.Trim() != "") { mb = " and 电话 like '%" + mb.Trim() + "%'"; } string where = "(1=1)" + nm + sx + dp + cd + mb; return(StaffLogic.GetInstance().GetStaffs(where)); }
private DataTable Search(string name, int sex = 0, Department dep = null, StaffCondition condition = null, string mobile = null) { string nm = ""; if (!string.IsNullOrEmpty(name)) { nm = " and 姓名 like '%" + name + "%'"; } string sx = ""; if (sex > 0) { sx = " and 性别=" + sex; } string dp = ""; if (dep != null) { dp = " and Depart=" + dep.ID; } string cd = ""; if (condition != null) { cd = " and Condition=" + condition.ID; } string mb = ""; if (!string.IsNullOrEmpty(mb) && mb.Trim() != "") { mb = " and 电话 like '%" + mb.Trim() + "%'"; } string where = "(1=1)" + nm + sx + dp + cd + mb + " order by ID desc"; return(StaffLogic.GetInstance().GetStaffs(where)); }
public bool UpdateStaffCondition(StaffCondition element) { string sql = "update TF_StaffCondition set 状态='" + element.状态 + "', 是否在职=" + (element.是否在职 ? "1" : "0") + ", 备注='" + element.备注 + "' where ID=" + element.ID; int r = sqlHelper.ExecuteSql(sql); return(r > 0); }
public bool DeleteStaffCondition(StaffCondition element) { string sql = "delete from TF_StaffCondition where ID=" + element.ID; int r = sqlHelper.ExecuteSql(sql); return(r > 0); }
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { if (comboBox1.SelectedIndex > -1) { StaffCondition staffCondition = comboBox1.SelectedItem as StaffCondition; if (staffCondition != null) { textBox1.Text = staffCondition.状态; textBox2.Text = staffCondition.备注; checkBox1.Checked = staffCondition.是否在职; } } }
private int GetIndexByCondition(StaffCondition condition, ComboBox comboBox6) { if (condition != null && comboBox6 != null) { for (int i = 0; i < comboBox6.Items.Count; i++) { CardType ct = comboBox6.Items[i] as CardType; if (ct != null && ct.ID == condition.ID) { return(i); } } } return(-1); }
public int AddStaffCondition(StaffCondition element) { string sql = "insert into TF_StaffCondition (状态, 是否在职, 备注) values ('" + element.状态 + "', " + (element.是否在职 ? "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 StaffCondition GetStaffConditionByName(string name) { string sql = "select * from TF_StaffCondition where 状态='" + name + "'"; DataTable dt = sqlHelper.Query(sql); if (dt != null && dt.Rows.Count > 0) { StaffCondition element = new StaffCondition(); element.ID = Convert.ToInt32(dt.Rows[0]["ID"]); element.状态 = dt.Rows[0]["状态"].ToString(); element.是否在职 = Convert.ToBoolean(dt.Rows[0]["是否在职"]); element.备注 = dt.Rows[0]["备注"].ToString(); return(element); } return(null); }
public StaffCondition GetStaffCondition(int id) { string sql = "select * from TF_StaffCondition where ID=" + id; DataTable dt = sqlHelper.Query(sql); if (dt != null && dt.Rows.Count > 0) { StaffCondition element = new StaffCondition(); element.ID = id; element.状态 = dt.Rows[0]["状态"].ToString(); element.是否在职 = Convert.ToBoolean(dt.Rows[0]["是否在职"]); 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) { StaffCondition staffCondition = (StaffCondition)comboBox1.SelectedItem; if (StaffConditionLogic.GetInstance().DeleteStaffCondition(staffCondition)) { LoadStaffConditions(); } } } else { MessageBox.Show("先选定要删除的员工状态!"); } }
public List <StaffCondition> GetAllStaffConditions() { List <StaffCondition> elements = new List <StaffCondition>(); string sql = "select * from TF_StaffCondition"; DataTable dt = sqlHelper.Query(sql); if (dt != null && dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { StaffCondition element = new StaffCondition(); element.ID = Convert.ToInt32(dt.Rows[i]["ID"]); element.状态 = dt.Rows[i]["状态"].ToString(); element.是否在职 = Convert.ToBoolean(dt.Rows[i]["是否在职"]); element.备注 = dt.Rows[i]["备注"].ToString(); elements.Add(element); } } return(elements); }
private void button2_Click(object sender, EventArgs e) { if (comboBox1.SelectedIndex > -1) { StaffCondition staffCondition = (StaffCondition)comboBox1.SelectedItem; staffCondition.状态 = textBox1.Text.Trim(); staffCondition.备注 = textBox2.Text.Trim(); staffCondition.是否在职 = checkBox1.Checked; StaffConditionLogic scl = StaffConditionLogic.GetInstance(); if (scl.ExistsNameOther(staffCondition.状态, staffCondition.ID)) { if (MessageBox.Show("系统中已经存在该员工状态,确定还要继续保存么?", "重名提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.OK) { if (scl.UpdateStaffCondition(staffCondition)) { LoadStaffConditions(); MessageBox.Show("修改成功!"); } } else { textBox1.Focus(); textBox1.SelectAll(); } } else { if (scl.UpdateStaffCondition(staffCondition)) { LoadStaffConditions(); MessageBox.Show("修改成功!"); } } } else { MessageBox.Show("先选定要修改的员工状态!"); } }
private void button1_Click(object sender, EventArgs e) { StaffCondition staffCondition = new StaffCondition(); staffCondition.状态 = textBox1.Text.Trim(); staffCondition.备注 = textBox2.Text.Trim(); staffCondition.是否在职 = checkBox1.Checked; StaffConditionLogic scl = StaffConditionLogic.GetInstance(); if (scl.ExistsName(staffCondition.状态)) { if (MessageBox.Show("系统中已经存在该员工状态,确定还要继续保存么?", "重名提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.OK) { int id = scl.AddStaffCondition(staffCondition); if (id > 0) { staffCondition.ID = id; LoadStaffConditions(); MessageBox.Show("添加成功!"); } } else { textBox1.Focus(); textBox1.SelectAll(); } } else { int id = scl.AddStaffCondition(staffCondition); if (id > 0) { staffCondition.ID = id; LoadStaffConditions(); MessageBox.Show("添加成功!"); } } }
public static R GetData <R>(DataRow row, FieldMap <string, string> map, R element, Type t) where R : class { if (row != null && map != null) { if (element != null && t != null) { PropertyInfo[] pis = t.GetProperties(); for (int i = 0; i < pis.Length; i++) { PropertyInfo pi = pis[i]; if (pi.CanWrite && map.Keys.Contains(pi.Name)) { try { t.GetProperty(pi.Name).SetValue(element, row[map[pi.Name]], null); } catch { try { string colName = map[pi.Name]; object cell = row[colName]; if (cell != null) { if (colName.Contains("性别")) { t.GetProperty(pi.Name).SetValue(element, (性别)Enum.Parse(typeof(性别), cell.ToString()), null); } else if (colName.Contains("类型") || colName.Contains("种类") || colName.Contains("卡种")) { CardType ct = CardTypeLogic.GetInstance().GetCardTypeByName(cell.ToString()); t.GetProperty(pi.Name).SetValue(element, ct, null); } else if (colName.Contains("状态")) { StaffCondition sc = StaffConditionLogic.GetInstance().GetStaffConditionByName(cell.ToString()); t.GetProperty(pi.Name).SetValue(element, sc, null); } else if (colName.Contains("开始日") || colName.Contains("到期日") || colName.Contains("生日") || colName.Contains("日期") || colName.Contains("时间")) { DateTime dt = DateTime.MinValue; DateTime T; if (DateTime.TryParse(cell.ToString(), out T)) { dt = T; } t.GetProperty(pi.Name).SetValue(element, dt, null); } } } catch (Exception e) { throw e; } } } } } } return(element); }