private void gridViewKhunggio_CellValueChanging(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e) { if (e.RowHandle >= 0) { if (e.Column == colDeleteKhunggio) { Khunggio objKhunggio = new Khunggio(); objKhunggio.IDKhunggio = Convert.ToInt32(gridViewKhunggio.GetRowCellValue(e.RowHandle, "IDKhunggio")); if (Convert.ToBoolean(gridViewKhunggio.GetRowCellValue(e.RowHandle, colDeleteKhunggio)) == true) { //warnning if (MessageBox.Show(this, "Bạn có muốn xóa Khung giờ này không?", "Cảnh báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { if (new DataAccess().deleteKhunggio(objKhunggio) == true) { ((frmMain)(this.MdiParent)).setStatus("Xóa Khung giờ thành công"); gridViewKhunggio.DeleteRow(e.RowHandle); AddItemForComboboxGiaLoaiPhong(); } else { MessageBox.Show(this, "Xóa Khung giờ 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 gridViewKhunggio.SetRowCellValue(e.RowHandle, colDeleteKhunggio, true); } } } } }
private void gridViewKhunggio_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e) { if (e.RowHandle >= 0) { if (e.Column == colDeleteKhunggio) { //do nothing } else { //update here Khunggio objKhunggio = new Khunggio(); objKhunggio.IDKhunggio = Convert.ToInt32(gridViewKhunggio.GetRowCellValue(e.RowHandle, "IDKhunggio")); objKhunggio.Ten = Convert.ToString(gridViewKhunggio.GetRowCellValue(e.RowHandle, "Ten")); if (objKhunggio.Ten == "") { gridControlKhunggio.DataSource = new DataAccess().getAllKhunggio().Tables[0]; MessageBox.Show(this, "Không có tên khung giờ", "Thông báo lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } objKhunggio.GioBD = Convert.ToString(gridViewKhunggio.GetRowCellValue(e.RowHandle, "GioBD")); if (objKhunggio.GioBD == "") { gridControlKhunggio.DataSource = new DataAccess().getAllKhunggio().Tables[0]; MessageBox.Show(this, "Không có giờ bắt đầu", "Thông báo lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } objKhunggio.GioKT = Convert.ToString(gridViewKhunggio.GetRowCellValue(e.RowHandle, "GioKT")); if (objKhunggio.GioKT == "") { gridControlKhunggio.DataSource = new DataAccess().getAllKhunggio().Tables[0]; MessageBox.Show(this, "Không có giờ kết thúc", "Thông báo lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } objKhunggio.Ghichu = Convert.ToString(gridViewKhunggio.GetRowCellValue(e.RowHandle, "Ghichu")); if (new DataAccess().updateKhunggio(objKhunggio) == true) { gridControlKhunggio.DataSource = new DataAccess().getAllKhunggio().Tables[0]; ((frmMain)(this.MdiParent)).setStatus("Cập nhật dữ liệu Khung giờ thành công"); } else { gridControlKhunggio.DataSource = new DataAccess().getAllKhunggio().Tables[0]; MessageBox.Show(this, "Cập nhật dữ liệu Khung giờ không thành công", "Thông báo lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
public bool deleteKhunggio(Khunggio objKhunggio) { return(new KhunggioService().deleteKhunggio(objKhunggio)); }
public bool updateKhunggio(Khunggio objKhunggio) { return(new KhunggioService().updateKhunggio(objKhunggio)); }
public int insertKhunggio(Khunggio objKhunggio) { return(new KhunggioService().insertKhunggio(objKhunggio)); }
private void gridViewKhunggio_RowUpdated(object sender, DevExpress.XtraGrid.Views.Base.RowObjectEventArgs e) { int i, rowcount; DataRowView aRowView = (DataRowView)(e.Row); DataRow aRow = aRowView.Row; if (aRow.RowState == DataRowState.Added) { //insert command here Khunggio objKhunggio = new Khunggio(); //objKhunggio.IDKhunggio = Convert.ToInt32(aRow["IDKhunggio"]); objKhunggio.Ten = Convert.ToString(aRow["Ten"]); if (objKhunggio.Ten == "") { gridControlKhunggio.DataSource = new DataAccess().getAllKhunggio().Tables[0]; MessageBox.Show(this, "Không có tên khung giờ", "Thông báo lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } DataSet ds = new DataAccess().getAllKhunggio(); rowcount = Convert.ToInt32(ds.Tables[0].Rows.Count); for (i = 0; i < rowcount; i++) { if (objKhunggio.Ten == Convert.ToString(ds.Tables[0].Rows[i]["Ten"])) { MessageBox.Show(this, "Khung giờ trùng tên", "Thông báo lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); gridControlKhunggio.DataSource = new DataAccess().getAllKhunggio().Tables[0]; return; } } try { objKhunggio.GioBD = Convert.ToString(aRow["GioBD"]); if (objKhunggio.GioBD == "") { gridControlKhunggio.DataSource = new DataAccess().getAllKhunggio().Tables[0]; MessageBox.Show(this, "Không có giờ bắt đầu", "Thông báo lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } objKhunggio.GioKT = Convert.ToString(aRow["GioKT"]); if (objKhunggio.GioKT == "") { gridControlKhunggio.DataSource = new DataAccess().getAllKhunggio().Tables[0]; MessageBox.Show(this, "Không có giờ kết thúc", "Thông báo lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } objKhunggio.Ghichu = Convert.ToString(aRow["Ghichu"]); } catch { gridControlKhunggio.DataSource = new DataAccess().getAllKhunggio().Tables[0]; return; } if (new DataAccess().insertKhunggio(objKhunggio) >= 0) { gridControlKhunggio.DataSource = new DataAccess().getAllKhunggio().Tables[0]; ((frmMain)(this.MdiParent)).setStatus("Thêm mới Khung giờ thành công"); AddItemForComboboxGiaLoaiPhong(); } else { gridControlKhunggio.DataSource = new DataAccess().getAllKhunggio().Tables[0]; MessageBox.Show(this, "Thêm mới Khung giờ không thành công", "Thông báo lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }