public ActionResult Details(int?id, int page = 1, int pageSize = 10, string search = null)
        {
            if (id == null)
            {
                putErrorMessage("Đường dẫn không chính xác");
                return(RedirectToAction("TheoDoi"));
            }
            ViewBag.cultureInfo = CultureInfo;
            var dl = DaiLyManager.find((int)id);

            if (dl == null)
            {
                putErrorMessage("Không tìm thấy đại lý");
                return(RedirectToAction("TheoDoi"));
            }
            ViewBag.currentDaiLy = dl;
            var DMCongNo = dl.CongNo;

            if (!String.IsNullOrEmpty(search))
            {
                DMCongNo          = CongNoDaiLyManager.filter(search, DMCongNo);
                ViewBag.SearchKey = search;
            }
            ViewBag.tongSoLuongNo = DMCongNo.Sum(cn => cn.SoLuong);
            ViewBag.tongTienNo    = DMCongNo.Sum(cn => cn.ThanhTien);
            var models = DMCongNo.ToPagedList(page, pageSize);

            setAlertMessage();
            return(View(models));
        }
 public ActionResult Delete(int?id, FormCollection collection)
 {
     try
     {
         if (id == null)
         {
             putErrorMessage("Đường dẫn không chính xác");
             return(RedirectToAction("Index"));
         }
         var model = DaiLyManager.find((int)id);
         if (model == null || model.TrangThai == 0)
         {
             putErrorMessage("Không tìm thấy đại lý");
             return(RedirectToAction("Index"));
         }
         // TODO: Add delete logic here
         if (model.delete())
         {
             putSuccessMessage("Đã xóa");
             return(RedirectToAction("Index"));
         }
         else
         {
             putErrorMessage("Xóa thất bại");
             return(RedirectToAction("Delete", new { id }));
         }
     }
     catch (Exception ex)
     {
         putErrorMessage(ex.Message);
         return(RedirectToAction("Delete", new { id }));
     }
 }
 private void cmbDaiLy_SelectionChangeCommitted(object sender, EventArgs e)
 {
     _currentDaiLy     = DaiLyManager.find(int.Parse(cmbDaiLy.SelectedValue.ToString()));
     txbMaSoDaiLy.Text = _currentDaiLy.MaSoDaiLy + "";
     loadSach();
     cmbDaiLy.Enabled = false;
 }
        // GET: DaiLy/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                putErrorMessage("Đường dẫn không chính xác");
                return(RedirectToAction("Index"));
            }
            var model = DaiLyManager.find((int)id);

            if (model == null || model.TrangThai == 0)
            {
                putErrorMessage("Không tìm thấy đại lý");
                return(RedirectToAction("Index"));
            }
            setAlertMessage();
            return(View(model));
        }
        public ViewResult BlankEditorRow(int masodaily, int masosach = 0)
        {
            var dl      = DaiLyManager.find((int)masodaily);
            var chitiet = new ChiTietHoaDonDaiLy();

            if (masosach != 0)
            {
                chitiet.MaSoSach = (int)masosach;
                if (_hoadon.ChiTiet.Contains(chitiet))
                {
                    return(null);
                }
            }
            else
            {
                var founded = false;
                foreach (Sach s in dl.getSachNo())
                {
                    chitiet.MaSoSach = s.MaSoSach;
                    chitiet.Sach     = s;
                    if (_hoadon.ChiTiet.Contains(chitiet))
                    {
                        continue;
                    }
                    founded = true;
                    break;
                }
                if (!founded)
                {
                    return(null);
                }
            }
            ViewBag.currentDaiLy = dl;
            ViewBag.cultureInfo  = CultureInfo;
            ViewBag.DMSach       = new SelectList(dl.getSachNo(),
                                                  nameof(SachManager.Properties.MaSoSach),
                                                  nameof(SachManager.Properties.TenSach), "");
            chitiet.SoLuong = 1;
            chitiet.DonGia  = chitiet.Sach.GiaNhap;
            _hoadon.addDetail(chitiet);
            ViewData["masodaily"] = dl.MaSoDaiLy;
            return(View("ChiTietEditorRow", chitiet));
        }
 // GET: PhieuNhap/ThanhToan
 public ActionResult ThanhToan(int?masodaily)
 {
     if (masodaily != null)
     {
         var dl = DaiLyManager.find((int)masodaily);
         if (dl == null || dl.TrangThai == 0)
         {
             putErrorMessage("Không tìm thấy đại lý");
             return(RedirectToAction("ThanhToan"));
         }
         ViewBag.cultureInfo  = CultureInfo;
         ViewBag.currentDaiLy = dl;
         ViewBag.DMSach       = new SelectList(dl.getSachNo(),
                                               nameof(SachManager.Properties.MaSoSach),
                                               nameof(SachManager.Properties.TenSach), "");
         if (_hoadon == null)
         {
             _hoadon = new HoaDonDaiLy();
         }
         _hoadon.MaSoDaiLy = dl.MaSoDaiLy;
         _hoadon.DaiLy     = dl;
         _hoadon.NgayLap   = DateTime.Now;
         setAlertMessage();
         return(View(_hoadon));
     }
     else
     {
         ViewBag.DMDaiLy = new SelectList(DaiLyManager.getAllAlive()
                                          .Where(dl => dl.TongTienNo > 0).ToList(),
                                          nameof(DaiLyManager.Properties.MaSoDaiLy),
                                          nameof(DaiLyManager.Properties.TenDaiLy), "");
         _hoadon = new HoaDonDaiLy();
         setAlertMessage();
         return(View());
     }
 }