public List <Staff> GetAllStaffs() { List <Staff> elements = new List <Staff>(); string sql = "select * from TF_Staff"; DataTable dt = sqlHelper.Query(sql); if (dt != null && dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { Staff element = new Staff(); element.ID = Convert.ToInt32(dt.Rows[i]["ID"]); element.Depart = DepartmentLogic.GetInstance().GetDepartment(Convert.ToInt32(dt.Rows[i]["Depart"])); element.Condition = StaffConditionLogic.GetInstance().GetStaffCondition(Convert.ToInt32(dt.Rows[i]["Condition"])); element.性别 = (性别)Enum.ToObject(typeof(性别), Convert.ToInt32(dt.Rows[i]["性别"])); element.姓名 = dt.Rows[i]["姓名"].ToString(); element.电话 = dt.Rows[i]["电话"].ToString(); element.生日 = Convert.ToDateTime(dt.Rows[i]["生日"]); element.宿舍 = dt.Rows[i]["宿舍"].ToString(); element.备注 = dt.Rows[i]["备注"].ToString(); element.钥匙数 = Convert.ToInt32(dt.Rows[i]["钥匙数"]); element.工衣数 = Convert.ToInt32(dt.Rows[i]["工衣数"]); element.工牌数 = Convert.ToInt32(dt.Rows[i]["工牌数"]); element.是否全部回收 = Convert.ToBoolean(dt.Rows[i]["是否全部回收"]); elements.Add(element); } } return(elements); }
public Staff GetStaffByName(string name) { string sql = "select * from TF_Staff where 姓名 like '%" + name + "%'"; DataTable dt = sqlHelper.Query(sql); if (dt != null && dt.Rows.Count > 0) { Staff element = new Staff(); element.ID = Convert.ToInt32(dt.Rows[0]["ID"]); element.Depart = DepartmentLogic.GetInstance().GetDepartment(Convert.ToInt32(dt.Rows[0]["Depart"])); element.Condition = StaffConditionLogic.GetInstance().GetStaffCondition(Convert.ToInt32(dt.Rows[0]["Condition"])); element.性别 = (性别)Enum.ToObject(typeof(性别), Convert.ToInt32(dt.Rows[0]["性别"])); element.姓名 = dt.Rows[0]["姓名"].ToString(); element.电话 = dt.Rows[0]["电话"].ToString(); element.生日 = Convert.ToDateTime(dt.Rows[0]["生日"]); element.宿舍 = dt.Rows[0]["宿舍"].ToString(); element.备注 = dt.Rows[0]["备注"].ToString(); element.钥匙数 = Convert.ToInt32(dt.Rows[0]["钥匙数"]); element.工衣数 = Convert.ToInt32(dt.Rows[0]["工衣数"]); element.工牌数 = Convert.ToInt32(dt.Rows[0]["工牌数"]); element.是否全部回收 = Convert.ToBoolean(dt.Rows[0]["是否全部回收"]); return(element); } return(null); }
private void LoadStaffConditions() { List <StaffCondition> elements = StaffConditionLogic.GetInstance().GetAllStaffConditions(); comboBox1.Items.Clear(); foreach (StaffCondition element in elements) { comboBox1.Items.Add(element); } dataGridView1.DataSource = StaffConditionLogic.GetInstance().GetStaffConditions(string.Empty); }
private void LoadStaffConditions() { List <StaffCondition> elements = StaffConditionLogic.GetInstance().GetAllStaffConditions(); comboBox6.Items.Clear(); comboBox7.Items.Clear(); comboBox7.Items.Add("--不限--"); foreach (StaffCondition element in elements) { comboBox6.Items.Add(element); comboBox7.Items.Add(element); } comboBox7.SelectedIndex = 0; }
private DataTable Search(string name = null, int flag = 0) { string nm = ""; if (!string.IsNullOrEmpty(name) && name.Trim() != "") { nm = " and 状态 like '%" + name + "%'"; } string jy = ""; if (flag > 0) { jy = " and 是否在职=" + (flag == 1 ? "1" : "0"); } string where = "(1=1)" + nm + jy; return(StaffConditionLogic.GetInstance().GetStaffConditions(where)); }
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("先选定要删除的员工状态!"); } }
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); }