Пример #1
0
 private void txbLoc_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Enter)
     {
         gdvDanhMucSach.DataSource = SachManager.filter(txbLoc.Text, _DMSach);
     }
 }
 public ActionResult LoNhap(DateTime?startDate, DateTime?endDate, int page = 1, int pageSize = 10, string search = null)
 {
     if (startDate != null && endDate != null)
     {
         ViewBag.cultureInfo = CultureInfo;
         ViewBag.startDate   = startDate;
         ViewBag.endDate     = endDate;
         List <Sach> DMSach = SachManager.getAll()
                              .Where(s => s.tongSoLuongNhapTheoThang(
                                         ((DateTime)startDate).Month,
                                         ((DateTime)startDate).Year,
                                         ((DateTime)endDate).Month,
                                         ((DateTime)endDate).Year) > 0 &&
                                     s.tongTienNhapTheoThang(
                                         ((DateTime)startDate).Month,
                                         ((DateTime)startDate).Year,
                                         ((DateTime)endDate).Month,
                                         ((DateTime)endDate).Year) > 0).ToList();
         if (!String.IsNullOrEmpty(search))
         {
             DMSach            = SachManager.filter(search, DMSach);
             ViewBag.SearchKey = search;
         }
         ViewBag.tongSoLuongNhap = DMSach.Sum(s => s.SoLuongNhapTheoThang);
         ViewBag.tongTienNhap    = DMSach.Sum(s => s.TongTienNhapTheoThang);
         var models = DMSach.ToPagedList(page, pageSize);
         setAlertMessage();
         return(View(models));
     }
     setAlertMessage();
     return(View());
 }
Пример #3
0
        //Xóa sách đã chọn
        private void btnXoa_Click(object sender, EventArgs e)
        {
            DialogResult dialogResult = MessageBox.Show("Bạn có muốn xóa sản phẩm", "Thông báo", MessageBoxButtons.YesNo);

            if (dialogResult == DialogResult.Yes)
            {
                if (!txbMaSach.Text.Equals(""))
                {
                    if (SachManager.delete(int.Parse(txbMaSach.Text)))
                    {
                        MessageBox.Show("Xóa sách thành công");
                        reload();
                    }
                    else
                    {
                        MessageBox.Show("Không xóa được, vui lòng kiểm tra lại");
                    }
                }
                else
                {
                    MessageBox.Show("Nhập vào mã sách cần xóa");
                }
            }
            else if (dialogResult == DialogResult.No)
            {
                return;
            }
        }
        public ActionResult Search(string request = null, int page = 1, int pageSize = 9)
        {
            if (String.IsNullOrEmpty(request))
            {
                return(RedirectToAction("Index"));
            }
            List <Sach> DMSach = null;

            if (Session[Core.Constants.SESSION.BOOKS] == null)
            {
                DMSach = SachManager.getAllAlive();
                Session[Core.Constants.SESSION.BOOKS] = DMSach;
            }
            else
            {
                DMSach = Session[Core.Constants.SESSION.BOOKS] as List <Sach>;
            }
            DMSach = SachManager.filter(request, DMSach);
            if (DMSach.Count == 0)
            {
                putErrorMessage("Không có kết quả nào");
            }
            ViewBag.searchKey = request;
            var models = DMSach.ToPagedList(page, pageSize);

            setAlertMessage();
            return(View(models));
        }
Пример #5
0
 public ActionResult Edit(Sach model, HttpPostedFileBase file)
 {
     try
     {
         // TODO: Add update logic here
         if (ModelState.IsValid)
         {
             if (file != null)
             {
                 model.HinhAnhTypeImage = Image.FromStream(file.InputStream);
             }
             if (SachManager.edit(model))
             {
                 putSuccessMessage("Cập nhật thành công");
                 return(RedirectToAction("Details", new { id = model.MaSoSach }));
             }
         }
         else
         {
             putModelStateFailErrors(ModelState);
         }
         return(RedirectToAction("Edit", new { id = model.MaSoSach }));
     }
     catch (Exception ex)
     {
         putErrorMessage(ex.Message);
         return(RedirectToAction("Edit", new { id = model.MaSoSach }));
     }
 }
