public JsonResult Create(WMS_SupplierModel 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 + ",SupplierCode" + model.SupplierCode, "成功", "创建", "WMS_Supplier");
             return(Json(JsonHandler.CreateMessage(1, Resource.InsertSucceed)));
         }
         else
         {
             //string ErrorCol = errors.Error;
             string ErrorCol = " :输入错误数据";
             LogHandler.WriteServiceLog(GetUserTrueName(), "Id" + model.Id + ",SupplierCode" + model.SupplierCode + "," + ErrorCol, "失败", "创建", "WMS_Supplier");
             return(Json(JsonHandler.CreateMessage(0, Resource.InsertFail + ErrorCol)));
         }
     }
     else
     {
         return(Json(JsonHandler.CreateMessage(0, Resource.InsertFail)));
     }
 }
        public ActionResult Edit(long id)
        {
            ViewBag.EditStatus = true;
            WMS_SupplierModel entity = m_BLL.GetById(id);

            return(View(entity));
        }
示例#3
0
        public void AdditionalCheckExcelData(DBContainer db, ref WMS_SupplierModel model)
        {
            //获取超量接收
            if (!String.IsNullOrEmpty(model.MoreAccept))
            {
                if (model.MoreAccept != "允许" && model.MoreAccept != "不允许")
                {
                    throw new Exception("超量接收只能维护允许或者不允许!");
                }
            }
            else
            {
                throw new Exception("超量接收不能为空!");
            }

            //获取供应商编码
            if (!String.IsNullOrEmpty(model.SupplierCode))
            {
                var supplierCode = model.SupplierCode;
                Expression <Func <WMS_Supplier, bool> > exp = x => x.SupplierCode == supplierCode;

                //var supplier = m_SupplierRep.GetSingleWhere(exp);
                var supplier = db.WMS_Supplier.FirstOrDefault(exp);
                if (supplier != null)
                {
                    throw new Exception("供应商编码重复!");
                }
            }
            else
            {
                throw new Exception("供应商编码不能为空!");
            }
            //获取供应商类型
            if (!String.IsNullOrEmpty(model.SupplierType))
            {
                var supplier = model.SupplierType;
                Expression <Func <SysParam, bool> > exp = x => x.ParamName == supplier && x.TypeCode == "SupplierType";

                var part = m_SysParamRep.GetSingleWhere(exp);
                if (part == null)
                {
                    throw new Exception("供应商类型不存在!");
                }
            }
            ////供应商名称不能为空
            //if (String.IsNullOrEmpty(model.SupplierName))
            //{
            //    throw new Exception("供应商名称不能为空!");
            //}
            //供应商简称不能为空
            if (String.IsNullOrEmpty(model.SupplierShortName))
            {
                throw new Exception("供应商简称不能为空!");
            }
            //供应商类型不能为空
            //if (String.IsNullOrEmpty(model.SupplierType))
            //{
            //    throw new Exception("供应商类型不能为空!");
            //}
        }
        public virtual WMS_SupplierModel GetById(object id)
        {
            if (IsExists(id))
            {
                WMS_Supplier      entity = m_Rep.GetById(id);
                WMS_SupplierModel model  = new WMS_SupplierModel();
                model.Id                = entity.Id;
                model.SupplierCode      = entity.SupplierCode;
                model.SupplierShortName = entity.SupplierShortName;
                model.SupplierName      = entity.SupplierName;
                model.SupplierType      = entity.SupplierType;
                model.LinkMan           = entity.LinkMan;
                model.LinkManTel        = entity.LinkManTel;
                model.LinkManAddress    = entity.LinkManAddress;
                model.Status            = entity.Status;
                model.MoreAccept        = entity.MoreAccept;
                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);
            }
        }
