public ActionResult DisplaySearchResult(string value)
        {
            List <RawItemPriceUpdateViewModel> RIPList      = (List <RawItemPriceUpdateViewModel>)Session["ViewModelList"];
            RawItemPriceUpdateViewModel        RIPViewModel = RIPList.Where(o => o.RIM_VEM_ID.Equals(value)).FirstOrDefault();

            TempData["SearchItemSelected"] = RIPViewModel;
            return(RedirectToAction("Index", "RawItemPriceUpdate"));
        }
예제 #2
0
        public static bool UpdateRawItemPrice(RawItemPriceUpdateViewModel RIPViewModel)
        {
            using (CFMMCDEntities db = new CFMMCDEntities())
            {
                RIM_VEM_Lookup RVLRow;
                if (db.RIM_VEM_Lookup.Where(o => o.RIM_VEM_ID.Equals(RIPViewModel.RIM_VEM_ID)).Any())
                {
                    RVLRow = db.RIM_VEM_Lookup.Single(o => o.RIM_VEM_ID.Equals(RIPViewModel.RIM_VEM_ID));
                }
                else
                {
                    RVLRow = new RIM_VEM_Lookup();
                }

                RVLRow.RIM_VEM_ID = RIPViewModel.RIM_VEM_ID;
                RVLRow.RIMRIC     = int.Parse(RIPViewModel.RIMRIC);
                RVLRow.VEMVEN     = int.Parse(RIPViewModel.VEMVEN);
                RVLRow.VEMDS1     = RIPViewModel.VEMDS1.Trim();
                RVLRow.RIMCPR     = double.Parse(RIPViewModel.RIMCPR);
                RVLRow.RIMRID     = db.INVRIMP0.Single(o => o.RIMRIC.ToString().Equals(RIPViewModel.RIMRIC)).RIMRID;
                //RVLRow.RIMPDT = DateTime.Parse(RIPViewModel.RIMPDT);
                //RVLRow.RIMCPN = double.Parse(RIPViewModel.RIMCPN);

                try
                {
                    if (!db.RIM_VEM_Lookup.Where(o => o.RIM_VEM_ID.Equals(RIPViewModel.RIM_VEM_ID)).Any())
                    {
                        db.RIM_VEM_Lookup.Add(RVLRow);
                    }
                    db.SaveChanges();
                    return(true);
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine(e.Source);
                    System.Diagnostics.Debug.WriteLine(e.Message);
                    System.Diagnostics.Debug.WriteLine(e.StackTrace);
                    System.Diagnostics.Debug.WriteLine(e.InnerException);
                    Exception f = e.InnerException;
                    while (f != null)
                    {
                        System.Diagnostics.Debug.WriteLine("INNER:");
                        System.Diagnostics.Debug.WriteLine(f.Message);
                        System.Diagnostics.Debug.WriteLine(f.Source);
                        f = f.InnerException;
                    }
                    System.Diagnostics.Debug.WriteLine(e.Data);
                    return(false);
                }
            }
        }
 public ActionResult Index(RawItemPriceUpdateViewModel RIPViewModel)
 {   // Search
     RIPViewModel.RawItemPriceMasterList = RawItemPriceManager.SearchRawItemPrice(RIPViewModel);
     if (RIPViewModel.RawItemPriceMasterList != null)
     {
         TempData["SearchResult"] = 1;   // Stores 1 if a search returned results.
         Session["ViewModelList"] = RIPViewModel.RawItemPriceMasterList;
     }
     else
     {
         ModelState.AddModelError("", "No results found");
     }
     return(View(RIPViewModel));
 }