Пример #6
0
        // GET: Sach/Details/5
        public ActionResult Details(int?id)  // id là mã số sách
        {
            if (id == null)
            {
                putErrorMessage("Đường dẫn không chính xác");
                return(RedirectToAction("Index"));
            }
            ViewBag.cultureInfo = CultureInfo; // Sử dụng cho hiển thị tiền tệ VNĐ
            var model = SachManager.find((int)id);

            if (model == null || model.TrangThai == 0)
            {
                putErrorMessage("Không tìm thấy");
                return(RedirectToAction("Index"));
            }
            if (model.HinhAnh == null)
            {
                ViewBag.DefaultImage = "/Resources/DefaultImage.png"; // Load hình ảnh mặc định nếu chưa có hình
            }
            else
            {
                ViewBag.imgSrc = ImagesHelper.ImageToDataBase64String(model.HinhAnhTypeImage);
            }
            setAlertMessage();
            return(View(model));
        }
Пример #7
0
 public ActionResult Delete(int id, FormCollection collection)
 {
     try
     {
         var model = SachManager.find((int)id);
         if (model == null || model.TrangThai == 0)
         {
             putErrorMessage("Không tìm thấy");
             return(RedirectToAction("Index"));
         }
         // TODO: Add delete logic here
         if (model.delete())
         {
             putSuccessMessage("Xóa thành công");
             return(RedirectToAction("Index"));
         }
         else
         {
             putErrorMessage("Xóa không thành công");
             return(RedirectToAction("Delete", new { id }));
         }
     }
     catch (Exception ex)
     {
         putErrorMessage(ex.Message);
         return(View(id));
     }
 }
Пример #8
0
        // GET: Sach
        public ActionResult Index(int page = 1, int pageSize = 10, string search = null)
        {
            List <Sach> DMSach = null;

            if (Session[Core.Constants.TEMPDATA.BOOKS] == null)
            {
                DMSach = SachManager.getAllAlive();
                Session[Core.Constants.TEMPDATA.BOOKS] = DMSach;
            }
            else
            {
                DMSach = Session[Core.Constants.TEMPDATA.BOOKS] as List <Sach>;
            }

            ViewBag.cultureInfo = CultureInfo;
            if (!String.IsNullOrEmpty(search))
            {
                DMSach            = SachManager.filter(search, DMSach);
                ViewBag.SearchKey = search;
            }

            var models = DMSach.ToPagedList(page, pageSize);

            setAlertMessage();
            return(View(models));
        }
 // 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        = PhieuXuatManager.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
             _currentPhieu = null;
             putErrorMessage("Phiếu đã duyệt");
             return(RedirectToAction("Details", new { id = id }));
         }
     }
     ViewBag.cultureInfo = CultureInfo;
     ViewBag.DMSach      = new SelectList(SachManager.getAllAlive()
                                          .Where(s => s.Soluong > 0).ToList(),
                                          nameof(SachManager.Properties.MaSoSach),
                                          nameof(SachManager.Properties.TenSach), "");
     ViewBag.DMDaiLy = new SelectList(DaiLyManager.getAllAlive(),
                                      nameof(DaiLyManager.Properties.MaSoDaiLy),
                                      nameof(DaiLyManager.Properties.TenDaiLy), "");
     setAlertMessage();
     return(View(_phieu));
 }
Пример #10
0
 public List <Sach> getSachNo()
 {
     return(CongNo
            .Where(cn => cn.SoLuong > 0)
            .GroupBy(cn => cn.MaSoSach)
            .Select(group => SachManager.find(group.Key)).ToList());
 }
