Example #1
0
        private void btnThue_Click(object sender, EventArgs e)
        {
            if (dgvThue.RowCount == 0)
            {
                MessageBox.Show("Vui lòng thêm DVD! :D");
                txtThongTinThue.Focus();
                return;
            }
            bRentOrder = new bPhieuMuon();
            bRentOrder.insertPhieuMuon(new ePhieuMuon(0, int.Parse(lbMaKhachHang.Text.ToString()), DateTime.Now));
            int idPhieuMuon = bRentOrder.getAllPhieuMuon().Last().IdPhieuMuon;

            bRentOrderDetail = new bChiTietPhieuMuon();
            bDVD             = new bDvd();
            eDvd newitem = new eDvd();

            foreach (DataGridViewRow dgvr in dgvThue.Rows)
            {
                newitem.IdDvd     = Convert.ToInt32(dgvr.Cells[0].Value);
                newitem.IdTiltle  = bDVD.getDvd(newitem.IdDvd).IdTiltle;
                newitem.TinhTrang = "Thue";
                bDVD.updateDvd(newitem);
                bRentOrderDetail.insertChiTietPhieuMuon(new eChiTietPhieuMuon(idPhieuMuon, newitem.IdDvd, 0, DateTime.Now, false));
            }
            MessageBox.Show("Bạn đã thuê thành công! :D");
            btnThueFunction_Click(sender, e);
        }
Example #2
0
        private void btnXacNhanNo_Click(object sender, EventArgs e)
        {
            dgvListNo.Rows.Clear();
            dgvListNo.Columns.Clear();
            dgvListNo.Columns.Add("0", "Id Phiếu mượn");
            dgvListNo.Columns.Add("1", "Id Dvd");
            dgvListNo.Columns.Add("2", "Số tiền nợ");
            int tongTre = 0;

            bRentOrder       = new bPhieuMuon();
            bRentOrderDetail = new bChiTietPhieuMuon();
            var listPhieuMuon = bRentOrder.getAllPhieuMuon().Where(n => n.IdKhach == int.Parse(txtKhachNo.Text)).ToList();
            int idOrder       = 0;
            int idDvd         = 0;

            foreach (var phieumuon in listPhieuMuon)
            {
                idOrder = phieumuon.IdPhieuMuon;
                var list = bRentOrderDetail.getAllChiTietPhieuMuon().Where(n => n.IdPhieuMuon == idOrder && n.TinhTrang == true && n.PhiTre > 0);
                if (list.Count() > 0)
                {
                    foreach (var item in list)
                    {
                        idDvd    = item.IdDvd;
                        tongTre += item.PhiTre;
                        dgvListNo.Rows.Add(idOrder, idDvd, item.PhiTre);
                    }
                }
            }
        }
Example #3
0
        private void LoadDsReportCus()
        {
            dgvThongKe.Rows.Clear();
            bCus             = new bKhachHang();
            bTua             = new bTitle();
            bDVD             = new bDvd();
            bRentOrder       = new bPhieuMuon();
            bRentOrderDetail = new bChiTietPhieuMuon();
            var list = bCus.getAllKhachHang();

            foreach (var item in list)
            {
                int i                = 0;
                int idKhach          = item.IdKhach;
                int soLuongDiaMuon   = 0;
                int soLuongDiaQuaHan = 0;
                int tongPhiTre       = 0;
                var listRent         = bRentOrder.getAllPhieuMuon().Where(n => n.IdKhach == idKhach);
                foreach (var itemMuon in listRent)
                {
                    int idMuon      = itemMuon.IdPhieuMuon;
                    var listChiTiet = bRentOrderDetail.getAllChiTietPhieuMuon().Where(n => n.IdPhieuMuon == idMuon);
                    foreach (var itemChitiet in listChiTiet)
                    {
                        int ngayFree = bTua.getTitle(bDVD.getDvd(itemChitiet.IdDvd).IdTiltle).ThoiGianThue;
                        tongPhiTre      += itemChitiet.PhiTre;
                        soLuongDiaQuaHan = listChiTiet.Where(n => lateDateCounting(n.NgayTra, itemMuon.NgayTao, ngayFree) > 0).Count();
                    }
                    soLuongDiaMuon += listChiTiet.Count();
                }
                dgvThongKe.Rows.Add(bCus.getKhachHang(idKhach).TenKhach, bCus.getKhachHang(idKhach).SdtKhach, soLuongDiaMuon, soLuongDiaQuaHan, tongPhiTre);
            }
        }
