//Duyệt phiếu
        public ActionResult Accept(int?id)
        {
            if (id == null)
            {
                putErrorMessage("Đường dẫn không chính xác");
                return(RedirectToAction("All"));
            }
            var model = HoaDonNXBManager.find((int)id);

            if (model == null)
            {
                putErrorMessage("Không tìm thấy");
                return(RedirectToAction("All"));
            }
            if (model.TrangThai == 1)
            {
                putErrorMessage("Phiếu đã duyệt");
                return(RedirectToAction("Details", new { id = id }));
            }
            if (model.accept())
            {
                putSuccessMessage("Duyệt thành công");
                return(RedirectToAction("Details", new { id = id }));
            }
            else
            {
                putErrorMessage("Duyệt không thành công, vui lòng kiểm tra lại công nợ");
                return(RedirectToAction("Edit", new { id }));
            }
        }
 // GET: PhieuNhap/Edit/5
 public ActionResult Edit(int?id)
 {
     if (id == null)
     {
         putErrorMessage("Đường dẫn không chính xác");
         return(RedirectToAction("All"));
     }
     if (_currentHoaDon == null || _currentHoaDon != id)
     {
         _currentHoaDon = id;
         _hoadon        = HoaDonNXBManager.find((int)id);
         if (_hoadon == null)
         {
             putErrorMessage("Không tìm thấy");
             return(RedirectToAction("All"));
         }
         if (_hoadon.TrangThai == 1)
         {
             //Nếu đã duyệt thì không cho sửa, chuyển sang trang chi tiết
             _currentHoaDon = null;
             putErrorMessage("Hóa đơn đã duyệt");
             return(RedirectToAction("Details", new { id = id }));
         }
     }
     ViewBag.cultureInfo = CultureInfo;
     ViewBag.currentNXB  = _hoadon.NXB;
     ViewBag.DMSach      = new SelectList(_hoadon.NXB.Sach.Where(s => s.CongNoNXB.Count > 0).ToList(),
                                          nameof(SachManager.Properties.MaSoSach),
                                          nameof(SachManager.Properties.TenSach), "");
     setAlertMessage();
     return(View(_hoadon));
 }
        private void btnLuu_Click(object sender, EventArgs e)
        {
            DialogResult dialogResult = MessageBox.Show("Bạn có muốn lưu", "Thông báo", MessageBoxButtons.YesNo);

            if (dialogResult == DialogResult.Yes)
            {
                List <ChiTietHoaDonNXB> ListChiTiet = new List <ChiTietHoaDonNXB>();
                HoaDonNXB hd = new HoaDonNXB();
                hd.MaSoNXB = int.Parse(txbMaSoNXB.Text.ToString());
                hd.NgayLap = DateTime.Parse(dtpNgayLap.Value.ToString("yyyy-MM-dd"));
                //Lay list chi tiet
                for (int i = 0; i < gdvChiTiet.RowCount - 1; i++)
                {
                    if (!String.IsNullOrEmpty(Convert.ToString(gdvChiTiet.Rows[i].Cells[0].Value)) && !String.IsNullOrEmpty(Convert.ToString(gdvChiTiet.Rows[i].Cells[1].Value)) && !String.IsNullOrEmpty(Convert.ToString(gdvChiTiet.Rows[i].Cells[2].Value)))
                    {
                        ChiTietHoaDonNXB ct = new ChiTietHoaDonNXB();
                        ct.MaSoSach = int.Parse(gdvChiTiet.Rows[i].Cells[0].Value.ToString());
                        ct.SoLuong  = int.Parse(gdvChiTiet.Rows[i].Cells[1].Value.ToString());
                        ct.DonGia   = int.Parse(gdvChiTiet.Rows[i].Cells[2].Value.ToString());
                        ListChiTiet.Add(ct);
                    }
                }
                //Kiem tra chi tiet . Chi ong code cai nay nhin no gon hon ne
                if (ListChiTiet.Count > 1)
                {
                    for (int i = 0; i < ListChiTiet.Count - 1; i++)
                    {
                        for (int j = i + 1; j < ListChiTiet.Count; j++)
                        {
                            if (ListChiTiet[i].MaSoSach.Equals(ListChiTiet[j].MaSoSach))
                            {
                                MessageBox.Show("Không nhập trùng sách");
                                return;
                            }
                        }
                    }
                }
                hd.ChiTiet = ListChiTiet;


                //for (int i = 0; i < ListChiTiet.Count; i++)
                //{

                //    hd.addDetail(ListChiTiet[i]);
                //}

                int x = HoaDonNXBManager.add(hd);
                if (x != 0)
                {
                    MessageBox.Show("Đã thêm thành công hóa đơn nhà xuất bản");
                    txbMaHoaDon.Text = x + "";
                }
            }
            else if (dialogResult == DialogResult.No)
            {
                return;
            }
        }
        // GET: PhieuNhap/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                putErrorMessage("Đường dẫn không chính xác");
                return(RedirectToAction("All"));
            }
            var model = HoaDonNXBManager.find((int)id);

            if (model == null)
            {
                putErrorMessage("Không tìm thấy");
                return(RedirectToAction("All"));
            }
            setAlertMessage();
            return(View(model));
        }