Пример #11
0
 public ActionResult Create(Sach model, HttpPostedFileBase file)
 {
     try
     {
         // TODO: Add update logic here
         if (ModelState.IsValid)
         {
             if (file != null)
             {
                 model.HinhAnhTypeImage = Image.FromStream(file.InputStream);
             }
             var result = SachManager.add(model);
             if (result != 0)
             {
                 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"));
     }
     catch (Exception ex)
     {
         putErrorMessage(ex.Message);
         return(RedirectToAction("Create"));
     }
 }
        private void gdvChiTiet_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            int dong = e.RowIndex;

            if (dong != 0)
            {
                if (!TenSach.Equals("") && !SoLuong.Equals(""))
                {
                    if (!String.IsNullOrEmpty(Convert.ToString(gdvChiTiet.Rows[dong - 1].Cells[1].Value)))
                    {
                        int  x = int.Parse(gdvChiTiet.Rows[dong - 1].Cells[0].Value.ToString());
                        Sach s = SachManager.find(x);
                        gdvChiTiet.Rows[dong - 1].Cells[2].Value = s.GiaNhap;
                        lbTongTien.Text = Tongtien(dong - 1) + "";
                    }
                    else
                    {
                        MessageBox.Show("số lượng và đơn giá không được để trống");
                    }
                }
                else
                {
                    MessageBox.Show("Vui lòng nhập đầy đủ thông tin trên dòng");
                }
            }
        }
        public ViewResult BlankEditorRow()
        {
            var chitiet = new ChiTietPhieuXuat();
            var founded = false;

            foreach (Sach s in SachManager.getAllAlive().Where(s => s.Soluong > 0).ToList())
            {
                chitiet.MaSoSach = s.MaSoSach;
                if (_phieu.ChiTiet.Contains(chitiet))
                {
                    continue;
                }
                founded = true;
                break;
            }
            if (!founded)
            {
                return(null);
            }
            ViewBag.cultureInfo = CultureInfo;
            ViewBag.DMSach      = new SelectList(SachManager.getAllAlive()
                                                 .Where(s => s.Soluong > 0).ToList(),
                                                 nameof(SachManager.Properties.MaSoSach),
                                                 nameof(SachManager.Properties.TenSach), "");
            chitiet.SoLuong = 1;
            chitiet.DonGia  = chitiet.Sach.GiaBan;
            _phieu.addDetail(chitiet);
            return(View("ChiTietEditorRow", chitiet));
        }
        protected override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            var sess = (NguoiDung)Session[Core.Constants.SESSION.USERNAME];

            if (sess == null)
            {
                //filterContext.Result = new RedirectToRouteResult(
                //    new RouteValueDictionary(new { controller = "Account", action = "Login"}));
            }
            else
            {
                ViewBag.currentUser = sess;
            }
            ViewBag.Catalory = LinhVucManager.getAllALive();
            List <Sach> DMSach = null;

            if (Session[Core.Constants.SESSION.BOOKS] == null)
            {
                DMSach = SachManager.getAllAlive();
                Session[Core.Constants.SESSION.BOOKS] = DMSach;
            }
            else
            {
                DMSach = Session[Core.Constants.SESSION.BOOKS] as List <Sach>;
            }
            //Sách còn tồn nhiều nhất
            ViewBag.newProduct = DMSach.OrderByDescending(s => s.Soluong).FirstOrDefault();
            //Sách có giá cao nhất
            ViewBag.hightRateProducts = DMSach.OrderByDescending(s => s.GiaBan).Take(2).ToList();
            base.OnActionExecuted(filterContext);
        }
Пример #15
0
        // GET: Sach/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                putErrorMessage("Đường dẫn không chính xác");
                return(RedirectToAction("Index"));
            }
            var model = SachManager.find((int)id);

            if (model == null || model.TrangThai == 0)
            {
                putErrorMessage("Không tìm thấy");
                return(RedirectToAction("Index"));
            }
            //Combobox Nhà xuất bản
            ViewBag.DMNXB = new SelectList(NhaXuatBanManager.getAllAlive(),
                                           nameof(NhaXuatBanManager.Properties.MaSoNXB),
                                           nameof(NhaXuatBanManager.Properties.TenNXB), "");
            //Combobox lĩnh vực
            ViewBag.DMLinhVuc = new SelectList(LinhVucManager.getAllALive(),
                                               nameof(LinhVucManager.Properties.MaSoLinhVuc),
                                               nameof(LinhVucManager.Properties.TenLinhVuc), "");
            if (model.HinhAnh != null)
            {
                ViewBag.imgSrc = ImagesHelper.ImageToDataBase64String(model.HinhAnhTypeImage);
            }
            setAlertMessage();
            return(View(model));
        }
 public void loadSach()
 {
     _DMSach = SachManager.getAllAlive()
               .Where(p => p.tongSoLuongNhapTheoThang(_startMonth, _startYear, _endMonth, _endYear) > 0 &&
                      p.tongTienNhapTheoThang(_startMonth, _startYear, _endMonth, _endYear) > 0).ToList();
     lbTongLuongNhap.Text = _DMSach.Sum(s => s.SoLuongNhapTheoThang).ToString();
     gdvLoNhap.DataSource = _DMSach;
 }
