Exemplo n.º 1
0
        public int insertHoadonxuat(BKIT.Entities.Hoadonxuat objHoadonxuat)
        {
            Database db         = DatabaseFactory.CreateDatabase();
            string   sqlCommand = "INSERT INTO Hoadonxuat(IDHoadonXuat,TenHoadon,Ngayxuat,IDNhanvien,IDNhanvienXuatHD,IDPhong,GioBD,GioKT,Tratruoc,Phuthu,Thue,Giam,Ghichu,IDGiaLoaiphong,Trangthai, Tanggio, IDKhachhang, Nhacnho, Suco) " +
                                  "VALUES (@idhoadonxuat,@tenhoadon,@ngayxuat,@idnhanvien,@idnhanvienxuathd,@idphong,@giobd,@giokt,@tratruoc,@phuthu,@thue,@giam,@ghichu,@idgialoaiphong,@trangthai,@tanggio,@idkhachhang,@nhacnho,@suco);";
            //string sqlCommand = "INSERT INTO Hoadonxuat(IDHoadonXuat,Ngayxuat,IDNhanvien,IDPhong,GioBD,Phuthu,Thue,Giam,Ghichu,IDGiaLoaiphong) " +
            //    "VALUES (@idhoadonxuat,@ngayxuat,@idnhanvien,@idphong,@giobd,@phuthu,@thue,@giam,@ghichu,@idgialoaiphong)";
            DbCommand dbCommand = db.GetSqlStringCommand(sqlCommand);

            try
            {
                int ID = GetNextAVailableID();
                objHoadonxuat.IDHoadonXuat = ID;
                db.AddInParameter(dbCommand, "idhoadonxuat", DbType.Int32, objHoadonxuat.IDHoadonXuat);
                db.AddInParameter(dbCommand, "tenhoadon", DbType.String, objHoadonxuat.TenHoadon);
                db.AddInParameter(dbCommand, "ngayxuat", DbType.DateTime, objHoadonxuat.Ngayxuat);
                db.AddInParameter(dbCommand, "idnhanvien", DbType.Int32, objHoadonxuat.IDNhanvien);
                db.AddInParameter(dbCommand, "idnhanvienxuathd", DbType.Int32, objHoadonxuat.IDNhanvienXuatHD);
                db.AddInParameter(dbCommand, "idphong", DbType.Int32, objHoadonxuat.IDPhong);
                db.AddInParameter(dbCommand, "giobd", DbType.DateTime, new DateTime(objHoadonxuat.GioBD.Year, objHoadonxuat.GioBD.Month,
                                                                                    objHoadonxuat.GioBD.Day, objHoadonxuat.GioBD.Hour, objHoadonxuat.GioBD.Minute, objHoadonxuat.GioBD.Second));
                db.AddInParameter(dbCommand, "giokt", DbType.DateTime, new DateTime(objHoadonxuat.GioKT.Year, objHoadonxuat.GioKT.Month,
                                                                                    objHoadonxuat.GioKT.Day, objHoadonxuat.GioKT.Hour, objHoadonxuat.GioKT.Minute, objHoadonxuat.GioKT.Second));
                db.AddInParameter(dbCommand, "tratruoc", DbType.Int32, objHoadonxuat.Tratruoc);
                db.AddInParameter(dbCommand, "phuthu", DbType.Int32, objHoadonxuat.Phuthu);
                db.AddInParameter(dbCommand, "thue", DbType.Int32, objHoadonxuat.Thue);
                db.AddInParameter(dbCommand, "giam", DbType.Int32, objHoadonxuat.Giam);
                db.AddInParameter(dbCommand, "ghichu", DbType.String, objHoadonxuat.Ghichu);
                db.AddInParameter(dbCommand, "idgialoaiphong", DbType.Int32, objHoadonxuat.IDGiaLoaiphong);
                db.AddInParameter(dbCommand, "trangthai", DbType.Int32, objHoadonxuat.Trangthai);
                db.AddInParameter(dbCommand, "tanggio", DbType.Int32, objHoadonxuat.Tanggio);
                db.AddInParameter(dbCommand, "idkhachhang", DbType.Int32, objHoadonxuat.IDKhachhang);
                db.AddInParameter(dbCommand, "nhacnho", DbType.Boolean, objHoadonxuat.Nhacnho);
                db.AddInParameter(dbCommand, "suco", DbType.Int32, objHoadonxuat.Suco);


                db.ExecuteNonQuery(dbCommand);
                dbCommand.Connection.Close();
                return(ID);
            }
            catch
            {
                dbCommand.Connection.Close();
                return(-1);
            }
        }
