Esempio n. 1
0
        private void wbntQuanlyphong_ButtonClick(object sender, DevExpress.XtraBars.Docking2010.ButtonEventArgs e)
        {
            switch (e.Button.Properties.Tag.ToString())
            {
            case "Thêm Dịch Vụ":
                ((ChiTietThanhToanPhong)tabbedControlGroup1.SelectedTabPage.Tag).ThemDichVu();
                break;

            case "Xóa Dịch Vụ":
                ((ChiTietThanhToanPhong)tabbedControlGroup1.SelectedTabPage.Tag).XoaDichVu();
                break;

            case "Thanh toán":

                //hoaDon.TienGio = (double)txtTongTienGio.EditValue;

                HoaDonBUS.CapNhatHoaDonDaThanhToan(hoaDon);
                foreach (DevExpress.XtraLayout.LayoutControlGroup layoutGroup in this.tabbedControlGroup1.TabPages)
                {
                    ((ChiTietThanhToanPhong)layoutGroup.Tag).LuuKhuyenMai();
                    ((ChiTietThanhToanPhong)layoutGroup.Tag).LuuTienGio();
                    ((ChiTietThanhToanPhong)layoutGroup.Tag).CapNhatThongTinThuePhong();

                    switch (PhongBUS.LayThongTinPhong(thuePhong.MaPhong).MaTinhTrangPhong)
                    {
                    case 1:
                    case 5:
                        if (ThamSoBUS.LayChuyenSangChoDonDepSauKhiThanhToan())
                        {
                            PhongBUS.CapNhatTinhTrangPhong(((ChiTietThanhToanPhong)layoutGroup.Tag).thuePhong.MaPhong, 5);
                        }
                        else
                        {
                            PhongBUS.CapNhatTinhTrangPhong(((ChiTietThanhToanPhong)layoutGroup.Tag).thuePhong.MaPhong, 0);
                        }
                        break;

                    case 7:
                        if (ThamSoBUS.LayChuyenSangChoDonDepSauKhiThanhToan())
                        {
                            PhongBUS.CapNhatTinhTrangPhong(((ChiTietThanhToanPhong)layoutGroup.Tag).thuePhong.MaPhong, 6);
                        }
                        else
                        {
                            PhongBUS.CapNhatTinhTrangPhong(((ChiTietThanhToanPhong)layoutGroup.Tag).thuePhong.MaPhong, 4);
                        }
                        break;
                    }
                }

                if (khachHang.MaLoaiKH != 0)
                {
                    KhachHangBUS.CapNhatDiemTichLuy(khachHang.MaKH, khachHang.DiemTichLuy + ThamSoBUS.QuyDoiDiem((double)txtTongTienThanhToan.EditValue));
                    khachHang.DiemTichLuy = khachHang.DiemTichLuy + ThamSoBUS.QuyDoiDiem((double)txtTongTienThanhToan.EditValue);

                    LoaiKhachHangDTO loaiKhachHangCoThe = KhachHangBUS.LayLoaiKhachHangCoTheDatDuoc(khachHang);
                    if (loaiKhachHangCoThe != null && loaiKhachHangCoThe.MaLoaiKH != 0)
                    {
                        if (khachHang.MaLoaiKH != loaiKhachHangCoThe.MaLoaiKH)
                        {
                            KhachHangBUS.CapNhatLoaiKhachHang(khachHang.MaKH, loaiKhachHangCoThe.MaLoaiKH);
                            XtraMessageBox.Show("Khách hàng được cập nhật lên loại '" + loaiKhachHangCoThe.TenLoaiKH + "'! ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                }


                goBackHome();

                break;

            case "In hóa đơn":

                XtraDialogArgs args = new XtraDialogArgs(caption: "Chọn dịch vụ", content: new ReportViewer(reportHoaDon), buttons: new DialogResult[] { DialogResult.OK });
                XtraDialog.Show(args);

                // DevExpress.XtraBars.Docking2010.Customization.FlyoutDialog.Show(this.FindForm(),new ReportViewer(reportHoaDon));
                break;

            case "In hóa đơn tạm tính":
                double TongTienGio = 0, TongTienKhuyenMai = 0, TongTienDichVu = 0;
                dsDichVuPhong.Tables.Clear();


                for (int i = 0; i < this.tabbedControlGroup1.TabPages.Count; i++)
                {
                    TongTienGio       += ((ChiTietThanhToanPhong)this.tabbedControlGroup1.TabPages[i].Tag).GetTongTienGio();
                    TongTienKhuyenMai += ((ChiTietThanhToanPhong)this.tabbedControlGroup1.TabPages[i].Tag).GetTongTienKhuyenMai();
                    TongTienDichVu    += ((ChiTietThanhToanPhong)this.tabbedControlGroup1.TabPages[i].Tag).GetTongTienDichVu();

                    dsHoaDon.Tables[1].Rows[i]["TienPhong"] = ((ChiTietThanhToanPhong)this.tabbedControlGroup1.TabPages[i].Tag).GetTongTienGio() + ((ChiTietThanhToanPhong)this.tabbedControlGroup1.TabPages[i].Tag).GetTongTienDichVu() + ((ChiTietThanhToanPhong)this.tabbedControlGroup1.TabPages[i].Tag).GetTongTienKhuyenMai();

                    dsDichVuPhong.Tables.Add(((ChiTietThanhToanPhong)tabbedControlGroup1.TabPages[i].Tag).GetDichVuPhong_DataTable());
                }


                DataTable MergedDataTable = new DataTable("dichvuphong");

                MergedDataTable.Merge(dsDichVuPhong.Tables[0]);

                if (!ReadOnlyMode)     //ReadOnly Mode
                {
                    MergedDataTable.Columns.Add(new DataColumn("MaTemp"));
                    for (int i = 0; i < MergedDataTable.Rows.Count; i++)
                    {
                        MergedDataTable.Rows[i]["MaTemp"] = i;
                    }
                    MergedDataTable.PrimaryKey = new DataColumn[] { MergedDataTable.Columns["MaTemp"] };
                    for (int i = 1; i < dsDichVuPhong.Tables.Count; i++)
                    {
                        foreach (DataRow dr in dsDichVuPhong.Tables[i].Rows)
                        {
                            DataRow row = MergedDataTable.NewRow();
                            row["MaTemp"]      = MergedDataTable.Rows.Count;
                            row["MaDVP"]       = dr["MaDVP"];
                            row["MaThuePhong"] = dr["MaThuePhong"];
                            row["MaDV"]        = dr["MaDV"];
                            row["ThoiGian"]    = dr["ThoiGian"];
                            row["SoLuong"]     = dr["SoLuong"];
                            row["Gia"]         = dr["Gia"];
                            row["TenDV"]       = dr["TenDV"];
                            row["DonVi"]       = dr["DonVi"];
                            row["colType"]     = dr["colType"];
                            MergedDataTable.Rows.Add(row);
                        }
                    }

                    for (int i = 0; i < this.tabbedControlGroup1.TabPages.Count; i++)
                    {
                        foreach (DataRow dr in ((ChiTietThanhToanPhong)tabbedControlGroup1.TabPages[i].Tag).GetTienGio_DataTable().Rows)
                        {
                            DataRow row = MergedDataTable.NewRow();
                            row["MaTemp"]      = MergedDataTable.Rows.Count;
                            row["MaDVP"]       = -1;
                            row["MaThuePhong"] = ((ChiTietThanhToanPhong)tabbedControlGroup1.TabPages[i].Tag).GetThuePhong().MaThuePhong;
                            row["MaDV"]        = -1;
                            row["ThoiGian"]    = DateTime.MinValue;
                            row["SoLuong"]     = dr["SoLuong"];
                            row["Gia"]         = dr["DonGia"];
                            row["TenDV"]       = dr["Ngay"] + " " + dr["KhoangThoiGian"];
                            row["DonVi"]       = "VNĐ/Giờ";
                            row["colType"]     = "Tiền Giờ";
                            MergedDataTable.Rows.Add(row);
                        }
                    }
                }
                else
                {
                    for (int i = 1; i < dsDichVuPhong.Tables.Count; i++)
                    {
                        MergedDataTable.Merge(dsDichVuPhong.Tables[i]);
                    }

                    MergedDataTable.Columns.Add(new DataColumn("MaTemp"));
                    for (int i = 0; i < MergedDataTable.Rows.Count; i++)
                    {
                        MergedDataTable.Rows[i]["MaTemp"] = i;
                    }
                    MergedDataTable.PrimaryKey = new DataColumn[] { MergedDataTable.Columns["MaTemp"] };

                    for (int i = 0; i < this.tabbedControlGroup1.TabPages.Count; i++)
                    {
                        foreach (DataRow dr in BUS.TienGio_ThuePhongBUS.LayTienGio_ThuePhong_DataTable(((ChiTietThanhToanPhong)tabbedControlGroup1.TabPages[i].Tag).GetThuePhong().MaThuePhong).Rows)
                        {
                            DataRow row = MergedDataTable.NewRow();
                            row["MaTemp"]      = MergedDataTable.Rows.Count;
                            row["MaDVP"]       = -1;
                            row["MaThuePhong"] = dr["MaThuePhong"];
                            row["MaDV"]        = -1;
                            row["ThoiGian"]    = DateTime.MinValue;
                            row["SoLuong"]     = dr["SoLuong"];
                            row["Gia"]         = dr["DonGia"];
                            row["TenDV"]       = dr["Ngay"] + " " + dr["KhoangThoiGian"];
                            row["DonVi"]       = "VNĐ/Giờ";
                            row["colType"]     = "Tiền Giờ";
                            MergedDataTable.Rows.Add(row);
                        }
                    }
                }


                if (dsHoaDon.Tables.Count == 3)
                {
                    dsHoaDon.Relations.RemoveAt(1);
                    dsHoaDon.Tables[2].Constraints.Clear();
                    dsHoaDon.Tables.RemoveAt(2);
                }
                dsHoaDon.Tables.Add(MergedDataTable);
                dsHoaDon.Relations.Add("chitietdichvu", dsHoaDon.Tables[1].Columns["MaThuePhong"], dsHoaDon.Tables[2].Columns["MaThuePhong"]);



                txtTongTienGio.EditValue       = TongTienGio;
                txtTongTienKhuyenMai.EditValue = TongTienKhuyenMai;
                txtTongTienDichVu.EditValue    = TongTienDichVu;
                txtTongTienThanhToan.EditValue = TongTienGio + TongTienKhuyenMai + TongTienDichVu - Convert.ToDouble(txtTienTraTruoc.EditValue);


                hoaDon.MaNhanVienThanhToan = (this.ParentForm as MainForm).nhanVien.MaNhanVien;
                hoaDon.TongTienThanhToan   = (double)txtTongTienThanhToan.EditValue;
                hoaDon.NgayThanhToan       = txtNgayThanhToan.Time;
                hoaDon.SoTienKhuyenMai     = (double)txtTongTienKhuyenMai.EditValue;

                reportHoaDon HoaDon = new reportHoaDon();
                HoaDon.BindingData(dsHoaDon, khachHang, hoaDon, TongTienGio, TongTienKhuyenMai, TongTienDichVu, Convert.ToDouble(txtTienTraTruoc.EditValue), txtGhiChu.Text, true);

                XtraDialogArgs phieudatphong = new XtraDialogArgs(caption: "Hóa đơn tạm tính", content: new ReportViewer(HoaDon), buttons: new DialogResult[] { DialogResult.OK });
                XtraDialog.Show(phieudatphong);
                break;
            }
        }
Esempio n. 2
0
        public void CalcTongTien_UpdateHoaDon()
        {
            double TongTienGio = 0, TongTienKhuyenMai = 0, TongTienDichVu = 0;

            dsDichVuPhong.Tables.Clear();


            for (int i = 0; i < this.tabbedControlGroup1.TabPages.Count; i++)
            {
                TongTienGio       += ((ChiTietThanhToanPhong)this.tabbedControlGroup1.TabPages[i].Tag).GetTongTienGio();
                TongTienKhuyenMai += ((ChiTietThanhToanPhong)this.tabbedControlGroup1.TabPages[i].Tag).GetTongTienKhuyenMai();
                TongTienDichVu    += ((ChiTietThanhToanPhong)this.tabbedControlGroup1.TabPages[i].Tag).GetTongTienDichVu();

                dsHoaDon.Tables[1].Rows[i]["TienPhong"] = ((ChiTietThanhToanPhong)this.tabbedControlGroup1.TabPages[i].Tag).GetTongTienGio() + ((ChiTietThanhToanPhong)this.tabbedControlGroup1.TabPages[i].Tag).GetTongTienDichVu() + ((ChiTietThanhToanPhong)this.tabbedControlGroup1.TabPages[i].Tag).GetTongTienKhuyenMai();

                dsDichVuPhong.Tables.Add(((ChiTietThanhToanPhong)tabbedControlGroup1.TabPages[i].Tag).GetDichVuPhong_DataTable());
            }


            DataTable MergedDataTable = new DataTable("dichvuphong");

            MergedDataTable.Merge(dsDichVuPhong.Tables[0]);

            if (!ReadOnlyMode) //ReadOnly Mode
            {
                MergedDataTable.Columns.Add(new DataColumn("MaTemp"));
                for (int i = 0; i < MergedDataTable.Rows.Count; i++)
                {
                    MergedDataTable.Rows[i]["MaTemp"] = i;
                }
                MergedDataTable.PrimaryKey = new DataColumn[] { MergedDataTable.Columns["MaTemp"] };
                for (int i = 1; i < dsDichVuPhong.Tables.Count; i++)
                {
                    foreach (DataRow dr in dsDichVuPhong.Tables[i].Rows)
                    {
                        DataRow row = MergedDataTable.NewRow();
                        row["MaTemp"]      = MergedDataTable.Rows.Count;
                        row["MaDVP"]       = dr["MaDVP"];
                        row["MaThuePhong"] = dr["MaThuePhong"];
                        row["MaDV"]        = dr["MaDV"];
                        row["ThoiGian"]    = dr["ThoiGian"];
                        row["SoLuong"]     = dr["SoLuong"];
                        row["Gia"]         = dr["Gia"];
                        row["TenDV"]       = dr["TenDV"];
                        row["DonVi"]       = dr["DonVi"];
                        row["colType"]     = dr["colType"];
                        MergedDataTable.Rows.Add(row);
                    }
                }

                for (int i = 0; i < this.tabbedControlGroup1.TabPages.Count; i++)
                {
                    foreach (DataRow dr in ((ChiTietThanhToanPhong)tabbedControlGroup1.TabPages[i].Tag).GetTienGio_DataTable().Rows)
                    {
                        DataRow row = MergedDataTable.NewRow();
                        row["MaTemp"]      = MergedDataTable.Rows.Count;
                        row["MaDVP"]       = -1;
                        row["MaThuePhong"] = ((ChiTietThanhToanPhong)tabbedControlGroup1.TabPages[i].Tag).GetThuePhong().MaThuePhong;
                        row["MaDV"]        = -1;
                        row["ThoiGian"]    = DateTime.MinValue;
                        row["SoLuong"]     = dr["SoLuong"];
                        row["Gia"]         = dr["DonGia"];
                        row["TenDV"]       = dr["Ngay"] + " " + dr["KhoangThoiGian"];
                        row["DonVi"]       = "VNĐ/Giờ";
                        row["colType"]     = "Tiền Giờ";
                        MergedDataTable.Rows.Add(row);
                    }
                }
            }
            else
            {
                for (int i = 1; i < dsDichVuPhong.Tables.Count; i++)
                {
                    MergedDataTable.Merge(dsDichVuPhong.Tables[i]);
                }

                MergedDataTable.Columns.Add(new DataColumn("MaTemp"));
                for (int i = 0; i < MergedDataTable.Rows.Count; i++)
                {
                    MergedDataTable.Rows[i]["MaTemp"] = i;
                }
                MergedDataTable.PrimaryKey = new DataColumn[] { MergedDataTable.Columns["MaTemp"] };

                for (int i = 0; i < this.tabbedControlGroup1.TabPages.Count; i++)
                {
                    foreach (DataRow dr in BUS.TienGio_ThuePhongBUS.LayTienGio_ThuePhong_DataTable(((ChiTietThanhToanPhong)tabbedControlGroup1.TabPages[i].Tag).GetThuePhong().MaThuePhong).Rows)
                    {
                        DataRow row = MergedDataTable.NewRow();
                        row["MaTemp"]      = MergedDataTable.Rows.Count;
                        row["MaDVP"]       = -1;
                        row["MaThuePhong"] = dr["MaThuePhong"];
                        row["MaDV"]        = -1;
                        row["ThoiGian"]    = DateTime.MinValue;
                        row["SoLuong"]     = dr["SoLuong"];
                        row["Gia"]         = dr["DonGia"];
                        row["TenDV"]       = dr["Ngay"] + " " + dr["KhoangThoiGian"];
                        row["DonVi"]       = "VNĐ/Giờ";
                        row["colType"]     = "Tiền Giờ";
                        MergedDataTable.Rows.Add(row);
                    }
                }
            }


            if (dsHoaDon.Tables.Count == 3)
            {
                dsHoaDon.Relations.RemoveAt(1);
                dsHoaDon.Tables[2].Constraints.Clear();
                dsHoaDon.Tables.RemoveAt(2);
            }
            dsHoaDon.Tables.Add(MergedDataTable);
            dsHoaDon.Relations.Add("chitietdichvu", dsHoaDon.Tables[1].Columns["MaThuePhong"], dsHoaDon.Tables[2].Columns["MaThuePhong"]);



            txtTongTienGio.EditValue       = TongTienGio;
            txtTongTienKhuyenMai.EditValue = TongTienKhuyenMai;
            txtTongTienDichVu.EditValue    = TongTienDichVu;
            txtTongTienThanhToan.EditValue = TongTienGio + TongTienKhuyenMai + TongTienDichVu - Convert.ToDouble(txtTienTraTruoc.EditValue);


            hoaDon.MaNhanVienThanhToan = (this.ParentForm as MainForm).nhanVien.MaNhanVien;
            hoaDon.TongTienThanhToan   = (double)txtTongTienThanhToan.EditValue;
            hoaDon.NgayThanhToan       = txtNgayThanhToan.Time;
            hoaDon.SoTienKhuyenMai     = (double)txtTongTienKhuyenMai.EditValue;

            reportHoaDon.BindingData(dsHoaDon, khachHang, hoaDon, TongTienGio, TongTienKhuyenMai, TongTienDichVu, Convert.ToDouble(txtTienTraTruoc.EditValue), txtGhiChu.Text);


            reportHoaDon.CreateDocument();
            documentViewer1.DocumentSource = reportHoaDon;
            documentViewer1.Zoom           = 0.83f;
        }