private void ModEmployee_Load(object sender, EventArgs e) { this.Left = (Global.baseWidth) / 2; this.Top = Global.baseHeight / 4; #region 初始化 部门 DataTable dt = tbll.GetList(null, null, null); DataView dataView = dt.DefaultView; dataView.Sort = "C_ID asc"; cmbUnit.DataSource = dataView.ToTable(); cmbUnit.DisplayMember = "C_NAME"; cmbUnit.ValueMember = "C_ID"; cmbUnit.SelectedValue = unitId; #endregion #region 初始化 岗位 DataTable dtt = bll.GetGWList(); DataView dataViewt = dtt.DefaultView; cmbGW.DataSource = dataViewt.ToTable(); cmbGW.DisplayMember = "C_NAME"; cmbGW.ValueMember = "C_ID"; #endregion //初始化 男女 DataTable dtSex = new DataTable(); dtSex.Columns.Add("C_ID"); dtSex.Columns.Add("C_NAME"); DataRow dr = dtSex.NewRow(); dr["C_ID"] = "男"; dr["C_NAME"] = "男"; dtSex.Rows.InsertAt(dr, 0); DataRow dr1 = dtSex.NewRow(); dr1["C_ID"] = "女"; dr1["C_NAME"] = "女"; dtSex.Rows.InsertAt(dr1, 1); cmbSex.DataSource = dtSex; cmbSex.DisplayMember = "C_NAME"; cmbSex.ValueMember = "C_ID"; employee = bll.getEmployeeById(id); if (employee == null) { MessageBox.Show("获取员工信息失败!", "信息", MessageBoxButtons.OK, MessageBoxIcon.Warning); this.Close(); } else { this.lblId.Text = employee.C_id; this.txtName.Text = employee.C_name; this.cmbUnit.SelectedValue = employee.C_unitId; this.cmbGW.Text = employee.C_gangWei; this.txtMemo.Text = employee.C_memo; this.cmbSex.SelectedValue = employee.C_sex; this.dtpbrithday.Value = employee.D_birthday; this.txtAddress.Text = employee.C_address; this.txtOt.Text = employee.C_office_tel; this.txtMp.Text = employee.C_move_tel; } }
/// <summary> /// 保存员工信息 /// </summary> /// <param name="user">员工信息</param> /// <returns></returns> public bool update(T_JB_EMPLOYEE employee) { try { int count = 0; string sql = " UPDATE [T_JB_EMPLOYEE] SET [C_UNIT_ID]=@C_UNIT_ID, [C_NAME]=@C_NAME,[C_SEX]=@C_SEX, " + " [C_GANGWEI]=@C_GANGWEI, [D_BIRTHDAY]=@D_BIRTHDAY, [C_MEMO]=@C_MEMO, " + " C_ADDRESS=@C_ADDRESS, C_OFFICE_TEL=@C_OFFICE_TEL, C_MOVE_TEL=@C_MOVE_TEL WHERE [C_ID]=@C_ID "; Hashtable table = new Hashtable(); table.Add("C_ID", employee.C_id); table.Add("C_UNIT_ID", employee.C_unitId); table.Add("C_NAME", employee.C_name); table.Add("C_GANGWEI", employee.C_gangWei); table.Add("C_MEMO", employee.C_memo); table.Add("C_SEX", employee.C_sex); table.Add("D_BIRTHDAY", employee.D_birthday); table.Add("C_ADDRESS", employee.C_address); table.Add("C_OFFICE_TEL", employee.C_office_tel); table.Add("C_MOVE_TEL", employee.C_move_tel); DbParameter[] parms = dbHelper.getParams(table); count = dbHelper.ExecuteCommand(sql, parms); if (count > 0) { return(true); } else { return(false); } } catch (Exception ex) { Log.write(ex.Message + "\r\n" + ex.StackTrace); throw ex; } finally { dbHelper.getConnection().Close(); } }
private void btnLogin_Click(object sender, EventArgs e) { try { if (checkInput()) { #region 增加 lblName.Visible = false; T_JB_EMPLOYEE temp = new T_JB_EMPLOYEE(); temp.C_name = txtName.Text.Trim(); temp.C_unitId = cmbUnit.SelectedValue.ToString(); temp.C_gangWei = cmbGW.Text.Trim().ToString(); temp.C_sex = cmbSex.SelectedValue.ToString(); temp.C_memo = txtMemo.Text.Trim(); temp.C_address = this.txtAddress.Text.Trim(); temp.C_office_tel = this.txtOt.Text.Trim(); temp.C_move_tel = this.txtMp.Text.Trim(); temp.D_birthday = dtpbrithday.Value; if (bll.save(temp, Global.longid)) { MessageBox.Show("员工保存成功!", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information); Log.saveLog("添加员工成功!姓名:" + temp.C_name); reset(); } else { MessageBox.Show("员工保存失败!", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information); } #endregion } } catch (Exception) { MessageBox.Show("与数据库连接失败,请查看网络连接是否正常。如不能解决请与网络管理员联系!", "严重错误:", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// 获得员工的详细信息 /// </summary> /// <param name="id"></param> /// <returns></returns> public T_JB_EMPLOYEE getEmployeeById(string id) { T_JB_EMPLOYEE employee = null; string sql = " select a.C_ID,a.C_NAME,a.C_UNIT_ID,b.C_NAME as C_UNIT_NAME,a.C_SEX,a.C_GANGWEI," + " D_BIRTHDAY, C_ADDRESS, C_OFFICE_TEL, C_MOVE_TEL,a.C_MEMO " + " from T_JB_EMPLOYEE a left join T_DM_UNIT b on a.C_UNIT_ID = b.C_ID where a.C_ID = '" + id + "'"; try { DataTable dt = dbHelper.GetDataSet(sql); if (dt != null && dt.Rows.Count > 0) { employee = new T_JB_EMPLOYEE(); employee.C_id = dt.Rows[0]["C_ID"].ToString(); employee.C_name = dt.Rows[0]["C_NAME"].ToString(); employee.C_unitId = dt.Rows[0]["C_UNIT_ID"].ToString(); employee.C_sex = dt.Rows[0]["C_SEX"].ToString(); employee.C_gangWei = dt.Rows[0]["C_GANGWEI"].ToString(); employee.D_birthday = DateTime.Parse(dt.Rows[0]["D_BIRTHDAY"].ToString()); employee.C_address = dt.Rows[0]["C_ADDRESS"].ToString(); employee.C_office_tel = dt.Rows[0]["C_OFFICE_TEL"].ToString(); employee.C_move_tel = dt.Rows[0]["C_MOVE_TEL"].ToString(); employee.C_memo = dt.Rows[0]["C_MEMO"].ToString(); } } catch (Exception ex) { Log.write(ex.Message + "\r\n" + ex.StackTrace); throw ex; } finally { dbHelper.getConnection().Close(); } return(employee); }
/// <summary> /// 保存员工信息 /// </summary> /// <param name="user">员工信息</param> /// <returns></returns> public bool update(T_JB_EMPLOYEE materiel) { return(dal.update(materiel)); }
/// <summary> /// 保存员工信息 /// </summary> /// <param name="user">员工信息</param> /// <returns></returns> public bool save(T_JB_EMPLOYEE materiel, string userid) { return(dal.save(materiel, userid)); }
/// <summary> /// 保存员工信息 /// </summary> /// <param name="user">员工信息</param> /// <returns></returns> public bool save(T_JB_EMPLOYEE employee, string userid) { int result = 0; DbConnection conn = dbHelper.getConnection(); try { conn.Open(); } catch (Exception ex) { Log.write(ex.Message + "\r\n" + ex.StackTrace); conn.Close(); throw ex; } DbTransaction tran = conn.BeginTransaction(); DbCommand com = conn.CreateCommand(); string sql = string.Empty; try { com.Transaction = tran; long dec_id = 0; string c_id = string.Empty; sql = "SELECT max(c_id) FROM T_JB_EMPLOYEE "; com.CommandText = sql; object obj = com.ExecuteScalar(); dec_id = Convert.IsDBNull(obj) ? 0 : Convert.ToInt64(obj); sql = "INSERT INTO [T_JB_EMPLOYEE]([C_ID],[C_UNIT_ID], [C_NAME], [C_SEX], " + " [C_GANGWEI],[D_BIRTHDAY],[C_MEMO]," + " C_ADDRESS, C_OFFICE_TEL, C_MOVE_TEL ) " + " VALUES(@C_ID,@C_UNIT_ID,@C_NAME,@C_SEX,@C_GANGWEI,@D_BIRTHDAY,@C_MEMO, " + " @C_ADDRESS,@C_OFFICE_TEL,@C_MOVE_TEL)"; com.CommandText = sql; Hashtable table = new Hashtable(); dec_id = dec_id + 1; c_id = dec_id.ToString().PadLeft(4, '0'); table.Add("C_ID", c_id); table.Add("C_UNIT_ID", employee.C_unitId); table.Add("C_NAME", employee.C_name); table.Add("C_SEX", employee.C_sex); table.Add("C_GANGWEI", employee.C_gangWei); table.Add("D_BIRTHDAY", employee.D_birthday); table.Add("C_MEMO", employee.C_memo); table.Add("C_ADDRESS", employee.C_address); table.Add("C_OFFICE_TEL", employee.C_office_tel); table.Add("C_MOVE_TEL", employee.C_move_tel); DbParameter[] parms = dbHelper.getParams(table); com.Parameters.Clear(); com.Parameters.AddRange(parms); result = com.ExecuteNonQuery(); tran.Commit(); if (result > 0) { return(true); } else { return(false); } } catch (Exception ex) { tran.Rollback(); conn.Close(); Log.write(ex.Message + "\r\n" + ex.StackTrace); throw ex; } finally { conn.Close(); } }