private void gridViewKMPhong_CellValueChanging(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e) { if (e.RowHandle >= 0) { if (e.Column == colDeleteKMPhong) { KhuyenmaiPhong objKMSP = new KhuyenmaiPhong(); objKMSP.IDKhuyenmai = Convert.ToInt32(gridViewKMPhong.GetRowCellValue(e.RowHandle, "IDKhuyenmai")); if (Convert.ToBoolean(gridViewKMPhong.GetRowCellValue(e.RowHandle, colDeleteKMPhong)) == true) { //warnning if (MessageBox.Show(this, "Bạn có muốn xóa khuyến mãi này không?", "Cảnh báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { if (new DataAccess().deleteKhuyenmaiPhong(objKMSP) == true) { ((frmMain)(this.MdiParent)).setStatus("Xóa khuyến mãi thành công"); gridViewKMPhong.DeleteRow(e.RowHandle); } else { MessageBox.Show(this, "Xóa khuyến mãi không thành công", "Thông báo lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); ((frmMain)(this.MdiParent)).setStatus(""); } } else { //set the image to uncheck gridViewKMPhong.SetRowCellValue(e.RowHandle, colDeleteKMPhong, true); } } } } }
private void gridViewKMPhong_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e) { if (e.RowHandle >= 0) { if (e.Column == colDeleteKMPhong) { //do nothing } else { //update here KhuyenmaiPhong objKMSP = new KhuyenmaiPhong(); objKMSP.IDKhuyenmai = Convert.ToInt32(gridViewKMPhong.GetRowCellValue(e.RowHandle, "IDKhuyenmai")); objKMSP.Giam = Convert.ToInt32(gridViewKMPhong.GetRowCellValue(e.RowHandle, "Giam")); objKMSP.NgayBD = Convert.ToDateTime(gridViewKMPhong.GetRowCellValue(e.RowHandle, "NgayBD")); objKMSP.NgayKT = Convert.ToDateTime(gridViewKMPhong.GetRowCellValue(e.RowHandle, "NgayKT")); objKMSP.Ghichu = ""; DataSet dsPhong = new DataAccess().getLoaiPhongByTenLoaiPhong(Convert.ToString(gridViewKMPhong.GetRowCellValue(e.RowHandle, "TenLoaiPhong"))); try { objKMSP.IDNhomSP = Convert.ToInt32(dsPhong.Tables[0].Rows[0]["IDLoaiPhong"]); } catch { objKMSP.IDNhomSP = -1; } if ((objKMSP.IDNhomSP == -1) || (objKMSP.Giam <= 0)) { getKMPhong(); MessageBox.Show(this, "Thông tin khuyến mãi không hợp lệ (không có nhóm sản phẩm cùng tên hoặc giảm <= 0)", "Thông báo lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (new DataAccess().updateKhuyenmaiPhong(objKMSP) == true) { getKMPhong(); ((frmMain)(this.MdiParent)).setStatus("Cập nhật dữ liệu khuyến mãi thành công"); } else { getKMPhong(); MessageBox.Show(this, "Cập nhật dữ liệu khuyến mãi không thành công", "Thông báo lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
private void gridViewKMPhong_RowUpdated(object sender, DevExpress.XtraGrid.Views.Base.RowObjectEventArgs e) { DataRowView aRowView = (DataRowView)(e.Row); DataRow aRow = aRowView.Row; if (aRow.RowState == DataRowState.Added) { //insert command here //update here KhuyenmaiPhong objKMSP = new KhuyenmaiPhong(); objKMSP.Giam = Convert.ToInt32(aRow["Giam"]); objKMSP.NgayBD = Convert.ToDateTime(aRow["NgayBD"]); objKMSP.NgayKT = Convert.ToDateTime(aRow["NgayKT"]); objKMSP.Ghichu = ""; DataSet dsSP = new DataAccess().getLoaiPhongByTenLoaiPhong(Convert.ToString(aRow["TenLoaiPhong"])); try { objKMSP.IDNhomSP = Convert.ToInt32(dsSP.Tables[0].Rows[0]["IDLoaiPhong"]); } catch { objKMSP.IDNhomSP = -1; } if ((objKMSP.IDNhomSP == -1) || (objKMSP.Giam <= 0)) { getKMPhong(); MessageBox.Show(this, "Thông tin khuyến mãi không hợp lệ (không có nhóm sản phẩm cùng tên hoặc giảm <= 0)", "Thông báo lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (new DataAccess().insertKhuyenmaiPhong(objKMSP) >= 0) { getKMPhong(); ((frmMain)(this.MdiParent)).setStatus("Cập nhật dữ liệu khuyến mãi thành công"); } else { getKMPhong(); MessageBox.Show(this, "Cập nhật dữ liệu khuyến mãi không thành công", "Thông báo lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public bool deleteKhuyenmaiPhong(KhuyenmaiPhong objKhuyenmai) { return(new KhuyenmaiPhongService().deleteKhuyenmaiPhong(objKhuyenmai)); }
public bool updateKhuyenmaiPhong(KhuyenmaiPhong objKhuyenmai) { return(new KhuyenmaiPhongService().updateKhuyenmaiPhong(objKhuyenmai)); }
public int insertKhuyenmaiPhong(KhuyenmaiPhong objKhuyenmai) { return(new KhuyenmaiPhongService().insertKhuyenmaiPhong(objKhuyenmai)); }