Ejemplo n.º 1
0
        public bool updateChitietHDXuat(BKIT.Entities.ChitietHDXuat objChitietHDXuat)
        {
            Database db         = DatabaseFactory.CreateDatabase();
            string   sqlCommand = "UPDATE ChitietHDXuat SET IDHoadonXuat = @idhoadonxuat, IDSanpham = @idsanpham, Gia = @gia, Soluong = @soluong, Giam = @giam, Ghichu = @ghichu, Trangthai = @trangthai " +
                                  "WHERE IDChitietHDXuat = @idchitiethdxuat";
            DbCommand dbCommand = db.GetSqlStringCommand(sqlCommand);

            try
            {
                db.AddInParameter(dbCommand, "idhoadonxuat", DbType.Int32, objChitietHDXuat.IDHoadonXuat);
                db.AddInParameter(dbCommand, "idsanpham", DbType.Int32, objChitietHDXuat.IDSanpham);
                db.AddInParameter(dbCommand, "gia", DbType.Int32, objChitietHDXuat.Gia);
                db.AddInParameter(dbCommand, "soluong", DbType.Int32, objChitietHDXuat.Soluong);
                db.AddInParameter(dbCommand, "giam", DbType.Int32, objChitietHDXuat.Giam);
                db.AddInParameter(dbCommand, "ghichu", DbType.String, objChitietHDXuat.Ghichu);

                db.AddInParameter(dbCommand, "trangthai", DbType.Boolean, objChitietHDXuat.Trangthai);
                db.AddInParameter(dbCommand, "idchitiethdxuat", DbType.Int32, objChitietHDXuat.IDChitietHDXuat);
                db.ExecuteNonQuery(dbCommand);
                dbCommand.Connection.Close();
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Ejemplo n.º 2
0
        public int insertChitietHDXuat(BKIT.Entities.ChitietHDXuat objChitietHDXuat)
        {
            Database db         = DatabaseFactory.CreateDatabase();
            string   sqlCommand = "INSERT INTO ChitietHDXuat(IDChitietHDXuat,IDHoadonXuat,IDSanpham,Gia,Soluong,Giam,Ghichu,Trangthai) " +
                                  "VALUES (@idchitiethdxuat,@idhoadonxuat,@idsanpham,@gia,@soluong,@giam,@ghichu,@trangthai)";
            DbCommand dbCommand = db.GetSqlStringCommand(sqlCommand);

            try
            {
                int ID = GetNextAVailableID();
                objChitietHDXuat.IDChitietHDXuat = ID;
                db.AddInParameter(dbCommand, "idchitiethdxuat", DbType.Int32, objChitietHDXuat.IDChitietHDXuat);
                db.AddInParameter(dbCommand, "idhoadonxuat", DbType.Int32, objChitietHDXuat.IDHoadonXuat);
                db.AddInParameter(dbCommand, "idsanpham", DbType.Int32, objChitietHDXuat.IDSanpham);
                db.AddInParameter(dbCommand, "gia", DbType.Int32, objChitietHDXuat.Gia);
                db.AddInParameter(dbCommand, "soluong", DbType.Int32, objChitietHDXuat.Soluong);
                db.AddInParameter(dbCommand, "giam", DbType.Int32, objChitietHDXuat.Giam);
                db.AddInParameter(dbCommand, "ghichu", DbType.String, objChitietHDXuat.Ghichu);
                db.AddInParameter(dbCommand, "trangthai", DbType.Boolean, objChitietHDXuat.Trangthai);
                db.ExecuteNonQuery(dbCommand);
                dbCommand.Connection.Close();
                return(ID);
            }
            catch
            {
                dbCommand.Connection.Close();
                return(-1);
            }
        }
Ejemplo n.º 3
0
        private void AddSPBD(int IDReceipt, int IDLoaiSP, int IDSanPham, string TenSP, int num)
        {
            //add a quantity of a product to current bill
            //check if the parameters are legal

            //DataSet prdPrice = new DataAccess().getGiaXuatSPByIDSanPham(ID);
            //if ((prdPrice != null) && (prdPrice.Tables[0].Rows.Count > 0))
            //{
            //txtPrice.Text = prdPrice.Tables[0].Rows[0][1].ToString();
            if (IDReceipt >= 0)
            {

                DataSet dsGia = new DataAccess().getGiaXuatSPByIDSanPham(IDSanPham);
                //if (ds == null)
                //    return;
                //if (ds.Tables[0].Rows.Count == 0)
                //{
                ChitietHDXuat obj = new ChitietHDXuat();
                obj.IDHoadonXuat = IDReceipt;
                obj.IDSanpham = IDSanPham;
                try
                {
                    obj.Gia = Convert.ToInt32(dsGia.Tables[0].Rows[0]["Gia"]);
                }
                catch
                {
                    MessageBox.Show("Chưa có giá cho " + TenSP, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                obj.Soluong = num;
                //get khuyen mai with this product ID
                DataSet ds = new DataAccess().getKhuyenmaiByIDLoaiSP(IDLoaiSP, DateTime.Now.Date);
                if (ds != null)
                {
                    try
                    {
                        obj.Giam = Convert.ToInt32(ds.Tables[0].Rows[0]["Giam"]);
                    }
                    catch (Exception ex)
                    {
                        obj.Giam = 0;
                    }
                }
                else
                    obj.Giam = 0;
                obj.Trangthai = false;
                int res = new DataAccess().insertChitietHDXuat(obj);
                if (res < 0)
                {
                    MessageBox.Show("Không thêm sản phẩm ban đầu vào hóa đơn hiện tại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

            }
        }
Ejemplo n.º 4
0
        public bool deleteChitietHDXuat(BKIT.Entities.ChitietHDXuat objChitietHDXuat)
        {
            Database  db         = DatabaseFactory.CreateDatabase();
            string    sqlCommand = "DELETE FROM ChitietHDXuat WHERE IDChitietHDXuat = @idchitiethdxuat";
            DbCommand dbCommand  = db.GetSqlStringCommand(sqlCommand);

            try
            {
                db.AddInParameter(dbCommand, "idchitiethdxuat", DbType.Int32, objChitietHDXuat.IDChitietHDXuat);
                db.ExecuteNonQuery(dbCommand);
                dbCommand.Connection.Close();
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Ejemplo n.º 5
0
 private void gridViewBillProduct_RowUpdated(object sender, DevExpress.XtraGrid.Views.Base.RowObjectEventArgs e)
 {
     ChitietHDXuat obj = new ChitietHDXuat();
     obj.IDChitietHDXuat = Convert.ToInt32(gridViewBillProduct.GetRowCellValue(e.RowHandle, "IDChitietHDXuat"));
     obj.IDGiaxuat = Convert.ToInt32(gridViewBillProduct.GetRowCellValue(e.RowHandle, "IDGiaXuatSP"));
     obj.IDHoadonXuat = Convert.ToInt32(gridViewBillProduct.GetRowCellValue(e.RowHandle, "IDHoadonXuat"));
     obj.IDSanpham = Convert.ToInt32(gridViewBillProduct.GetRowCellValue(e.RowHandle, "IDSanpham"));
     obj.Soluong = Convert.ToInt32(gridViewBillProduct.GetRowCellValue(e.RowHandle, "Soluong"));
     obj.Giam = Convert.ToInt32(gridViewBillProduct.GetRowCellValue(e.RowHandle, "Giam"));
     obj.Bep = Convert.ToBoolean(gridViewBillProduct.GetRowCellValue(e.RowHandle, "Bep")); ;
     if (new DataAccess().updateChitietHDXuat(obj) == false)
         MessageBox.Show(this, "Cập nhật sản phẩm không thành công", "Thông báo lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
     updateBillDisplay(iCurrentReceiptID);
 }
Ejemplo n.º 6
0
        private void gridViewBillProduct_CellValueChanging(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
        {
            if (e.RowHandle >= 0)
            {
                if ((currentReceipt.Trangthai < 1) || (Program.userLevel == Level.Admin))
                {
                    if (e.Column == colDeleteCTHD)
                    {
                        ////delete here
                        //get the number of avalable product with this bill
                        DataSet dsCTHD = new DataAccess().getChitietHDXuatByIDSanphamAndIDHoadon(Convert.ToInt32(gridViewBillProduct.GetRowCellValue(e.RowHandle, "IDSanpham")), iCurrentReceiptID);
                        int i;
                        int sum = 0;
                        for (i = 0; i < dsCTHD.Tables[0].Rows.Count; i++)
                        {
                            sum = sum + Convert.ToInt32(dsCTHD.Tables[0].Rows[i]["Soluong"]);
                        }
                        ChitietHDXuat obj = new ChitietHDXuat();
                        obj.Giam = Convert.ToInt32(gridViewBillProduct.GetRowCellValue(e.RowHandle, "Giam"));
                        obj.IDGiaxuat = Convert.ToInt32(gridViewBillProduct.GetRowCellValue(e.RowHandle, "IDGiaXuatSP"));
                        obj.IDHoadonXuat = Convert.ToInt32(gridViewBillProduct.GetRowCellValue(e.RowHandle, "IDHoadonXuat"));
                        obj.IDSanpham = Convert.ToInt32(gridViewBillProduct.GetRowCellValue(e.RowHandle, "IDSanpham"));
                        obj.Soluong = Convert.ToInt32(gridViewBillProduct.GetRowCellValue(e.RowHandle, "Soluong"));
                        obj.Bep = Convert.ToBoolean(gridViewBillProduct.GetRowCellValue(e.RowHandle, "Bep"));
                        if (sum <= 0)
                        {
                            MessageBox.Show("Hiện tại không còn sản phầm này trong hóa đơn", "Thông báo");
                            return;
                        }
                        frmReturnProduct rt = new frmReturnProduct(false,sum, Convert.ToString(gridViewBillProduct.GetRowCellValue(e.RowHandle, "TenSanPham")));
                        rt.ShowDialog();
                        int rtnum = rt.getReturnNum();
                        // bool directRet = rt.getDirectRet();
                        string text = rt.getText();
                        rt.Close();
                        if (rtnum <= 0) return;
                        obj.Soluong = -rtnum;
                        obj.Ghichu = text;
                        if (new DataAccess().insertChitietHDXuat(obj) < 0)
                            MessageBox.Show(this, "Trả sản phẩm không thành công", "Thông báo lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        else
                            updateBillDisplay(iCurrentReceiptID);

                    }

                }
                else
                {
                    MessageBox.Show(this, "Hóa đơn đã khóa sổ, không thay đổi được. Liên hệ quản lý để thay đổi", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                }

            }
        }
Ejemplo n.º 7
0
        private void AddSP(int num)
        {
            //add a quantity of a product to current bill
            //check if the parameters are legal

            if (gridViewSanPham.FocusedRowHandle >= 0)
            {
                //list all products by ID
                int ID = Convert.ToInt32(gridViewSanPham.GetRowCellValue(gridViewSanPham.FocusedRowHandle, "IDSanPham"));
                iCurrentProductID = ID;
                int IDLoaiSP = Convert.ToInt32(gridViewSanPham.GetRowCellValue(gridViewSanPham.FocusedRowHandle, "IDNhomSP"));
                //DataSet prdPrice = new DataAccess().getGiaXuatSPByIDSanPham(ID);
                //if ((prdPrice != null) && (prdPrice.Tables[0].Rows.Count > 0))
                //{
                //txtPrice.Text = prdPrice.Tables[0].Rows[0][1].ToString();
                if (iCurrentReceiptID >= 0)
                {
                    if (currentReceipt.Trangthai > 1)
                    {
                        MessageBox.Show("Hóa đơn này đã đóng, không được thay đổi", "Thông báo");
                        return;
                    }
                    else if ((currentReceipt.Trangthai > 0) && (Program.userLevel != Level.Admin))
                    {
                        MessageBox.Show("Đăng nhập với quyền Quản lý để thay đổi", "Thông báo");
                        return;
                    }
                    if(currentReceipt.Trangthai > 0)
                    {
                        if (MessageBox.Show("Bạn có muốn thêm sản phẩm vào hóa đơn đã đóng", "Cảnh báo", MessageBoxButtons.YesNo) == DialogResult.No)
                            return;
                    }
                    //get khuyen mai with this product ID
                    DataSet ds = new DataAccess().getKhuyenmaiByIDLoaiSP(IDLoaiSP, DateTime.Now.Date);
                    //if (ds == null)
                    //    return;
                    //if (ds.Tables[0].Rows.Count == 0)
                    //{
                    //get the number of added product
                    frmReturnProduct rt = new frmReturnProduct(true, 0, Convert.ToString(gridViewSanPham.GetRowCellValue(gridViewSanPham.FocusedRowHandle, "TenSanPham")));
                    rt.ShowDialog();
                    int rtnum = rt.getReturnNum();
                    // bool directRet = rt.getDirectRet();
                    string text = rt.getText();
                    rt.Close();
                    if (rtnum <= 0) return;
                    ChitietHDXuat obj = new ChitietHDXuat();
                    obj.IDHoadonXuat = iCurrentReceiptID;
                    obj.IDSanpham = iCurrentProductID;
                    obj.IDGiaxuat = Convert.ToInt32(gridViewSanPham.GetRowCellValue(gridViewSanPham.FocusedRowHandle, "IDGiaXuatSP"));
                    obj.Soluong = rtnum;
                    if (ds != null)
                    {
                        try
                        {
                            obj.Giam = Convert.ToInt32(ds.Tables[0].Rows[0]["Giam"]);
                        }
                        catch (Exception ex)
                        {
                            obj.Giam = 0;
                        }
                    }
                    else
                        obj.Giam = 0;
                    obj.Bep = false;
                    int res = new DataAccess().insertChitietHDXuat(obj);
                    if (res < 0)
                    {
                        MessageBox.Show("Không thêm sản phẩm " + gridViewSanPham.GetRowCellValue(gridViewSanPham.FocusedRowHandle, "TenSanPham") + " vào hóa đơn hiện tại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }

                    updateBillDisplay(iCurrentReceiptID);
                    int i;
                    for (i = 0; i < gridViewBillProduct.RowCount; i++)
                    {
                        if (Convert.ToInt32(gridViewBillProduct.GetRowCellValue(i, "IDSanpham")) == iCurrentProductID)
                            break;
                    }
                    gridViewBillProduct.Focus();
                    gridViewBillProduct.FocusedRowHandle = i;
                    gridViewBillProduct.FocusedColumn = colBillNum;

                }
            }
        }
Ejemplo n.º 8
0
        private void btnPrintCooking_Click(object sender, EventArgs e)
        {
            if (iCurrentReceiptID >= 0)
            {
                int i;
                DataSetHoaDon dsBill = new DataSetHoaDon();
                DataSet dsSP = new DataAccess().getChitietHDXuatByID(iCurrentReceiptID);
                DataSet dsHD = new DataAccess().getHoadonxuatByIDHoadonXuat(iCurrentReceiptID);
                ChitietHDXuat obj = new ChitietHDXuat();

                for (i = 0; i < dsSP.Tables[0].Rows.Count; i++)
                {
                    if (Convert.ToBoolean(dsSP.Tables[0].Rows[i]["Bep"]) == false)
                    {
                        DataRow dr1 = dsBill.Tables["RDatadetail"].NewRow();
                        dr1["STT"] = (i + 1).ToString();
                        dr1["TenSanPham"] = dsSP.Tables[0].Rows[i]["TenSanPham"].ToString();
                        dr1["DVT"] = dsSP.Tables[0].Rows[i]["DVT"].ToString();
                        dr1["DonGia"] = dsSP.Tables[0].Rows[i]["Gia"].ToString();
                        dr1["Soluong"] = dsSP.Tables[0].Rows[i]["Soluong"].ToString();
                        dr1["ThanhTien"] = Convert.ToDecimal(dsSP.Tables[0].Rows[i]["Thanhtien"]).ToString("###,###,###,###");

                        dsBill.Tables["RDatadetail"].Rows.Add(dr1);

                    }
                }

                //read Company Information
                string strCompanyName = "";
                string strCompanyAddress = "";
                string strCompanyPhone = "";
                string strLoiChao1 = "";
                string strLoiChao2 = "";
                DataSet dsSetting = new DataAccess().getSettingByDate("");
                if (dsSetting != null)
                {
                    if (dsSetting.Tables[0].Rows.Count > 0)
                    {
                        if (!(dsSetting.Tables[0].Rows[0]["TenCT"] is DBNull))
                            strCompanyName = Convert.ToString(dsSetting.Tables[0].Rows[0]["TenCT"]);
                        if (!(dsSetting.Tables[0].Rows[0]["Diachi"] is DBNull))
                            strCompanyAddress = Convert.ToString(dsSetting.Tables[0].Rows[0]["Diachi"]);
                        if (!(dsSetting.Tables[0].Rows[0]["Phone"] is DBNull))
                            strCompanyPhone = Convert.ToString(dsSetting.Tables[0].Rows[0]["Phone"]);
                        if (!(dsSetting.Tables[0].Rows[0]["Loichao1"] is DBNull))
                            strLoiChao1 = Convert.ToString(dsSetting.Tables[0].Rows[0]["Loichao1"]);
                        if (!(dsSetting.Tables[0].Rows[0]["Loichao2"] is DBNull))
                            strLoiChao2 = Convert.ToString(dsSetting.Tables[0].Rows[0]["Loichao2"]);
                    }
                }

                DataRow dr = dsBill.Tables["HeaderData"].NewRow();
                dr["Ngayxuat"] = currentReceipt.Ngayxuat.ToString("dd/MM/yyyy HH:mm:ss tt");
                dr["Phong"] = "";
                dr["GiaPhong"] = "";
                dr["HoadonID"] = iCurrentReceiptID.ToString();
                dr["GioBD"] = Convert.ToDateTime(dsHD.Tables[0].Rows[0]["GioBD"]).ToShortTimeString();
                dr["GioKT"] = Convert.ToDateTime(dsHD.Tables[0].Rows[0]["GioKT"]).ToShortTimeString();
                dr["Nhanvien"] = cboEmployee.Text;
                dr["Thue"] = numTax.Value.ToString();
                dr["Tiengiam"] = numExtra.Value.ToString();
                dr["Phuthu"] = numExtra.Value.ToString();
                dr["Tiengio"] = "";
                dr["Tienhang"] = txtProductMoney.Text;
                dr["Tongcong"] = txtBilltotal.Text;
                dr["Tratruoc"] = numDeposit.Value.ToString("###,###,##0");
                dr["Tralai"] = txtReturnMoney.Text;
                dr["TenCongTy"] = strCompanyName;
                dr["DiaChi"] = "ĐC: " + strCompanyAddress;
                dr["SoDT"] = "ĐT: " + strCompanyPhone;
                dr["Loichao1"] = strLoiChao1;
                dr["Loichao2"] = strLoiChao2;
                dsBill.Tables["HeaderData"].Rows.Add(dr);

                if (dsBill != null)
                {
                    //load last setting
                    DataSet ds = new DataAccess().getSettingByDate("");
                    string printer;
                    try
                    {
                        printer = Convert.ToString(ds.Tables[0].Rows[0]["MayInBep"]);
                        myPrinters.SetDefaultPrinter(printer);
                    }
                    catch
                    {
                        MessageBox.Show("Chưa cài đặt máy in!", "Thông báo");
                    }
                    frmViewReport frmView = new frmViewReport(dsBill, true);
                    if (frmView.ShowDialog() == DialogResult.Yes)
                    {
                        for (i = 0; i < dsSP.Tables[0].Rows.Count; i++)
                        {
                            if (Convert.ToBoolean(dsSP.Tables[0].Rows[i]["Bep"]) == false)
                            {
                                //update bep
                                obj.IDChitietHDXuat = Convert.ToInt32(dsSP.Tables[0].Rows[i]["IDChitietHDXuat"]);
                                obj.IDHoadonXuat = Convert.ToInt32(dsSP.Tables[0].Rows[i]["IDHoadonXuat"]);
                                obj.IDSanpham = Convert.ToInt32(dsSP.Tables[0].Rows[i]["IDSanpham"]);
                                obj.IDGiaxuat = Convert.ToInt32(dsSP.Tables[0].Rows[i]["IDGiaXuatSP"]);
                                obj.Soluong = Convert.ToInt32(dsSP.Tables[0].Rows[i]["Soluong"]);
                                obj.Kho = Convert.ToBoolean(dsSP.Tables[0].Rows[i]["Kho"]);
                                obj.Giam = Convert.ToInt32(dsSP.Tables[0].Rows[i]["Giam"]);
                                obj.Ghichu = Convert.ToString(dsSP.Tables[0].Rows[i]["Ghichu"]);
                                obj.Bep = true;
                                try
                                {
                                    if (new DataAccess().updateChitietHDXuat(obj) != true)
                                        MessageBox.Show("Lỗi dữ liệu", "Thông báo");
                                }
                                catch { }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 9
0
        void TransferRoom()
        {
            //check if whether transfer column diff zero
            if (newRoom < 0)
            {
                MessageBox.Show("Bạn hãy chọn phòng để chuyển sản phẩm!", "Thông báo", MessageBoxButtons.OK);
                return;
            }
            if (newIDHoadonXuat < 0)
            {
                if (MessageBox.Show("Bạn có chắc muốn mở phòng " + gridViewRoom.GetRowCellValue(gridViewRoom.FocusedRowHandle, "TenPhong").ToString() + " và chuyển sản phẩm?", "Thông báo", MessageBoxButtons.YesNo) == DialogResult.No)
                    return;
            }
            int i;
            int id;
            /*
            bool found = false;

            for (i = 0; i < gridViewTransferedProductNew.RowCount; i++)
            {
                if (Convert.ToInt32(gridViewTransferedProductNew.GetRowCellValue(i, "Transfer")) != 0)
                {
                    gridViewTransferedProductNew.FocusedRowHandle = i;
                    found = true;
                    break;
                }
            }

            for (i = 0; i < gridViewBillProduct.RowCount; i++)
            {
                if (Convert.ToInt32(gridViewBillProduct.GetRowCellValue(i, "Transfer")) != 0)
                {
                    gridViewBillProduct.FocusedRowHandle = i;
                    found = true;
                    break;
                }
            }
            if (found)
            {
                if (MessageBox.Show("Sản phẩm chưa được chuyển hết (Cột 'Chuyển khác 0). Bạn có muốn tiếp tục cập nhật Hóa đơn?", "Thông báo", MessageBoxButtons.YesNo) == DialogResult.No)
                    return;
            }
            else
            {
                if (MessageBox.Show("Bạn có chắc muốn cập nhật Hóa đơn?", "Xác nhận", MessageBoxButtons.YesNo) == DialogResult.No)
                    return;
            }
            */
            //update old chi tiet hoa don
            TransferAllDown();
            //delete old chitiethdxuat
            for (i = 0; i < oldProduct.Rows.Count; i++)
            {
                ChitietHDXuat objCTHDX = new ChitietHDXuat();
                objCTHDX.IDChitietHDXuat = Convert.ToInt32(oldProduct.Rows[i]["IDChitietHDXuat"]);
                if (!(new DataAccess().deleteChitietHDXuat(objCTHDX)))
                {
                    MessageBox.Show("Lỗi Cơ sở dữ liệu!", "Lỗi");
                    return;
                }
            }

            //update new HD
            if (newIDHoadonXuat >= 0)   // hoa don da duoc mo
            {
                for (i = 0; i < newProduct.Rows.Count; i++)
                {
                    ChitietHDXuat objCTHDX = new ChitietHDXuat();
                    objCTHDX.IDChitietHDXuat = Convert.ToInt32(newProduct.Rows[i]["IDChitietHDXuat"]);
                    objCTHDX.Gia = Convert.ToInt32(newProduct.Rows[i]["Gia"]);
                    objCTHDX.Giam = Convert.ToInt32(newProduct.Rows[i]["Giam"]);
                    objCTHDX.IDHoadonXuat = newIDHoadonXuat;
                    objCTHDX.IDSanpham = Convert.ToInt32(newProduct.Rows[i]["IDSanpham"]);
                    objCTHDX.Soluong = Convert.ToInt32(newProduct.Rows[i]["Soluong"]);
                    objCTHDX.Trangthai = Convert.ToBoolean(newProduct.Rows[i]["Trangthai"]);
                    objCTHDX.Ghichu = Convert.ToString(newProduct.Rows[i]["Ghichu"]);
                    //if (objCTHDX.IDChitietHDXuat >= 0)
                    //{
                    //    if (objCTHDX.Soluong <= 0)
                    //    {
                    //        if (!(new DataAccess().deleteChitietHDXuat(objCTHDX)))
                    //        {
                    //            MessageBox.Show("Lỗi Cơ sở dữ liệu!", "Lỗi");
                    //            return;
                    //        }
                    //    }
                    //    else
                    //    {

                    //        if (!(new DataAccess().updateChitietHDXuat(objCTHDX)))
                    //        {
                    //            MessageBox.Show("Lỗi Cơ sở dữ liệu!", "Lỗi");
                    //            return;
                    //        }
                    //    }
                    //}
                    if (objCTHDX.IDChitietHDXuat < 0)
                    {
                        id = new DataAccess().insertChitietHDXuat(objCTHDX);
                        if (id < 0)
                        {
                            MessageBox.Show("Lỗi Cơ sở dữ liệu!", "Lỗi");
                            return;
                        }
                        else
                            newProduct.Rows[i]["IDChitietHDXuat"] = id;

                    }
                }

            }
            else //open new bill
            {
                Hoadonxuat currentReceipt = new Hoadonxuat();
                currentReceipt.Giam = 0;
                currentReceipt.GioBD = DateTime.Now;
                currentReceipt.GioKT = DateTime.Now;
                currentReceipt.Nhacnho = false;
                currentReceipt.Tratruoc = 0;
                currentReceipt.IDPhong = newRoom;
                currentReceipt.Ngayxuat = DateTime.Now.Date;
                currentReceipt.Phuthu = 0;
                currentReceipt.Thue = 0;
                currentReceipt.Trangthai = 0;
                currentReceipt.Tanggio = 0;
                currentReceipt.Thue = 0;
                currentReceipt.TenHoadon = newRoomName + " " + DateTime.Now.ToString("dd/MM/yy-hh:mm");
                currentReceipt.Phuthu = 0;

                currentReceipt.IDNhanvien = Program.IDNhanvien;
                currentReceipt.IDNhanvienXuatHD = Program.IDNhanvien;
                currentReceipt.IDKhachhang = 0;
                currentReceipt.Ghichu = "Chuyen toan bo tu phong "+oldRoomName;
                currentReceipt.Suco = 1;
                //get current hour class
                TimeSpan ctime = DateTime.Now.TimeOfDay;

                DataSet hourclass = new DataAccess().getAllKhunggio();
                int idkhunggio = 0;
                for (i = 0; i < hourclass.Tables[0].Rows.Count; i++)
                {
                    string time = Convert.ToString(hourclass.Tables[0].Rows[i]["GioBD"]);
                    int sh = Convert.ToInt32(time.Substring(0, time.IndexOf(":")));
                    int sm = Convert.ToInt32(time.Substring(time.IndexOf(":") + 1));
                    string time1 = Convert.ToString(hourclass.Tables[0].Rows[i]["GioKT"]);
                    int eh = Convert.ToInt32(time1.Substring(0, time.IndexOf(":")));
                    int em = Convert.ToInt32(time1.Substring(time1.IndexOf(":") + 1));
                    if ((ctime.Hours < eh) || ((ctime.Hours == eh) && (ctime.Minutes <= em)))
                    {
                        if ((ctime.Hours > sh) || ((ctime.Hours == sh) && (ctime.Minutes > sm)))
                        {
                            idkhunggio = Convert.ToInt32(hourclass.Tables[0].Rows[i]["IDKhunggio"]);
                            break;
                        }
                    }
                }
                //get Room price

                DataSet ds1 = new DataAccess().getGiaLoaiPhongByIDLoaiPhongAndIDKhunggio(Convert.ToInt32(gridViewRoom.GetRowCellValue(gridViewRoom.FocusedRowHandle, "IDLoaiPhong")), idkhunggio);
                if (ds1.Tables[0].Rows.Count > 0)
                    currentReceipt.IDGiaLoaiphong = Convert.ToInt32(ds1.Tables[0].Rows[0]["Gia"]);
                else
                {
                    MessageBox.Show("Chưa có bảng giá cho phòng " + Convert.ToString(gridViewRoom.GetRowCellValue(gridViewRoom.FocusedRowHandle, "TenPhong")) +
                        " vào khung giờ này. Mở phòng không thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    return;
                }
                //get khuyen mai
                //get khuyen mai tang gio cua phong
                DataSet dsKM = new DataAccess().getKhuyenmaiByIDLoaiPhong(newRoomGroup, DateTime.Now.Date);
                //Hoadonxuat currentReceipt = new Hoadonxuat();
                try
                {
                    currentReceipt.Giam = Convert.ToInt32(dsKM.Tables[0].Rows[0]["Giam"]);
                }
                catch (Exception ex)
                {
                    currentReceipt.Giam = 0;
                }
                newIDHoadonXuat = new DataAccess().insertHoadonxuat(currentReceipt);
                if (newIDHoadonXuat > -1)
                {
                    //wait for databa is update
                    //ContactAction(0xbf, Convert.ToInt32(ds.Tables[0].Rows[0]["Congtac"]));
                    //open electric cb
                    //MessageBox.Show("Mở Phòng " + Convert.ToInt32(gridViewRoom.GetRowCellValue(gridViewRoom.FocusedRowHandle, "TenPhong")) +
                    //    " thành công", "Thông báo");
                    //turnOnRoom.Enqueue(newRoom);
                    //update status for this Room
                    Phong updateRoom = new Phong();
                    updateRoom.IDPhong = newRoom;
                    updateRoom.IDLoaiPhong = Convert.ToInt32(gridViewRoom.GetRowCellValue(gridViewRoom.FocusedRowHandle, "IDLoaiPhong"));
                    updateRoom.Congtac = Convert.ToInt32(gridViewRoom.GetRowCellValue(gridViewRoom.FocusedRowHandle, colCB));
                    updateRoom.TenPhong = Convert.ToString(gridViewRoom.GetRowCellValue(gridViewRoom.FocusedRowHandle, "TenPhong"));
                    updateRoom.Ghichu = Convert.ToString(gridViewRoom.GetRowCellValue(gridViewRoom.FocusedRowHandle, "Ghichu"));
                    updateRoom.Trangthai = true;
                    bool a = new DataAccess().updatePhong(updateRoom);
                    if (!a)
                    {
                        MessageBox.Show("Không cập nhật được trạng thái cho phòng " + updateRoom.TenPhong, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                        return;
                    }
                    //update current status gridview
                    gridViewRoom.SetFocusedRowCellValue(colRoomStatus, true);
                    //add chitietHDxuat
                    for (i = 0; i < newProduct.Rows.Count; i++)
                    {
                        ChitietHDXuat objCTHDX = new ChitietHDXuat();
                        objCTHDX.IDChitietHDXuat = -1;
                        objCTHDX.Gia = Convert.ToInt32(newProduct.Rows[i]["Gia"]);
                        objCTHDX.Giam = Convert.ToInt32(newProduct.Rows[i]["Giam"]);
                        objCTHDX.IDHoadonXuat = newIDHoadonXuat;
                        objCTHDX.IDSanpham = Convert.ToInt32(newProduct.Rows[i]["IDSanpham"]);
                        objCTHDX.Soluong = Convert.ToInt32(newProduct.Rows[i]["Soluong"]);
                        objCTHDX.Trangthai = Convert.ToBoolean(newProduct.Rows[i]["Trangthai"]);
                        objCTHDX.Ghichu = Convert.ToString(newProduct.Rows[i]["Ghichu"]);
                        if (objCTHDX.Soluong > 0)
                        {

                            id = new DataAccess().insertChitietHDXuat(objCTHDX);
                            if (id < 0)
                            {
                                MessageBox.Show("Lỗi Cơ sở dữ liệu!", "Lỗi");
                                return;
                            }
                            else
                                newProduct.Rows[i]["IDChitietHDXuat"] = id;
                        }
                    }

                }

                else
                {
                    MessageBox.Show("Mở Phòng " + Convert.ToInt32(gridViewRoom.GetRowCellValue(gridViewRoom.FocusedRowHandle, "TenPhong")) +
                        " không thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    return;
                }
            }
            //Add gio phong
            DataSet dsOldBill = new DataAccess().getHoadonxuatByIDHoadonXuat(oldIDHoadonXuat);
            if (dsOldBill == null)
            {
                MessageBox.Show("Không tìm thấy hóa đơn phòng cần chuyển!", "Lỗi dữ liệu");
                return;
            }
            if (dsOldBill.Tables[0].Rows.Count == 0)
            {
                MessageBox.Show("Không tìm thấy hóa đơn phòng cần chuyển!", "Lỗi dữ liệu");
                return;
            }
            ChitietHDXuat objCTHDX_LT = new ChitietHDXuat();
            objCTHDX_LT.Gia = Convert.ToInt32(dsOldBill.Tables[0].Rows[0]["IDGiaLoaiphong"]) / 60;
            objCTHDX_LT.Giam = Convert.ToInt32(dsOldBill.Tables[0].Rows[0]["Giam"]);
            objCTHDX_LT.IDHoadonXuat = newIDHoadonXuat;
            objCTHDX_LT.IDSanpham = -1; //San pham la tien gio
            TimeSpan ts = (Convert.ToDateTime(dsOldBill.Tables[0].Rows[0]["GioKT"])).Subtract(Convert.ToDateTime(dsOldBill.Tables[0].Rows[0]["GioBD"]));
            objCTHDX_LT.Soluong = ts.Hours * 60 + ts.Minutes;
            objCTHDX_LT.Trangthai = true;
            objCTHDX_LT.Ghichu = "Phòng " + oldRoomName;
            id = new DataAccess().insertChitietHDXuat(objCTHDX_LT);
            if (id < 0)
            {
                MessageBox.Show("Lỗi Cơ sở dữ liệu!", "Lỗi");
                return;
            }
            //update new list
            DataRow aRow2 = newProduct.NewRow();
            aRow2["IDSanpham"] = -1;
            aRow2["IDChitietHDXuat"] = id;
            aRow2["Soluong"] = ts.Hours * 60 + ts.Minutes; ;

            aRow2["Gia"] = objCTHDX_LT.Gia;
            aRow2["Ghichu"] = objCTHDX_LT.Ghichu;
            aRow2["Trangthai"] = objCTHDX_LT.Trangthai;
            aRow2["Giam"] = objCTHDX_LT.Giam;
            aRow2["TenSanPham"] = "Tiền phòng cũ";
            aRow2["Transfer"] = 0;
            newProduct.Rows.Add(aRow2);

            //add tien phu thu
            objCTHDX_LT.Gia = Convert.ToInt32(dsOldBill.Tables[0].Rows[0]["Phuthu"]);
            objCTHDX_LT.Giam = 0;
            objCTHDX_LT.IDHoadonXuat = newIDHoadonXuat;
            objCTHDX_LT.IDSanpham = -2; //San pham la tien phu thu

            objCTHDX_LT.Soluong = 1;
            objCTHDX_LT.Trangthai = true;
            objCTHDX_LT.Ghichu = "Phòng " + oldRoomName;
            id = new DataAccess().insertChitietHDXuat(objCTHDX_LT);
            if (id < 0)
            {
                MessageBox.Show("Lỗi Cơ sở dữ liệu!", "Lỗi");
                return;
            }
            //update new list
            DataRow aRow1 = newProduct.NewRow();
            aRow1["IDSanpham"] = -2;
            aRow1["IDChitietHDXuat"] = id;
            aRow1["Soluong"] = 1;

            aRow1["Gia"] = objCTHDX_LT.Gia;
            aRow1["Ghichu"] = objCTHDX_LT.Ghichu;
            aRow1["Trangthai"] = objCTHDX_LT.Trangthai;
            aRow1["Giam"] = objCTHDX_LT.Giam;
            aRow1["TenSanPham"] = "Phụ thu phòng cũ";
            aRow1["Transfer"] = 0;
            newProduct.Rows.Add(aRow1);
            //delete old HD
            Hoadonxuat delHD = new Hoadonxuat();
            delHD.IDHoadonXuat = oldIDHoadonXuat;
            if (!(new DataAccess().deleteHoadonxuat(delHD)))
            {
                MessageBox.Show("Lỗi Cơ sở dữ liệu!", "Lỗi");
                return;
            }
            DataSet dsRoom = new DataAccess().getAllPhongAndLoaiPhong(oldRoom);
            Phong updateNewRoom = new Phong();
            updateNewRoom.IDPhong = oldRoom;
            updateNewRoom.IDLoaiPhong = Convert.ToInt32(dsRoom.Tables[0].Rows[0]["IDLoaiPhong"]);
            updateNewRoom.TenPhong = Convert.ToString(dsRoom.Tables[0].Rows[0]["TenPhong"]);
            updateNewRoom.Ghichu = Convert.ToString(dsRoom.Tables[0].Rows[0]["Ghichu"]);
            updateNewRoom.Trangthai = false;
            updateNewRoom.Congtac = Convert.ToInt32(dsRoom.Tables[0].Rows[0]["Congtac"]);
            bool b = new DataAccess().updatePhong(updateNewRoom);
            if (!b)
            {
                MessageBox.Show("Không cập nhật được trạng thái cho phòng " + updateNewRoom.TenPhong, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return;
            }
            oldIDHoadonXuat = -1;
            oldRoom = -1;
            updateReceiptSuco(newIDHoadonXuat, LoaiSuco.Chuyenphong, "Chuyển từ phòng " + oldRoomName);
            refreshProduct();
            actionType = 1;
            MessageBox.Show("Chuyển sản phẩm thành công", "Thông báo", MessageBoxButtons.OK);
        }
Ejemplo n.º 10
0
        void DevideRoom()
        {
            //check if whether transfer column diff zero
            if (newRoom < 0)
            {
                MessageBox.Show("Bạn hãy chọn phòng để chuyển sản phẩm!", "Thông báo", MessageBoxButtons.OK);
                return;
            }
            if (newIDHoadonXuat < 0)
            {
                if (MessageBox.Show("Bạn có chắc muốn mở phòng " + gridViewRoom.GetRowCellValue(gridViewRoom.FocusedRowHandle, "TenPhong").ToString() + " và chuyển sản phẩm?", "Thông báo", MessageBoxButtons.YesNo) == DialogResult.No)
                    return;
            }
            bool found = false;
            int i;
            for (i = 0; i < gridViewTransferedProductNew.RowCount; i++)
            {
                if (Convert.ToInt32(gridViewTransferedProductNew.GetRowCellValue(i, "Transfer")) != 0)
                {
                    gridViewTransferedProductNew.FocusedRowHandle = i;
                    found = true;
                    break;
                }
            }

            for (i = 0; i < gridViewBillProduct.RowCount; i++)
            {
                if (Convert.ToInt32(gridViewBillProduct.GetRowCellValue(i, "Transfer")) != 0)
                {
                    gridViewBillProduct.FocusedRowHandle = i;
                    found = true;
                    break;
                }
            }
            if (found)
            {
                if (MessageBox.Show("Sản phẩm chưa được chuyển hết (Cột 'Chuyển khác 0). Bạn có muốn tiếp tục cập nhật Hóa đơn?", "Thông báo", MessageBoxButtons.YesNo) == DialogResult.No)
                    return;
            }
            else
            {
                if (MessageBox.Show("Bạn có chắc muốn cập nhật Hóa đơn?", "Xác nhận", MessageBoxButtons.YesNo) == DialogResult.No)
                    return;
            }

            //update new HD
            if (newIDHoadonXuat >= 0)   // hoa don da duoc mo
            {
                for (i = 0; i < newProduct.Rows.Count; i++)
                {
                    ChitietHDXuat objCTHDX = new ChitietHDXuat();
                    objCTHDX.IDChitietHDXuat = Convert.ToInt32(newProduct.Rows[i]["IDChitietHDXuat"]);
                    objCTHDX.Gia = Convert.ToInt32(newProduct.Rows[i]["Gia"]);
                    objCTHDX.Giam = Convert.ToInt32(newProduct.Rows[i]["Giam"]);
                    objCTHDX.IDHoadonXuat = newIDHoadonXuat;
                    objCTHDX.IDSanpham = Convert.ToInt32(newProduct.Rows[i]["IDSanpham"]);
                    objCTHDX.Soluong = Convert.ToInt32(newProduct.Rows[i]["Soluong"]);
                    objCTHDX.Trangthai = Convert.ToBoolean(newProduct.Rows[i]["Trangthai"]) ;
                    objCTHDX.Ghichu = Convert.ToString(newProduct.Rows[i]["Ghichu"]) ;
                    if (objCTHDX.IDChitietHDXuat >= 0)
                    {
                        if (objCTHDX.Soluong <= 0)
                        {
                            if (!(new DataAccess().deleteChitietHDXuat(objCTHDX)))
                            {
                                MessageBox.Show("Lỗi Cơ sở dữ liệu!", "Lỗi");
                                return;
                            }
                        }
                        else
                        {

                            if (!(new DataAccess().updateChitietHDXuat(objCTHDX)))
                            {
                                MessageBox.Show("Lỗi Cơ sở dữ liệu!", "Lỗi");
                                return;
                            }
                        }
                    }
                    else
                    {
                        int id = new DataAccess().insertChitietHDXuat(objCTHDX);
                        if (id < 0)
                        {
                            MessageBox.Show("Lỗi Cơ sở dữ liệu!", "Lỗi");
                            return;
                        }
                        else
                            oldProduct.Rows[i]["IDChitietHDXuat"] = id;

                    }
                }
                actionType = 2; //tach phong dang hoat dong

            }
            else //open new bill
            {
                Hoadonxuat currentReceipt = new Hoadonxuat();
                currentReceipt.Giam = 0;
                currentReceipt.GioBD = DateTime.Now;
                currentReceipt.GioKT = DateTime.Now;
                currentReceipt.Nhacnho = false;
                currentReceipt.Tratruoc = 0;
                currentReceipt.IDPhong = newRoom;
                currentReceipt.Ngayxuat = DateTime.Now.Date;
                currentReceipt.Phuthu = 0;
                currentReceipt.TenHoadon = newRoomName + " " + DateTime.Now.ToString("dd/MM/yy-hh:mm");
                currentReceipt.Thue = 0;
                currentReceipt.Trangthai = 0;
                currentReceipt.Tanggio = 0;
                currentReceipt.Thue = 0;
                currentReceipt.Phuthu = 0;
                currentReceipt.IDNhanvien = Program.IDNhanvien;
                currentReceipt.IDNhanvienXuatHD = Program.IDNhanvien;
                currentReceipt.IDKhachhang = 0;
                currentReceipt.Ghichu = "Chuyen tu phong "+oldRoomName;
                currentReceipt.Suco = 1;
                //get current hour class
                TimeSpan ctime = DateTime.Now.TimeOfDay;

                DataSet hourclass = new DataAccess().getAllKhunggio();
                int idkhunggio = 0;
                for (i = 0; i < hourclass.Tables[0].Rows.Count; i++)
                {
                    string time = Convert.ToString(hourclass.Tables[0].Rows[i]["GioBD"]);
                    int sh = Convert.ToInt32(time.Substring(0, time.IndexOf(":")));
                    int sm = Convert.ToInt32(time.Substring(time.IndexOf(":") + 1));
                    string time1 = Convert.ToString(hourclass.Tables[0].Rows[i]["GioKT"]);
                    int eh = Convert.ToInt32(time1.Substring(0, time.IndexOf(":")));
                    int em = Convert.ToInt32(time1.Substring(time1.IndexOf(":") + 1));
                    if ((ctime.Hours < eh) || ((ctime.Hours == eh) && (ctime.Minutes <= em)))
                    {
                        if ((ctime.Hours > sh) || ((ctime.Hours == sh) && (ctime.Minutes > sm)))
                        {
                            idkhunggio = Convert.ToInt32(hourclass.Tables[0].Rows[i]["IDKhunggio"]);
                            break;
                        }
                    }
                }
                //get Room price

                DataSet ds1 = new DataAccess().getGiaLoaiPhongByIDLoaiPhongAndIDKhunggio(Convert.ToInt32(gridViewRoom.GetRowCellValue(gridViewRoom.FocusedRowHandle,"IDLoaiPhong")), idkhunggio);
                if (ds1.Tables[0].Rows.Count > 0)
                    currentReceipt.IDGiaLoaiphong = Convert.ToInt32(ds1.Tables[0].Rows[0]["Gia"]);
                else
                {
                    MessageBox.Show("Chưa có bảng giá cho phòng " + Convert.ToString(gridViewRoom.GetRowCellValue(gridViewRoom.FocusedRowHandle, "TenPhong")) +
                        " vào khung giờ này. Mở phòng không thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    return;
                }
                //KM
                //get khuyen mai
                //get khuyen mai tang gio cua phong
                DataSet dsKM = new DataAccess().getKhuyenmaiByIDLoaiPhong(newRoomGroup, DateTime.Now.Date);
                //Hoadonxuat currentReceipt = new Hoadonxuat();
                try
                {
                    currentReceipt.Giam = Convert.ToInt32(dsKM.Tables[0].Rows[0]["Giam"]);
                }
                catch (Exception ex)
                {
                    currentReceipt.Giam = 0;
                }
                newIDHoadonXuat = new DataAccess().insertHoadonxuat(currentReceipt);
                if (newIDHoadonXuat > -1)
                {
                    //wait for databa is update
                    //ContactAction(0xbf, Convert.ToInt32(ds.Tables[0].Rows[0]["Congtac"]));
                    //open electric cb
                    //MessageBox.Show("Mở Phòng " + Convert.ToInt32(gridViewRoom.GetRowCellValue(gridViewRoom.FocusedRowHandle, "TenPhong")) +
                    //    " thành công", "Thông báo");
                    //turnOnRoom.Enqueue(newRoom);
                        //update status for this Room
                        Phong updateRoom = new Phong();
                        updateRoom.IDPhong = newRoom;
                        updateRoom.IDLoaiPhong = Convert.ToInt32(gridViewRoom.GetRowCellValue(gridViewRoom.FocusedRowHandle,"IDLoaiPhong"));
                        updateRoom.TenPhong = Convert.ToString(gridViewRoom.GetRowCellValue(gridViewRoom.FocusedRowHandle,"TenPhong"));
                        updateRoom.Ghichu = Convert.ToString(gridViewRoom.GetRowCellValue(gridViewRoom.FocusedRowHandle,"Ghichu"));
                        updateRoom.Trangthai = true;
                        updateRoom.Congtac = Convert.ToInt32(gridViewRoom.GetRowCellValue(gridViewRoom.FocusedRowHandle, colCB));
                        bool a = new DataAccess().updatePhong(updateRoom);
                        if (!a)
                        {
                            MessageBox.Show("Không cập nhật được trạng thái cho phòng " + updateRoom.TenPhong, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                            return;
                        }
                        //update current status gridview
                        gridViewRoom.SetFocusedRowCellValue(colRoomStatus, true);
                    //add chitietHDxuat
                        for (i = 0; i < newProduct.Rows.Count; i++)
                        {
                            ChitietHDXuat objCTHDX = new ChitietHDXuat();
                            objCTHDX.IDChitietHDXuat = -1;
                            objCTHDX.Gia = Convert.ToInt32(newProduct.Rows[i]["Gia"]);
                            objCTHDX.Giam = Convert.ToInt32(newProduct.Rows[i]["Giam"]);
                            objCTHDX.IDHoadonXuat = newIDHoadonXuat;
                            objCTHDX.IDSanpham = Convert.ToInt32(newProduct.Rows[i]["IDSanpham"]);
                            objCTHDX.Soluong = Convert.ToInt32(newProduct.Rows[i]["Soluong"]);
                            objCTHDX.Trangthai = Convert.ToBoolean(newProduct.Rows[i]["Trangthai"]);
                            objCTHDX.Ghichu = Convert.ToString(newProduct.Rows[i]["Ghichu"]);

                            if (objCTHDX.Soluong > 0)
                            {

                                int id = new DataAccess().insertChitietHDXuat(objCTHDX);
                                if (id < 0)
                                {
                                    MessageBox.Show("Lỗi Cơ sở dữ liệu!", "Lỗi");
                                    return;
                                }
                                else
                                    newProduct.Rows[i]["IDChitietHDXuat"] = id;
                            }
                        }
                        actionType = 3;//tahc phong va mo them phong moi
                }

                else
                {
                    MessageBox.Show("Mở Phòng " + Convert.ToInt32(gridViewRoom.GetRowCellValue(gridViewRoom.FocusedRowHandle, "TenPhong")) +
                        " không thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    return;
                }
            }
            //update old chi tiet hoa don
            for (i = 0; i < oldProduct.Rows.Count; i++)
            {
                ChitietHDXuat objCTHDX = new ChitietHDXuat();
                objCTHDX.IDChitietHDXuat = Convert.ToInt32(oldProduct.Rows[i]["IDChitietHDXuat"]);
                if (Convert.ToInt32(oldProduct.Rows[i]["Soluong"]) <= 0)
                {
                    // chuyen het san pham cua 1 row qua phong moi
                    // delete san pham nay khoi chi tiet hoa don xuat
                    if (!(new DataAccess().deleteChitietHDXuat(objCTHDX)))
                    {
                        MessageBox.Show("Lỗi Cơ sở dữ liệu!", "Lỗi");
                        return;
                    }
                }
                else
                {
                    // cap nhat lai chi tiet hoa don xuat
                    objCTHDX.Gia = Convert.ToInt32(oldProduct.Rows[i]["Gia"]);
                    objCTHDX.Giam = Convert.ToInt32(oldProduct.Rows[i]["Giam"]);
                    objCTHDX.IDHoadonXuat = oldIDHoadonXuat;
                    objCTHDX.IDSanpham = Convert.ToInt32(oldProduct.Rows[i]["IDSanpham"]);
                    objCTHDX.Soluong = Convert.ToInt32(oldProduct.Rows[i]["Soluong"]);
                    objCTHDX.Trangthai = Convert.ToBoolean(oldProduct.Rows[i]["Trangthai"]);
                    objCTHDX.Ghichu = Convert.ToString(oldProduct.Rows[i]["Ghichu"]);
                    if (!(new DataAccess().updateChitietHDXuat(objCTHDX)))
                    {
                        MessageBox.Show("Lỗi Cơ sở dữ liệu!", "Lỗi");
                        return;
                    }
                }
            }
            //update su co cho receipt cu
            updateReceiptSuco(oldIDHoadonXuat,LoaiSuco.Tachphong,"Tách sang phòng "+ newRoomName);
            updateReceiptSuco(newIDHoadonXuat,LoaiSuco.Tachphong, "Tách từ phòng " + oldRoomName);
            MessageBox.Show("Chuyển sản phẩm thành công", "Thông báo", MessageBoxButtons.OK);
        }
Ejemplo n.º 11
0
 public bool updateChitietHDXuat(ChitietHDXuat objChitietHDXuat)
 {
     return new ChitietHDXuatService().updateChitietHDXuat(objChitietHDXuat);
 }
Ejemplo n.º 12
0
 public int insertChitietHDXuat(ChitietHDXuat objChitietHDXuat)
 {
     return new ChitietHDXuatService().insertChitietHDXuat(objChitietHDXuat);
 }
Ejemplo n.º 13
0
 public bool deleteChitietHDXuat(ChitietHDXuat objChitietHDXuat)
 {
     return new ChitietHDXuatService().deleteChitietHDXuat(objChitietHDXuat);
 }