Exemplo n.º 5
0
        private void btXoa_Click(object sender, EventArgs e)
        {
            DialogResult dialogResult = MessageBox.Show("Bạn có muốn xóa", "Thông báo", MessageBoxButtons.YesNo);

            if (dialogResult == DialogResult.Yes)
            {
                if (HoaDonNXBManager.delete(_CurrentHD.MaSoHoaDon))
                {
                    MessageBox.Show("Đã xóa thành công");
                }
                else
                {
                    MessageBox.Show("Không xóa được");
                }
            }
            else if (dialogResult == DialogResult.No)
            {
                return;
            }
        }
        // GET: PhieuNhap
        public ActionResult All(int page = 1, int pageSize = 10, string search = null)
        {
            List <HoaDonNXB> DMHoaDon = null;

            ViewBag.cultureInfo = CultureInfo;
            if (!String.IsNullOrEmpty(search))
            {
                DMHoaDon          = HoaDonNXBManager.filter(search);
                ViewBag.SearchKey = search;
            }
            else
            {
                DMHoaDon = HoaDonNXBManager.getAll();
            }
            ViewBag.tongTien = DMHoaDon.Sum(hd => hd.TongTien);
            //ViewBag.tongSoLuong = DMHoaDon.Sum(hd => hd.ChiTiet.Sum(ct => ct.SoLuong));
            var models = DMHoaDon.ToPagedList(page, pageSize);

            setAlertMessage();
            return(View(models));
        }
 public ActionResult Delete(int?id, FormCollection collection)
 {
     try
     {
         if (HoaDonNXBManager.delete((int)id))
         {
             putSuccessMessage("Đã xóa");
             _currentHoaDon = null;
             return(RedirectToAction("All"));
         }
         else
         {
             putErrorMessage("Xóa không thành công");
             return(RedirectToAction("Delete", new { id }));
         }
     }
     catch (Exception ex)
     {
         putErrorMessage(ex.Message);
         return(RedirectToAction("Delete", new { id }));
     }
 }
        // GET: PhieuNhap/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                putErrorMessage("Đường dẫn không chính xác");
                return(RedirectToAction("All"));
            }
            var model = HoaDonNXBManager.find((int)id);

            if (model == null)
            {
                putErrorMessage("Không tìm thấy");
                return(RedirectToAction("All"));
            }
            if (model.TrangThai == 1)
            {
                putErrorMessage("Hóa đơn đã duyệt");
                return(RedirectToAction("Details", new { id = model.MaSoHoaDon }));
            }
            setAlertMessage();
            return(View(model));
        }
 public ActionResult ThanhToan(HoaDonNXB model, FormCollection collection)
 {
     try
     {
         // TODO: Add insert logic here
         if (ModelState.IsValid)
         {
             var result = HoaDonNXBManager.add(model);
             if (result != 0)
             {
                 _hoadon = null;
                 putSuccessMessage("Thêm hóa đơn thành công");
                 return(RedirectToAction("Details", new { id = result }));
             }
             else
             {
                 putErrorMessage("Thánh toán không thành công");
                 return(RedirectToAction("ThanhToan", new { masonxb = _hoadon.MaSoNXB }));
             }
         }
         else
         {
             putModelStateFailErrors(ModelState);
             return(RedirectToAction("ThanhToan", new { masonxb = _hoadon.MaSoNXB }));
         }
         //ViewBag.cultureInfo = CultureInfo;
         //ViewBag.currentNXB = _hoadon.NXB;
         //ViewBag.DMSach = new SelectList(_hoadon.NXB.Sach.Where(s => s.CongNoNXB.Count > 0).ToList(),
         //                        nameof(SachManager.Properties.MaSoSach),
         //                        nameof(SachManager.Properties.TenSach), "");
         //_hoadon.NgayLap = DateTime.Now;
         //return View(_hoadon);
     }
     catch (Exception ex)
     {
         putErrorMessage(ex.Message);
         return(RedirectToAction("ThanhToan", new { masonxb = _hoadon.MaSoNXB }));
     }
 }
 public ActionResult Edit(HoaDonNXB model, FormCollection collection)
 {
     try
     {
         if (ModelState.IsValid)
         {
             if (HoaDonNXBManager.edit(model))
             {
                 _currentHoaDon = null;
                 putSuccessMessage("Cập nhật thành công");
                 return(RedirectToAction("Details", new { id = model.MaSoHoaDon }));
             }
             else
             {
                 putErrorMessage("Cập nhật thất bại");
             }
         }
         else
         {
             putModelStateFailErrors(ModelState);
         }
         return(RedirectToAction("Edit", new { id = model.MaSoHoaDon }));
         // TODO: Add update logic here
         //_hoadon = model;
         //ViewBag.currentNXB = _hoadon.NXB;
         //ViewBag.DMSach = new SelectList(_hoadon.NXB.Sach.Where(s => s.CongNoNXB.Count > 0).ToList(),
         //                        nameof(SachManager.Properties.MaSoSach),
         //                        nameof(SachManager.Properties.TenSach), "");
         //return View(_hoadon);
     }
     catch (Exception ex)
     {
         putErrorMessage(ex.Message);
         return(RedirectToAction("Edit", new { id = model.MaSoHoaDon }));
     }
 }