Exemplo n.º 2
0
        public bool deleteHoadonxuat(BKIT.Entities.Hoadonxuat objHoadonxuat)
        {
            Database  db         = DatabaseFactory.CreateDatabase();
            string    sqlCommand = "DELETE FROM Hoadonxuat WHERE IDHoadonXuat = @idhoadonxuat";
            DbCommand dbCommand  = db.GetSqlStringCommand(sqlCommand);

            try
            {
                db.AddInParameter(dbCommand, "idhoadonxuat", DbType.Int32, objHoadonxuat.IDHoadonXuat);
                db.ExecuteNonQuery(dbCommand);
                dbCommand.Connection.Close();
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Exemplo n.º 3
0
        public bool updateHoadonxuat(BKIT.Entities.Hoadonxuat objHoadonxuat)
        {
            Database db         = DatabaseFactory.CreateDatabase();
            string   sqlCommand = "UPDATE Hoadonxuat SET TenHoadon = @tenhoadon, Ngayxuat = @ngayxuat, IDNhanvien = @idnhanvien,IDNhanvienXuatHD = @idnhanvienxuathd, IDPhong = @idphong, GioBD = @giobd, GioKT = @giokt, Tratruoc = @tratruoc, Phuthu = @phuthu, Thue = @thue, Giam = @giam, Ghichu = @ghichu, IDGiaLoaiphong = @idgialoaiphong, Trangthai = @trangthai, Tanggio = @tanggio, IDKhachhang = @idkhachhang, Nhacnho = @nhacnho, Suco = @suco  " +
                                  "WHERE IDHoadonXuat = @idhoadonxuat";
            DbCommand dbCommand = db.GetSqlStringCommand(sqlCommand);

            try
            {
                db.AddInParameter(dbCommand, "tenhoadon", DbType.String, objHoadonxuat.TenHoadon);
                db.AddInParameter(dbCommand, "ngayxuat", DbType.DateTime, objHoadonxuat.Ngayxuat);
                db.AddInParameter(dbCommand, "idnhanvien", DbType.Int32, objHoadonxuat.IDNhanvien);
                db.AddInParameter(dbCommand, "idnhanvienxuathd", DbType.Int32, objHoadonxuat.IDNhanvienXuatHD);
                db.AddInParameter(dbCommand, "idphong", DbType.Int32, objHoadonxuat.IDPhong);
                db.AddInParameter(dbCommand, "giobd", DbType.DateTime, new DateTime(objHoadonxuat.GioBD.Year, objHoadonxuat.GioBD.Month,
                                                                                    objHoadonxuat.GioBD.Day, objHoadonxuat.GioBD.Hour, objHoadonxuat.GioBD.Minute, objHoadonxuat.GioBD.Second));
                db.AddInParameter(dbCommand, "giokt", DbType.DateTime, new DateTime(objHoadonxuat.GioKT.Year, objHoadonxuat.GioKT.Month,
                                                                                    objHoadonxuat.GioKT.Day, objHoadonxuat.GioKT.Hour, objHoadonxuat.GioKT.Minute, objHoadonxuat.GioKT.Second));
                db.AddInParameter(dbCommand, "tratruoc", DbType.Int32, objHoadonxuat.Tratruoc);
                db.AddInParameter(dbCommand, "phuthu", DbType.Int32, objHoadonxuat.Phuthu);
                db.AddInParameter(dbCommand, "thue", DbType.Int32, objHoadonxuat.Thue);
                db.AddInParameter(dbCommand, "giam", DbType.Int32, objHoadonxuat.Giam);
                db.AddInParameter(dbCommand, "ghichu", DbType.String, objHoadonxuat.Ghichu);

                db.AddInParameter(dbCommand, "idgialoaiphong", DbType.Int32, objHoadonxuat.IDGiaLoaiphong);
                db.AddInParameter(dbCommand, "trangthai", DbType.Int32, objHoadonxuat.Trangthai);
                db.AddInParameter(dbCommand, "tanggio", DbType.Int32, objHoadonxuat.Tanggio);
                db.AddInParameter(dbCommand, "idkhachhang", DbType.Int32, objHoadonxuat.IDKhachhang);
                db.AddInParameter(dbCommand, "nhacnho", DbType.Boolean, objHoadonxuat.Nhacnho);
                db.AddInParameter(dbCommand, "suco", DbType.Int32, objHoadonxuat.Suco);
                db.AddInParameter(dbCommand, "idhoadonxuat", DbType.Int32, objHoadonxuat.IDHoadonXuat);
                db.ExecuteNonQuery(dbCommand);
                dbCommand.Connection.Close();
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Exemplo n.º 4
0
        private void gridViewDMHD_CellValueChanging(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
        {
            if (e.RowHandle >= 0)
            {
                if (e.Column == colDeleteDMHD)
                {
                    if (Program.userLevel != Level.Admin)
                    {
                        MessageBox.Show("Liên hệ quản lý để xóa Hóa đơn này", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    Hoadonxuat objKMSP = new Hoadonxuat();
                    objKMSP.IDHoadonXuat = Convert.ToInt32(gridViewDMHD.GetRowCellValue(e.RowHandle, "IDHoadonXuat"));

                    if (Convert.ToBoolean(gridViewDMHD.GetRowCellValue(e.RowHandle, colDeleteDMHD)) == true)
                    {
                        //warnning
                        if (MessageBox.Show(this, "Bạn có muốn xóa hóa đơn này không?", "Cảnh báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                        {
                            if (new DataAccess().deleteChitietHDXuatOfHDXuat(objKMSP) == true)
                            {
                                if (new DataAccess().deleteHoadonxuat(objKMSP) == true)
                                {
                                    ((frmMain)(this.MdiParent)).setStatus("Xóa khuyến mãi thành công");
                                    gridViewDMHD.DeleteRow(e.RowHandle);
                                    iCurrentReceiptID = Convert.ToInt32(gridViewDMHD.GetRowCellValue(gridViewDMHD.FocusedRowHandle, "IDHoadonXuat"));
                                    updateReceiptGrid(iCurrentReceiptID);
                                }
                                else
                                {
                                    MessageBox.Show(this, "Xóa hóa đơn không thành công", "Thông báo lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                    ((frmMain)(this.MdiParent)).setStatus("");
                                }
                            }
                            else
                            {
                                MessageBox.Show(this, "Xóa sản phẩm 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
                            gridViewDMHD.SetRowCellValue(e.RowHandle, colDeleteDMHD, true);
                        }
                    }
                }
            }
        }
Exemplo n.º 5
0
 public frmReceiptProduct()
 {
     InitializeComponent();
     currentReceipt = new Hoadonxuat();
 }
Exemplo n.º 6
0
 public bool deleteChitietHDXuatOfHDXuat(BKIT.Entities.Hoadonxuat objHDXuat)
 {
     return(new ChitietHDXuatService().deleteChitietHDXuatOfHDXuat(objHDXuat));
 }
Exemplo n.º 7
0
 public frmReceipt()
 {
     InitializeComponent();
     currentReceipt = new Hoadonxuat();
     dateReceipt.Format = DateTimePickerFormat.Custom;
     dateReceipt.CustomFormat = "dd/MM/yyyy";
     InitCOMPort();
     listCBtoTurnOff = new List<CBReq>();
 }
Exemplo n.º 8
0
 bool updateReceiptSuco(int IDHoaDon)
 {
     DataSet dsBill = new DataAccess().getHoadonxuatByIDHoadonXuat(IDHoaDon);
     if (dsBill == null)
         return false;
     if (dsBill.Tables[0].Rows.Count <= 0)
         return false;
     Hoadonxuat tmpReceipt = new Hoadonxuat();
     tmpReceipt.Suco = 1;
     tmpReceipt.IDNhanvien = Convert.ToInt32(dsBill.Tables[0].Rows[0]["IDNhanvien"]);
     tmpReceipt.IDPhong = Convert.ToInt32(dsBill.Tables[0].Rows[0]["IDPhong"]);
     tmpReceipt.Giam = Convert.ToInt32(dsBill.Tables[0].Rows[0]["Giam"]);
     tmpReceipt.Thue = Convert.ToInt32(dsBill.Tables[0].Rows[0]["Thue"]);
     tmpReceipt.Phuthu = Convert.ToInt32(dsBill.Tables[0].Rows[0]["Phuthu"]);
     tmpReceipt.IDGiaLoaiphong = Convert.ToInt32(dsBill.Tables[0].Rows[0]["IDGiaLoaiphong"]);
     tmpReceipt.Ngayxuat = Convert.ToDateTime(dsBill.Tables[0].Rows[0]["Ngayxuat"]);
     tmpReceipt.GioBD = Convert.ToDateTime(dsBill.Tables[0].Rows[0]["GioBD"]);
     tmpReceipt.GioKT = Convert.ToDateTime(dsBill.Tables[0].Rows[0]["GioKT"]);
     tmpReceipt.Tratruoc = Convert.ToInt32(dsBill.Tables[0].Rows[0]["Tratruoc"]);
     tmpReceipt.Ghichu = Convert.ToString(dsBill.Tables[0].Rows[0]["Ghichu"]);
     tmpReceipt.Trangthai = Convert.ToInt32(dsBill.Tables[0].Rows[0]["Trangthai"]);
     tmpReceipt.IDHoadonXuat = IDHoaDon;
     tmpReceipt.IDNhanvienXuatHD = Convert.ToInt32(dsBill.Tables[0].Rows[0]["IDNhanvienXuatHD"]);
     tmpReceipt.IDNhanvien = Convert.ToInt32(dsBill.Tables[0].Rows[0]["IDNhanvien"]);
     tmpReceipt.Nhacnho = Convert.ToBoolean(dsBill.Tables[0].Rows[0]["Nhacnho"]);
     tmpReceipt.IDKhachhang = Convert.ToInt32(dsBill.Tables[0].Rows[0]["IDKhachhang"]);
     if (new DataAccess().updateHoadonxuat(tmpReceipt))
         return true;
     return false;
 }
Exemplo n.º 9
0
        int OpenNewReceipt(int IDPhong)
        {
            int i;
            Phong room = new DataAccess().getPhongByID(IDPhong);
            if (room.Trangthai)
            {
                MessageBox.Show("Phòng đang hoạt động. Đóng phòng để mở hóa đơn mới", "Thông báo");
                return -1;
            }
            Hoadonxuat currentReceipt = new Hoadonxuat();
            currentReceipt.Giam = 0;
            currentReceipt.GioBD = DateTime.Now;
            currentReceipt.GioKT = DateTime.Now;
            currentReceipt.Nhacnho = false;
            currentReceipt.Tratruoc = 0;
            currentReceipt.IDPhong = IDPhong;
            currentReceipt.Ngayxuat = DateTime.Now.Date;
            currentReceipt.Phuthu = 0;
            currentReceipt.TenHoadon = room.TenPhong + " " + DateTime.Now.ToString("dd/MM/yy-hh:mm");
            currentReceipt.Thue = 0;
            currentReceipt.Trangthai = 0;
            currentReceipt.Thue = 0;
            currentReceipt.Phuthu = 0;
            currentReceipt.IDNhanvien = Program.IDNhanvien;
            currentReceipt.IDNhanvienXuatHD = Program.IDNhanvien;
            currentReceipt.IDKhachhang = 0;
            currentReceipt.Ghichu = "";
            currentReceipt.Suco = 0;
            //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(room.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 " + room.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 -1;
            }
            //KM
            //get khuyen mai
            //get khuyen mai tang gio cua phong
            DataSet dsKM = new DataAccess().getKhuyenmaiByIDLoaiPhong(room.IDLoaiPhong, DateTime.Now.Date);
            //Hoadonxuat currentReceipt = new Hoadonxuat();
            try
            {
                currentReceipt.Giam = Convert.ToInt32(dsKM.Tables[0].Rows[0]["Giam"]);
            }
            catch (Exception ex)
            {
                currentReceipt.Giam = 0;
            }
            int 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
                room.Trangthai = true;
                bool a = new DataAccess().updatePhong(room);
                if (!a)
                {
                    MessageBox.Show("Không cập nhật được trạng thái cho phòng " + room.TenPhong, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    return newIDHoadonXuat;
                }

                //Add SPBD
                DataSet dsSPBD = new DataAccess().getAllSPBandauIDLoaiPhong(room.IDLoaiPhong);
                for (i = 0; i < dsSPBD.Tables[0].Rows.Count; i++)
                {
                    int IDSanPham = Convert.ToInt32(dsSPBD.Tables[0].Rows[i]["IDSanPham"]);
                    int IDLoaiSP = Convert.ToInt32(dsSPBD.Tables[0].Rows[i]["IDNhomSP"]);
                    string TenSanPham = Convert.ToString(dsSPBD.Tables[0].Rows[i]["TenSanPham"]);
                    int num = Convert.ToInt32(dsSPBD.Tables[0].Rows[i]["Soluong"]);
                    AddSPBD(newIDHoadonXuat, IDLoaiSP, IDSanPham, TenSanPham, num);
                }
                return newIDHoadonXuat;
            }
            else
                return -1;
        }
Exemplo n.º 10
0
 public Hoadonxuat getHoadonxuatByID(int ID)
 {
     Database db = DatabaseFactory.CreateDatabase();
     Hoadonxuat rs = new Hoadonxuat();
     string sqlCommand = "SELECT * FROM Hoadonxuat WHERE IDHoadonXuat = @id ";
     try
     {
         DbCommand dbCommand = db.GetSqlStringCommand(sqlCommand);
         db.AddInParameter(dbCommand, "id", DbType.Int32, ID);
         DataSet ds = db.ExecuteDataSet(dbCommand);
         dbCommand.Connection.Close();
         if (ds.Tables[0].Rows.Count <= 0)
             return null;
         //get current Bill
         rs.IDNhanvien = Convert.ToInt32(ds.Tables[0].Rows[0]["IDNhanvien"]);
         rs.IDPhong = Convert.ToInt32(ds.Tables[0].Rows[0]["IDPhong"]);
         rs.Giam = Convert.ToInt32(ds.Tables[0].Rows[0]["Giam"]);
         rs.Thue = Convert.ToInt32(ds.Tables[0].Rows[0]["Thue"]);
         rs.Phuthu = Convert.ToInt32(ds.Tables[0].Rows[0]["Phuthu"]);
         rs.IDGiaLoaiphong = Convert.ToInt32(ds.Tables[0].Rows[0]["IDGiaLoaiphong"]);
         rs.Ngayxuat = Convert.ToDateTime(ds.Tables[0].Rows[0]["Ngayxuat"]);
         rs.GioBD = Convert.ToDateTime(ds.Tables[0].Rows[0]["GioBD"]);
         rs.GioKT = Convert.ToDateTime(ds.Tables[0].Rows[0]["GioKT"]);
         rs.Tratruoc = Convert.ToInt32(ds.Tables[0].Rows[0]["Tratruoc"]);
         rs.Ghichu = Convert.ToString(ds.Tables[0].Rows[0]["Ghichu"]);
         rs.Trangthai = Convert.ToInt32(ds.Tables[0].Rows[0]["Trangthai"]);
         rs.IDHoadonXuat = ID;
         rs.IDNhanvienXuatHD = Convert.ToInt32(ds.Tables[0].Rows[0]["IDNhanvienXuatHD"]);
         rs.Nhacnho = Convert.ToBoolean(ds.Tables[0].Rows[0]["Nhacnho"]);
         rs.IDKhachhang = Convert.ToInt32(ds.Tables[0].Rows[0]["IDKhachhang"]);
         rs.Tanggio = Convert.ToInt32(ds.Tables[0].Rows[0]["Tanggio"]);
         rs.Suco = Convert.ToInt32(ds.Tables[0].Rows[0]["Suco"]);
         rs.TenHoadon = Convert.ToString(ds.Tables[0].Rows[0]["TenHoadon"]);
         return rs;
     }
     catch
     {
         return null;
     }
 }
Exemplo n.º 11
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);
        }
Exemplo n.º 12
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);
        }
Exemplo n.º 13
0
        private void Start()
        {
            //open or close selected room
            //first search if selected room is available
            DataSet ds = new DataAccess().getPhongByIDPhong(iCurrentFreeRoomID);

            if (ds.Tables[0].Rows.Count > 0)
            {
                iCurrentFreeRoomGroupID = Convert.ToInt32(ds.Tables[0].Rows[0]["IDLoaiphong"]);
                Hoadonxuat currentReceipt = new Hoadonxuat();
                    //in case of the room is available
                    //ask to open room and create new receipt for this room
                    if (MessageBox.Show("Bạn có muốn mở phòng " + Convert.ToString(gridViewRoom.GetRowCellValue(gridViewRoom.FocusedRowHandle, "TenPhong")) + "?", "Thông báo mở phòng", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.Cancel)
                        return;
                    //get khuyen mai tang gio cua phong
                    DataSet dsKM = new DataAccess().getKhuyenmaiByIDLoaiPhong(iCurrentFreeRoomGroupID, DateTime.Now.Date);
                    //Hoadonxuat currentReceipt = new Hoadonxuat();
                    try
                    {
                        currentReceipt.Giam = Convert.ToInt32(dsKM.Tables[0].Rows[0]["Giam"]);
                    }
                    catch (Exception ex)
                    {
                        currentReceipt.Giam = 0;
                    }
                    currentReceipt.TenHoadon = Convert.ToString(ds.Tables[0].Rows[0]["TenPhong"]) + " " + DateTime.Now.ToString("dd/MM/yy-hh:mm");
                    currentReceipt.GioBD = DateTime.Now;
                    currentReceipt.GioKT = DateTime.Now;
                    currentReceipt.Tratruoc = 0;
                    currentReceipt.Nhacnho = false;
                    currentReceipt.IDPhong = iCurrentFreeRoomID;
                    currentReceipt.Ngayxuat = DateTime.Now.Date;
                    currentReceipt.Phuthu = 0;
                    currentReceipt.Thue = 0;
                    currentReceipt.Trangthai = 0;
                    currentReceipt.Thue = 0;
                    currentReceipt.Phuthu = 0;
                    currentReceipt.IDNhanvien = 0;
                    currentReceipt.IDNhanvienXuatHD = Program.IDNhanvien;
                    currentReceipt.IDKhachhang = 0;
                    currentReceipt.Ghichu = "";
                    currentReceipt.Suco = 0;
                    //get current hour class
                    TimeSpan ctime = DateTime.Now.TimeOfDay;
                    //TimeSpan stime = new TimeSpan();
                    //TimeSpan etime = new TimeSpan();
                    DataSet hourclass = new DataAccess().getAllKhunggio();
                    int idkhunggio = 0;
                    int i;
                    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(iCurrentFreeRoomGroupID, idkhunggio);
                    if (ds1.Tables[0].Rows.Count > 0)
                        currentReceipt.IDGiaLoaiphong = Convert.ToInt32(ds1.Tables[0].Rows[0]["IDGiaLoaiphong"]);
                    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;
                    }
                    int res = new DataAccess().insertHoadonxuat(currentReceipt);
                    if (res > -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");
                        iCurrentReceiptID = res;
                        iEffectedRoomID = iCurrentFreeRoomID;
                        //add starting product for the room
                        DataSet dsSPBD = new DataAccess().getAllSPBandauIDLoaiPhong(Convert.ToInt32(ds.Tables[0].Rows[0]["IDLoaiPhong"]));
                        for (i = 0; i < dsSPBD.Tables[0].Rows.Count; i++)
                        {
                            int IDSanPham = Convert.ToInt32(dsSPBD.Tables[0].Rows[i]["IDSanPham"]);
                            int IDLoaiSP = Convert.ToInt32(dsSPBD.Tables[0].Rows[i]["IDNhomSP"]);
                            string TenSanPham = Convert.ToString(dsSPBD.Tables[0].Rows[i]["TenSanPham"]);
                            int num = Convert.ToInt32(dsSPBD.Tables[0].Rows[i]["Soluong"]);
                            AddSPBD(res, IDLoaiSP, IDSanPham, TenSanPham, num);
                        }
                        bNewReceipt = true;
                        //update Hoadon group display
                               //update status for this Room
                            Phong updateRoom = new Phong();
                            updateRoom.IDPhong = Convert.ToInt32(ds.Tables[0].Rows[0]["IDPhong"]);
                            updateRoom.IDLoaiPhong = Convert.ToInt32(ds.Tables[0].Rows[0]["IDLoaiPhong"]);
                            updateRoom.TenPhong = Convert.ToString(ds.Tables[0].Rows[0]["TenPhong"]);
                            updateRoom.Ghichu = Convert.ToString(ds.Tables[0].Rows[0]["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
                            initDataGrid();

                        //return ro main
                        this.Hide();
                        //btnStart.Image = Karaoke.Properties.Resources.Status_user_busy_icon1;
                    }
                    else
                    {
                        MessageBox.Show("Mở Hóa đơn mới " + Convert.ToInt32(gridViewRoom.GetRowCellValue(gridViewRoom.FocusedRowHandle, "TenPhong")) +
                            " không thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    }

            }
        }
Exemplo n.º 14
0
 public bool updateHoadonxuat(Hoadonxuat objHoadonxuat)
 {
     return new HoadonxuatService().updateHoadonxuat(objHoadonxuat);
 }
Exemplo n.º 15
0
 public int insertHoadonxuat(Hoadonxuat objHoadonxuat)
 {
     return new HoadonxuatService().insertHoadonxuat(objHoadonxuat);
 }
Exemplo n.º 16
0
 public bool deleteHoadonxuat(Hoadonxuat objHoadonxuat)
 {
     return new HoadonxuatService().deleteHoadonxuat(objHoadonxuat);
 }