Пример #17
0
 private void LoadTT()
 {
     _Sach = SachManager.getAll()
             .Where(s => s.tongSoLuongBanTheoThang(_startMonth, _startYear, _endMonth, _endYear) > 0 &&
                    s.tongTienBanTheoThang(_startMonth, _startYear, _endMonth, _endYear) > 0).ToList();
     gdvDMSach.DataSource = _Sach;
     lbSachBanDuoc.Text   = _Sach.Sum(s => s.TongSoLuongBanTheoThang) + "";
     lbTongTien.Text      = _Sach.Sum(s => s.TongTienBanTheoThang) + "";
 }
Пример #18
0
        public bool isExisted()
        {
            Sach sach = SachManager.find(this.MaSoSach);

            if (sach == null)
            {
                return(false);
            }
            return(true);
        }
Пример #19
0
        private void button1_Click(object sender, EventArgs e)
        {
            SachManager    sachManager = new SachManager();
            OpenFileDialog theDialog   = new OpenFileDialog();

            theDialog.Title  = "Open Excel File";
            theDialog.Filter = "Excel files|*.xlsx";
            if (theDialog.ShowDialog() == DialogResult.OK)
            {
                string path = theDialog.InitialDirectory + theDialog.FileName;
                sachManager.saveListSach(excelHelper.GetListSachFromExcel(path));
            }
        }
Пример #20
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);
     }
 }
Пример #21
0
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpNotFoundResult("Bad Request"));
            }
            var model = SachManager.find((int)id);

            if (model == null)
            {
                return(new HttpNotFoundResult("Not Found!"));
            }


            return(View(model));
        }
Пример #22
0
        public bool isContentExisted()
        {
            var obj = new { };
            Dictionary <String, dynamic> param = new Dictionary <string, dynamic>();

            param.Add(SachManager.Properties.TenSach, this.TenSach);
            param.Add(SachManager.Properties.TenTacGia, this.TenTacGia);
            param.Add(SachManager.Properties.LinhVucSach, this.LinhVucSach.MaSoLinhVuc);
            param.Add(SachManager.Properties.NXB, this.NXB.MaSoNXB);
            List <Sach> result = SachManager.findBy(param);

            if (result.Count > 0)
            {
                return(true);
            }
            return(false);
        }
 // GET: PhieuNhap/Create
 public ActionResult Create()
 {
     ViewBag.cultureInfo = CultureInfo;
     ViewBag.DMSach      = new SelectList(SachManager.getAllAlive()
                                          .Where(s => s.Soluong > 0).ToList(),
                                          nameof(SachManager.Properties.MaSoSach),
                                          nameof(SachManager.Properties.TenSach), "");
     ViewBag.DMDaiLy = new SelectList(DaiLyManager.getAllAlive(),
                                      nameof(DaiLyManager.Properties.MaSoDaiLy),
                                      nameof(DaiLyManager.Properties.TenDaiLy), "");
     if (_phieu == null)
     {
         _phieu = new PhieuXuat();
     }
     _phieu.NgayLap = DateTime.Now;
     setAlertMessage();
     return(View(_phieu));
 }
        public ViewResult AddToCart(int id, int?quantity)
        {
            currentPhieu.ChiTiet = Session[Core.Constants.SESSION.SHOPPING_CART] as List <ChiTietPhieuXuat>;
            var sach = SachManager.find(id);

            if (sach == null)
            {
                return(null);
            }
            if (quantity != null)
            {
                currentPhieu.addDetail(sach, (int)quantity);
            }
            else
            {
                currentPhieu.addDetail(sach, 1);
            }
            Session[Core.Constants.SESSION.SHOPPING_CART] = currentPhieu.ChiTiet;
            return(View("Cart"));
        }