Exemplo n.º 11
0
        private void btDuyet_Click(object sender, EventArgs e)
        {
            DialogResult dialogResult = MessageBox.Show("Bạn có muốn duyệt hóa đơn", "Thông báo", MessageBoxButtons.YesNo);

            if (dialogResult == DialogResult.Yes)
            {
                if (_CurrentHD != null && _CurrentHD.TrangThai == 0)
                {
                    if (_CurrentHD.accept())
                    {
                        MessageBox.Show("Duyệt hóa đơn thành công");
                        gdvHoaDon.DataSource = HoaDonNXBManager.getAll();
                    }
                    else
                    {
                        MessageBox.Show("Duyệt không thành công, vui lòng kiểm tra lại công nợ");
                    }
                }
            }
            else if (dialogResult == DialogResult.No)
            {
                return;
            }
        }
Exemplo n.º 12
0
 private void btChuaDuyet_Click(object sender, EventArgs e)
 {
     gdvHoaDon.DataSource = HoaDonNXBManager.getUnaproved();
 }
Exemplo n.º 13
0
 private void btLoadAll_Click(object sender, EventArgs e)
 {
     gdvHoaDon.DataSource = HoaDonNXBManager.getAll();
 }
Exemplo n.º 14
0
 public bool accept()
 {
     //Kiểm tra số lượng có thể duyệt không
     foreach (ChiTietHoaDonNXB ct in this.ChiTiet)
     {
         //Nếu tổng số lượng sách mà nhà xuất bản nợ ít hơn só sách sẽ thanh toán thì hủy duyệt
         if (ct.Sach.TongSoLuongNXBNo < ct.SoLuong)
         {
             return(false);
         }
     }
     //Duyệt từng chi tiết
     foreach (ChiTietHoaDonNXB ct in this.ChiTiet)
     {
         //
         //Cập nhật công nợ
         var sl    = ct.SoLuong;              // Số lượng sách thanh toán
         var count = ct.Sach.CongNoNXB.Count; // Số lượng các công nợ
         var index = 0;
         while (sl > 0)
         {
             if (index == count)
             {
                 //Đã duyệt hết các công nợ
                 break;
             }
             if (ct.Sach.CongNoNXB[index].SoLuong >= sl) // Nếu công nợ nhiều hơn hoặc bằng số lượng thanh toán
             {
                 //Giảm số lượng công nợ
                 ct.Sach.CongNoNXB[index].SoLuong -= sl;
                 sl -= sl;
                 //Cập nhật
                 if (!CongNoNXBManager.edit(ct.Sach.CongNoNXB[index]))
                 {
                     return(false);
                 }
             }
             else // Nếu công nợ ít hơn số lượng thanh toán
             {
                 sl -= ct.Sach.CongNoNXB[index].SoLuong;
                 ct.Sach.CongNoNXB[index].SoLuong = 0;
                 //Cập nhật
                 if (!CongNoNXBManager.edit(ct.Sach.CongNoNXB[index]))
                 {
                     return(false);
                 }
             }
             index++;
         }
         ct.TrangThai = 1;
     }
     //Thay đổi trang thái phiếu nhập
     this.TrangThai = 1;
     if (HoaDonNXBManager.edit(this))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }