Пример #1
0
        public ActionResult ImportWholeSalerInventory(HttpPostedFileBase chooseFile)
        {
            if (chooseFile == null)
            {
                TempData["message"] = "Vui lòng chọn file";
                return(RedirectToAction("ImportWholeSalerInventory", "Home", ViewBag.message));
            }
            if (Path.GetExtension(chooseFile.FileName) != ".xlsx" && Path.GetExtension(chooseFile.FileName) != ".xls")
            {
                TempData["message"] = "Định dạng file excel không hợp lệ";
                return(RedirectToAction("ImportWholeSalerInventory", "Home", ViewBag.message));
            }
            ExcelPackage package = new ExcelPackage(chooseFile.InputStream);
            DataTable    Dt      = ExcelPackageExtensions.ConvertToDataTable(package);
            List <WholeSaler_Inventory> lstImport = Dt.DataTableToListBaseHeader <WholeSaler_Inventory>();

            foreach (var imp in lstImport)
            {
                var entity = wholeSalerRepository.List.Where(x => x.InvtID == imp.InvtID &&
                                                             x.Period == imp.Period &&
                                                             x.WholeSalerID == imp.WholeSalerID).FirstOrDefault();
                if (entity == null)
                {
                    imp.LastUpdatedDateTime = DateTime.Now;
                    imp.CreatedDateTime     = DateTime.Now;
                    wholeSalerRepository.InsertOrUpdate(imp);
                }
            }

            return(View());
        }
Пример #2
0
        public ActionResult ImportTarget(HttpPostedFileBase chooseFile)
        {
            //string message = ValidationSellOut(chooseFile);
            //if (!string.IsNullOrEmpty(message))
            //{
            //    return RedirectToAction("ImportSellOut", "Home", message);
            //}
            if (chooseFile == null)
            {
                TempData["message"] = "Vui lòng chọn file";
                return(RedirectToAction("ImportSellOut", "Home", ViewBag.message));
            }
            if (Path.GetExtension(chooseFile.FileName) != ".xlsx" && Path.GetExtension(chooseFile.FileName) != ".xls")
            {
                TempData["message"] = "Định dạng file excel không hợp lệ";
                return(RedirectToAction("ImportSellOut", "Home", ViewBag.message));
            }
            ExcelPackage package = new ExcelPackage(chooseFile.InputStream);
            DataTable    Dt      = ExcelPackageExtensions.ConvertToDataTable(package);


            List <MT_SellOut> lstTarget = Dt.DataTableToListBaseHeader <MT_SellOut>();

            if (Dt.Columns.Count > 8)
            {
                TempData["message"] = "Vui lòng chọn templete sell out để có thể import!";
                return(RedirectToAction("ImportSellOut", "Home", ViewBag.message));
            }



            String salesOrg = lstTarget.ElementAt(0).SalesOrg;

            if (salesOrg != "1100" && salesOrg != "1500")
            {
                TempData["message"] = "Vui lòng chọn templete out in để có thể import!";
                return(RedirectToAction("ImportSellOut", "Home", ViewBag.message));
            }
            //lstTarget.RemoveAt(0);
            int lineID = 0;

            foreach (var item in lstTarget)
            {
                item.LineID      = lineID;
                item.CompanyCode = DMSEnum.CompanyCode;
                sellOutRepository.InsertOrUpdate(item);
                lineID++;
            }
            TempData["success"] = DMSEnum.Success;
            return(RedirectToAction("ImportSellOut", "Home", ViewBag.message));
        }
Пример #3
0
        public ActionResult ImportPerform(HttpPostedFileBase chooseFile)
        {
            if (chooseFile == null)
            {
                TempData["message"] = "Vui lòng chọn file";
                return(RedirectToAction("ImportSellOut", "Home", ViewBag.message));
            }
            if (Path.GetExtension(chooseFile.FileName) != ".xlsx" && Path.GetExtension(chooseFile.FileName) != ".xls")
            {
                TempData["message"] = "Định dạng file excel không hợp lệ";
                return(RedirectToAction("ImportSellOut", "Home", ViewBag.message));
            }
            ExcelPackage package = new ExcelPackage(chooseFile.InputStream);
            DataTable    Dt      = ExcelPackageExtensions.ConvertToDataTable(package);

            //if (Dt.Columns.Count > 8)
            //{
            //    TempData["message"] = "Vui lòng chọn templete sell out để có thể import!";
            //    return RedirectToAction("ImportSellOut", "Home", ViewBag.message);
            //}
            List <MT_SellOut> lstTarget = Dt.DataTableToListBaseHeader <MT_SellOut>();


            String salesOrg = lstTarget.ElementAt(0).SalesOrg;

            if (salesOrg != "1100" && salesOrg != "1500")
            {
                TempData["message"] = "Vui lòng chọn templete out in để có thể import!";
                return(RedirectToAction("ImportSellOut", "Home", ViewBag.message));
            }
            //var db = new DemoEntities1();
            //var lstEmp = db.sp_Employee_GetAll();
            //List<SellOutViewModel> empViewModel = lstEmp.Select(c => new SellOutViewModel
            //{
            //    EmployeeCode = c.EmployeeCode,
            //    EmployeeName = c.EmployeeName,
            //    SalesForceCode = c.SalesForceCode,
            //    Parentcode = c.Parentcode,
            //    SalesForceName = c.SalesForceName,
            //    SalesForceLevel = c.SalesForceLevel

            //}).ToList();

            //DataTable Dt11 = ExcelPackageExtensions.ToDataTable(empViewModel);

            //--------------------------------------------------------

            foreach (var item in lstTarget)
            {
                sellOutRepository.Update(item, x => x.Perform);
            }

            lstTarget = sellOutRepository.List.ToList();
            foreach (var item in lstTarget)
            {
                item.Rate = Math.Round((Double.Parse(item.Perform) / Double.Parse(item.Target) * 100)).ToString();
                sellOutRepository.Update(item, x => x.Rate);
            }
            var    lstSalesForce = salesForceRepository.List.ToList();
            string day           = DateTime.Now.ToString("dd/MM/yyyy");



            var result = lstSalesForce.Join(lstTarget,
                                            dep => dep.EmployeeCode,
                                            e => e.ID,
                                            (e, dep) => new { e, dep })

                         .Select(i => new MT_SellOut
            {
                Day             = day,
                SalesOrg        = i.dep.SalesOrg,
                CustomerCode    = i.dep.CustomerCode,
                SalesRouteCode  = i.dep.SalesRouteCode,
                ID              = i.dep.ID,
                Name            = i.dep.Name,
                Store           = i.dep.Store,
                Target          = i.dep.Target,
                Perform         = i.dep.Perform,
                Rate            = i.dep.Rate,
                LineID          = i.dep.LineID,
                CompanyCode     = DMSEnum.CompanyCode,
                SalesForceLevel = i.e.SalesForceLevel,
                ParentCode      = i.e.ParentCode,
                SalesForceCode  = i.e.SalesForceCode
            }
                                 ).OrderBy(x => x.LineID)

                         .ToList();



            foreach (var item in result)
            {
                sellOutRepository.InsertOrUpdate(item);
            }

            DataTable Dt1 = ExcelPackageExtensions.ToDataTable(result);

            return(View(Dt1));
        }