Ejemplo n.º 1
0
 // 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 (_currentPhieu == null || _currentPhieu != id)
     {
         _currentPhieu = id;
         _phieu        = PhieuNhapManager.find((int)id);
         if (_phieu == null)
         {
             putErrorMessage("Không tìm thấy");
             return(RedirectToAction("All"));
         }
         if (_phieu.TrangThai == 1)
         {
             //Nếu đã duyệt thì không cho sửa, chuyển sang trang chi tiết
             putErrorMessage("Phiếu đã duyệt");
             return(RedirectToAction("Details", new { id = id }));
         }
     }
     ViewBag.cultureInfo = CultureInfo;
     ViewBag.currentNXB  = _phieu.NXB;
     ViewBag.DMSach      = new SelectList(_phieu.NXB.Sach,
                                          nameof(SachManager.Properties.MaSoSach),
                                          nameof(SachManager.Properties.TenSach), "");
     setAlertMessage();
     return(View(_phieu));
 }
Ejemplo n.º 2
0
        //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 = PhieuNhapManager.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 thất bại");
                return(RedirectToAction("Delete", new { id }));
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Duyệt phiếu nhập
 /// </summary>
 /// <returns></returns>
 public bool accept()
 {
     //Duyệt từng chi tiết
     foreach (ChiTietPhieuNhap ct in this.ChiTiet)
     {
         //Cập nhật thông tin sách
         ct.Sach.Soluong += ct.SoLuong;
         if (!SachManager.edit(ct.Sach))
         {
             return(false);
         }
         //Ghi thẻ kho
         var tk = new TheKho
         {
             MaSoSach = ct.MaSoSach,
             SoLuong  = ct.Sach.Soluong,
             NgayGhi  = DateTime.Now
         };
         if (TheKhoManager.add(tk) == 0)
         {
             return(false);
         }
         //Cập nhật công nợ
         var congno = new CongNoNXB
         {
             MaSoNXB  = this.MaSoNXB,
             MaSoSach = ct.MaSoSach,
             SoLuong  = ct.SoLuong,
             DonGia   = ct.DonGia,
             Thang    = DateTime.Now
         };
         if (CongNoNXBManager.add(congno) == 0)
         {
             return(false);
         }
         ct.TrangThai = 1;
     }
     //Thay đổi trang thái phiếu nhập
     this.TrangThai = 1;
     if (PhieuNhapManager.edit(this))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Ejemplo n.º 4
0
        // 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 = PhieuNhapManager.find((int)id);

            if (model == null)
            {
                putErrorMessage("Không tìm thấy");
                return(RedirectToAction("All"));
            }
            setAlertMessage();
            return(View(model));
        }
Ejemplo n.º 5
0
        private void btXoa_Click(object sender, EventArgs e)
        {
            ///  List<ChiTietPhieuNhap> _DSCTPN = PhieuNhapManager.ChiTiet.getAll();
            /// kiểm trạng trạng thái
            DialogResult dialogResult = MessageBox.Show("Bạn có muốn xóa", "Thông báo", MessageBoxButtons.YesNo);

            if (dialogResult == DialogResult.Yes)
            {
                if (!txbMaPhieuNhap.Text.Equals(""))
                {
                    PhieuNhap pn    = new PhieuNhap();
                    int       x     = int.Parse(txbMaPhieuNhap.Text.ToString());
                    var       phieu = PhieuNhapManager.find(x);

                    if (phieu.TrangThai != 1)
                    {
                        if (PhieuNhapManager.delete(phieu.MaSoPhieuNhap))
                        {
                            MessageBox.Show("Đã xóa thành công");
                            LoadDSPM();
                        }
                        else
                        {
                            MessageBox.Show("Không xóa được");
                        }
                    }
                    else
                    {
                        MessageBox.Show("Không tìm thấy");
                    }
                }
                else
                {
                    MessageBox.Show("Chọn phiếu nhập cần xóa");
                }
            }
            else if (dialogResult == DialogResult.No)
            {
                return;
            }
        }
Ejemplo n.º 6
0
        // GET: PhieuNhap
        public ActionResult All(int page = 1, int pageSize = 10, string search = null)
        {
            List <PhieuNhap> DMPhieu = null;

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

            setAlertMessage();
            return(View(models));
        }
Ejemplo n.º 7
0
 public ActionResult Delete(int id, FormCollection collection)
 {
     try
     {
         if (PhieuNhapManager.delete((int)id))
         {
             putSuccessMessage("Xóa thành công");
             return(RedirectToAction("All"));
         }
         else
         {
             putErrorMessage("Xóa thất bại");
         }
         return(RedirectToAction("Delete", new { id }));
     }
     catch (Exception ex)
     {
         putErrorMessage(ex.Message);
         return(RedirectToAction("Delete", new { id }));
     }
 }
Ejemplo n.º 8
0
        // 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 = PhieuNhapManager.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 = model.MaSoPhieuNhap }));
            }
            setAlertMessage();
            return(View(model));
        }
Ejemplo n.º 9
0
 public ActionResult Create(PhieuNhap model, FormCollection collection)
 {
     try
     {
         // TODO: Add insert logic here
         if (ModelState.IsValid)
         {
             var result = PhieuNhapManager.add(model);
             if (result != 0)
             {
                 _phieu = null;
                 putSuccessMessage("Thêm thành công");
                 return(RedirectToAction("Details", new { id = result }));
             }
             else
             {
                 putErrorMessage("Thêm không thành công");
             }
         }
         else
         {
             putModelStateFailErrors(ModelState);
         }
         return(RedirectToAction("Create", new { masonxb = _phieu.MaSoNXB }));
         //ViewBag.cultureInfo = CultureInfo;
         //ViewBag.currentNXB = _phieu.NXB;
         //ViewBag.DMSach = new SelectList(_phieu.NXB.Sach,
         //                        nameof(SachManager.Properties.MaSoSach),
         //                        nameof(SachManager.Properties.TenSach), "");
         //_phieu.NgayLap = DateTime.Now;
         //setAlertMessage();
         //return View(_phieu);
     }
     catch (Exception ex)
     {
         putErrorMessage(ex.Message);
         return(RedirectToAction("Create", new { masonxb = _phieu.MaSoNXB }));
     }
 }
