public int insertPhong(BKIT.Entities.Phong objPhong)
        {
            Database db         = DatabaseFactory.CreateDatabase();
            string   sqlCommand = "INSERT INTO Phong(IDPhong,TenPhong,IDLoaiPhong,Congtac,Trangthai,Ghichu) " +
                                  "VALUES (@idphong,@tenphong,@idloaiphong,@congtac,@trangthai,@ghichu)";
            DbCommand dbCommand = db.GetSqlStringCommand(sqlCommand);

            try
            {
                int ID = GetNextAVailableID();
                objPhong.IDPhong = ID;
                db.AddInParameter(dbCommand, "idphong", DbType.Int32, objPhong.IDPhong);
                db.AddInParameter(dbCommand, "tenphong", DbType.String, objPhong.TenPhong);
                db.AddInParameter(dbCommand, "idloaiphong", DbType.Int32, objPhong.IDLoaiPhong);
                db.AddInParameter(dbCommand, "congtac", DbType.Int32, objPhong.Congtac);
                db.AddInParameter(dbCommand, "trangthai", DbType.Boolean, objPhong.Trangthai);
                db.AddInParameter(dbCommand, "ghichu", DbType.String, objPhong.Ghichu);
                db.ExecuteNonQuery(dbCommand);
                dbCommand.Connection.Close();
                return(ID);
            }
            catch
            {
                dbCommand.Connection.Close();
                return(-1);
            }
        }
        public bool deletePhong(BKIT.Entities.Phong objPhong)
        {
            Database  db         = DatabaseFactory.CreateDatabase();
            string    sqlCommand = "DELETE FROM Phong WHERE IDPhong = @idphong";
            DbCommand dbCommand  = db.GetSqlStringCommand(sqlCommand);

            try
            {
                db.AddInParameter(dbCommand, "idphong", DbType.Int32, objPhong.IDPhong);
                db.ExecuteNonQuery(dbCommand);
                dbCommand.Connection.Close();
                return(true);
            }
            catch
            {
                return(false);
            }
        }
        public bool updatePhong(BKIT.Entities.Phong objPhong)
        {
            Database db         = DatabaseFactory.CreateDatabase();
            string   sqlCommand = "UPDATE Phong SET TenPhong = @tenphong, IDLoaiPhong = @idloaiphong, Congtac = @congtac, Trangthai = @trangthai, Ghichu = @ghichu " +
                                  "WHERE IDPhong = @idphong";
            DbCommand dbCommand = db.GetSqlStringCommand(sqlCommand);

            try
            {
                db.AddInParameter(dbCommand, "tenphong", DbType.String, objPhong.TenPhong);
                db.AddInParameter(dbCommand, "idloaiphong", DbType.Int32, objPhong.IDLoaiPhong);
                db.AddInParameter(dbCommand, "congtac", DbType.Int32, objPhong.Congtac);
                db.AddInParameter(dbCommand, "trangthai", DbType.Boolean, objPhong.Trangthai);
                db.AddInParameter(dbCommand, "ghichu", DbType.String, objPhong.Ghichu);
                db.AddInParameter(dbCommand, "idphong", DbType.Int32, objPhong.IDPhong);
                db.ExecuteNonQuery(dbCommand);
                dbCommand.Connection.Close();
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Beispiel #4
0
        private void gridViewPhong_RowUpdated(object sender, DevExpress.XtraGrid.Views.Base.RowObjectEventArgs e)
        {
            DataRowView aRowView = (DataRowView)(e.Row);
            DataRow aRow = aRowView.Row;
            if (aRow.RowState == DataRowState.Added)
            {
                //insert command here
                Phong objPhong = new Phong();
                objPhong.TenPhong = Convert.ToString(aRow["TenPhong"]);
                if (objPhong.TenPhong == "")
                {
                    gridControlPhong.DataSource = new DataAccess().getPhongByIDLoaiPhong(curIDLoaiPhong).Tables[0];
                    MessageBox.Show(this, "Không có tên phòng", "Thông báo lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                try
                {
                    Int32.Parse(Convert.ToString(aRow["Congtac"]));
                    if (Convert.ToString(aRow["Congtac"]) == "")
                    {
                        gridControlPhong.DataSource = new DataAccess().getPhongByIDLoaiPhong(curIDLoaiPhong).Tables[0];
                        MessageBox.Show(this, "Không nhập công tắc cho phòng", "Thông báo lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    objPhong.Congtac = Convert.ToInt32(aRow["Congtac"]);
                    if (new DataAccess().IsCongtacExisted(objPhong.Congtac))
                    {
                        gridControlPhong.DataSource = new DataAccess().getPhongByIDLoaiPhong(curIDLoaiPhong).Tables[0];
                        MessageBox.Show(this, "Công tắc này đã có, yêu cầu nhập số khác!", "Thông báo lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
                catch
                {
                    gridControlPhong.DataSource = new DataAccess().getPhongByIDLoaiPhong(curIDLoaiPhong).Tables[0];
                    MessageBox.Show(this, "Công tắc không phải là số", "Thông báo lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                objPhong.IDLoaiPhong = curIDLoaiPhong;
                objPhong.Ghichu = Convert.ToString(aRow["Ghichu"]);

                if (new DataAccess().insertPhong(objPhong) >= 0)
                {
                    gridControlPhong.DataSource = new DataAccess().getPhongByIDLoaiPhong(curIDLoaiPhong).Tables[0];
                    ((frmMain)(this.MdiParent)).setStatus("Thêm mới Nhóm sản phẩm thành công");
                }
                else
                {
                    gridControlPhong.DataSource = new DataAccess().getPhongByIDLoaiPhong(curIDLoaiPhong).Tables[0];
                    MessageBox.Show(this, "Thêm mới Nhóm sản phẩm không thành công", "Thông báo lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Beispiel #5
0
        private void gridViewPhong_CellValueChanging(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
        {
            if (e.RowHandle >= 0)
            {
                if (e.Column == colDeletePhong)
                {
                    Phong objPhong = new Phong();
                    objPhong.IDPhong = Convert.ToInt32(gridViewPhong.GetRowCellValue(e.RowHandle, "IDPhong"));

                    //objPhong.IDLoaiPhong = curIDLoaiPhong;
                    if (Convert.ToBoolean(gridViewPhong.GetRowCellValue(e.RowHandle, colDeletePhong)) == true)
                    {
                        //warnning
                        if (MessageBox.Show(this, "Bạn có muốn xóa Loại phòng này không?", "Cảnh báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                        {
                            if (new DataAccess().deletePhong(objPhong) == true)
                            {
                                ((frmMain)(this.MdiParent)).setStatus("Xóa Loại phòng thành công");
                                gridViewPhong.DeleteRow(e.RowHandle);
                            }
                            else
                            {
                                MessageBox.Show(this, "Xóa Loại phòng không thành công", "Thông báo lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                ((frmMain)(this.MdiParent)).setStatus("");
                            }
                        }
                        else
                        {
                            //set the image to uncheck
                            gridViewPhong.SetRowCellValue(e.RowHandle, colDeletePhong, true);
                        }
                    }
                }
            }
        }
Beispiel #6
0
        private void gridViewPhong_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
        {
            if (e.RowHandle >= 0)
            {
                if (e.Column == colDeletePhong)
                {
                    //do nothing
                }
                else
                {
                    //update here
                    Phong objPhong = new Phong();
                    objPhong.IDPhong = Convert.ToInt32(gridViewPhong.GetRowCellValue(e.RowHandle, "IDPhong"));
                    objPhong.TenPhong = Convert.ToString(gridViewPhong.GetRowCellValue(e.RowHandle, "TenPhong"));
                    if (objPhong.TenPhong == "")
                    {
                        gridControlPhong.DataSource = new DataAccess().getPhongByIDLoaiPhong(curIDLoaiPhong).Tables[0];
                        MessageBox.Show(this, "Không có tên phòng!", "Thông báo lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    try
                    {
                        Int32.Parse(Convert.ToString(gridViewPhong.GetRowCellValue(e.RowHandle, "Congtac")));
                        if (Convert.ToString(gridViewPhong.GetRowCellValue(e.RowHandle, "Congtac")) == "")
                        {
                            gridControlPhong.DataSource = new DataAccess().getPhongByIDLoaiPhong(curIDLoaiPhong).Tables[0];
                            MessageBox.Show(this, "Không nhập công tắc cho phòng!", "Thông báo lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                        objPhong.Congtac = Convert.ToInt32(gridViewPhong.GetRowCellValue(e.RowHandle, "Congtac"));
                        if (new DataAccess().IsCongtacExistedExceptIDPhong(objPhong.Congtac,objPhong.IDPhong))
                        {
                            gridControlPhong.DataSource = new DataAccess().getPhongByIDLoaiPhong(curIDLoaiPhong).Tables[0];
                            MessageBox.Show(this, "Công tắc này đã có, yêu cầu nhập số khác!", "Thông báo lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }

                        if (new DataAccess().IsTenPhongExistedExceptIDPhong(objPhong.TenPhong,objPhong.IDPhong))
                        {
                            gridControlPhong.DataSource = new DataAccess().getPhongByIDLoaiPhong(curIDLoaiPhong).Tables[0];
                            MessageBox.Show(this, "Tên phòng này đã có, yêu cầu nhập tên khác!", "Thông báo lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                    }
                    catch
                    {
                        gridControlPhong.DataSource = new DataAccess().getPhongByIDLoaiPhong(curIDLoaiPhong).Tables[0];
                        MessageBox.Show(this, "Giá trị công tắc không hợp lệ (phải nhập số)", "Thông báo lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    objPhong.IDLoaiPhong = curIDLoaiPhong;
                    objPhong.Ghichu = Convert.ToString(gridViewPhong.GetRowCellValue(e.RowHandle, "Ghichu"));

                    if (new DataAccess().updatePhong(objPhong) == true)
                    {
                        gridControlPhong.DataSource = new DataAccess().getPhongByIDLoaiPhong(curIDLoaiPhong).Tables[0];
                        ((frmMain)(this.MdiParent)).setStatus("Cập nhật dữ liệu Loai phòng thành công");
                    }
                    else
                    {
                        gridControlPhong.DataSource = new DataAccess().getPhongByIDLoaiPhong(curIDLoaiPhong).Tables[0];
                        MessageBox.Show(this, "Cập nhật dữ liệu Loai phòng không thành công", "Thông báo lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }
Beispiel #7
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);
        }
Beispiel #8
0
        /*
        private void updateRoomGrid(int IDPhong)
        {
            gridRoom.DataSource = new DataAccess().getAllPhongAndLoaiPhong().Tables[0];
            gridViewRoom.ExpandAllGroups();
            //get focus to current
            int i;
            for (i = 0; i < gridViewRoom.RowCount; i++)
            {
                if (Convert.ToInt32(gridViewRoom.GetRowCellValue(i, "IDPhong")) == IDPhong)
                    break;
            }
            gridViewRoom.FocusedRowHandle = i;
            iCurrentRoomID = Convert.ToInt32(gridViewRoom.GetRowCellValue(i, "IDPhong"));
            displayLastRoomReceipt();
        }

        private void gridViewRoom_DoubleClick(object sender, EventArgs e)
        {
            Start(0);
            updateRoomGrid(iCurrentRoomID);
        }
        private void gridViewRoom_CellValueChanging(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
        {
            if (e.RowHandle >= 0)
            {

                if (e.Column == colRoomStatus)
                {
                    Start(iCurrentRoomID);
                    updateRoomGrid(iCurrentRoomID);
                }
            }
        }
        private void gridViewRoom_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            if (e.FocusedRowHandle >= 0 && e.PrevFocusedRowHandle >= 0)
            {
                {
                    displayLastRoomReceipt();
                }
            }
        }
        */
        private void Start(int roomID)
        {
            //open or close selected room
            //first search if selected room is available
            if (iCurrentRoomID < 0) return ;
            DataSet ds = new DataAccess().getPhongByIDPhong(iCurrentRoomID);

            if (ds.Tables[0].Rows.Count > 0)
            {
                iCurrentRoomGroupID = Convert.ToInt32(ds.Tables[0].Rows[0]["IDLoaiphong"]);
                if (Convert.ToBoolean(ds.Tables[0].Rows[0]["Trangthai"]) == true)
                {
                    //in case of the room has been openned
                    //ask to open room and create new receipt for this room

                    //CBReq req = new CBReq(Convert.ToInt32(ds.Tables[0].Rows[0]["Congtac"]), 10);
                    //listCBtoTurnOff.Add(req);
                    //get the last opening receipt of this rom
                    DataSet lastBill = new DataAccess().getLastHoadonxuatByIDPhong(iCurrentRoomID);
                    //Hoadonxuat currentReceipt = new Hoadonxuat();
                    currentReceipt.TenHoadon = Convert.ToString(lastBill.Tables[0].Rows[0]["TenHoadon"]);
                    currentReceipt.IDHoadonXuat = Convert.ToInt32(lastBill.Tables[0].Rows[0]["IDHoadonXuat"]);
                    currentReceipt.Giam = Convert.ToInt32(lastBill.Tables[0].Rows[0]["Giam"]);
                    currentReceipt.GioBD = Convert.ToDateTime(lastBill.Tables[0].Rows[0]["GioBD"]);
                    currentReceipt.GioKT = Convert.ToDateTime(lastBill.Tables[0].Rows[0]["GioKT"]); ;
                    currentReceipt.IDPhong = iCurrentRoomID;
                    currentReceipt.Ngayxuat = Convert.ToDateTime(lastBill.Tables[0].Rows[0]["Ngayxuat"]).Date;
                    currentReceipt.Phuthu = Convert.ToInt32(lastBill.Tables[0].Rows[0]["Phuthu"]);
                    currentReceipt.Thue = Convert.ToInt32(lastBill.Tables[0].Rows[0]["Thue"]);
                    currentReceipt.IDGiaLoaiphong = Convert.ToInt32(lastBill.Tables[0].Rows[0]["IDGiaLoaiphong"]);
                    currentReceipt.IDNhanvien = Convert.ToInt32(lastBill.Tables[0].Rows[0]["IDNhanvien"]);
                    currentReceipt.IDNhanvienXuatHD = Convert.ToInt32(lastBill.Tables[0].Rows[0]["IDNhanvienXuatHD"]);
                    currentReceipt.Tratruoc = Convert.ToInt32(lastBill.Tables[0].Rows[0]["Tratruoc"]);
                    currentReceipt.Nhacnho = Convert.ToBoolean(lastBill.Tables[0].Rows[0]["Nhacnho"]);
                    currentReceipt.IDKhachhang = Convert.ToInt32(lastBill.Tables[0].Rows[0]["IDKhachhang"]);
                    currentReceipt.Ghichu = Convert.ToString(lastBill.Tables[0].Rows[0]["Ghichu"]);
                    currentReceipt.Tanggio = Convert.ToInt32(lastBill.Tables[0].Rows[0]["Tanggio"]);
                    currentReceipt.Suco = Convert.ToInt32(lastBill.Tables[0].Rows[0]["Suco"]);
                    currentReceipt.Trangthai = Convert.ToInt32(lastBill.Tables[0].Rows[0]["Trangthai"]);
                    if (currentReceipt.Trangthai != (int)ReceiptStatus.Paid)
                    {
                        if (MessageBox.Show("Hóa đơn chưa xác nhận thu tiền. Bạn có muốn tiếp tục đóng phòng " + Convert.ToString(ds.Tables[0].Rows[0]["TenPhong"]) + "?", "Thông báo đóng phòng", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
                            return;
                        currentReceipt.Trangthai = (int)ReceiptStatus.ClosingNotPaid;
                    }
                    else
                        currentReceipt.Trangthai = (int)ReceiptStatus.Closing;
                    ContactAction(0xfb, Convert.ToInt32(ds.Tables[0].Rows[0]["Congtac"]));
                    bool res = new DataAccess().updateHoadonxuat(currentReceipt);
                    if (res)
                    {
                        //wait for databa is update
                        //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.Congtac = Convert.ToInt32(ds.Tables[0].Rows[0]["Congtac"]);
                        updateRoom.TenPhong = Convert.ToString(ds.Tables[0].Rows[0]["TenPhong"]);
                        updateRoom.Ghichu = Convert.ToString(ds.Tables[0].Rows[0]["Ghichu"]);
                        updateRoom.Trangthai = false;
                        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;
                        }

                        //close display
                        updateBillDisplay(-1, false);
                    }
                    else
                    {
                        MessageBox.Show("Đóng Phòng " + Convert.ToString(ds.Tables[0].Rows[0]["TenPhong"]) +
                            " không thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    }
                }
                else
                {
                    //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(ds.Tables[0].Rows[0]["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(iCurrentRoomGroupID, 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 = iCurrentRoomID;
                    currentReceipt.Ngayxuat = DateTime.Now.Date;
                    currentReceipt.Phuthu = 0;
                    currentReceipt.Thue = 0;
                    currentReceipt.Tanggio = 0;
                    currentReceipt.Trangthai = 0;
                    currentReceipt.Thue = 0;
                    currentReceipt.Phuthu = 0;
                    currentReceipt.IDNhanvien = 0;
                    currentReceipt.IDNhanvienXuatHD = Program.IDNhanvien;
                    currentReceipt.IDKhachhang = Convert.ToInt32(cboCustomer.SelectedValue);
                    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(iCurrentRoomGroupID, 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(Convert.ToString(ds.Tables[0].Rows[0]["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;
                        //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);
                        }
                        //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.Congtac = Convert.ToInt32(ds.Tables[0].Rows[0]["Congtac"]);
                        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 Hoadon group display
                        if (updateBillDisplay(res,false))
                        {

                            //update current status gridview
                            //gridViewRoom.SetFocusedRowCellValue(colRoomStatus, true);
                        }
                        //btnStart.Image = Karaoke.Properties.Resources.Status_user_busy_icon1;
                    }
                    else
                    {
                        MessageBox.Show("Mở Phòng " + Convert.ToString(ds.Tables[0].Rows[0]["TenPhong"]) +
                            " không thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    }
                }
            }
        }
Beispiel #9
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);
        }
Beispiel #10
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);
                    }

            }
        }
Beispiel #11
0
 public bool updatePhong(Phong objPhong)
 {
     return new PhongService().updatePhong(objPhong);
 }
Beispiel #12
0
 public int insertPhong(Phong objPhong)
 {
     return new PhongService().insertPhong(objPhong);
 }
Beispiel #13
0
 public bool deletePhong(Phong objPhong)
 {
     return new PhongService().deletePhong(objPhong);
 }