Ejemplo n.º 1
0
        private static ImportFileViewModel ShowImportComponentView()
        {
            var view = new ImportFileView();

            var viewModel = new ImportFileViewModel();

            viewModel.BrowseFileFilter = "Gum Component (*.gucx)|*.gucx";

            var componentFilesNotInProject = FileManager.GetAllFilesInDirectory(
                GumState.Self.ProjectState.ComponentFilePath.FullPath, "gucx")
                                             .Select(item => new FilePath(item))
                                             .ToList();

            var componentFilesInProject = GumState.Self.ProjectState.GumProjectSave
                                          .Components
                                          .Select(item => new FilePath(GumState.Self.ProjectState.ComponentFilePath + item.Name + ".gucx"))
                                          .ToArray();

            componentFilesNotInProject = componentFilesNotInProject
                                         .Except(componentFilesInProject)
                                         .ToList();

            viewModel.UnfilteredFileList.AddRange(componentFilesNotInProject.Select(item => item.FullPath));
            viewModel.RefreshFilteredList();


            view.DataContext = viewModel;
            var result = view.ShowDialog();

            return(viewModel);
        }
        //public ActionResult ImportFromCsv(HttpPostedFileBase ImportCsv)
        public ActionResult ImportFromCsv(ImportFileViewModel model)
        {
            try
            {
                if (model.ImportFile != null)
                {
                    var file = model.ImportFile;

                    if (file != null && file.ContentLength > 0)
                    {
                        var fileBytes = new byte[file.ContentLength];
                        file.InputStream.Read(fileBytes, 0, file.ContentLength);
                        //do stuff with the bytes
                        string fileName = file.FileName;
                        string filePath = Path.Combine(Request.PhysicalApplicationPath, "Files\\", fileName);

                        System.IO.File.WriteAllBytes(filePath, fileBytes);

                        //File Uploaded
                        //using (var reader = new StreamReader(ImportCsv.InputStream))
                        //using (var reader = new StreamReader(model.ImportFile.InputStream))
                        using (var reader = new StreamReader(filePath))
                            using (var csvReader = new CsvReader(reader))
                            {
                                csvReader.Read();
                                //Read CSV File
                                var products = csvReader.GetRecords <ProductCsvModel>().ToList();
                            }

                        if (System.IO.File.Exists(filePath))
                        {
                            System.IO.File.Delete(filePath);
                        }

                        return(RedirectToAction("DataImport", "Product"));
                        //return Content(Boolean.TrueString);
                        //return Json(new { msg = "Product data uploaded successfully.", status = MessageType.success.ToString() }, JsonRequestBehavior.AllowGet);
                    }
                    else
                    {
                        //return Content("Sorry! Could not found this file.");
                        return(RedirectToAction("DataImport", "Product"));
                    }
                }
                else
                {
                    //Upload file Null Message
                    return(RedirectToAction("DataImport", "Product"));
                    //return Content("Upload file could not found.");
                    //return Json(new { msg = "Upload file could not found.", status = MessageType.success.ToString() }, JsonRequestBehavior.AllowGet);
                }
            }
            catch (Exception ex)
            {
                return(RedirectToAction("DataImport", "Product"));
                //return Content("Oop! Error.");
                //return Json(new { msg = ExceptionHelper.ExceptionMessageFormat(ex, log: false), status = MessageType.error.ToString() }, JsonRequestBehavior.AllowGet);
            }
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> UploadFile([FromForm] ImportFileViewModel importFile, CancellationToken cancellationToken)
        {
            var csvData = await GetCsvData(importFile.File, cancellationToken);

            var dataToImport = await GetDataToImport(csvData, cancellationToken);

            var import = await Mediator.Send(dataToImport, cancellationToken);

            return(RedirectToAction("Index", "Vehicle"));
        }
Ejemplo n.º 4
0
        public async Task <ActionResult> Import(ImportFileViewModel model)
        {
            try
            {
                T[] newItems = fileConverter.ConvertFileToObjects <T>(model.MyFile);
                await dbService.AddMultipleAsync(newItems);

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }
Ejemplo n.º 5
0
        public JsonResult Save(ImportFileViewModel info)
        {
            info.CREATEDDATE = DateTime.Now;
            info.CREATEDUSER = LoginUser.Current.USERNAME;
            MD_IMPORTDETAIL detail     = info.GetDetailImportFile();
            var             resultJson = APIHelper.CallAPI <JsonResultData>("importdetail/Insert", new
            {
                data = detail
            });

            if (!resultJson.IsOk)
            {
                return(Json(resultJson, JsonRequestBehavior.AllowGet));
            }
            var lstCnt = info.GetImportContainer();

            foreach (var cnt in lstCnt)
            {
                resultJson = APIHelper.CallAPI <JsonResultData>("importpkl/Insert", new
                {
                    data = cnt
                });
                if (!resultJson.IsOk)
                {
                    return(Json(resultJson, JsonRequestBehavior.AllowGet));
                }
            }
            var lstPallet = info.GetImportPallet();

            foreach (var pallet in lstPallet)
            {
                var searchcontract = APIHelper.CallAPI <JsonResultObject <List <MD_IMPORTCONTRACT> > >("importcontract/getdetailbycode", new
                {
                    code = detail.IMPORTCONTRACTCODE
                });
                if (!searchcontract.IsOk)
                {
                    return(Json(searchcontract, JsonRequestBehavior.AllowGet));
                }
                var contract     = searchcontract.dataObj.First();
                var fullcontract = new ImpContractEditViewModel(contract);
                var supplier     = fullcontract.SupplierDetail.SUPPLIERNAME;
                var material     = APIHelper.CallAPI <JsonResultObject <List <MD_MATERIAL> > >("material/getdetail", new
                {
                    id = pallet.MATERIALID
                });
                if (!material.IsOk)
                {
                    return(Json(material, JsonRequestBehavior.AllowGet));
                }
                var materialName = material.dataObj != null?material.dataObj.FirstOrDefault().NAME : string.Empty;

                var submaterialName = string.Empty;
                if (pallet.SUBMATERIALID.HasValue)
                {
                    var submaterial = APIHelper.CallAPI <JsonResultObject <List <MD_SUBMATERIAL> > >("submaterial/getdetail", new
                    {
                        id = pallet.SUBMATERIALID.Value
                    });
                    if (!submaterial.IsOk)
                    {
                        return(Json(submaterial, JsonRequestBehavior.AllowGet));
                    }
                    submaterialName = submaterial.dataObj != null?submaterial.dataObj.FirstOrDefault().NAME : string.Empty;
                }
                string Origin  = string.Empty;
                var    Sorigin = fullcontract.ItemList.Where(x => x.MATERIALID == pallet.MATERIALID && pallet.SUBMATERIALID.HasValue ? pallet.SUBMATERIALID.Value == x.SUBMATERIALID.Value : !x.SUBMATERIALID.HasValue);
                if (Sorigin.Count() > 0)
                {
                    Origin = Sorigin.First().ORIGIN;
                }
                var    fullNameMaterial = materialName + (string.IsNullOrEmpty(submaterialName) ? "" : " " + submaterialName);
                string objectSerialize  = string.Format("LAMIPEL ERP\nMaterial:{5}\nPallet No:{0}\nFile No:{1}\nSupplier:{2}\nContract No:{3}\nInvoice PKL:{4}\nContainer:{6}\nPCS:{7}\nNW:{8}\nSQFT:{9}\nSAVG:{10}\nWAVG:{11}", string.IsNullOrEmpty(pallet.PALLETDONECODE) ? "" : pallet.PALLETDONECODE, detail.IMPFILE, supplier, contract.IMPORTCODE, detail.INVOICE, fullNameMaterial, pallet.IMPORTPKL, pallet.PCS, pallet.NW, pallet.SQFT, pallet.SAVG, pallet.WAVG);
                pallet.SCANCODE = Barcode.Current.CreateQRString(objectSerialize);
                List <string> dataprint = new List <string>();
                dataprint.Add(string.IsNullOrEmpty(pallet.PALLETDONECODE) ? "" : pallet.PALLETDONECODE); //dataprint.Add(pallet.NAME);
                dataprint.Add(materialName);
                dataprint.Add(submaterialName);
                dataprint.Add(pallet.PCS.HasValue ? pallet.PCS.Value.ToString("#,##0") : "0");
                dataprint.Add(pallet.NW.HasValue ? pallet.NW.Value.ToString("#,##0") : "0");
                dataprint.Add(lstCnt.Where(x => x.PKLNAME == pallet.IMPORTPKL).First().PKLIDENTITY); //dataprint.Add(pallet.WAVG.HasValue ? pallet.WAVG.Value.ToString("#,##0") : "0");
                dataprint.Add(pallet.SQFT.HasValue ? pallet.SQFT.Value.ToString("#,##0") : "0");
                dataprint.Add(Origin);                                                               //origin
                dataprint.Add(info.ISLWG ? "YES" : "NO");                                            //lwg
                dataprint.Add(pallet.SCANCODE);
                var cnt = lstCnt.Where(x => x.PKLNAME == pallet.IMPORTPKL && x.IMPFILE == detail.IMPFILE);
                dataprint.Add(cnt != null && cnt.Count() > 0 ? cnt.First().PKLDONECODE : "");//dataprint.Add(pallet.IMPORTPKL);
                dataprint.Add(supplier.Length > 15 ? supplier.Substring(0, 15) : supplier);
                pallet.TEMPLATEPRINT = BarcodeHelper.XMLHelper.Current.BuilResouce("ImportLabelPrint", dataprint.ToArray());
                resultJson           = APIHelper.CallAPI <JsonResultData>("importpallet/Insert", new
                {
                    data = pallet
                });
                if (!resultJson.IsOk)
                {
                    return(Json(resultJson, JsonRequestBehavior.AllowGet));
                }
            }
            return(Json(resultJson, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 6
0
 public ImportFileDialog(ImportFileViewModel model)
 {
     DataContext = model;
     InitializeComponent();
 }
        //public ActionResult ImportFromXls(HttpPostedFileBase ImportExcel)
        public ActionResult ImportFromXls(ImportFileViewModel model)
        {
            try
            {
                if (model.ImportFile != null)
                {
                    var file = model.ImportFile;

                    if (file != null && file.ContentLength > 0)
                    {
                        var fileBytes = new byte[file.ContentLength];
                        file.InputStream.Read(fileBytes, 0, file.ContentLength);
                        //do stuff with the bytes
                        string fileName = file.FileName;
                        string filePath = Path.Combine(Request.PhysicalApplicationPath, "Files\\", fileName);

                        System.IO.File.WriteAllBytes(filePath, fileBytes);

                        //File Uploaded
                        HSSFWorkbook hssfWorkbook;

                        string filefullpath = filePath;

                        //StreamReader streamReader = new StreamReader(model.ImportFile.InputStream);

                        using (FileStream fileStream = new FileStream(filefullpath, FileMode.Open, FileAccess.Read))
                        {
                            hssfWorkbook = new HSSFWorkbook(fileStream);
                            //hssfWorkbook = new HSSFWorkbook();
                        }

                        var products = new List <ProductXlsModel>();

                        //the columns
                        var properties = new string[] { "ProductId", "ProductName", "ProductPrice", "CategoryId", "CategoryName" };

                        ISheet sheet = hssfWorkbook.GetSheet("Products");
                        for (int row = 1; row <= sheet.LastRowNum; row++)
                        {
                            if (sheet.GetRow(row) != null) //null is when the row only contains empty cells
                            {
                                int productId = Convert.ToInt32(sheet.GetRow(row).GetCell(GetColumnIndex(properties, "ProductId")).NumericCellValue);

                                string  productName  = sheet.GetRow(row).GetCell(GetColumnIndex(properties, "ProductName")).StringCellValue;
                                decimal productPrice = Convert.ToDecimal(sheet.GetRow(row).GetCell(GetColumnIndex(properties, "ProductPrice")).StringCellValue);
                                int     categoryId   = Convert.ToInt32(sheet.GetRow(row).GetCell(GetColumnIndex(properties, "CategoryId")).NumericCellValue);
                                string  categoryName = sheet.GetRow(row).GetCell(GetColumnIndex(properties, "CategoryName")).StringCellValue;

                                var product = new ProductXlsModel {
                                    ProductId = productId, ProductName = productName, ProductPrice = productPrice, CategoryId = categoryId, CategoryName = categoryName
                                };

                                products.Add(product);
                            }
                        }

                        if (System.IO.File.Exists(filefullpath))
                        {
                            System.IO.File.Delete(filefullpath);
                        }

                        return(RedirectToAction("DataImport", "Product"));
                        //return Content(Boolean.TrueString);
                        //return Json(new { msg = "Product data uploaded successfully.", status = MessageType.success.ToString() }, JsonRequestBehavior.AllowGet);
                    }
                    else
                    {
                        //return Content("Sorry! Could not found this file.");
                        return(RedirectToAction("DataImport", "Product"));
                    }
                }
                else
                {
                    //Upload file Null Message
                    return(RedirectToAction("DataImport", "Product"));
                    //return Content("Upload file could not found.");
                    //return Json(new { msg = "Upload file could not found.", status = MessageType.success.ToString() }, JsonRequestBehavior.AllowGet);
                }
            }
            catch (Exception ex)
            {
                return(RedirectToAction("DataImport", "Product"));
                //return Content("Oop! Error.");
                //return Json(new { msg = ExceptionHelper.ExceptionMessageFormat(ex, log: false), status = MessageType.error.ToString() }, JsonRequestBehavior.AllowGet);
            }
        }
Ejemplo n.º 8
0
        internal static void ShowImportComponentUi()
        {
            if (ObjectFinder.Self.GumProjectSave == null || string.IsNullOrEmpty(ProjectManager.Self.GumProjectSave.FullFileName))
            {
                MessageBox.Show("You must first save the project before adding a new component");
                return;
            }

            ImportFileViewModel viewModel = ShowImportComponentView();

            ComponentSave lastImportedComponent = null;

            for (int i = 0; i < viewModel.SelectedFiles.Count; ++i)
            {
                string fileName         = viewModel.SelectedFiles[i];
                string desiredDirectory = FileManager.GetDirectory(
                    ProjectManager.Self.GumProjectSave.FullFileName) + "Components/";

                var shouldAdd = true;

                if (!FileManager.IsRelativeTo(fileName, desiredDirectory))
                {
                    string fileNameWithoutPath = FileManager.RemovePath(fileName);

                    var copyResult = MessageBox.Show("The file " + fileNameWithoutPath + " must be in the Gum project's Components folder. " +
                                                     "Would you like to copy the file?", "Copy?", MessageBoxButtons.YesNo);

                    shouldAdd = copyResult == DialogResult.Yes;

                    if (shouldAdd)
                    {
                        try
                        {
                            string destination = desiredDirectory + fileNameWithoutPath;
                            System.IO.File.Copy(fileName, destination);

                            fileName = destination;
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Error copying the file: " + ex.ToString());
                            break;
                        }
                    }
                }

                if (shouldAdd)
                {
                    string strippedName = FileManager.RemovePath(FileManager.RemoveExtension(fileName));

                    var componentSave = FileManager.XmlDeserialize <ComponentSave>(fileName);

                    var componentReferences = ProjectManager.Self.GumProjectSave.ComponentReferences;
                    componentReferences.Add(new ElementReference {
                        Name = componentSave.Name, ElementType = ElementType.Component
                    });
                    componentReferences.Sort((first, second) => first.Name.CompareTo(second.Name));

                    var components = ProjectManager.Self.GumProjectSave.Components;
                    components.Add(componentSave);
                    components.Sort((first, second) => first.Name.CompareTo(second.Name));

                    componentSave.InitializeDefaultAndComponentVariables();

                    GumCommands.Self.FileCommands.TryAutoSaveElement(componentSave);

                    lastImportedComponent = componentSave;
                }
            }

            if (lastImportedComponent != null)
            {
                GumCommands.Self.GuiCommands.RefreshElementTreeView();
                SelectedState.Self.SelectedComponent = lastImportedComponent;
                GumCommands.Self.FileCommands.TryAutoSaveProject();
            }
        }
Ejemplo n.º 9
0
        internal static void ShowImportScreenUi()
        {
            if (ObjectFinder.Self.GumProjectSave == null || string.IsNullOrEmpty(ProjectManager.Self.GumProjectSave.FullFileName))
            {
                MessageBox.Show("You must first save the project before adding a new screen");

                return;
            }

            ImportFileViewModel viewModel = ShowImportScreenView();

            for (int i = 0; i < viewModel.SelectedFiles.Count; ++i)
            {
                string fileName = viewModel.SelectedFiles[i];

                string desiredDirectory =
                    FileManager.GetDirectory(
                        ProjectManager.Self.GumProjectSave.FullFileName) + "Screens/";

                var shouldAdd = true;


                if (FileManager.IsRelativeTo(fileName, desiredDirectory) == false)
                {
                    var copyResult = MessageBox.Show("The file must be in the Gum project's Screens folder.  " +
                                                     "Would you like to copy the file?.", "Copy?", MessageBoxButtons.YesNo);

                    shouldAdd = copyResult == DialogResult.Yes;

                    try
                    {
                        string destination = desiredDirectory + FileManager.RemovePath(fileName);
                        System.IO.File.Copy(fileName,
                                            destination);

                        fileName = destination;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Error copying the file: " + ex.ToString());
                    }
                }

                if (shouldAdd)
                {
                    string strippedName = FileManager.RemovePath(FileManager.RemoveExtension(fileName));

                    ProjectManager.Self.GumProjectSave.ScreenReferences.Add(
                        new ElementReference {
                        Name = strippedName, ElementType = ElementType.Screen
                    });

                    ProjectManager.Self.GumProjectSave.ScreenReferences.Sort(
                        (first, second) => first.Name.CompareTo(second.Name));

                    var screenSave = FileManager.XmlDeserialize <ScreenSave>(fileName);

                    ProjectManager.Self.GumProjectSave.Screens.Add(screenSave);

                    ProjectManager.Self.GumProjectSave.Screens.Sort(
                        (first, second) => first.Name.CompareTo(second.Name));

                    screenSave.Initialize(null);

                    GumCommands.Self.GuiCommands.RefreshElementTreeView();

                    SelectedState.Self.SelectedScreen = screenSave;

                    GumCommands.Self.FileCommands.TryAutoSaveProject();
                    GumCommands.Self.FileCommands.TryAutoSaveElement(screenSave);
                }
            }
        }