public int insertSPPhaChe(BKIT.Entities.SPPhaChe objSPPhaChe)
        {
            Database db         = DatabaseFactory.CreateDatabase();
            string   sqlCommand = "INSERT INTO SPPhaChe(IDSPPhaChe,IDSanPham,IDSPCha,ThanhPhan,Ghichu) " +
                                  "VALUES (@IDSPPhaChe,@IDSanPham,@IDSPCha,@ThanhPhan,@Ghichu)";
            DbCommand dbCommand = db.GetSqlStringCommand(sqlCommand);

            try
            {
                int ID = GetNextAVailableID();
                objSPPhaChe.IDSPPhaChe = ID;
                db.AddInParameter(dbCommand, "IDSPPhaChe", DbType.Int32, objSPPhaChe.IDSPPhaChe);
                db.AddInParameter(dbCommand, "IDSanPham", DbType.Int32, objSPPhaChe.IDSanPham);
                db.AddInParameter(dbCommand, "IDSPCha", DbType.Int32, objSPPhaChe.IDSPCha);
                db.AddInParameter(dbCommand, "ThanhPhan", DbType.Decimal, objSPPhaChe.ThanhPhan);
                db.AddInParameter(dbCommand, "Ghichu", DbType.String, objSPPhaChe.GhiChu);

                db.ExecuteNonQuery(dbCommand);
                dbCommand.Connection.Close();
                return(ID);
            }
            catch
            {
                dbCommand.Connection.Close();
                return(-1);
            }
        }
        public bool deleteSPPhaChe(BKIT.Entities.SPPhaChe objSPPhaChe)
        {
            Database  db         = DatabaseFactory.CreateDatabase();
            string    sqlCommand = "DELETE FROM SPPhaChe WHERE IDSPPhaChe = @idSPPhaChe";
            DbCommand dbCommand  = db.GetSqlStringCommand(sqlCommand);

            try
            {
                db.AddInParameter(dbCommand, "idSPPhaChe", DbType.Int32, objSPPhaChe.IDSPPhaChe);
                db.ExecuteNonQuery(dbCommand);
                dbCommand.Connection.Close();
                return(true);
            }
            catch
            {
                return(false);
            }
        }
        public bool updateSPPhaChe(BKIT.Entities.SPPhaChe objSPPhaChe)
        {
            Database db         = DatabaseFactory.CreateDatabase();
            string   sqlCommand = "UPDATE SPPhaChe SET IDSanPham = @IDSanPham, IDSPCha = @IDSPCha, ThanhPhan = @ThanhPhan, Ghichu = @Ghichu " +
                                  "WHERE IDSPPhaChe = @IDSPPhaChe";
            DbCommand dbCommand = db.GetSqlStringCommand(sqlCommand);

            try
            {
                db.AddInParameter(dbCommand, "IDSanPham", DbType.Int32, objSPPhaChe.IDSanPham);
                db.AddInParameter(dbCommand, "IDSPCha", DbType.Int32, objSPPhaChe.IDSPCha);
                db.AddInParameter(dbCommand, "ThanhPhan", DbType.Decimal, objSPPhaChe.ThanhPhan);
                db.AddInParameter(dbCommand, "Ghichu", DbType.String, objSPPhaChe.GhiChu);
                db.AddInParameter(dbCommand, "IDSPPhaChe", DbType.Int32, objSPPhaChe.IDSPPhaChe);
                db.ExecuteNonQuery(dbCommand);
                dbCommand.Connection.Close();
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Пример #4
0
        private void gridViewCongThucPhaChe_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
        {
            if (e.RowHandle >= 0)
            {
                if (e.Column == colDeleteCTPhaChe)
                {
                    //do nothing
                }
                else
                {
                    //update here
                    SPPhaChe objSPPhaChe = new SPPhaChe();

                    objSPPhaChe.IDSPPhaChe = Convert.ToInt32(gridViewCongThucPhaChe.GetRowCellValue(e.RowHandle, "IDSPPhaChe"));
                    objSPPhaChe.IDSanPham = Convert.ToInt32(gridViewCongThucPhaChe.GetRowCellValue(e.RowHandle, "IDSanPham"));
                    objSPPhaChe.IDSPCha = Convert.ToInt32(new DataAccess().getIDSanPhamByTenSP(gridViewCongThucPhaChe.GetRowCellValue(e.RowHandle, "TenSanPham").ToString()).Tables[0].Rows[0][0]);
                    objSPPhaChe.GhiChu = Convert.ToString(gridViewCongThucPhaChe.GetRowCellValue(e.RowHandle,"GhiChu"));
                    objSPPhaChe.ThanhPhan = Convert.ToInt32(gridViewCongThucPhaChe.GetRowCellValue(e.RowHandle,"ThanhPhan"));

                    if (objSPPhaChe.ThanhPhan >= 0)
                    {
                        if (new DataAccess().updateSPPhaChe(objSPPhaChe) == true)
                        {
                            ((frmMain)(this.MdiParent)).setStatus("Cập nhật dữ liệu bảng nguyên liệu thành công");
                        }
                        else
                        {
                            MessageBox.Show(this, "Cập nhật dữ liệu bảng nguyên liệu không thành công", "Thông báo lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    else
                    {
                        getBangNguyenLieu(curIDSanPham);
                        MessageBox.Show(this, "Thành phần nguyên liệu không hợp lệ.", "Thông báo lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }
Пример #5
0
        private void gridViewCongThucPhaChe_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
                SPPhaChe objSPPhaChe = new SPPhaChe();

                objSPPhaChe.IDSanPham = curIDSanPham;
                if (Convert.ToString(aRow["TenSanPham"]) == "")
                {
                    getBangNguyenLieu(curIDSanPham);
                    MessageBox.Show(this, "Chưa nhập tên thành phần nguyên liệu cho sản phẩm!", "Thông báo lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else
                {
                    objSPPhaChe.IDSPCha = Convert.ToInt32(new DataAccess().getIDSanPhamByTenSP(aRow["TenSanPham"].ToString()).Tables[0].Rows[0][0]);
                }
                if (Convert.ToString(aRow["ThanhPhan"]) == "")
                {
                    getBangNguyenLieu(curIDSanPham);
                    MessageBox.Show(this, "Chưa nhập thành phần nguyên liệu cho sản phẩm!", "Thông báo lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else
                {
                    objSPPhaChe.ThanhPhan = Convert.ToInt32(aRow["ThanhPhan"]);
                    if (objSPPhaChe.ThanhPhan < 0)
                    {
                        getBangNguyenLieu(curIDSanPham);
                        MessageBox.Show(this, "Thành phần pha chế chưa hợp lệ!", "Thông báo lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                }
                objSPPhaChe.GhiChu = Convert.ToString(aRow["GhiChu"]);

                if (new DataAccess().insertSPPhaChe(objSPPhaChe) >= 0)
                {
                    getBangNguyenLieu(curIDSanPham);
                    ((frmMain)(this.MdiParent)).setStatus("Thêm mới Thành phần nguyên liệu thành công");

                }
                else
                {
                    getBangNguyenLieu(curIDSanPham);
                    MessageBox.Show(this, "Thêm mới thành phần nguyên liệu không thành công", "Thông báo lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    ((frmMain)(this.MdiParent)).setStatus("");
                }

            }
        }
Пример #6
0
        private void gridViewCongThucPhaChe_CellValueChanging(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
        {
            if (e.RowHandle >= 0)
            {
                if (e.Column == colDeleteCTPhaChe)
                {
                    SPPhaChe objSPPhaChe = new SPPhaChe();
                    objSPPhaChe.IDSPPhaChe = Convert.ToInt32(gridViewCongThucPhaChe.GetRowCellValue(e.RowHandle, "IDSPPhaChe"));

                    if (Convert.ToBoolean(gridViewCongThucPhaChe.GetRowCellValue(e.RowHandle, colDeleteCTPhaChe)) == true)
                    {
                        //warnning
                        if (MessageBox.Show(this, "Bạn có muốn xóa Thành phần nguyên liệu này không?", "Cảnh báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                        {
                            if (new DataAccess().deleteSPPhaChe(objSPPhaChe) == true)
                            {
                                ((frmMain)(this.MdiParent)).setStatus("Xóa thành phần nguyên liệu thành công");
                                gridViewCongThucPhaChe.DeleteRow(e.RowHandle);
                            }
                            else
                            {
                                MessageBox.Show(this, "Xóa thành phần nguyên liệu 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
                            gridViewSanPham.SetRowCellValue(e.RowHandle, colDeleteSanPham, true);
                        }
                    }
                }
            }
        }
Пример #7
0
 public bool updateSPPhaChe(SPPhaChe objSPPhaChe)
 {
     return new SPPhaCheService().updateSPPhaChe(objSPPhaChe);
 }
Пример #8
0
 public int insertSPPhaChe(SPPhaChe objSPPhaChe)
 {
     return new SPPhaCheService().insertSPPhaChe(objSPPhaChe);
 }
Пример #9
0
 public bool deleteSPPhaChe(SPPhaChe objSPPhaChe)
 {
     return new SPPhaCheService().deleteSPPhaChe(objSPPhaChe);
 }