Exemplo n.º 1
0
 public bool updateData(PhieuTra data)
 {
     return(obj.updateData(data));
 }
Exemplo n.º 2
0
        public IActionResult SubmitKiemTraPhieuTra(List <CT_PhieuMuon> model, int id)
        {
            var phieumuon = _context.PhieuMuon.Find(id);
            var ctpm      = _context.CT_PhieuMuon.Where(s => s.PhieuMuonID == id).ToList();

            //tinh so ngay muon
            TimeSpan songaymuon = DateTime.Now.Subtract(phieumuon.NgayMuon);

            if (phieumuon.TinhTrangPhieuMuonID == 2) //2 là phiếu mượn đã trả
            {
                return(RedirectToAction("index", "phieumuon"));
            }
            else
            {
                //so ngay muon ko qua han
                if (songaymuon.Days <= 4)
                {
                    PhieuTra phieutra = new PhieuTra();
                    phieutra.DocGiaID = phieumuon.DocGiaID;
                    phieutra.NgayTra  = DateTime.Now;
                    _context.PhieuTra.Add(phieutra);
                    _context.SaveChanges();

                    foreach (var a in ctpm)
                    {
                        CT_PhieuTra ctpt = new CT_PhieuTra();
                        ctpt.SoNgayMuon = songaymuon.Days;
                        ctpt.PhieuTraID = phieutra.PhieuTraID;
                        ctpt.SachID     = a.SachID;
                        _context.CT_PhieuTra.Add(ctpt);
                        _context.SaveChanges();
                    }

                    var docgia = _context.DocGia.FirstOrDefault(l => l.DocGiaID == phieutra.DocGiaID);
                    docgia.SLSachDaMuon = 0;
                    _context.SaveChanges();

                    //cập nhật lại tình trạng phiếu mượn
                    phieumuon.TinhTrangPhieuMuonID = 2;//2 là phiếu mượn hoan thanh
                    _context.SaveChanges();

                    double sum = 0;

#pragma warning disable CS0162 // Unreachable code detected
                    for (int i = 0; i < model.Count; i++)
#pragma warning restore CS0162 // Unreachable code detected
                    {
                        if (model[i].IsSelected)
                        {
                            var sach = _context.Sach.FirstOrDefault(x => x.SachID == model[i].SachID);
                            sach.TinhTrangSachID = 1; //1 chua thue
                            _context.SaveChanges();
                        }

                        else
                        {
                            var sach = _context.Sach.FirstOrDefault(x => x.SachID == model[i].SachID);
                            sach.TinhTrangSachID = 3; //3 mat
                            sum += sach.Gia;
                        }
                    }
                    PhieuThuTienPhat pttp = new PhieuThuTienPhat();
                    pttp.DocGiaID   = docgia.DocGiaID;
                    pttp.TienCoc    = phieumuon.TienCoc;
                    pttp.PhieuTraID = phieutra.PhieuTraID;
                    pttp.TienPhat   = sum;
                    pttp.TienConLai = phieumuon.TienCoc - pttp.TienPhat;
                    _context.PhieuThuTienPhat.Add(pttp);
                    docgia.ConLai = pttp.TienConLai;
                    _context.SaveChanges();
                    return(RedirectToAction("details", new RouteValueDictionary(new { Controller = "phieuthutienphat", Action = "details", id = pttp.PhieuThuTienPhatID })));
                }
                //so ngay muon qua han
                else
                {
                    PhieuTra phieutra = new PhieuTra();
                    phieutra.DocGiaID = phieumuon.DocGiaID;
                    phieutra.NgayTra  = DateTime.Now;
                    _context.PhieuTra.Add(phieutra);
                    _context.SaveChanges();

                    // tien tra tre han
                    double sum = 0;
                    sum = (songaymuon.Days - 4) * 1000;


                    foreach (var a in ctpm)
                    {
                        CT_PhieuTra ctpt = new CT_PhieuTra();
                        ctpt.SoNgayMuon = songaymuon.Days;
                        ctpt.PhieuTraID = phieutra.PhieuTraID;
                        ctpt.SachID     = a.SachID;
                        _context.CT_PhieuTra.Add(ctpt);
                        _context.SaveChanges();
                    }

                    var docgia = _context.DocGia.FirstOrDefault(l => l.DocGiaID == phieutra.DocGiaID);
                    docgia.SLSachDaMuon = 0;
                    _context.SaveChanges();

                    //cập nhật lại tình trạng phiếu mượn
                    phieumuon.TinhTrangPhieuMuonID = 2;//2 là phiếu mượn hoan thanh
                    _context.SaveChanges();

                    for (int i = 0; i < model.Count; i++)
                    {
                        // trễ hạn nhưng đủ sách
                        if (model[i].IsSelected == true)
                        {
                            var sach = _context.Sach.FirstOrDefault(x => x.SachID == model[i].SachID);
                            sach.TinhTrangSachID = 1; //1 chua thue
                            _context.SaveChanges();
                        }
                        // trễ hạn nhưng thiếu sách
                        else
                        {
                            var sach = _context.Sach.FirstOrDefault(x => x.SachID == model[i].SachID);
                            sach.TinhTrangSachID = 3; //3 mat
                            sum += sach.Gia;
                        }
                    }
                    PhieuThuTienPhat pttp = new PhieuThuTienPhat();
                    pttp.DocGiaID   = docgia.DocGiaID;
                    pttp.PhieuTraID = phieutra.PhieuTraID;
                    pttp.TienCoc    = phieumuon.TienCoc;
                    pttp.TienPhat   = sum;
                    pttp.TienConLai = phieumuon.TienCoc - pttp.TienPhat;
                    _context.PhieuThuTienPhat.Add(pttp);
                    _context.SaveChanges();

                    return(RedirectToAction("details", new RouteValueDictionary(new { Controller = "phieuthutienphat", Action = "details", id = pttp.PhieuThuTienPhatID })));
                }
            }
        }