예제 #4
0
        public static bool ImportExcel(Stream file)
        {
            using (CFMMCDEntities db = new CFMMCDEntities())
            {
                using (XLWorkbook workBook = new XLWorkbook(file))
                {
                    IXLWorksheet workSheet = workBook.Worksheet(1);

                    var  RIPViewModelList = new List <RawItemPriceUpdateViewModel>();
                    bool firstRow         = true;
                    foreach (IXLRow row in workSheet.Rows())
                    {
                        if (firstRow)
                        {
                            firstRow = false;
                        }
                        else
                        {
                            if (row.Cells() == null || row.Cells().Count() <= 0)
                            {
                                continue;
                            }
                            RawItemPriceUpdateViewModel vm = new RawItemPriceUpdateViewModel();
                            vm.RIMRIC = row.Cells().ElementAt(0).Value.ToString();
                            vm.RIMRID = row.Cells().ElementAt(1).Value.ToString();
                            vm.RIMCPR = row.Cells().ElementAt(2).Value.ToString();
                            vm.VEMDS1 = row.Cells().ElementAt(3).Value.ToString();
                            if (!db.INVRIMP0.Where(o => o.RIMRIC.ToString().Equals(vm.RIMRIC)).Any())
                            {
                                continue;
                            }
                            if (!db.INVVEMP0.Where(o => o.VEMDS1.Equals(vm.VEMDS1)).Any())
                            {
                                continue;
                            }
                            vm.VEMVEN     = db.INVVEMP0.FirstOrDefault(o => o.VEMDS1.Equals(vm.VEMDS1)).VEMVEN.ToString();
                            vm.RIM_VEM_ID = vm.RIMRIC + vm.VEMVEN;
                            if (!db.RIM_VEM_Lookup.Where(o => o.RIM_VEM_ID.Equals(vm.RIM_VEM_ID)).Any())
                            {
                                continue;
                            }
                            RIPViewModelList.Add(vm);
                        }
                    }
                    return(UpdateRawItemPrice(RIPViewModelList));
                }
            }
        }
        /*
         * Default method.
         * TempData is used to store the ViewModel after a Search action.
         */
        public ActionResult Index()
        {
            // Validate log in and user access
            UserAccessSession UASession = (UserAccessSession)Session["UserAccess"];

            if (UASession == null || !UASession.RIP)
            {
                return(RedirectToAction("Login", "Account"));
            }
            // Set NavBar Links accordingly
            Session["CurrentPage"] = new CurrentPageSession("RIP", "HOME", "LOG");

            // SearchItemSelected is assigned value at DisplaySearchResult
            RawItemPriceUpdateViewModel RIPViewModel = (RawItemPriceUpdateViewModel)TempData["SearchItemSelected"];

            if (RIPViewModel == null)
            {
                RIPViewModel = new RawItemPriceUpdateViewModel();
            }
            RIPViewModel.SearchItem             = "ALL";
            RIPViewModel.RawItemPriceMasterList = RawItemPriceManager.SearchRawItemPrice(RIPViewModel);
            return(View(RIPViewModel));
        }
