Ejemplo n.º 1
0
        public WX3Model UpdateModelWx3Exsits(WX3Model res, WX3Model model)
        {
            WX3Model update = res;

            update.AvailQty += model.AvailQty;
            update.ResvQty  += model.ResvQty;
            return(update);
        }
Ejemplo n.º 2
0
 public bool checkExsistingInListWx3(List <WX3Model> wx3s, WX3Model model)
 {
     return(wx3s.SingleOrDefault(p => p.LotNo == model.LotNo && p.VendorCode == model.VendorCode && p.ProductCode == model.ProductCode) != null);
 }
Ejemplo n.º 3
0
        public IActionResult UploadWX3(IFormFile fExcelWX3)
        {
            if (fExcelWX3 != null && CheckGetExtentionsFileIsSupported(fExcelWX3))
            {
                using (var stream = new MemoryStream())
                {
                    fExcelWX3.CopyTo(stream);
                    using (ExcelPackage package = new ExcelPackage(stream))
                    {
                        ExcelWorksheet workSheet = package.Workbook.Worksheets.First();
                        if (workSheet != null)
                        {
                            // List to ADD database
                            List <WX3Model> wx3s      = new List <WX3Model>();
                            int             totalRows = workSheet.Dimension.Rows;
                            for (int i = 4; i <= totalRows; i++)
                            {
                                if (workSheet.Cells[i, 4].Value != null && workSheet.Cells[i, 4].Value.ToString() == "STORAGE")
                                {
                                    WX3Model model = new WX3Model
                                    {
                                        ProductCode = workSheet.Cells[i, 7].Value.ToString(),
                                        ProductDesc = workSheet.Cells[i, 8].Value.ToString(),
                                        VendorCode  = workSheet.Cells[i, 6].Value.ToString() != String.Empty ? workSheet.Cells[i, 6].Value.ToString() : "_",
                                        LotNo       = workSheet.Cells[i, 9].Value != null ? workSheet.Cells[i, 9].Value.ToString() : "_",
                                        AvailQty    = Convert.ToInt32(workSheet.Cells[i, 32].Value.ToString()),
                                        ResvQty     = Convert.ToInt32(workSheet.Cells[i, 33].Value.ToString())
                                    };

                                    if (IsStorageLocationIlegal(model.VendorCode))
                                    {
                                        if (checkExsistingInListWx3(wx3s, model))
                                        {
                                            WX3Model res = wx3s.SingleOrDefault(p => p.LotNo == model.LotNo && p.VendorCode == model.VendorCode && p.ProductCode == model.ProductCode);
                                            res = UpdateModelWx3Exsits(res, model);
                                        }
                                        else
                                        {
                                            WX3Model res = new WX3Model()
                                            {
                                                ProductCode = model.ProductCode,
                                                ProductDesc = model.ProductDesc,
                                                VendorCode  = model.VendorCode,
                                                LotNo       = model.LotNo,
                                                AvailQty    = Convert.ToInt32(workSheet.Cells[i, 32].Value.ToString()),
                                                ResvQty     = Convert.ToInt32(workSheet.Cells[i, 33].Value.ToString())
                                            };
                                            wx3s.Add(res);
                                        }
                                    }
                                }
                            }
                            HttpContext.Session.SetComplexData("WX3List", wx3s);
                            return(RedirectToAction("Index"));
                        }
                        else
                        {
                            ViewBag.Error = "Không tìm thấy sheet cần thiết của hệ thống để import dữ liệu! Vui lòng kiểm tra tên của Sheet theo yêu cầu của hệ thống !";
                            return(View("Index"));
                        }
                    }
                }
            }
            else
            {
                ViewBag.Error = "Vui lòng chọn file excel hoặc định dạng file của bạn không được hỗ trợ. Lưu ý những file được hỗ trợ bao gồm : .xlsx, .csv ";
                return(RedirectToAction("Index"));
            }
            return(RedirectToAction("Index"));
        }