Пример #25
0
 private void loadTT()
 {
     if (x == 1)
     {
         _DMSachNXB = SachManager.getAll()
                      .Where(s => s.tongSoLuongNXBNoTheoThang(_startMonth, _startYear, _endMonth, _endYear) > 0 &&
                             s.tongTienNXBNoTheoThang(_startMonth, _startYear, _endMonth, _endYear) > 0).ToList();
         gdvDMSach.DataSource = _DMSachNXB;
         lbSoLuongNo.Text     = _DMSachNXB.Sum(s => s.TongSoLuongNXBNoTheoThang) + "";
         lbTongTien.Text      = _DMSachNXB.Sum(s => s.TongTienNXBNoTheoThang) + "";
     }
     if (x == 2)
     {
         _DMSachDLy = SachManager.getAll()
                      .Where(s => s.tongSoLuongDaiLyNoTheoThang(_startMonth, _startYear, _endMonth, _endYear) > 0 && s.tongTienDaiLyNoTheoThang(_startMonth, _startYear, _endMonth, _endYear) > 0).ToList();
         gdvDMSach.DataSource = _DMSachDLy;
         lbSoLuongNo.Text     = _DMSachDLy.Sum(s => s.TongSoLuongDaiLyNoTheoThang) + "";
         lbTongTien.Text      = _DMSachDLy.Sum(s => s.TongTienDaiLyNoTheoTang) + "";
     }
 }
        public FileStreamResult LoNhap(DateTime startDate, DateTime endDate)
        {
            List <Sach> DMSach = SachManager.getAll()
                                 .Where(s => s.tongSoLuongNhapTheoThang(
                                            ((DateTime)startDate).Month,
                                            ((DateTime)startDate).Year,
                                            ((DateTime)endDate).Month,
                                            ((DateTime)endDate).Year) > 0 &&
                                        s.tongTienNhapTheoThang(
                                            ((DateTime)startDate).Month,
                                            ((DateTime)startDate).Year,
                                            ((DateTime)endDate).Month,
                                            ((DateTime)endDate).Year) > 0).ToList();
            var printer = new PrintHelper();

            printer.FileName   = "report.pdf";
            printer.FolderPath = "D://";
            printer.Title      = "Thống kê lô nhập";
            var info = new MemoryStream(printer.printLoNhap(DMSach, startDate, endDate));

            return(new FileStreamResult(info, "application/pdf"));
        }
 public ViewResult ChangeDetailRow(int masosach, int?masosach_new, int?soluong)
 {
     foreach (ChiTietPhieuXuat ct in _phieu.ChiTiet)
     {
         if (ct.MaSoSach.Equals(masosach))
         {
             if (masosach_new != null)
             {
                 ct.MaSoSach = (int)masosach_new;
                 ct.Sach     = SachManager.find(ct.MaSoSach);
                 ct.DonGia   = ct.Sach.GiaBan;
                 ct.SoLuong  = 1;
             }
             if (soluong != null)
             {
                 ct.SoLuong = (int)soluong;
             }
             break;
         }
     }
     return(null);
 }
        public ActionResult Index()
        {
            var rand = new Random();
            //Giới hạn sách hiển thị
            var         limit  = 6;
            List <Sach> DMSach = null;

            if (Session[Core.Constants.SESSION.BOOKS] == null)
            {
                DMSach = SachManager.getAllAlive();
                Session[Core.Constants.SESSION.BOOKS] = DMSach;
            }
            else
            {
                DMSach = Session[Core.Constants.SESSION.BOOKS] as List <Sach>;
            }
            //Láy random 6 sách
            var models = DMSach.OrderBy(c => rand.Next()).Take(limit);

            //Danh mục lĩnh vực
            ViewBag.DMLinhVuc = LinhVucManager.getAllALive().Take(5).ToList();
            return(View(models));
        }
 public ActionResult LoNhapDetails(int?id, int page = 1, int pageSize = 10)
 {
     if (id != null)
     {
         ViewBag.cultureInfo = CultureInfo;
         var sach = SachManager.find((int)id);
         if (sach != null)
         {
             ViewBag.currentSach = sach;
             var models = sach.PhieuNhap.ToPagedList(page, pageSize);
             setAlertMessage();
             return(View(models));
         }
         else
         {
             putErrorMessage("Không tìm thấy");
         }
     }
     else
     {
         putErrorMessage("Đường dẫn không đúng");
     }
     return(RedirectToAction("LoNhap"));
 }
        public ActionResult List(int?id, int page = 1, int pageSize = 9, string search = null)
        {
            if (id == null)
            {
                return(new HttpNotFoundResult("Bad Request!"));
            }
            var model = LinhVucManager.find((int)id);

            if (model == null || model.TrangThai == 0)
            {
                return(new HttpNotFoundResult("Not Found!"));
            }
            List <Sach> DMSach = model.Sach;

            if (!String.IsNullOrEmpty(search))
            {
                DMSach            = SachManager.filter(search, DMSach);
                ViewBag.SearchKey = search;
            }
            ViewBag.currentLV = model;
            var models = DMSach.ToPagedList(page, pageSize);

            return(View(models));
        }