/// <summary> /// Lưu thông tin /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSave_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtUnitID.Text)) { txtUnitID.Properties.Appearance.BorderColor = System.Drawing.Color.Red; XtraMessageBox.Show("Mã Đơn Vị không được để trống !", "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Error); txtUnitID.Focus(); } else if (string.IsNullOrEmpty(txtUnitName.Text)) { txtUnitName.Properties.Appearance.BorderColor = System.Drawing.Color.Red; XtraMessageBox.Show("Tên Đơn Vị không được để trống !", "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Error); txtUnitName.Focus(); } else { if (_unitService.CheckUnitIdExit(txtUnitID.Text)) { var unit = new Unit() { UnitID = txtUnitID.Text, UnitName = txtUnitName.Text, Description = txtDescription.Text, CreatedDate = DateTime.Now, IsActive = checkActive.Checked, CreatedBy = null }; try { _unitService.Add(unit); InsertSysLog(txtUnitName.Text); if (XtraMessageBox.Show("Thêm thành công.\n Bạn có muốn thêm mới Đơn Vị nữa không?", "THÔNG BÁO", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { ResetControls(); } else { DialogResult = DialogResult.No; } } catch (Exception ex) { XtraMessageBox.Show(string.Format("Lỗi {0}", ex.Message), "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { txtUnitID.Properties.Appearance.BorderColor = System.Drawing.Color.Red; XtraMessageBox.Show(string.Format("Mã Đơn vị {0} đã tồn tại rồi", txtUnitID.Text), "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Error); txtUnitID.SelectAll(); txtUnitID.Focus(); } } }
private void btnSave_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtUnitID.Text)) { Ultils.TextControlNotNull(txtUnitID, "Mã Đơn Vị"); } else if (string.IsNullOrEmpty(txtUnitName.Text)) { Ultils.TextControlNotNull(txtUnitName, "Tên Đơn Vị"); } else { if (string.IsNullOrEmpty(_unitId)) { _unit = new Unit() { UnitID = txtUnitID.Text.Trim(), UnitName = txtUnitName.Text, Active = checkActive.Checked, CreatedDate = DateTime.Now, CreatedBy = Program.CurrentUser.Username, }; try { if (_unitService.CheckUnitIdExit(_unit.UnitID)) { _unitService.Add(_unit); _logService.InsertLog(Program.CurrentUser.Username, "Thêm", this.Text); MessageBoxHelper.ShowMessageBoxSuccess("Thêm thành công!"); ResetControls(); } else { MessageBoxHelper.ShowMessageBoxError(string.Format("Mã Đơn vị <{0}> này đã được tạo rồi!", _unit.UnitID)); } } catch (Exception ex) { MessageBoxHelper.ShowMessageBoxError(ex.Message); } } else { _unit = _unitService.GetUnitById(_unitId); if (_unitId != null) { _unit.UnitName = txtUnitName.Text; _unit.Description = txtDescription.Text; _unit.Active = checkActive.Checked; _unit.ModifyDate = DateTime.Now; _unit.ModifyBy = Program.CurrentUser.Username; try { _unitService.Update(_unit); MessageBoxHelper.ShowMessageBoxSuccess("Sửa thành công!"); ResetControls(); } catch (Exception ex) { MessageBoxHelper.ShowMessageBoxError(ex.Message); } } } } }