예제 #6
0
 public static bool DeleteRawItemPrice(RawItemPriceUpdateViewModel RIPViewModel)
 {
     using (CFMMCDEntities db = new CFMMCDEntities())
     {
         try
         {
             if (db.RIM_VEM_Lookup.Where(o => o.RIM_VEM_ID.Equals(RIPViewModel.RIM_VEM_ID)).Any())
             {
                 RIM_VEM_Lookup rowToRemove = db.RIM_VEM_Lookup.FirstOrDefault(o => o.RIM_VEM_ID.Equals(RIPViewModel.RIM_VEM_ID));
                 db.RIM_VEM_Lookup.Remove(rowToRemove);
                 db.SaveChanges();
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
         catch (Exception e)
         {
             System.Diagnostics.Debug.WriteLine(e.Source);
             System.Diagnostics.Debug.WriteLine(e.Message);
             System.Diagnostics.Debug.WriteLine(e.StackTrace);
             System.Diagnostics.Debug.WriteLine(e.InnerException);
             Exception f = e.InnerException;
             while (f != null)
             {
                 System.Diagnostics.Debug.WriteLine("INNER:");
                 System.Diagnostics.Debug.WriteLine(f.Message);
                 System.Diagnostics.Debug.WriteLine(f.Source);
                 f = f.InnerException;
             }
             System.Diagnostics.Debug.WriteLine(e.Data);
             return(false);
         }
     }
 }
        public ActionResult UpdateDelete(RawItemPriceUpdateViewModel RIPViewModel, string command)
        {
            UserSession user       = (UserSession)Session["User"];
            string      PageAction = "";
            bool        result     = false;

            if (Request.Files.Count > 0)
            {
                HttpPostedFileBase file = Request.Files["FileUploaded"];
                if ((file != null) && (file.ContentLength > 0) && !string.IsNullOrEmpty(file.FileName))
                {
                    result     = RawItemPriceManager.ImportExcel(file.InputStream);
                    PageAction = "Import";
                }
            }
            if (command == "Save")
            {
                result     = RawItemPriceManager.UpdateRawItemPrice(RIPViewModel.RawItemPriceMasterList);
                PageAction = "Update price";
            }
            else if (command == "Import")
            {
                result     = true;
                PageAction = "(NO ACTION) Import price";
            }
            if (result)
            {
                TempData["SuccessMessage"] = PageAction + " successful";
                new AuditLogManager().Audit(user.Username, DateTime.Now, "Raw Item Price Update", PageAction, RIPViewModel.RIMRIC, RIPViewModel.RIMRID);
            }
            else
            {
                TempData["ErrorMessage"] = PageAction + " failed";
            }
            return(RedirectToAction("Index"));
        }
예제 #8
0
        public static List <RawItemPriceUpdateViewModel> SearchRawItemPrice(RawItemPriceUpdateViewModel RIPViewModel)
        {
            using (CFMMCDEntities db = new CFMMCDEntities())
            {
                List <RawItemPriceUpdateViewModel> RIPList = new List <RawItemPriceUpdateViewModel>();
                List <RIM_VEM_Lookup> RIPRowList;
                if (RIPViewModel.SearchItem == null || RIPViewModel.SearchItem.Equals(""))
                {
                    return(null);
                }
                if (db.RIM_VEM_Lookup.Where(o => o.RIMRID.Contains(RIPViewModel.SearchItem)).Any())
                {
                    RIPRowList = db.RIM_VEM_Lookup.Where(o => o.RIMRID.Equals(RIPViewModel.SearchItem)).ToList();
                }
                else if (db.RIM_VEM_Lookup.Where(o => o.RIMRIC.ToString().Equals(RIPViewModel.SearchItem)).Any())
                {
                    RIPRowList = db.RIM_VEM_Lookup.Where(o => o.RIMRIC.ToString().Equals(RIPViewModel.SearchItem)).ToList();
                }
                else if (RIPViewModel.SearchItem.ToUpper().Equals("ALL"))
                {
                    RIPRowList = db.RIM_VEM_Lookup.ToList();
                }
                else
                {
                    return(null);
                }
                foreach (RIM_VEM_Lookup rim in RIPRowList)
                {
                    RawItemPriceUpdateViewModel vm = new RawItemPriceUpdateViewModel();
                    vm.RIM_VEM_ID = rim.RIM_VEM_ID;
                    if (rim.RIMRIC != null)
                    {
                        vm.RIMRIC = rim.RIMRIC.ToString();
                    }
                    if (rim.VEMVEN != null)
                    {
                        vm.VEMVEN = rim.VEMVEN.ToString();
                    }
                    if (rim.VEMDS1 != null)
                    {
                        vm.VEMDS1 = rim.VEMDS1.Trim();
                    }
                    if (rim.RIMCPR != null)
                    {
                        vm.RIMCPR = rim.RIMCPR.ToString();
                    }
                    if (rim.RIMRID != null)
                    {
                        vm.RIMRID = rim.RIMRID.ToString();
                    }
                    string Status = db.INVRIMP0.Single(o => o.RIMRIC.ToString().Equals(rim.RIMRIC.ToString())).RIMSTA;
                    if (Status != null && Status.Equals("0"))
                    {
                        vm.RIMSTA = true;
                    }

                    RIPList.Add(vm);
                }
                if (RIPList == null || RIPList.ElementAt(0) == null)
                {
                    return(null);
                }
                return(RIPList);
            }
        }