private void btnXoa_Click(object sender, EventArgs e) { try { if (this.dgvList.RowCount > 0) { if (this.TenBang != "tbl_DM_QuocGia") { DBTools._IsCheck IsCheck; IsCheck = DBTools.CheckExistsRecord(this.DanhMuc_IsChecExitForeginKeyCommand(int.Parse(this.dgvList.CurrentRow.Cells[this.TenTruong1].Value.ToString()))); if (IsCheck == DBTools._IsCheck._TRUE) { MessageBox.Show(Declare.msgFrmDM_Chung_KhongXoa, Declare.titleWarning, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } else if (IsCheck == DBTools._IsCheck._EXCEPTION) { MessageBox.Show("Lỗi xóa " + this.Text.Trim().ToLower() + ": " + DBTools._LastError.Message, Declare.titleError, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } if (MessageBox.Show("Bạn có chắc chắn xóa " + this.Text.Trim().ToLower() + " này không?", Declare.titleNotice, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes) { if (DBTools.DeleteRecord(this.DanhMuc_DeleteCommand(int.Parse(this.dgvList.CurrentRow.Cells[this.TenTruong1].Value.ToString())))) { Common.LogAction("Xóa " + this.Text.ToLower(), "Completed. " + this.TenTruong1 + "=" + this.dgvList.CurrentRow.Cells[this.TenTruong1].Value, -1); int Index = this.cm.Position; this.dtDanhSach.DefaultView.Delete(Index); if (Index < this.dtDanhSach.Rows.Count) { this.DanhMuc_CapNhatSoTT(0); this.DanhMuc_HienThi(this.cm.Position); } else { if (Index > 0) { this.dgvList.CurrentRow.Selected = true; } } MessageBox.Show("Xóa danh mục " + this.Text.ToString().Trim().ToLower() + " thành công.", Declare.titleNotice, MessageBoxButtons.OK, MessageBoxIcon.Information); } else { Common.LogAction("Xóa " + this.Text.ToLower(), "Failed. " + this.TenTruong1 + "=" + this.dgvList.CurrentRow.Cells[this.TenTruong1].Value, -1); MessageBox.Show("Lỗi xóa " + this.Text.Trim().ToLower() + ": " + DBTools._LastError.Message, Declare.titleError, MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } catch (Exception ex) { #if DEBUG MessageBox.Show("Lỗi ngoại lệ: " + ex.ToString(), Declare.titleError, MessageBoxButtons.OK, MessageBoxIcon.Error); #else MessageBox.Show("Lỗi ngoại lệ: " + ex.Message, Declare.titleError, MessageBoxButtons.OK, MessageBoxIcon.Error); #endif } btnThemMoi.Enabled = true; }
private void btnDelete_Click(object sender, EventArgs e) { try { if (this.dgvUser.RowCount > 0) { int IdUser = int.Parse(this.dgvUser.CurrentRow.Cells["UserId"].Value.ToString()); DBTools._IsCheck IsCheck; IsCheck = DBTools.CheckExistsRecord(this.ChecIsDelete_NguoiDung(IdUser)); if (IsCheck == DBTools._IsCheck._TRUE) { MessageBox.Show("Thông tin người dùng này đã được sử dụng. Nên không thể xóa được", Declare.titleWarning, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } else if (IsCheck == DBTools._IsCheck._EXCEPTION) { MessageBox.Show("Lỗi kiểm tra dữ liệu: " + DBTools._LastError.Message, Declare.titleError, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (dgvUser.Rows.Count > 0) { if (MessageBox.Show(Declare.msgRemoveData, Declare.titleNotice, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { object obj = DBTools.ExecuteQuery("Delete From tbl_DM_NguoiDung Where IdNguoiDung = " + Common.IntValue(dgvUser.Rows[dgvUser.CurrentCell.RowIndex].Cells[1].Value.ToString()), CommandType.Text); if (obj == null) { MessageBox.Show(Declare.msgDeleteErr, Declare.titleError, MessageBoxButtons.OK, MessageBoxIcon.Error); } else { this.RefreshGrid(); } } } Common.LogAction("Xóa người dùng", "UserId " + IdUser, -1); MessageBox.Show("Đã xóa người dùng", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (System.Exception ex) { #if DEBUG MessageBox.Show("Lỗi ngoại lệ: " + ex.ToString(), Declare.titleError, MessageBoxButtons.OK, MessageBoxIcon.Error); #else MessageBox.Show("Lỗi ngoại lệ: " + ex.Message, Declare.titleError, MessageBoxButtons.OK, MessageBoxIcon.Error); #endif } }
//TuanLM moidfied 30/03/08 private bool DanhMuc_SuHopLeCuaThongTin() { if (string.Compare(this.Text.Trim().ToLower(), "quốc gia") != 0) { //kiem tra ma if (this.txtMa.Text.Trim().Length == 0) { MessageBox.Show("Mã " + this.Text.ToLower() + " chưa nhập." + "\n" + "-Hãy nhập mã " + this.Text.ToLower(), Declare.titleNotice, MessageBoxButtons.OK, MessageBoxIcon.Information); this.txtMa.Focus(); return(false); } string strSqlMa = "Select * from " + this.TenBang + " where " + this.TenTruong2 + "=N'" + this.txtMa.Text.Trim() + "'" + " and " + this.TenTruong1 + " <> " + IdMa; if (this.blnThemMoi) { if (DBTools.ExistData(strSqlMa) == true) { MessageBox.Show("Mã " + this.txtMa.Text + " đã tồn tại." + "\n" + "-Hãy nhập lại mã " + this.Text.ToLower(), Declare.titleWarning, MessageBoxButtons.OK, MessageBoxIcon.Warning); this.txtMa.Focus(); return(false); } } else { if (string.Compare(this.txtMa.Text.Trim().ToUpper(), this.strMa) != 0) { if (DBTools.ExistData(strSqlMa) == true) { MessageBox.Show("Mã " + this.txtMa.Text + " đã tồn tại." + "\n" + "-Hãy nhập lại mã " + this.Text.ToLower(), Declare.titleWarning, MessageBoxButtons.OK, MessageBoxIcon.Warning); this.txtMa.Focus(); return(false); } } } //kiem tra ten if (this.txtTen.Text.Trim().Length == 0) { MessageBox.Show("Tên " + this.Text.ToLower() + " chưa nhập." + "\n" + "-Hãy nhập tên " + this.Text.ToLower(), Declare.titleNotice, MessageBoxButtons.OK, MessageBoxIcon.Information); this.txtTen.Focus(); return(false); } else { string strSqlTen = "Select * from " + this.TenBang + " where " + this.TenTruong3 + "=N'" + this.txtTen.Text.Trim() + "'"; if (this.blnThemMoi) { if (DBTools.ExistData(strSqlTen) == true) { MessageBox.Show("Tên " + this.txtTen.Text + " đã tồn tại." + "\n" + "-Hãy nhập lại tên " + this.Text.ToLower(), Declare.titleWarning, MessageBoxButtons.OK, MessageBoxIcon.Warning); this.txtTen.Focus(); return(false); } } else { if (string.Compare(this.txtTen.Text.Trim(), this.strTen) != 0) { if (DBTools.ExistData(strSqlTen) == true) { MessageBox.Show("Tên " + this.txtTen.Text + " đã tồn tại." + this.strTen + "\n" + "-Hãy nhập lại tên " + this.Text.ToLower(), Declare.titleWarning, MessageBoxButtons.OK, MessageBoxIcon.Warning); this.txtTen.Focus(); return(false); } } } } } else//if(string.Compare(this.Text.Trim().ToLower(), "quốc gia")==0) { //kiem tra ma if (this.txtMa.Text.Trim().Length == 0) { MessageBox.Show("Mã " + this.Text.ToLower() + " chưa nhập." + "\n" + "-Hãy nhập mã " + this.Text.ToLower(), Declare.titleNotice, MessageBoxButtons.OK, MessageBoxIcon.Information); this.txtMa.Focus(); return(false); } if (this.blnThemMoi) { if (DBTools.ExistData("Select * from tbl_DM_QuocGia where MaQuocGia=N'" + this.txtMa.Text.Trim() + "'") == true) { MessageBox.Show("Mã " + this.txtMa.Text + " đã tồn tại." + "\n" + "-Hãy nhập lại mã " + this.Text.ToLower(), Declare.titleWarning, MessageBoxButtons.OK, MessageBoxIcon.Warning); this.txtMa.Focus(); return(false); } } else { if (this.txtMa.Text.Trim() != strMa) { if (DBTools.ExistData("Select * from tbl_DM_QuocGia where MaQuocGia=N'" + this.txtMa.Text.Trim() + "'") == true) { MessageBox.Show("Mã " + this.Text.ToLower() + " đã tồn tại." + "\n" + "-Hãy nhập lại mã " + this.Text.ToLower(), Declare.titleWarning, MessageBoxButtons.OK, MessageBoxIcon.Warning); this.txtMa.Focus(); return(false); } } } //kiem tra ten string strTen; strTen = this.dgvList.CurrentRow.Index >= 0 ? this.dgvList.CurrentRow.Cells[this.TenTruong3].Value.ToString().ToLower() : ""; if (this.txtTen.Text.Trim().Length == 0) { MessageBox.Show("Tên " + this.Text.ToLower() + " chưa nhập." + "\n" + "-Hãy nhập tên " + this.Text.ToLower(), Declare.titleNotice, MessageBoxButtons.OK, MessageBoxIcon.Information); this.txtTen.Focus(); return(false); } if (this.blnThemMoi) { if (DBTools.ExistData("Select * from tbl_DM_QuocGia where TenQuocGia=N'" + this.txtTen.Text.Trim() + "'") == true) { MessageBox.Show("Tên " + this.Text.ToLower() + " đã tồn tại." + "\n" + "-Hãy nhập lại tên " + this.Text.ToLower(), Declare.titleWarning, MessageBoxButtons.OK, MessageBoxIcon.Warning); this.txtTen.Focus(); return(false); } } else { if (this.txtTen.Text.Trim().ToLower() != strTen) { if (DBTools.ExistData("Select * from tbl_DM_QuocGia where TenQuocGia=N'" + this.txtTen.Text.Trim() + "'") == true) { MessageBox.Show("Tên " + this.Text.ToLower() + " đã tồn tại." + "\n" + "-Hãy nhập lại tên " + this.Text.ToLower(), Declare.titleWarning, MessageBoxButtons.OK, MessageBoxIcon.Warning); this.txtTen.Focus(); return(false); } } } } if (!this.blnThemMoi) { if (this.TenBang != "tbl_DM_QuocGia") { DBTools._IsCheck IsCheck; IsCheck = DBTools.CheckExistsRecord(this.DanhMuc_IsChecExitForeginKeyCommand(int.Parse(this.dgvList.CurrentRow.Cells[this.TenTruong1].Value.ToString()))); if (IsCheck == DBTools._IsCheck._TRUE) { if (!this.chkSuDung.Checked) { MessageBox.Show("Dữ liệu của danh mục " + this.Text + " đã được sử dụng nên trạng thái sử dụng luôn được chọn", Declare.titleWarning, MessageBoxButtons.OK, MessageBoxIcon.Warning); this.chkSuDung.Focus(); return(false); } } else if (IsCheck == DBTools._IsCheck._EXCEPTION) { MessageBox.Show("Lỗi kiểm tra dữ liệu " + this.Text.Trim().ToLower() + ": " + DBTools._LastError.Message, Declare.titleError, MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } } } return(true); }