public int UpdateStaffTable(EntityStaff entity) { string SqlStr = ""; SqlStr = "update tc_staff set "; SqlStr += "staff_name = '" + entity.Staff_name.Trim() + "' "; SqlStr += ",staff_yxm = '" + entity.Staff_yxm.Trim() + "' "; SqlStr += ",staff_sex = '" + entity.Staff_sex.Trim() + "' "; SqlStr += ",staff_birthday = '" + entity.Staff_birthday + "' "; SqlStr += ",staff_card = '" + entity.Staff_card.Trim() + "' "; SqlStr += ",staff_tel = '" + entity.Staff_tel.Trim() + "' "; SqlStr += ",staff_edu = '" + entity.Staff_edu.Trim() + "' "; SqlStr += ",staff_introduction = '" + entity.Staff_introduction.Trim() + "' "; SqlStr += ",staff_dep = '" + entity.Staff_dep.Trim() + "' "; SqlStr += ",staff_contract_num = '" + entity.Staff_contract_num.Trim() + "' "; SqlStr += ",staff_job_title = '" + entity.Staff_job_title.Trim() + "' "; SqlStr += ",staff_specialities = '" + entity.Staff_specialities.Trim() + "' "; SqlStr += " where staff_code= '" + entity.Staff_code.Trim() + "' "; SqlCommand sqlCommand = new SqlCommand(); sqlCommand.CommandText = SqlStr; ExcuteSql(sqlCommand); return(Constants.SystemConfig.SERVER_SUCCESS); }
/// <summary> /// Basic constructor /// </summary> /// <param name="parentControlUnit">Control unit the event is triggered, i.e. the unit the staff member enters or leaves</param> /// <param name="isEnter">Flag if the event is called for an entering or leaving staff member</param> /// <param name="staff">The staff member that is entering or leaving</param> /// <param name="del">Delegate resposnible for the staff movement</param> /// <param name="staffArea">Possible waiting area the staff members waits in after arrival</param> public EventControlUnitStaffEnterLeave(ControlUnit parentControlUnit, bool isEnter, EntityStaff staff, IDelegate del, EntityWaitingArea staffArea = null) : base(EventType.Standalone, parentControlUnit) { _isEnter = isEnter; _staff = staff; _incomingDelegate = del; _staffWaitingArea = staffArea; } // end of EventInpatientStaffEnterLeave
public int InsertStaffRow(EntityStaff entity) { string SqlStr = ""; SqlStr = "insert into tc_staff(Staff_code,Staff_name,Staff_yxm,Staff_sex," + "Staff_birthday,Staff_card,Staff_tel,Staff_edu,Staff_introduction,Staff_dep,Staff_contract_num,Staff_job_title,Staff_specialities)"; SqlStr += " values('" + entity.Staff_code.Trim() + "','" + entity.Staff_name.Trim() + "','" + entity.Staff_yxm.Trim() + "','" + entity.Staff_sex.Trim() + "','" + entity.Staff_birthday + "','" + entity.Staff_card.Trim() + "','" + entity.Staff_tel.Trim() + "','" + entity.Staff_edu.Trim() + "','" + entity.Staff_introduction.Trim() + "','" + entity.Staff_dep.Trim() + "','" + entity.Staff_contract_num.Trim() + "','" + entity.Staff_job_title.Trim() + "','" + entity.Staff_specialities.Trim() + "')"; SqlCommand sqlCommand = new SqlCommand(); sqlCommand.CommandText = SqlStr; ExcuteSql(sqlCommand); return(Constants.SystemConfig.SERVER_SUCCESS); }
private void btnCommit_Click(object sender, EventArgs e) { foreach (Control control in groupBox2.Controls) { if (control is TextBox) { if (control.Name != "txtStaffIntroduction") { if (Util.CheckRegex(control.Text.Trim()) && !((TextBox)control).ReadOnly) { MessageBox.Show("不可以输入非法字符,请重新输入!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); control.Focus(); return; } } } } if (txt_staff_contract_num.Text.Trim().Equals(string.Empty)) { MessageBox.Show("合同编号不能为空!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); txt_staff_contract_num.Focus(); return; } if (txtStaffName.Text.Trim().Equals(string.Empty)) { MessageBox.Show("员工姓名不能为空!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); txtStaffName.Focus(); return; } //if (Util.GetByteLength(txtStaffName.Text.Trim()) > 10) //{ // MessageBox.Show("员工姓名过长!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); // txtStaffName.Focus(); // return; //} if (txtStaffCard.Text.Trim().Equals(string.Empty)) { MessageBox.Show("身份证号不能为空!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); txtStaffCard.Focus(); return; } if (!Util.CheckIdCard(txtStaffCard.Text.Trim())) { MessageBox.Show("身份证格式不正确!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); txtStaffCard.Focus(); return; } try { result = -1; //如果是添加 if (dataType == DataType.Insert) { staffEntity = new EntityStaff(); staffEntity.Staff_name = txtStaffName.Text.Trim(); staffEntity.Staff_yxm = Util.IndexCode(txtStaffName.Text.Trim()).ToUpper(); staffEntity.Staff_sex = comBoxSex.Text; staffEntity.Staff_birthday = DateTime.Parse(dateTimeBrithday.Value.ToString("yyyy-MM-dd")); staffEntity.Staff_card = txtStaffCard.Text.Trim(); staffEntity.Staff_edu = comBoxStaffEdu.Text; staffEntity.Staff_tel = txtTel.Text.Trim(); staffEntity.Staff_introduction = txtStaffIntroduction.Text; staffEntity.Staff_dep = txt_staff_dep.Text; staffEntity.Staff_contract_num = txt_staff_contract_num.Text; staffEntity.Staff_specialities = txt_staff_specialities.Text; staffEntity.Staff_job_title = txt_staff_job_title.Text; //打开数据库连接 dataAccess = new DataAccess(); dataAccess.Open(); MakePrimaryKey primaryKey = new MakePrimaryKey(dataAccess.Connection, dataAccess.Transaction); staffEntity.Staff_code = primaryKey.MakeCode("员工"); //取得操作类 GetData getData = new GetData(dataAccess.Connection); if (getData.InsertIsOnly("tc_staff", "staff_contract_num", Util.ChangeForSqlString(txt_staff_contract_num.Text.Trim()))) { MessageBox.Show("您输入的合同编号已经存在!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); txt_staff_contract_num.Focus(); return; } if (getData.InsertIsOnly("tc_staff", "staff_card", Util.ChangeForSqlString(txtStaffCard.Text.Trim()))) { MessageBox.Show("您输入的身份证号已经存在!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); txtStaffCard.Focus(); return; } //取得结果符 result = getData.InsertStaffRow(staffEntity); if (result == 0) { MessageBox.Show("数据已经保存成功!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("操作添加时发生错误,请检查数据库!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } } else if (dataType == DataType.Update) { if (dgvStaff.SelectedRows != null && dgvStaff.SelectedRows.Count != 0) { countNum = dgvStaff.SelectedRows[0].Index; } //赋值实体类 staffEntity = new EntityStaff(); staffEntity.Staff_code = txtStaffCode.Text.Trim(); staffEntity.Staff_name = txtStaffName.Text.Trim(); staffEntity.Staff_yxm = Util.IndexCode(txtStaffName.Text.Trim()).ToUpper(); staffEntity.Staff_sex = comBoxSex.Text; staffEntity.Staff_birthday = DateTime.Parse(dateTimeBrithday.Value.ToString("yyyy-MM-dd")); staffEntity.Staff_card = txtStaffCard.Text.Trim(); staffEntity.Staff_edu = comBoxStaffEdu.Text; staffEntity.Staff_tel = txtTel.Text.Trim(); staffEntity.Staff_introduction = txtStaffIntroduction.Text; staffEntity.Staff_job_title = txt_staff_job_title.Text; staffEntity.Staff_dep = txt_staff_dep.Text; staffEntity.Staff_contract_num = txt_staff_contract_num.Text; staffEntity.Staff_specialities = txt_staff_specialities.Text; //打开数据库连接 dataAccess = new DataAccess(); dataAccess.Open(); //打开事务 dataAccess.BeginTransaction(); //取得操作类 GetData getData = new GetData(dataAccess.Connection, dataAccess.Transaction); if (getData.UpdateIsOnly("tc_staff", "Staff_code", staffEntity.Staff_code, "staff_contract_num", Util.ChangeForSqlString(txt_staff_contract_num.Text.Trim()))) { MessageBox.Show("您输入的合同编号已经存在!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); txt_staff_contract_num.Focus(); return; } if (getData.UpdateIsOnly("tc_staff", "Staff_code", staffEntity.Staff_code, "staff_card", Util.ChangeForSqlString(txtStaffCard.Text.Trim()))) { MessageBox.Show("您输入的身份证号已经存在!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); txtStaffCard.Focus(); return; } //取得结果符 result = getData.UpdateStaffTable(staffEntity); //提交事务 dataAccess.Commit(); if (result == 0) { MessageBox.Show("数据已经保存成功!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("操作修改时发生错误,请检查数据库!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } } } catch (Exception ex) { if (dataAccess.Transaction != null) { //回滚 dataAccess.Rollback(); } MessageBox.Show("操作数据时发生错误,请检查数据库是否正常开启!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } finally { dataAccess.Close(); } //设置按钮状态 dataType = DataType.None; setButtonState(); BandingDgvStaff(); }