Example #4
0
        //Update phí trễ
        public void updateLateFee(int idDvd, int idOrder, int fee)
        {
            bRentOrderDetail = new bChiTietPhieuMuon();
            eChiTietPhieuMuon item = new eChiTietPhieuMuon();

            item.IdDvd       = idDvd;
            item.IdPhieuMuon = idOrder;
            item.PhiTre      = fee;
            item.NgayTra     = DateTime.Now;
            item.TinhTrang   = false;
            bRentOrderDetail.updateChiTietPhieuMuon(item);
        }
Example #5
0
        //Hàm tính giá trả
        public int feeCounting(int idDvd)
        {
            int      fee = 0;
            DateTime startDate;
            int      idOrder   = 0;
            int      soNgayTre = 0;

            bDVD             = new bDvd();
            bTua             = new bTitle();
            bRentOrder       = new bPhieuMuon();
            bRentOrderDetail = new bChiTietPhieuMuon();
            int idTitle = bDVD.getDvd(idDvd).IdTiltle;
            int freeDay = bTua.getTitle(idTitle).ThoiGianThue;
            var list    = bRentOrderDetail.getAllChiTietPhieuMuon().Where(n => n.IdDvd == idDvd && n.TinhTrang == false).ToList();

            foreach (var item in list)
            {
                idOrder = item.IdPhieuMuon;
            }
            var listNgayTao = bRentOrder.getAllPhieuMuon().Where(n => n.IdPhieuMuon == idOrder).ToList();

            startDate = bRentOrder.getPhieuMuon(idOrder).NgayTao;
            soNgayTre = lateDateCounting(DateTime.Now, startDate, freeDay);
            if (soNgayTre > 0)
            {
                DialogResult dialogResult = MessageBox.Show("Dvd này tồn tại phí trễ chưa thanh toán! Bạn có muốn thay toán ngay bây giờ không? :D", "Thông báo phí trễ", MessageBoxButtons.YesNo);
                if (dialogResult == DialogResult.Yes)
                {
                    fee = bTua.getTitle(idTitle).GiaThue *bTua.getTitle(idTitle).ThoiGianThue + bTua.getTitle(idTitle).PhiTre *soNgayTre;

                    dgvListTra.Rows.Add(idDvd, idOrder, startDate.Date, bTua.getTitle(idTitle).PhiTre *soNgayTre);
                    updateLateFee(idDvd, idOrder, bTua.getTitle(idTitle).PhiTre *soNgayTre);
                }
                else
                {
                    fee = bTua.getTitle(idTitle).GiaThue *bTua.getTitle(idTitle).ThoiGianThue;
                    dgvListTra.Rows.Add(idDvd, idOrder, startDate.Date, 0);
                    updateLateFee(idDvd, idOrder, bTua.getTitle(idTitle).PhiTre *soNgayTre);
                }
            }
            else
            {
                fee = bTua.getTitle(idTitle).GiaThue *bTua.getTitle(idTitle).ThoiGianThue;
                dgvListTra.Rows.Add(idDvd, idOrder, startDate.Date, 0);
                updateLateFee(idDvd, idOrder, 0);
            }

            return(fee);
        }
Example #6
0
        private void btnXacNhanIdTra_Click(object sender, EventArgs e)
        {
            bRentOrderDetail = new bChiTietPhieuMuon();
            int idDvd = int.Parse(txtIdDvdTra.Text);
            var list  = bRentOrderDetail.getAllChiTietPhieuMuon().Where(n => n.IdDvd == idDvd && n.TinhTrang == false).ToList();

            if (list.Any())
            {
                int tong = feeCounting(idDvd);
                lbTongTra.Text = (int.Parse(lbTongTra.Text) + tong).ToString();
            }
            else
            {
                MessageBox.Show("Dvd này đã được trả trước đó, vui lòng nhập lại! :D");
            }
        }
Example #7
0
        private void dgvListNo_DoubleClick(object sender, EventArgs e)
        {
            bRentOrderDetail = new bChiTietPhieuMuon();
            eChiTietPhieuMuon item = new eChiTietPhieuMuon();

            item.IdPhieuMuon = Convert.ToInt32(dgvListNo.CurrentRow.Cells[0].Value);
            item.IdDvd       = Convert.ToInt32(dgvListNo.CurrentRow.Cells[1].Value);
            item.PhiTre      = 0;
            item.NgayTra     = bRentOrderDetail.getChiTietPhieuMuon(item.IdPhieuMuon, item.IdDvd).NgayTra;
            item.TinhTrang   = true;
            DialogResult dialogResult1 = MessageBox.Show("Bạn muốn trả nợ đĩa" + dgvListNo.CurrentRow.Cells[0].Value.ToString() + "không? :D", "Thông báo phí trễ", MessageBoxButtons.YesNo);

            if (dialogResult1 == DialogResult.Yes)
            {
                bRentOrderDetail.updateChiTietPhieuMuon(item);
                MessageBox.Show("Bạn đã trả nợ đĩa " + item.IdDvd + "! :D");
            }
        }
