public static List <ImexItem> Read(int userID, int employeeID, FileInfo fileInfo, int bussinessID, int warehouseID, bool getDbPrice = false) { var result = new List <ImexItem>(); HSSFWorkbook hssfwb; using (FileStream file = new FileStream(fileInfo.FullName, FileMode.Open, FileAccess.Read)) { hssfwb = new HSSFWorkbook(file); } var sheet = hssfwb.GetSheetAt(0); if (sheet.LastRowNum > 0) { for (var i = 1; i <= sheet.LastRowNum; i++) { var row = sheet.GetRow(i); try { var item = new ImexItem(); item.Code = row.GetCellValue <string>(0); item.WarehouseID = warehouseID; //item.WarehouseName = row.GetCellValue<string>(1); item.Price = row.GetCellValue <decimal>(2); item.Quantity = row.GetCellValue <int>(3); result.Add(item); } catch { } } } if (result.Count > 0) { var dbItems = ImexItem.Get(userID, employeeID, warehouseID, result); foreach (var dbItem in dbItems) { var item = result.FirstOrDefault(i => i.Code == dbItem.Code && i.WarehouseID == dbItem.WarehouseID); item.ID = dbItem.ID; item.Code = dbItem.Code; item.Name = dbItem.Name; item.Image = dbItem.Image; item.WarehouseID = dbItem.WarehouseID; item.Maximum = dbItem.Quantity; item.Point = dbItem.Point; if (getDbPrice) { item.Price = dbItem.Price; } } } return(result); }
public ActionResult Add(int id, int subID) { var product = ImexItem.Get(UserID, Employee.ID, DbAction.Order.View, id, subID); product.Quantity = 1; if (Request.IsAjaxRequest()) { return(Json(new { result = true, html = RenderPartialViewToString(Views.List, product) }, JsonRequestBehavior.AllowGet)); } return(RedirectToAction("Create")); }
public static List <ImexItem> Read(int userID, int employeeID, FileInfo fileInfo, int bussinessID) { var result = new List <ImexItem>(); HSSFWorkbook hssfwb; using (FileStream file = new FileStream(fileInfo.FullName, FileMode.Open, FileAccess.Read)) { hssfwb = new HSSFWorkbook(file); } var sheet = hssfwb.GetSheetAt(0); if (sheet.LastRowNum > 0) { var whs = new List <string>(); for (var i = 1; i <= sheet.LastRowNum; i++) { var row = sheet.GetRow(i); try { var wh = row.GetCellValue <string>(2); if (!String.IsNullOrEmpty(wh) && !whs.Contains(wh)) { whs.Add(wh); } var item = new ImexItem(); item.Code = row.GetCellValue <string>(0); //item.WarehouseID = warehouseID; item.WarehouseName = wh; item.Price = row.GetCellValue <decimal>(3); item.Quantity = row.GetCellValue <int>(4); result.Add(item); } catch { } } var warehouses = WarehouseInfo.Find(userID, employeeID, whs); foreach (var item in result) { if (warehouses.FirstOrDefault(i => i.Name == item.WarehouseName) != null) { item.WarehouseID = warehouses.FirstOrDefault(i => i.Name == item.WarehouseName).ID; } } if (result.Count > 0) { var dbItems = ImexItem.Get(userID, employeeID, result); foreach (var dbItem in dbItems) { foreach (var item in result.Where(i => i.Code == dbItem.Code)) { item.ID = dbItem.ID; item.Code = dbItem.Code; item.Name = dbItem.Name; item.Price = dbItem.Price; //item.Quantity = 1; } } } result = result.Where(i => i.ID > 0 && i.WarehouseID > 0).ToList(); } return(result); }