示例#5
0
        public ActionResult Edit(long id)
        {
            ViewBag.Supplier = new SelectList(m_SupplierBLL.GetList(ref setNoPagerAscById, ""), "Id", "SupplierShortName");
            //输入框内值是否可以修改
            ViewBag.EditStatus = true;
            WMS_POModel entity = m_BLL.GetById(id);
            //给关联字段代理商简称赋值
            WMS_SupplierModel entity_s = m_SupplierBLL.GetById(entity.SupplierId);

            entity.SupplierShortName = entity_s.SupplierShortName;
            //给关联字段物料编码赋值
            WMS_PartModel entity_p = m_PartBLL.GetById(entity.PartId);

            entity.PartCode = entity_p.PartCode;
            return(View(entity));
        }
        public virtual bool Edit(ref ValidationErrors errors, WMS_SupplierModel model)
        {
            try
            {
                WMS_Supplier entity = m_Rep.GetById(model.Id);
                if (entity == null)
                {
                    errors.Add(Resource.Disable);
                    return(false);
                }
                entity.Id                = model.Id;
                entity.SupplierCode      = model.SupplierCode;
                entity.SupplierShortName = model.SupplierShortName;
                entity.SupplierName      = model.SupplierName;
                entity.SupplierType      = model.SupplierType;
                entity.LinkMan           = model.LinkMan;
                entity.LinkManTel        = model.LinkManTel;
                entity.LinkManAddress    = model.LinkManAddress;
                entity.Status            = model.Status;
                entity.MoreAccept        = model.MoreAccept;
                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 ActionResult Details(long id)
        {
            WMS_SupplierModel entity = m_BLL.GetById(id);

            return(View(entity));
        }
示例#9
0
        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_SupplierModel>(x => x.SupplierCode, "供应商编码(必输)");
                    excelFile.AddMapping <WMS_SupplierModel>(x => x.SupplierShortName, "供应商简称(必输)");
                    excelFile.AddMapping <WMS_SupplierModel>(x => x.SupplierName, "供应商名称(必输)");
                    excelFile.AddMapping <WMS_SupplierModel>(x => x.SupplierType, "供应商类型");
                    excelFile.AddMapping <WMS_SupplierModel>(x => x.LinkMan, "联系人");
                    excelFile.AddMapping <WMS_SupplierModel>(x => x.LinkManTel, "联系人电话");
                    excelFile.AddMapping <WMS_SupplierModel>(x => x.LinkManAddress, "联系人地址");
                    excelFile.AddMapping <WMS_SupplierModel>(x => x.MoreAccept, "超量接收(允许/不允许)(必输)");
                    excelFile.AddMapping <WMS_SupplierModel>(x => x.Remark, "说明");
                    //excelFile.AddMapping<WMS_SupplierModel>(x => x.CreatePerson, "创建人");
                    //excelFile.AddMapping<WMS_SupplierModel>(x => x.CreateTime, "创建时间");
                    //excelFile.AddMapping<WMS_SupplierModel>(x => x.ModifyPerson, "修改人");
                    //excelFile.AddMapping<WMS_SupplierModel>(x => x.ModifyTime, "修改时间");

                    //SheetName,第一个Sheet
                    var excelContent = excelFile.Worksheet <WMS_SupplierModel>(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_SupplierModel();
                            model.Id                = row.Id;
                            model.SupplierCode      = row.SupplierCode;
                            model.SupplierShortName = row.SupplierShortName;
                            model.SupplierName      = row.SupplierName;
                            model.SupplierType      = row.SupplierType;
                            model.LinkMan           = row.LinkMan;
                            model.LinkManTel        = row.LinkManTel;
                            model.LinkManAddress    = row.LinkManAddress;
                            model.MoreAccept        = row.MoreAccept;
                            //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;
                            }

                            //执行额外的数据校验
                            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, excelFile.GetColumnNames("Sheet1").Count()).Value = errorMessage;
                                continue;
                            }

                            //写入数据库
                            WMS_Supplier entity = new WMS_Supplier();
                            entity.Id                = model.Id;
                            entity.SupplierCode      = model.SupplierCode;
                            entity.SupplierShortName = model.SupplierShortName;
                            entity.SupplierName      = model.SupplierName;
                            entity.SupplierType      = model.SupplierType;
                            entity.LinkMan           = model.LinkMan;
                            entity.LinkManTel        = model.LinkManTel;
                            entity.LinkManAddress    = model.LinkManAddress;
                            entity.MoreAccept        = model.MoreAccept;
                            entity.MoreAccept        = "允许";
                            entity.Status            = "有效";
                            entity.Remark            = model.Remark;
                            entity.CreatePerson      = oper;
                            entity.CreateTime        = DateTime.Now;
                            entity.ModifyPerson      = oper;
                            entity.ModifyTime        = DateTime.Now;

                            db.WMS_Supplier.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, excelFile.GetColumnNames("Sheet1").Count()).Value = errorMessage;
                            }
                        }

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

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

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

            var excelFile = new ExcelQueryFactory(fileName);

            //对应列头
            excelFile.AddMapping <WMS_SupplierModel>(x => x.SupplierCode, "供应商编码");
            excelFile.AddMapping <WMS_SupplierModel>(x => x.SupplierShortName, "供应商简称");
            excelFile.AddMapping <WMS_SupplierModel>(x => x.SupplierName, "供应商名称");
            excelFile.AddMapping <WMS_SupplierModel>(x => x.SupplierType, "供应商类型");
            excelFile.AddMapping <WMS_SupplierModel>(x => x.LinkMan, "联系人");
            excelFile.AddMapping <WMS_SupplierModel>(x => x.LinkManTel, "联系人电话");
            excelFile.AddMapping <WMS_SupplierModel>(x => x.LinkManAddress, "联系人地址");
            excelFile.AddMapping <WMS_SupplierModel>(x => x.Status, "状态");
            excelFile.AddMapping <WMS_SupplierModel>(x => x.MoreAccept, "允许超量接收");
            excelFile.AddMapping <WMS_SupplierModel>(x => x.Remark, "说明");
            excelFile.AddMapping <WMS_SupplierModel>(x => x.CreatePerson, "创建人");
            excelFile.AddMapping <WMS_SupplierModel>(x => x.CreateTime, "创建时间");
            excelFile.AddMapping <WMS_SupplierModel>(x => x.ModifyPerson, "修改人");
            excelFile.AddMapping <WMS_SupplierModel>(x => x.ModifyTime, "修改时间");

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

            //检查数据正确性
            foreach (var row in excelContent)
            {
                var errorMessage = new StringBuilder();
                var entity       = new WMS_SupplierModel();
                entity.Id                = row.Id;
                entity.SupplierCode      = row.SupplierCode;
                entity.SupplierShortName = row.SupplierShortName;
                entity.SupplierName      = row.SupplierName;
                entity.SupplierType      = row.SupplierType;
                entity.LinkMan           = row.LinkMan;
                entity.LinkManTel        = row.LinkManTel;
                entity.LinkManAddress    = row.LinkManAddress;
                entity.Status            = row.Status;
                entity.MoreAccept        = row.MoreAccept;
                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);
        }