Example #8
0
        private void dgvThongKe_DoubleClick(object sender, EventArgs e)
        {
            dgvChiTietCusReport.Rows.Clear();
            bCus             = new bKhachHang();
            bRentOrder       = new bPhieuMuon();
            bRentOrderDetail = new bChiTietPhieuMuon();

            int idkhach  = bCus.getAllKhachHang().Single(n => n.TenKhach == dgvThongKe.CurrentRow.Cells[0].Value.ToString()).IdKhach;
            var listRent = bRentOrder.getAllPhieuMuon().Where(n => n.IdKhach == idkhach);

            foreach (var item in listRent)
            {
                var listChiTiet = bRentOrderDetail.getAllChiTietPhieuMuon().Where(n => n.IdPhieuMuon == item.IdPhieuMuon);
                foreach (var itemChiTier in listChiTiet)
                {
                    dgvChiTietCusReport.Rows.Add(itemChiTier.IdDvd, item.NgayTao, itemChiTier.NgayTra, itemChiTier.PhiTre);
                }
            }
        }
Example #9
0
        private void btnTraHet_Click(object sender, EventArgs e)
        {
            if (dgvListNo.Rows.Count == 0)
            {
                MessageBox.Show("Bạn không có nợ để trả! :D");
                return;
            }
            bRentOrderDetail = new bChiTietPhieuMuon();
            eChiTietPhieuMuon item = new eChiTietPhieuMuon();

            foreach (DataGridViewRow dgvr in dgvListNo.Rows)
            {
                item.IdPhieuMuon = Convert.ToInt32(dgvr.Cells[0].Value);
                item.IdDvd       = Convert.ToInt32(dgvr.Cells[1].Value);
                item.PhiTre      = 0;
                item.NgayTra     = DateTime.Now;
                item.TinhTrang   = true;
                bRentOrderDetail.updateChiTietPhieuMuon(item);
            }
            MessageBox.Show("Bạn đã trả mọi nợ đĩa! :D");
        }
Example #10
0
        private void btnTra_Click(object sender, EventArgs e)
        {
            if (dgvListTra.RowCount == 0)
            {
                MessageBox.Show("Vui lòng nhập DVD cần trả! :D");
                txtIdDvdTra.Focus();
                return;
            }
            bRentOrderDetail = new bChiTietPhieuMuon();
            eChiTietPhieuMuon item = new eChiTietPhieuMuon();

            bReserve       = new bPhieuDatTruoc();
            bReserveDetail = new bChiTietPhieuDatTruoc();
            foreach (DataGridViewRow dgvr in dgvListTra.Rows)
            {
                item.IdPhieuMuon = Convert.ToInt32(dgvr.Cells[1].Value);
                item.IdDvd       = Convert.ToInt32(dgvr.Cells[0].Value);
                item.PhiTre      = bRentOrderDetail.getChiTietPhieuMuon(item.IdPhieuMuon, item.IdDvd).PhiTre - Convert.ToInt32(dgvr.Cells[3].Value);
                item.NgayTra     = DateTime.Now;
                item.TinhTrang   = true;
                bDVD.updateDvd(new eDvd(item.IdDvd, bDVD.getDvd(item.IdDvd).IdTiltle, "TrenKe", true));
                bRentOrderDetail.updateChiTietPhieuMuon(item);
                int idTitle     = bDVD.getDvd(item.IdDvd).IdTiltle;
                var listReserve = bReserveDetail.getAllChiTietPhieuDatTruoc().Where(n => n.IdTitle == idTitle && n.TrangThai1 == false && n.Huy == true);
                if (listReserve.Any())
                {
                    bDVD.updateDvd(new eDvd(item.IdDvd, bDVD.getDvd(item.IdDvd).IdTiltle, "DatTruoc", true));
                    int idReserve = listReserve.First().IdPhieuDatTruoc;
                    bReserveDetail.updateChiTietPhieuDatTruoc(new eChiTietPhieuDatTruoc(idReserve, idTitle, true, true));
                }
            }
            bDVD = new bDvd();

            MessageBox.Show("Bạn đã trả thành công! :D");


            btnTraFunction_Click(sender, e);
        }
