Esempio n. 1
0
        public ActionResult Edit(long id)
        {
            ViewBag.EditStatus = true;
            WMS_CustomerModel entity = m_BLL.GetById(id);

            return(View(entity));
        }
        public void AdditionalCheckExcelData(DBContainer db, ref WMS_CustomerModel model)
        {
            //获取客户编码
            if (!String.IsNullOrEmpty(model.CustomerCode))
            {
                var customerCode = model.CustomerCode;
                Expression <Func <WMS_Customer, bool> > exp = x => x.CustomerCode == customerCode;

                //var customer = m_CustomerRep.GetSingleWhere(exp);
                var customer = db.WMS_Customer.FirstOrDefault(exp);
                if (customer != null)
                {
                    throw new Exception("客户编码重复!");
                }
            }
            else
            {
                throw new Exception("客户编码不能为空!");
            }
            //获取物料类型
            if (!String.IsNullOrEmpty(model.CustomerType))
            {
                var customer = model.CustomerType;
                Expression <Func <SysParam, bool> > exp = x => x.ParamName == customer && x.TypeCode == "CustomerType";

                var part = m_SysParamRep.GetSingleWhere(exp);
                if (part == null)
                {
                    throw new Exception("客户类型不存在!");
                }
            }
        }
Esempio n. 3
0
        public ActionResult Create(WMS_CustomerModel vm)
        {
            IEnumerable <SelectListItem> cuslist = ApplicationConfigHelper.GetProjectUserCustomers(base.UserInfo.ProjectID, base.UserInfo.ID).Where(c => c.State && (c.StoreType == 2 || c.StoreType == 3))
                                                   .Select(c => new SelectListItem()
            {
                Value = c.CustomerID.ToString(), Text = c.CustomerName
            });
            WMS_CustomerService service = new WMS_CustomerService();

            vm.StorerID = cuslist;
            IList <WMS_Customer> customer = new List <WMS_Customer>();

            //var segments = new SegmentService().GetSegmentsByCondition(new GetSegmentsByConditionRequest() { Name = "", State = true }).Result;
            //vm.Segments = segments.Select(s => new SelectListItem() { Value = s.ID.ToString(), Text = s.Name + "------>>详情>>" + s.Description });
            //vm.Types = vm.StoreStatus > 0 ? 1 : 0;
            customer.Add(vm.Convert());
            Response <IEnumerable <WMS_Customer> > response = service.AddCustomer(new AddWMS_CustomerRequest()
            {
                customers = customer
            });
            {
                WMS_Customer cus = service.selectCustomer(vm.StorerKey, vm.CustomerID.ToString());
                vm.ConvertDesc(cus);

                if (response.IsSuccess)
                {
                    //刷新缓存
                    //ApplicationConfigHelper.RefreshApplicationWMS_Customers();
                    //ApplicationConfigHelper.RefreshGetApplicationWMS_Customer();
                    vm.ViewType     = 0;
                    ViewBag.Message = "0";
                }
                return(View(vm));
            }
        }
Esempio n. 4
0
 public JsonResult Create(WMS_CustomerModel model)
 {
     model.Id           = 0;
     model.CreateTime   = ResultHelper.NowTime;
     model.CreatePerson = GetUserTrueName();
     if (model != null && ModelState.IsValid)
     {
         if (m_BLL.Create(ref errors, model))
         {
             LogHandler.WriteServiceLog(GetUserTrueName(), "Id" + model.Id + ",CustomerCode" + model.CustomerCode, "成功", "创建", "WMS_Customer");
             return(Json(JsonHandler.CreateMessage(1, Resource.InsertSucceed)));
         }
         else
         {
             //string ErrorCol = errors.Error;
             string ErrorCol = " :输入错误数据";
             LogHandler.WriteServiceLog(GetUserTrueName(), "Id" + model.Id + ",CustomerCode" + model.CustomerCode + "," + ErrorCol, "失败", "创建", "WMS_Customer");
             return(Json(JsonHandler.CreateMessage(0, Resource.InsertFail + ErrorCol)));
         }
     }
     else
     {
         return(Json(JsonHandler.CreateMessage(0, Resource.InsertFail)));
     }
 }
