예제 #1
0
        public void UpdateSupplierDetails(SupplierDetailsEF details)
        {
            var existingRecord = context.SupplierDetails.Find(details.SupplierDetailsId);

            if (existingRecord != null)
            {
                context.Entry(existingRecord).CurrentValues.SetValues(details);
                context.SaveChanges();
            }
        }
예제 #2
0
        public ActionResult EditSupplierDetails(List <SupplierDetailsEF> editedItems, string choice, string itemToAddCode, string supplierCode)
        {
            SupplierEF supplier = purchaseService.FindSupplierBySupplierCode(supplierCode);
            List <SupplierDetailsEF> supplierItems = purchaseService.FindSupplierItems(supplierCode);

            ViewData["supplier"]      = supplier;
            ViewData["supplierItems"] = supplierItems;

            if (editedItems == null)
            {
                editedItems = new List <SupplierDetailsEF>();
            }

            if (choice == "Add Item")
            {
                bool isValid = false;
                SupplierDetailsEF newItem = new SupplierDetailsEF();

                //check if exists in the supplier list of items
                foreach (var item in supplierItems)
                {
                    if (itemToAddCode == item.ItemCode)
                    {
                        newItem = item;
                        isValid = true;
                    }
                }
                //check for duplicate entry
                foreach (var item in editedItems)
                {
                    if (itemToAddCode == item.ItemCode)
                    {
                        isValid = false;
                    }
                }
                if (isValid)
                {
                    editedItems.Add(newItem);
                }
            }
            if (choice == "Submit")
            {
                purchaseService.AmendSupplierDetails(editedItems);
                return(RedirectToAction("ViewSupplierDetails", "ManageSupplier", new { page = 1, supplierCode = supplierCode }));
            }

            ModelState.Clear();
            return(View(editedItems));
        }
예제 #3
0
        public ActionResult ImportSupplierDetails(HttpPostedFileBase fileUploaded)
        {
            try
            {
                //Check if there is a file is sent to the controller
                if (fileUploaded != null && fileUploaded.ContentLength > 0)
                {
                    // Check if the file ends with csv extension
                    if (fileUploaded.FileName.EndsWith(".csv"))
                    {
                        // Read the file as a stream
                        StreamReader streamCsv = new StreamReader(fileUploaded.InputStream);

                        string csvDataLine = "";
                        int    CurrentLine = 0;

                        string[] LineData = null;

                        // Delete all data everytime a new file is uploaded.
                        purchaseService.ClearSupplierDetailsData();

                        // Looping to read the File stream and Add Data to the database line by line
                        while ((csvDataLine = streamCsv.ReadLine()) != null)
                        {
                            // Ignore the first line of the file, for column names.
                            if (CurrentLine != 0)
                            {
                                // Add the returned data to an array
                                LineData = csvDataLine.Split(',');

                                //Pass LineData array values
                                var newSupplierDetail = new SupplierDetailsEF()
                                {
                                    SupplierDetailsId = int.Parse(LineData[0]),
                                    SupplierCode      = LineData[1],
                                    ItemCode          = LineData[2],
                                    UnitPrice         = double.Parse(LineData[3]),
                                    SupplierRank      = int.Parse(LineData[4])
                                };

                                //Add Data to The Database
                                purchaseService.AddSupplierDetail(newSupplierDetail);
                            }
                            CurrentLine += 1;
                        }
                        Debug.Print("Loaded: " + (CurrentLine - 1) + " items to supplier details table.");
                    }
                    else
                    {
                        TempData["MessageError"] = "File Format is not Supported";
                    }
                }
                else
                {
                    TempData["MessageError"] = "Please Upload A File";
                }

                // Back to the first view
                return(RedirectToAction("Index", "ManageSupplier"));
            }
            catch (Exception ex)
            {
                TempData["MessageError"] = "Error:" + ex.Message;
                return(RedirectToAction("Index", "ManageSupplier"));
            }
        }
예제 #4
0
 public void AddToSupplierDetails(SupplierDetailsEF supplierDetails)
 {
     context.SupplierDetails.Add(supplierDetails);
     context.SaveChanges();
 }
예제 #5
0
        public ActionResult CreatePurchaseOrder(string supplier, string choice, string items,
                                                PurchaseOrderFormDTO purOrder)
        {
            List <SupplierDetailsEF> supplierItems = new List <SupplierDetailsEF>();
            List <SupplierEF>        supplierList  = purchaseService.FindAllSuppliers();

            ViewData["supplierList"] = supplierList;

            StaffEF createdBy = staffService.GetStaff();

            if (supplier == null)
            {
                supplierItems = null;
            }
            else
            {
                supplierItems = purchaseService.FindSupplierItems(supplier);
            }
            ViewData["supplier"]      = supplier;
            ViewData["supplierItems"] = supplierItems;


            if (choice == "setSupplier")
            {
                if (supplier == supplierList[0].SupplierCode)
                {
                    //do nothing when supplier is the same
                }
                else
                {
                    //clear form.
                    purOrder = new PurchaseOrderFormDTO();
                }
            }

            if (choice == "Add Item")
            {
                SupplierDetailsEF newSD = null;
                bool isValid            = false;

                foreach (var s in supplierItems)
                {
                    if (items == s.SupplierDetailsId.ToString())
                    {
                        newSD   = s;
                        isValid = true;
                    }
                }
                if (purOrder.SupplierDetailIds.Count() > 0 && isValid == true)
                {
                    foreach (var thing in purOrder.SupplierDetailIds)
                    {
                        if (thing == items)
                        {
                            isValid = false;
                        }
                    }
                }
                if (isValid == true)
                {
                    purOrder.Icodes.Add(newSD.Stock.ItemCode);
                    purOrder.Descs.Add(newSD.Stock.Description);
                    purOrder.Uoms.Add(newSD.Stock.Uom);
                    purOrder.Prices.Add(newSD.UnitPrice);
                    purOrder.SupplierDetailIds.Add(newSD.SupplierDetailsId.ToString());
                    purOrder.Quantities.Add(1);
                    purOrder.Remove.Add(false);
                }
            }

            if (choice == "CreatePO")
            {
                purOrder.SupplierId = supplierItems[0].SupplierCode;
                int newPOId = purchaseService.CreatePO(createdBy, purOrder);

                return(RedirectToAction("ViewPurchaseOrder", "ManagePurchase", new { purchaseOrderId = newPOId.ToString() }));
            }

            if (choice == "Remove")
            {
                for (int i = 0; i < purOrder.Remove.Count; i++)
                {
                    if (purOrder.Remove[i] == true)
                    {
                        purOrder.Icodes.RemoveAt(i);
                        purOrder.Descs.RemoveAt(i);
                        purOrder.Uoms.RemoveAt(i);
                        purOrder.Prices.RemoveAt(i);
                        purOrder.SupplierDetailIds.RemoveAt(i);
                        purOrder.Quantities.RemoveAt(i);
                        purOrder.Remove.RemoveAt(i);
                        i--;
                    }
                }
            }

            return(View(purOrder));
        }
예제 #6
0
 public void AddSupplierDetail(SupplierDetailsEF supplierDetails)
 {
     purchaseEFF.AddToSupplierDetails(supplierDetails);
 }