Exemplo n.º 3
0
 public bool insertData(PhieuTra data)
 {
     return(obj.insertData(data));
 }
Exemplo n.º 4
0
        private void btnTaoPT_Click(object sender, EventArgs e)
        {
            if (cmbMaDocGia.SelectedIndex < 0)
            {
                MessageBox.Show("Chọn mã độc giả trước!");
                return;
            }
            if (lstctpt.Count < 1)
            {
                MessageBox.Show("Dữ liệu trống!");
                return;
            }
            PhieuTra data = new PhieuTra();
            string   idPT = frm.getIDPT();

            data.MaPhieuTra = idPT;
            data.MaDocGia   = cmbMaDocGia.SelectedValue.ToString();
            data.NgayTra    = DateTime.Today.ToShortDateString();
            data.ThanhTien  = 0;
            for (int i = 0; i < lstctpt.Count; i++)
            {
                data.ThanhTien += lstctpt[i].ThanhTien;
            }
            bool check = false;

            check = objpt.insertData(data);

            String      idPM = "";
            List <CTPM> temp = new List <CTPM>();

            for (int i = 0; i < lstctpt.Count; i++)
            {
                CTPT pt = new CTPT();
                pt.MaCTPT = frm.getIDCTPT();
                MessageBox.Show(pt.MaCTPT);
                pt.MaPhieuTra = idPT;
                pt.MaSach     = lstctpt[i].MaSach;
                pt.ThanhTien  = lstctpt[i].ThanhTien;
                temp          = objctpm.getAll("", "maCTPM= '" + lstctpt[i].MaCTPM + "'", "");
                idPM          = temp[0].MaPM;
                temp          = objctpm.getAll("", "maPM= '" + idPM + "'", "");
                check         = objctpt.insertData(pt);
                objctpm.deleteData(lstctpt[i].MaCTPM);
                if (temp.Count == 1)
                {
                    objpm.deleteData(idPM);
                }
            }
            if (check)
            {
                MessageBox.Show("Tạo phiếu trả thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                if (MessageBox.Show("Bạn muốn xuất phiếu trả?", "Thông báo!", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    new frmPTReport(data.MaPhieuTra, data.MaDocGia, data.ThanhTien.ToString()).ShowDialog();
                }
            }
            else
            {
                MessageBox.Show("Tạo phiếu trả không thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            this.Hide();
        }