Esempio n. 5
0
        public ActionResult Create(string id, WMS_CustomerModel vm, int?ViewType, long?customerid)
        {
            IEnumerable <SelectListItem> cuslist = ApplicationConfigHelper.GetProjectUserCustomers(base.UserInfo.ProjectID, base.UserInfo.ID).Where(c => c.State && (c.StoreType == 2 || c.StoreType == 3))
                                                   .Select(c => new SelectListItem()
            {
                Value = c.CustomerID.ToString(), Text = c.CustomerName
            });
            WMS_CustomerService service = new WMS_CustomerService();

            vm.StorerID = cuslist;
            vm.ViewType = ViewType != null ? (int)ViewType : 2;
            //vm.StorerKey = "必填";
            //vm.City = "必填";
            //vm.Company = "必填";
            //vm.CompanyCode = "必填";
            //vm.UserDef10 = "必填";
            //vm.AddressLine1 = "必填";
            //vm.Contact1 = "必填";
            //vm.PhoneNum1 = "必填";
            bool isShowUserDef2 = true;

            if (id != null)
            {
                WMS_CustomerService customer = new WMS_CustomerService();
                WMS_Customer        cus      = customer.selectCustomer(id.ToString(), customerid.ToString());
                vm.ConvertDesc(cus);
                vm.CustomerID = customerid;
                //  vm.ViewType = 0;
                isShowUserDef2 = false;
            }
            ViewBag.isWrite = isShowUserDef2;

            return(View(vm));
        }