Example #11
0
 //Các nút truy xuất Databse
 #region Các nút truy xuất Databse
 private void btnXacNhanThongTinThue_Click(object sender, EventArgs e)
 {
     if (txtThongTinThue.Text.Length == 0)
     {
         if (lbNhapThongTinThue.Text == "Nhập Id khách hàng: ")
         {
             MessageBox.Show("Vui lòng nhập id của khách hàng! :D");
             txtThongTinThue.Focus();
         }
         else
         {
             MessageBox.Show("Vui lòng nhập id của DVD! :D");
             txtThongTinThue.Focus();
         }
     }
     else
     {
         if (lbNhapThongTinThue.Text == "Nhập Id khách hàng: ")
         {
             int    tongTre = 0;
             string idKhach = txtThongTinThue.Text;
             bRentOrder       = new bPhieuMuon();
             bRentOrderDetail = new bChiTietPhieuMuon();
             var listPhieuMuon = bRentOrder.getAllPhieuMuon().Where(n => n.IdKhach == int.Parse(txtThongTinThue.Text)).ToList();
             foreach (var phieumuon in listPhieuMuon)
             {
                 int a    = phieumuon.IdPhieuMuon;
                 var list = bRentOrderDetail.getAllChiTietPhieuMuon().Where(n => n.IdPhieuMuon == a && n.TinhTrang == true && n.PhiTre > 0);
                 if (list.Count() > 0)
                 {
                     foreach (var item in list)
                     {
                         tongTre += item.PhiTre;
                     }
                 }
             }
             if (tongTre > 0)
             {
                 DialogResult dialogResult = MessageBox.Show("Bạn có phí trễ chưa thanh toán! Bạn có muốn thay toán ngay bây giờ không? :D", "Thông báo phí trễ", MessageBoxButtons.YesNo);
                 if (dialogResult == DialogResult.Yes)
                 {
                     DialogResult dialogResult1 = MessageBox.Show("Bạn muốn trả hết nợ hay trả từng cái? (Chọn yes để trả hết, no để đến chi tiết! :D", "Thông báo phí trễ", MessageBoxButtons.YesNo);
                     if (dialogResult1 == DialogResult.Yes)
                     {
                         foreach (var phieumuon in listPhieuMuon)
                         {
                             int a    = phieumuon.IdPhieuMuon;
                             var list = bRentOrderDetail.getAllChiTietPhieuMuon().Where(n => n.IdPhieuMuon == a && n.TinhTrang == true && n.PhiTre > 0);
                             if (list.Count() > 0)
                             {
                                 foreach (var item in list)
                                 {
                                     bRentOrderDetail.updateChiTietPhieuMuon(new eChiTietPhieuMuon(item.IdPhieuMuon, item.IdDvd, 0, item.NgayTra, item.TinhTrang));
                                 }
                             }
                         }
                         MessageBox.Show("Bạn đã hết nợ! :D");
                     }
                     else
                     {
                         btnTraTienPhatFuncTion_Click(sender, e);
                         txtKhachNo.Text = idKhach;
                         btnXacNhanNo_Click(sender, e);
                     }
                 }
             }
             bCus = new bKhachHang();
             try
             {
                 eKhachHang temp = bCus.getKhachHang(int.Parse(txtThongTinThue.Text));
                 lbMaKhachHang.Text      = temp.IdKhach.ToString();
                 lbTenKhach.Text         = temp.TenKhach;
                 lbDiaChiKhach.Text      = temp.DiaChiKhach;
                 lbSoKhach.Text          = temp.SdtKhach;
                 lbNhapThongTinThue.Text = "Nhập Id Dvd: ";
                 txtThongTinThue.Clear();
                 txtThongTinThue.Focus();
             }
             catch (Exception)
             {
                 MessageBox.Show("Khách hàng không tồn tại! :D");
             }
         }
         else
         {
             bDVD = new bDvd();
             if (bDVD.getDvd(int.Parse(txtThongTinThue.Text.ToString())).TinhTrang == "Thue")
             {
                 MessageBox.Show("DVD đã được thuê! Vui lòng chọn DVD khác! :D");
                 txtThongTinThue.Clear();
                 txtThongTinThue.Focus();
             }
             else
             {
                 try
                 {
                     bTua = new bTitle();
                     dgvThue.Rows.Add(txtThongTinThue.Text,
                                      bTua.getTitle(bDVD.getDvd(int.Parse(txtThongTinThue.Text)).IdTiltle).TenTitle,
                                      bTua.getTitle(bDVD.getDvd(int.Parse(txtThongTinThue.Text)).IdTiltle).GiaThue);
                     txtThongTinThue.Clear();
                     txtThongTinThue.Focus();
                 }
                 catch (Exception)
                 {
                     MessageBox.Show("Dvd không tồn tại! :D");
                 }
             }
         }
     }
 }