public static UnidadeDeArmazenamento ParseToDb(StockkeepingUnitViewModel x) { if (x != null) { return(new UnidadeDeArmazenamento() { NºProduto = x.ProductNo, CódLocalização = x.Code, Descrição = x.Description, Inventário = x.Inventory, Bloqueado = x.Blocked, CódUnidadeMedidaProduto = x.CodeUnitMeasure, CustoUnitário = x.UnitCost, ValorEmArmazem = x.WareHouseValue, ArmazémPrincipal = x.CodeWareHouse, NºPrateleira = x.ShelfNo, NºFornecedor = x.VendorNo, CódProdForn = x.VendorItemNo, UltimoCustoDirecto = x.LastCostDirect, CódCategoriaProduto = x.CodeProcuctCategory, CódGrupoProduto = x.CodeProcuctGroup, PreçoDeVenda = x.PriceSale }); } else { return(null); } }
public bool SetSessionMovimentoProduto([FromBody] StockkeepingUnitViewModel data) { if (data.ProductNo != null) { HttpContext.Session.SetString("productNo", data.ProductNo); HttpContext.Session.SetString("codLocation", data.Code); return(true); } return(false); }
public JsonResult UpdateUnitStockeeping([FromBody] StockkeepingUnitViewModel data) { string eReasonCode = ""; //Create new eReasonCode = DBStockkeepingUnit.Update(DBStockkeepingUnit.ParseToDb(data)) == null ? "102" : ""; if (String.IsNullOrEmpty(eReasonCode)) { return(Json(data)); } else { return(Json(eReasonCode)); } }
public JsonResult GetUnitStockeepingId([FromBody] string idStock) { StockkeepingUnitViewModel result = DBStockkeepingUnit.ParseToViewModel(DBStockkeepingUnit.GetById(idStock)); return(Json(result)); }
public JsonResult OnPostImport_UnidadesArmazenamento() { var files = Request.Form.Files; List <StockkeepingUnitViewModel> ListToCreate = DBStockkeepingUnit.ParseToViewModel(DBStockkeepingUnit.GetAll()); StockkeepingUnitViewModel nrow = new StockkeepingUnitViewModel(); for (int i = 0; i < files.Count; i++) { IFormFile file = files[i]; string folderName = "Upload"; string webRootPath = _generalConfig.FileUploadFolder + "UnidadesArmazenamento\\" + "tmp\\"; string newPath = Path.Combine(webRootPath, folderName); StringBuilder sb = new StringBuilder(); if (!Directory.Exists(newPath)) { Directory.CreateDirectory(newPath); } if (file.Length > 0) { string sFileExtension = Path.GetExtension(file.FileName).ToLower(); ISheet sheet; string fullPath = Path.Combine(newPath, file.FileName); using (var stream = new FileStream(fullPath, FileMode.Create)) { file.CopyTo(stream); stream.Position = 0; if (sFileExtension == ".xls") { HSSFWorkbook hssfwb = new HSSFWorkbook(stream); //This will read the Excel 97-2000 formats sheet = hssfwb.GetSheetAt(0); //get first sheet from workbook } else { XSSFWorkbook hssfwb = new XSSFWorkbook(stream); //This will read 2007 Excel format sheet = hssfwb.GetSheetAt(0); //get first sheet from workbook } for (int j = (sheet.FirstRowNum + 1); j <= sheet.LastRowNum; j++) { IRow row = sheet.GetRow(j); if (row != null) { nrow = new StockkeepingUnitViewModel(); nrow.ProductNo = row.GetCell(0) != null?row.GetCell(0).ToString() : ""; nrow.Description = row.GetCell(1) != null?row.GetCell(1).ToString() : ""; nrow.Code = row.GetCell(2) != null?row.GetCell(2).ToString() : ""; nrow.InventoryText = row.GetCell(3) != null?row.GetCell(3).ToString() : ""; nrow.ShelfNo = row.GetCell(4) != null?row.GetCell(4).ToString() : ""; nrow.BlockedText = row.GetCell(5) != null?row.GetCell(5).ToString() : ""; nrow.CodeWareHouseText = row.GetCell(6) != null?row.GetCell(6).ToString() : ""; nrow.WareHouseValueText = row.GetCell(7) != null?row.GetCell(7).ToString() : ""; nrow.VendorNo = row.GetCell(8) != null?row.GetCell(8).ToString() : ""; nrow.VendorItemNo = row.GetCell(9) != null?row.GetCell(9).ToString() : ""; nrow.CodeUnitMeasure = row.GetCell(10) != null?row.GetCell(10).ToString() : ""; nrow.UnitCostText = row.GetCell(11) != null?row.GetCell(11).ToString() : ""; nrow.LastCostDirectText = row.GetCell(12) != null?row.GetCell(12).ToString() : ""; nrow.PriceSaleText = row.GetCell(13) != null?row.GetCell(13).ToString() : ""; ListToCreate.Add(nrow); } } } } if (ListToCreate.Count > 0) { foreach (StockkeepingUnitViewModel item in ListToCreate) { if (!string.IsNullOrEmpty(item.InventoryText)) { item.Inventory = Convert.ToDecimal(item.InventoryText); item.InventoryText = ""; } if (!string.IsNullOrEmpty(item.BlockedText)) { item.Blocked = item.BlockedText.ToLower() == "sim" ? true : false; item.BlockedText = ""; } if (!string.IsNullOrEmpty(item.CodeWareHouseText)) { item.CodeWareHouse = item.CodeWareHouseText.ToLower() == "sim" ? true : false; item.CodeWareHouseText = ""; } if (!string.IsNullOrEmpty(item.WareHouseValueText)) { item.WareHouseValue = Convert.ToDecimal(item.WareHouseValueText); item.WareHouseValueText = ""; } if (!string.IsNullOrEmpty(item.UnitCostText)) { item.UnitCost = Convert.ToDecimal(item.UnitCostText); item.UnitCostText = ""; } if (!string.IsNullOrEmpty(item.LastCostDirectText)) { item.LastCostDirect = Convert.ToDecimal(item.LastCostDirectText); item.LastCostDirectText = ""; } if (!string.IsNullOrEmpty(item.PriceSaleText)) { item.PriceSale = Convert.ToDecimal(item.PriceSaleText); item.PriceSaleText = ""; } } } } return(Json(ListToCreate)); }