コード例 #1
0
        // GET: Supplier/Edit/{id}
        //Store Manager, Store Supervisor
        public ActionResult Edit(string id)
        {
            if (id == null)
            {
                return(RedirectToAction("Index"));
            }

            // Get select list for supplier
            List <SupplierViewModel> supplierList = supplierService.GetAllSuppliers();
            SelectList selectList = new SelectList(supplierList, "SupplierCode", "SupplierName");

            ViewBag.selectList = selectList;

            ViewBag.unitOfMeasure = stationeryService.GetAllUOMList();

            //Get selectedID list for category
            List <Category> categories   = stationeryService.GetAllCategory();
            SelectList      selectListID = new SelectList(categories, "categoryID", "categoryName");

            ViewBag.selectListofCategory = selectListID;

            StationeryViewModel stationeryVM = stationeryService.FindStationeryViewModelByItemCode(id);

            return(View(stationeryVM));
        }
コード例 #2
0
        public bool UpdateStationeryInfo(StationeryViewModel stationeryVM)
        {
            Stationery stationery = ConvertFromViewModel(stationeryVM);

            IStationeryDAO stationeryDAO = new StationeryDAO();

            if (stationeryDAO.UpdateStationeryInfo(stationery) == 1)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #3
0
        private Stationery ConvertFromViewModel(StationeryViewModel stationeryVM)
        {
            Stationery stationery = new Stationery();

            stationery.itemCode           = stationeryVM.ItemCode;
            stationery.categoryID         = stationeryVM.CategoryID;
            stationery.description        = stationeryVM.Description;
            stationery.reorderLevel       = stationeryVM.ReorderLevel;
            stationery.reorderQty         = stationeryVM.ReorderQty;
            stationery.unitOfMeasure      = stationeryVM.UnitOfMeasure;
            stationery.stockQty           = stationeryVM.StockQty;
            stationery.location           = stationeryVM.Location;
            stationery.firstSupplierCode  = stationeryVM.FirstSupplierCode;
            stationery.secondSupplierCode = stationeryVM.SecondSupplierCode;
            stationery.thirdSupplierCode  = stationeryVM.ThirdSupplierCode;
            stationery.price = stationeryVM.Price;
            return(stationery);
        }
コード例 #4
0
        private StationeryViewModel ConvertToViewModel(Stationery s)
        {
            StationeryViewModel stationeryVM = new StationeryViewModel();

            stationeryVM.ItemCode           = s.itemCode;
            stationeryVM.CategoryID         = s.categoryID;
            stationeryVM.Description        = s.description;
            stationeryVM.ReorderLevel       = s.reorderLevel;
            stationeryVM.ReorderQty         = s.reorderQty;
            stationeryVM.UnitOfMeasure      = s.unitOfMeasure;
            stationeryVM.StockQty           = s.stockQty;
            stationeryVM.Location           = s.location;
            stationeryVM.FirstSupplierCode  = s.firstSupplierCode;
            stationeryVM.SecondSupplierCode = s.secondSupplierCode;
            stationeryVM.ThirdSupplierCode  = s.thirdSupplierCode;
            stationeryVM.Price    = s.price;
            stationeryVM.Category = s.Category;
            return(stationeryVM);
        }
コード例 #5
0
        public ActionResult Edit(StationeryViewModel stationeryVM)
        {
            ViewBag.unitOfMeasure = stationeryService.GetAllUOMList();

            // Get select list for supplier
            List <SupplierViewModel> supplierList = supplierService.GetAllSuppliers();
            SelectList selectList = new SelectList(supplierList, "SupplierCode", "SupplierName");

            ViewBag.selectList = selectList;

            //Get selectedID list for category
            List <Category> categories   = stationeryService.GetAllCategory();
            SelectList      selectListID = new SelectList(categories, "categoryID", "categoryName");

            ViewBag.selectListofCategory = selectListID;

            string  code  = stationeryVM.ItemCode;
            int     level = stationeryVM.ReorderLevel;
            int     qty   = stationeryVM.ReorderQty;
            decimal price = stationeryVM.Price;

            //for supplier validate
            string supplier1 = stationeryVM.FirstSupplierCode;
            string supplier2 = stationeryVM.SecondSupplierCode;
            string supplier3 = stationeryVM.ThirdSupplierCode;

            if (stationeryService.isExistingSupplierCode(supplier1, supplier2))
            {
                string errorMessage = String.Format("{0} has been used in First Supplier.", supplier1);
                ModelState.AddModelError("SecondSupplierCode", errorMessage);
            }

            if (stationeryService.isExistingSupplierCode(supplier1, supplier3))
            {
                string errorMessage = String.Format("{0} has been used in First Supplier.", supplier1);
                ModelState.AddModelError("ThirdSupplierCode", errorMessage);
            }

            if (stationeryService.isExistingSupplierCode(supplier2, supplier3))
            {
                string errorMessage = String.Format("{0} has been used in Second Supplier.", supplier2);
                ModelState.AddModelError("ThirdSupplierCode", errorMessage);
            }

            if (stationeryService.isPositiveLevel(level))
            {
                string errorMessage = String.Format("{0}  must be positive.", level);
                ModelState.AddModelError("ReorderLevel", errorMessage);
            }
            if (stationeryService.isPositiveQty(qty))
            {
                string errorMessage = String.Format("{0}  must be positive.", qty);
                ModelState.AddModelError("ReorderQty", errorMessage);
            }
            if (stationeryService.isPositivePrice(price))
            {
                string errorMessage = String.Format("{0}  must be positive.", price);
                ModelState.AddModelError("Price", errorMessage);
            }

            else if (ModelState.IsValid)
            {
                try
                {
                    if (stationeryService.UpdateStationeryInfo(stationeryVM))
                    {
                        TempData["SuccessMessage"] = String.Format("'{0}' has been updated", code);
                    }
                    else
                    {
                        TempData["ErrorMessage"] = String.Format("There is not change to '{0}'.", code);
                    }

                    return(RedirectToAction("Index"));
                }
                catch (Exception e)
                {
                    ViewBag.ExceptionMessage = e.Message;
                }
            }
            return(View(stationeryVM));
        }
コード例 #6
0
        public ActionResult AddSelected(string checker)
        {
            List <string>               itemCodes = new List <string>();
            List <Purchase_Detail>      model     = new List <Purchase_Detail>();
            Dictionary <string, string> kv        = new Dictionary <string, string>(); //kv pair of itemcode and sggestedqty
            List <StationeryViewModel>  modelAll  = shortFallList();                   // used if generate all is chosen

            if (checker == "addAll")                                                   //add all
            {
                foreach (StationeryViewModel svm in modelAll)
                {
                    itemCodes.Add(svm.ItemCode);
                }
            }

            else
            {
                //list of itemCodes to be reordered
                itemCodes = Request.QueryString.AllKeys.ToList();

                foreach (string s in itemCodes)
                {
                    string v = Request.QueryString.GetValues(s).First();
                    kv.Add(s, v);
                }
            }

            ////might need to remove
            //if (Session["detailsBundle"] != null)
            //{
            //    details = (Dictionary<Purchase_Detail, string>)Session["detailsBundle"];
            //    model = details.Keys.ToList<Purchase_Detail>();

            //}

            foreach (string i in itemCodes)
            {
                //takes the price of the first/default supplier
                Stationery s     = ctx.Stationeries.Where(x => x.itemCode == i).First();
                decimal    price = s.price;
                int        qtyToReorder;

                //find qty to reorder
                if (checker == "addAll")
                {
                    StationeryViewModel svm = modelAll.Where(x => x.ItemCode == i).First();
                    qtyToReorder = svm.Suggested;
                }
                else
                {
                    qtyToReorder = Int32.Parse(kv[i]);
                }
                Purchase_Detail pd = new Purchase_Detail();
                pd.orderNo  = findNextOrderNo();
                pd.itemCode = i;
                pd.qty      = qtyToReorder;
                pd.price    = price;
                pd.remarks  = String.Format("autogenerated from shortfall list on {0}", DateTime.Now.ToString());
                model.Add(pd);
                //find the default supplier

                string defaultSupplier = ctx.Stationeries.Where(x => x.itemCode == i).First().firstSupplierCode;

                details.Add(pd, defaultSupplier);
            }


            Session["detailsBundle"] = details;
            //to obtain latest order number
            int orderNo = findNextOrderNo();

            ViewBag.orderNo = orderNo;

            ViewBag.itemCodeList = stationeryService.GetAllItemCodes();
            //return View("~/Views/Purchase/RaisePurchaseOrder.cshtml", model);


            return(RedirectToAction("RaisePurchaseOrder", "Purchase", model));
        }
コード例 #7
0
 public bool AddNewStationery(StationeryViewModel stationeryVM)
 {
     return(stationeryDAO.AddNewStationery(ConvertFromViewModel(stationeryVM)));
 }