Exemplo n.º 1
0
        public int insertKhunggio(BKIT.Entities.Khunggio objKhunggio)
        {
            Database db         = DatabaseFactory.CreateDatabase();
            string   sqlCommand = "INSERT INTO Khunggio(IDKhunggio,Ten,GioBD,GioKT,Ghichu) " +
                                  "VALUES (@idkhunggio,@ten,@giobd,@giokt,@ghichu)";
            DbCommand dbCommand = db.GetSqlStringCommand(sqlCommand);

            try
            {
                int ID = GetNextAVailableID();
                objKhunggio.IDKhunggio = ID;
                db.AddInParameter(dbCommand, "idkhunggio", DbType.Int32, objKhunggio.IDKhunggio);
                db.AddInParameter(dbCommand, "ten", DbType.String, objKhunggio.Ten);
                db.AddInParameter(dbCommand, "giobd", DbType.String, objKhunggio.GioBD);
                db.AddInParameter(dbCommand, "giokt", DbType.String, objKhunggio.GioKT);
                db.AddInParameter(dbCommand, "ghichu", DbType.String, objKhunggio.Ghichu);
                db.ExecuteNonQuery(dbCommand);
                dbCommand.Connection.Close();
                return(ID);
            }
            catch
            {
                dbCommand.Connection.Close();
                return(-1);
            }
        }
Exemplo n.º 2
0
        public bool deleteKhunggio(BKIT.Entities.Khunggio objKhunggio)
        {
            Database  db         = DatabaseFactory.CreateDatabase();
            string    sqlCommand = "DELETE FROM Khunggio WHERE IDKhunggio = @idkhunggio";
            DbCommand dbCommand  = db.GetSqlStringCommand(sqlCommand);

            try
            {
                db.AddInParameter(dbCommand, "idkhunggio", DbType.Int32, objKhunggio.IDKhunggio);
                db.ExecuteNonQuery(dbCommand);
                dbCommand.Connection.Close();
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Exemplo n.º 3
0
        public bool updateKhunggio(BKIT.Entities.Khunggio objKhunggio)
        {
            Database db         = DatabaseFactory.CreateDatabase();
            string   sqlCommand = "UPDATE Khunggio SET Ten = @ten, GioBD = @giobd, GioKT = @giokt, Ghichu = @ghichu " +
                                  "WHERE IDKhunggio = @idkhunggio";
            DbCommand dbCommand = db.GetSqlStringCommand(sqlCommand);

            try
            {
                db.AddInParameter(dbCommand, "ten", DbType.String, objKhunggio.Ten);
                db.AddInParameter(dbCommand, "giobd", DbType.String, objKhunggio.GioBD);
                db.AddInParameter(dbCommand, "giokt", DbType.String, objKhunggio.GioKT);
                db.AddInParameter(dbCommand, "ghichu", DbType.String, objKhunggio.Ghichu);
                db.AddInParameter(dbCommand, "idkhunggio", DbType.Int32, objKhunggio.IDKhunggio);
                db.ExecuteNonQuery(dbCommand);
                dbCommand.Connection.Close();
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Exemplo n.º 4
0
        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);
                }

            }
        }
Exemplo n.º 5
0
        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);
                        }
                    }
                }
            }
        }
Exemplo n.º 6
0
        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);
                    }
                }
            }
        }
Exemplo n.º 7
0
 public bool updateKhunggio(Khunggio objKhunggio)
 {
     return new KhunggioService().updateKhunggio(objKhunggio);
 }
Exemplo n.º 8
0
 public int insertKhunggio(Khunggio objKhunggio)
 {
     return new KhunggioService().insertKhunggio(objKhunggio);
 }
Exemplo n.º 9
0
 public bool deleteKhunggio(Khunggio objKhunggio)
 {
     return new KhunggioService().deleteKhunggio(objKhunggio);
 }