public bool deleteLoaiPhong(BKIT.Entities.LoaiPhong objLoaiPhong) { Database db = DatabaseFactory.CreateDatabase(); string sqlCommand = "DELETE FROM LoaiPhong WHERE IDLoaiPhong = @idloaiphong"; DbCommand dbCommand = db.GetSqlStringCommand(sqlCommand); try { db.AddInParameter(dbCommand, "idloaiphong", DbType.Int32, objLoaiPhong.IDLoaiPhong); db.ExecuteNonQuery(dbCommand); dbCommand.Connection.Close(); return(true); } catch { return(false); } }
public bool updateLoaiPhong(BKIT.Entities.LoaiPhong objLoaiPhong) { Database db = DatabaseFactory.CreateDatabase(); string sqlCommand = "UPDATE LoaiPhong SET TenLoaiPhong = @tenloaiphong, Ghichu = @ghichu " + "WHERE IDLoaiPhong = @idloaiphong"; DbCommand dbCommand = db.GetSqlStringCommand(sqlCommand); try { db.AddInParameter(dbCommand, "tenloaiphong", DbType.String, objLoaiPhong.TenLoaiPhong); db.AddInParameter(dbCommand, "ghichu", DbType.String, objLoaiPhong.Ghichu); db.AddInParameter(dbCommand, "idloaiphong", DbType.Int32, objLoaiPhong.IDLoaiPhong); db.ExecuteNonQuery(dbCommand); dbCommand.Connection.Close(); return(true); } catch { return(false); } }
public int insertLoaiPhong(BKIT.Entities.LoaiPhong objLoaiPhong) { Database db = DatabaseFactory.CreateDatabase(); string sqlCommand = "INSERT INTO LoaiPhong(IDLoaiPhong,TenLoaiPhong,Ghichu) " + "VALUES (@idloaiphong,@tenloaiphong,@ghichu)"; DbCommand dbCommand = db.GetSqlStringCommand(sqlCommand); try { int ID = GetNextAVailableID(); objLoaiPhong.IDLoaiPhong = ID; db.AddInParameter(dbCommand, "idloaiphong", DbType.Int32, objLoaiPhong.IDLoaiPhong); db.AddInParameter(dbCommand, "tenloaiphong", DbType.String, objLoaiPhong.TenLoaiPhong); db.AddInParameter(dbCommand, "ghichu", DbType.String, objLoaiPhong.Ghichu); db.ExecuteNonQuery(dbCommand); dbCommand.Connection.Close(); return(ID); } catch { dbCommand.Connection.Close(); return(-1); } }
private void gridViewLoaiPhong_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 LoaiPhong objLoaiPhong = new LoaiPhong(); objLoaiPhong.TenLoaiPhong = Convert.ToString(aRow["TenLoaiPhong"]); if (objLoaiPhong.TenLoaiPhong == "") { getAllLoaiPhong(); MessageBox.Show(this, "Không có Tên Loại Phòng", "Thông báo lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } objLoaiPhong.Ghichu = Convert.ToString(aRow["Ghichu"]); if (new DataAccess().insertLoaiPhong(objLoaiPhong) >= 0) { getAllLoaiPhong(); ((frmMain)(this.MdiParent)).setStatus("Thêm mới Loại phòng thành công"); } else { getAllLoaiPhong(); MessageBox.Show(this, "Thêm mới Loại phòng không thành công", "Thông báo lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void gridViewLoaiPhong_CellValueChanging(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e) { if (e.RowHandle >= 0) { if (e.Column == colDeleteLoaiPhong) { LoaiPhong objLoaiPhong = new LoaiPhong(); objLoaiPhong.IDLoaiPhong = Convert.ToInt32(gridViewLoaiPhong.GetRowCellValue(e.RowHandle, "IDLoaiPhong")); if (Convert.ToBoolean(gridViewLoaiPhong.GetRowCellValue(e.RowHandle, colDeleteLoaiPhong)) == true) { //warnning if (MessageBox.Show(this, "Bạn có muốn xóa Loại phòng này không?", "Cảnh báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { if (new DataAccess().deleteLoaiPhong(objLoaiPhong) == true) { ((frmMain)(this.MdiParent)).setStatus("Xóa Loại phòng thành công"); gridViewLoaiPhong.DeleteRow(e.RowHandle); } else { MessageBox.Show(this, "Xóa Loại phòng 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 gridViewLoaiPhong.SetRowCellValue(e.RowHandle, colDeleteLoaiPhong, true); } } } } }
private void gridViewLoaiPhong_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e) { if (e.RowHandle >= 0) { if (e.Column == colDeleteLoaiPhong) { //do nothing } else { //update here LoaiPhong objLoaiPhong = new LoaiPhong(); objLoaiPhong.IDLoaiPhong = Convert.ToInt32(gridViewLoaiPhong.GetRowCellValue(e.RowHandle, "IDLoaiPhong")); objLoaiPhong.TenLoaiPhong = Convert.ToString(gridViewLoaiPhong.GetRowCellValue(e.RowHandle, "TenLoaiPhong")); if (objLoaiPhong.TenLoaiPhong == "") { getAllLoaiPhong(); MessageBox.Show(this, "Không có Tên Loại Phòng", "Thông báo lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } objLoaiPhong.Ghichu = Convert.ToString(gridViewLoaiPhong.GetRowCellValue(e.RowHandle, "Ghichu")); if (new DataAccess().updateLoaiPhong(objLoaiPhong) == true) { getAllLoaiPhong(); ((frmMain)(this.MdiParent)).setStatus("Cập nhật dữ liệu Loai phòng thành công"); } else { getAllLoaiPhong(); MessageBox.Show(this, "Cập nhật dữ liệu Loai phòng không thành công", "Thông báo lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
public bool deleteLoaiPhong(LoaiPhong objLoaiPhong) { return new LoaiPhongService().deleteLoaiPhong(objLoaiPhong); }
public bool updateLoaiPhong(LoaiPhong objLoaiPhong) { return new LoaiPhongService().updateLoaiPhong(objLoaiPhong); }
public int insertLoaiPhong(LoaiPhong objLoaiPhong) { return new LoaiPhongService().insertLoaiPhong(objLoaiPhong); }