예제 #1
0
 private void RemoveItems(FormCollection formCollection)
 {
     if (formCollection.Count > 0 && formCollection != null)
     {
         RemoveFormCollectionData removeItemFC = new RemoveFormCollectionData();
         //get the updated data after it remove the items from the list.
         SessionWrapper.StoreSession_Model(removeItemFC.RemoveItemFromGrid(formCollection));
     }
 }
예제 #2
0
        public ActionResult Index(HttpPostedFileBase file, FormCollection formCollection, string submitButton, IEnumerable <ImportViewModel> model1)
        {
            bool   isPageSizeChange = false;
            string pageSizeDDL      = string.Empty;

            if (formCollection.Count > 0)
            {
                if (string.IsNullOrEmpty(submitButton))
                {
                    foreach (string _formData in formCollection)
                    {
                        if (_formData == "PageSizeSelect")
                        {
                            pageSizeDDL      = formCollection[_formData];
                            isPageSizeChange = true;
                            break;
                        }
                    }
                }
            }
            if (isPageSizeChange)
            {
                if (Session["storedevices"] == null)
                {
                    return(View("Index"));
                }
                Int16 pageSize = Convert.ToInt16(pageSizeDDL);
                ((ImportViewModelManager)(Session["storedevices"])).PageSize = pageSize;
            }
            else
            {
                if (file == null && formCollection.Count == 0 && submitButton == null)
                {
                    InvalidFileSelected();
                }
                else if (file != null)
                {
                    if (Request.Files["file"].ContentLength > 0)
                    {
                        ReadExcelData_backup helper = new ReadExcelData_backup();
                        bool validate = helper.ValidateFileExtension(file);

                        if (!validate)
                        {
                            InvalidFileSelected();
                        }
                        else
                        {
                            string fileLocation = Server.MapPath("~/Excel/") + Request.Files["file"].FileName;
                            //store the file name in session...
                            Session.Add("fileLocation", fileLocation);

                            //extract from excel file....
                            ReadExcelData_backup   loadExcelData     = new ReadExcelData_backup();
                            List <ImportViewModel> loadExcelDataList = loadExcelData.LoadDataFromExcel(fileLocation);

                            if (Session["ErrorReadingExcel"] != null)
                            {
                                TempData["type"]    = "danger";
                                TempData["title"]   = "Invalid file!";
                                TempData["message"] = "Its not a valid file.";
                            }

                            ImportViewModelManager model = new ImportViewModelManager();

                            //validate the data...
                            foreach (var item in loadExcelDataList)
                            {
                                if (item.Location.Contains("DATA CENTER PITTSBURGH"))
                                {
                                    item.ValidationViewModel.LocationValidationFailed = "its not exists, wrong location name...";
                                }
                                if (item.SerialNumber.Length < 10 || item.SerialNumber.Length > 10)
                                {
                                    item.ValidationViewModel.SerialNumberValidationFailed = "serial number failed row";
                                }
                            }
                            model.DataModel         = loadExcelDataList;
                            Session["storedevices"] = model;
                        }
                    }
                }
                if (submitButton != null)
                {
                    RemoveFormCollectionData removeItemFC = new RemoveFormCollectionData();
                    if (submitButton.ToLower() == "save to db")
                    {
                        if (formCollection.Count > 0 && formCollection != null)
                        {
                            if (Session["storedevices"] == null)
                            {
                                return(View("Index"));
                            }
                            //helper.LoadDataFormCollection(formCollection);
                        }
                    }
                    else if (submitButton.ToLower() == "remove item from grid")
                    {
                        if (formCollection.Count > 0 && formCollection != null)
                        {
                            if (Session["storedevices"] == null)
                            {
                                return(View("Index"));
                            }

                            //get the updated data after it remove the items from the list.
                            Session["storedevices"] = removeItemFC.RemoveItemFromGrid(formCollection);
                        }
                    }
                    else
                    {
                        if (Session["storedevices"] == null)
                        {
                            return(View("Index"));
                        }
                        Int16 pageSize = Convert.ToInt16(submitButton);
                        ((ImportViewModelManager)(Session["storedevices"])).PageSize = pageSize;
                        submitButton = null;
                    }
                }
            }

            return(View(Session["storedevices"]));
        }