Esempio n. 6
0
        public virtual WMS_CustomerModel GetById(object id)
        {
            if (IsExists(id))
            {
                WMS_Customer      entity = m_Rep.GetById(id);
                WMS_CustomerModel model  = new WMS_CustomerModel();
                model.Id                = entity.Id;
                model.CustomerCode      = entity.CustomerCode;
                model.CustomerShortName = entity.CustomerShortName;
                model.CustomerName      = entity.CustomerName;
                model.CustomerType      = entity.CustomerType;
                model.LinkMan           = entity.LinkMan;
                model.LinkManTel        = entity.LinkManTel;
                model.LinkManAddress    = entity.LinkManAddress;
                model.Status            = entity.Status;
                model.Remark            = entity.Remark;
                model.CreatePerson      = entity.CreatePerson;
                model.CreateTime        = entity.CreateTime;
                model.ModifyPerson      = entity.ModifyPerson;
                model.ModifyTime        = entity.ModifyTime;

                return(model);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 7
0
        public ActionResult Edit(long id)
        {
            ViewBag.Inv = new SelectList(_InvInfoBll.GetList(ref setNoPagerAscById, ""), "Id", "InvName");

            WMS_Sale_OrderModel entity   = m_BLL.GetById(id);
            WMS_PartModel       entity_p = m_PartBLL.GetById(entity.PartId);

            entity.PartCode = entity_p.PartCode;
            WMS_CustomerModel entity_cu = m_CustomerBLL.GetById(entity.CustomerId);

            entity.CustomerShortName = entity_cu.CustomerShortName;

            return(View(entity));
        }
Esempio n. 8
0
        public virtual bool Edit(ref ValidationErrors errors, WMS_CustomerModel model)
        {
            try
            {
                WMS_Customer entity = m_Rep.GetById(model.Id);
                if (entity == null)
                {
                    errors.Add(Resource.Disable);
                    return(false);
                }
                entity.Id                = model.Id;
                entity.CustomerCode      = model.CustomerCode;
                entity.CustomerShortName = model.CustomerShortName;
                entity.CustomerName      = model.CustomerName;
                entity.CustomerType      = model.CustomerType;
                entity.LinkMan           = model.LinkMan;
                entity.LinkManTel        = model.LinkManTel;
                entity.LinkManAddress    = model.LinkManAddress;
                entity.Status            = model.Status;
                entity.Remark            = model.Remark;
                entity.CreatePerson      = model.CreatePerson;
                entity.CreateTime        = model.CreateTime;
                entity.ModifyPerson      = model.ModifyPerson;
                entity.ModifyTime        = model.ModifyTime;



                if (m_Rep.Edit(entity))
                {
                    return(true);
                }
                else
                {
                    errors.Add(Resource.NoDataChange);
                    return(false);
                }
            }
            catch (Exception ex)
            {
                errors.Add(ex.Message);
                ExceptionHander.WriteException(ex);
                return(false);
            }
        }
        public ActionResult Edit(long id)
        {
            WMS_ReturnInspectionModel entity = m_BLL.GetById(id);
            //给关联字段物料赋值
            WMS_PartModel entity_part = m_PartBLL.GetById(entity.PartID);

            entity.PartCode = entity_part.PartCode;
            entity.PartName = entity_part.PartName;
            entity.PartType = entity_part.PartType;
            //给关联字段客户编码赋值
            WMS_CustomerModel entity_cus = m_CustomerBLL.GetById(entity.CustomerId);

            entity.CustomerShortName = entity_cus.CustomerShortName;
            //给关联字段供应商赋值
            if (entity.SupplierId != null)
            {
                WMS_SupplierModel entity_sup = m_SupplierBLL.GetById(entity.SupplierId);
                entity.SupplierShortName = entity_sup.SupplierShortName;
            }



            return(View(entity));
        }
        public bool ImportExcelData(string oper, string filePath, ref ValidationErrors errors)
        {
            bool rtn = true;

            var targetFile = new FileInfo(filePath);

            if (!targetFile.Exists)
            {
                errors.Add("导入的数据文件不存在");
                return(false);
            }

            var excelFile = new ExcelQueryFactory(filePath);

            using (XLWorkbook wb = new XLWorkbook(filePath))
            {
                //第一个Sheet
                using (IXLWorksheet wws = wb.Worksheets.First())
                {
                    //对应列头
                    excelFile.AddMapping <WMS_CustomerModel>(x => x.CustomerCode, "客户编码");
                    excelFile.AddMapping <WMS_CustomerModel>(x => x.CustomerShortName, "客户简称");
                    excelFile.AddMapping <WMS_CustomerModel>(x => x.CustomerName, "客户名称");
                    excelFile.AddMapping <WMS_CustomerModel>(x => x.CustomerType, "客户类型");
                    excelFile.AddMapping <WMS_CustomerModel>(x => x.LinkMan, "联系人");
                    excelFile.AddMapping <WMS_CustomerModel>(x => x.LinkManTel, "联系电话");
                    excelFile.AddMapping <WMS_CustomerModel>(x => x.LinkManAddress, "联系地址");
                    //excelFile.AddMapping<WMS_CustomerModel>(x => x.Status, "状态");
                    excelFile.AddMapping <WMS_CustomerModel>(x => x.Remark, "说明");
                    //excelFile.AddMapping<WMS_CustomerModel>(x => x.CreatePerson, "创建人");
                    //excelFile.AddMapping<WMS_CustomerModel>(x => x.CreateTime, "创建时间");
                    //excelFile.AddMapping<WMS_CustomerModel>(x => x.ModifyPerson, "修改人");
                    //excelFile.AddMapping<WMS_CustomerModel>(x => x.ModifyTime, "修改时间");

                    //SheetName,第一个Sheet
                    var excelContent = excelFile.Worksheet <WMS_CustomerModel>(0);

                    //开启事务
                    using (DBContainer db = new DBContainer())
                    {
                        var tran     = db.Database.BeginTransaction();                      //开启事务
                        int rowIndex = 0;

                        //检查数据正确性
                        foreach (var row in excelContent)
                        {
                            rowIndex += 1;
                            string errorMessage = String.Empty;
                            var    model        = new WMS_CustomerModel();
                            model.Id                = row.Id;
                            model.CustomerCode      = row.CustomerCode;
                            model.CustomerShortName = row.CustomerShortName;
                            model.CustomerName      = row.CustomerName;
                            model.CustomerType      = row.CustomerType;
                            model.LinkMan           = row.LinkMan;
                            model.LinkManTel        = row.LinkManTel;
                            model.LinkManAddress    = row.LinkManAddress;
                            //model.Status = row.Status;
                            model.Remark = row.Remark;
                            //model.CreatePerson = row.CreatePerson;
                            //model.CreateTime = row.CreateTime;
                            //model.ModifyPerson = row.ModifyPerson;
                            //model.ModifyTime = row.ModifyTime;

                            if (!String.IsNullOrEmpty(errorMessage))
                            {
                                rtn = false;
                                errors.Add(string.Format("第 {0} 列发现错误:{1}{2}", rowIndex, errorMessage, "<br/>"));
                                wws.Cell(rowIndex + 1, excelFile.GetColumnNames("Sheet1").Count()).Value = errorMessage;
                                continue;
                                //rtn = false;
                                //errors.Add(string.Format("第 {0} 列发现错误:{1}{2}", rowIndex, errorMessage, "<br/>"));
                                //wws.Cell(rowIndex + 1, 15).Value = errorMessage;
                                //continue;
                            }

                            //执行额外的数据校验
                            try
                            {
                                AdditionalCheckExcelData(db, ref model);
                            }
                            catch (Exception ex)
                            {
                                rtn          = false;
                                errorMessage = ex.Message;
                                errors.Add(string.Format("第 {0} 列发现错误:{1}{2}", rowIndex, errorMessage, "<br/>"));
                                //wws.Cell(rowIndex + 1, 15).Value = errorMessage;
                                wws.Cell(rowIndex + 1, excelFile.GetColumnNames("Sheet1").Count()).Value = errorMessage;
                                continue;
                            }

                            //写入数据库
                            WMS_Customer entity = new WMS_Customer();
                            entity.Id                = model.Id;
                            entity.CustomerCode      = model.CustomerCode;
                            entity.CustomerShortName = model.CustomerShortName;
                            entity.CustomerName      = model.CustomerName;
                            entity.CustomerType      = model.CustomerType;
                            entity.LinkMan           = model.LinkMan;
                            entity.LinkManTel        = model.LinkManTel;
                            entity.LinkManAddress    = model.LinkManAddress;
                            entity.Status            = "有效";
                            entity.Remark            = model.Remark;
                            entity.CreatePerson      = oper;
                            entity.CreateTime        = DateTime.Now;
                            entity.ModifyPerson      = oper;
                            entity.ModifyTime        = DateTime.Now;

                            db.WMS_Customer.Add(entity);
                            try
                            {
                                db.SaveChanges();
                            }
                            catch (Exception ex)
                            {
                                rtn = false;
                                //将当前报错的entity状态改为分离,类似EF的回滚(忽略之前的Add操作)
                                db.Entry(entity).State = System.Data.Entity.EntityState.Detached;
                                errorMessage           = ex.InnerException.InnerException.Message;
                                errors.Add(string.Format("第 {0} 列发现错误:{1}{2}", rowIndex, errorMessage, "<br/>"));
                                //wws.Cell(rowIndex + 1, 15).Value = errorMessage;
                                wws.Cell(rowIndex + 1, excelFile.GetColumnNames("Sheet1").Count()).Value = errorMessage;
                            }
                        }

                        if (rtn)
                        {
                            tran.Commit();                                      //必须调用Commit(),不然数据不会保存
                        }
                        else
                        {
                            tran.Rollback();                                        //出错就回滚
                        }
                    }
                }
                wb.Save();
            }

            return(rtn);
        }
Esempio n. 11
0
        public ActionResult Details(long id)
        {
            WMS_CustomerModel entity = m_BLL.GetById(id);

            return(View(entity));
        }
Esempio n. 12
0
        /// <summary>
        /// 校验Excel数据,这个方法一般用于重写校验逻辑
        /// </summary>
        public virtual bool CheckImportData(string fileName, List <WMS_CustomerModel> list, ref ValidationErrors errors)
        {
            var targetFile = new FileInfo(fileName);

            if (!targetFile.Exists)
            {
                errors.Add("导入的数据文件不存在");
                return(false);
            }

            var excelFile = new ExcelQueryFactory(fileName);

            //对应列头
            excelFile.AddMapping <WMS_CustomerModel>(x => x.CustomerCode, "客户编码");
            excelFile.AddMapping <WMS_CustomerModel>(x => x.CustomerShortName, "客户简称");
            excelFile.AddMapping <WMS_CustomerModel>(x => x.CustomerName, "客户名称");
            excelFile.AddMapping <WMS_CustomerModel>(x => x.CustomerType, "客户类型");
            excelFile.AddMapping <WMS_CustomerModel>(x => x.LinkMan, "联系人");
            excelFile.AddMapping <WMS_CustomerModel>(x => x.LinkManTel, "联系电话");
            excelFile.AddMapping <WMS_CustomerModel>(x => x.LinkManAddress, "联系地址");
            excelFile.AddMapping <WMS_CustomerModel>(x => x.Status, "状态");
            excelFile.AddMapping <WMS_CustomerModel>(x => x.Remark, "说明");
            excelFile.AddMapping <WMS_CustomerModel>(x => x.CreatePerson, "创建人");
            excelFile.AddMapping <WMS_CustomerModel>(x => x.CreateTime, "创建时间");
            excelFile.AddMapping <WMS_CustomerModel>(x => x.ModifyPerson, "修改人");
            excelFile.AddMapping <WMS_CustomerModel>(x => x.ModifyTime, "修改时间");

            //SheetName
            var excelContent = excelFile.Worksheet <WMS_CustomerModel>(0);
            int rowIndex     = 1;

            //检查数据正确性
            foreach (var row in excelContent)
            {
                var errorMessage = new StringBuilder();
                var entity       = new WMS_CustomerModel();
                entity.Id                = row.Id;
                entity.CustomerCode      = row.CustomerCode;
                entity.CustomerShortName = row.CustomerShortName;
                entity.CustomerName      = row.CustomerName;
                entity.CustomerType      = row.CustomerType;
                entity.LinkMan           = row.LinkMan;
                entity.LinkManTel        = row.LinkManTel;
                entity.LinkManAddress    = row.LinkManAddress;
                entity.Status            = row.Status;
                entity.Remark            = row.Remark;
                entity.CreatePerson      = row.CreatePerson;
                entity.CreateTime        = row.CreateTime;
                entity.ModifyPerson      = row.ModifyPerson;
                entity.ModifyTime        = row.ModifyTime;

                //=============================================================================
                if (errorMessage.Length > 0)
                {
                    errors.Add(string.Format(
                                   "第 {0} 列发现错误:{1}{2}",
                                   rowIndex,
                                   errorMessage,
                                   "<br/>"));
                }
                list.Add(entity);
                rowIndex += 1;
            }
            if (errors.Count > 0)
            {
                return(false);
            }
            return(true);
        }