Ejemplo n.º 10
0
        private void btDuyet_Click(object sender, EventArgs e)
        {
            DialogResult dialogResult = MessageBox.Show("Bạn có muốn duyệt phiếu nhập", "Thông báo", MessageBoxButtons.YesNo);

            if (dialogResult == DialogResult.Yes)
            {
                if (!txbMaPhieuNhap.Text.Equals(""))
                {
                    int ma    = int.Parse(txbMaPhieuNhap.Text.ToString());
                    var Phieu = PhieuNhapManager.find(ma);

                    // thêm kiểm tra trạng thái phiếu nhập
                    if (Phieu != null)
                    {
                        if (Phieu.accept())
                        {
                            MessageBox.Show("Đã duyệt thành công");
                            LoadDSPM();
                        }
                        else
                        {
                            MessageBox.Show("Chưa duyệt được");
                        }
                    }
                    else
                    {
                        MessageBox.Show("Không tìm thấy phiếu nhập");
                    }
                }
                else
                {
                    MessageBox.Show("Chưa chọn phiếu nhập cần duyệt");
                }
            }
            else if (dialogResult == DialogResult.No)
            {
                return;
            }
        }
Ejemplo n.º 11
0
 public ActionResult Edit(PhieuNhap model, FormCollection collection)
 {
     try
     {
         if (ModelState.IsValid)
         {
             if (PhieuNhapManager.edit(model))
             {
                 _currentPhieu = null;
                 putSuccessMessage("Cập nhật thành công");
                 return(RedirectToAction("Details", new { id = model.MaSoPhieuNhap }));
             }
             else
             {
                 putErrorMessage("Cập nhật thất bại");
             }
         }
         else
         {
             putModelStateFailErrors(ModelState);
         }
         return(RedirectToAction("Edit", new { id = model.MaSoNXB }));
         // TODO: Add update logic here
         //_phieu = model;
         //ViewBag.currentNXB = _phieu.NXB;
         //ViewBag.DMSach = new SelectList(_phieu.NXB.Sach,
         //                        nameof(SachManager.Properties.MaSoSach),
         //                        nameof(SachManager.Properties.TenSach), "");
         //return View(_phieu);
     }
     catch (Exception ex)
     {
         putErrorMessage(ex.Message);
         return(RedirectToAction("Edit", new { id = model.MaSoNXB }));
     }
 }
Ejemplo n.º 12
0
 private void loadDSChuaDuyet()
 {
     __DSPN = PhieuNhapManager.getUnaproved();
     gdvPhieuNhap.DataSource = __DSPN;
 }
Ejemplo n.º 13
0
 private void LoadDSPM()
 {
     __DSPN = PhieuNhapManager.getAll();
     gdvPhieuNhap.DataSource = __DSPN;
 }
Ejemplo n.º 14
0
        //Khi Nhấn Lưu lại phiếu nhập
        private void btnLuu_Click(object sender, EventArgs e)
        {
            DialogResult dialogResult = MessageBox.Show("Bạn có muốn lưu phiếu nhập này", "Thông báo", MessageBoxButtons.YesNo);

            if (dialogResult == DialogResult.Yes)
            {
                decimal tongtien             = 0;
                List <ChiTietPhieuNhap> list = new List <ChiTietPhieuNhap>();
                if (!txbNguoiGiao.Text.Equals(""))
                {
                    PhieuNhap pn = new PhieuNhap();
                    pn.MaSoNXB   = int.Parse(cmbNhaXuatBan.SelectedValue.ToString());
                    pn.NgayLap   = DateTime.Parse(dtpNgayLap.Value.ToString("yyyy-MM-dd"));
                    pn.NguoiGiao = txbNguoiGiao.Text.ToString();

                    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)))
                        {
                            ChiTietPhieuNhap ctpn = new ChiTietPhieuNhap();
                            ctpn.MaSoSach = int.Parse(gdvChiTiet.Rows[i].Cells[0].Value.ToString());
                            ctpn.SoLuong  = int.Parse(gdvChiTiet.Rows[i].Cells[1].Value.ToString());
                            ctpn.DonGia   = int.Parse(gdvChiTiet.Rows[i].Cells[2].Value.ToString());
                            tongtien      = tongtien + ctpn.SoLuong * ctpn.DonGia;
                            if (list.Any(s => s.MaSoSach == ctpn.MaSoSach))
                            {
                                MessageBox.Show("Không được nhập trùng chi tiết");
                                return;
                            }
                            list.Add(ctpn);
                        }
                        else
                        {
                            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)))
                            {
                                MessageBox.Show("Chưa nhập đủ thông tin vào bảng");
                                return;
                            }
                        }
                    }

                    pn.ChiTiet = list;

                    pn.TongTien = tongtien;
                    int x = PhieuNhapManager.add(pn);
                    if (x != 0)
                    {
                        MessageBox.Show("đã thêm thành công");
                        txbMaPhieuNhap.Text = x + "";
                    }
                    else
                    {
                        MessageBox.Show("Không thêm được");
                    }
                }
                else
                {
                    MessageBox.Show("Bạn chưa nhập người giao hàng");
                }
            }
            else if (dialogResult == DialogResult.No)
            {
                return;
            }
        }