コード例 #1
0
        public void AdditionalCheckBelongSupplier(DBContainer db, ref WMS_PartModel model)
        {
            //验证物料编码
            if (!String.IsNullOrEmpty(model.PartCode))
            {
                var partCode = model.PartCode;
                Expression <Func <WMS_Part, bool> > exp = x => x.PartCode == partCode;

                //var part = m_PartRep.GetSingleWhere(exp);
                var part = db.WMS_Part.FirstOrDefault(exp);
                if (part == null)
                {
                    throw new Exception("物料编码不存在!");
                }
                else
                {
                    model.Id = part.Id;
                }
            }
            else
            {
                throw new Exception("物料编码不能为空!");
            }
            //安全库存不能为空
            if (String.IsNullOrEmpty(model.BelongSupplier))
            {
                throw new Exception("所属供应商不能为空!");
            }
        }
コード例 #2
0
        public JsonResult Edit(WMS_ReturnInspectionModel model)
        {
            //给关联字段物料赋值
            WMS_PartModel entity_part = m_PartBLL.GetById(model.PartID);

            model.PartType = entity_part.PartType;
            if (model.PartType == "外购件" && model.SupplierId == null)
            {
                return(Json(JsonHandler.CreateMessage(0, "外购件必须维护供应商")));
            }
            else
            {
                model.ModifyTime   = ResultHelper.NowTime;
                model.ModifyPerson = GetUserTrueName();
                if (model != null && ModelState.IsValid)
                {
                    if (m_BLL.Edit(ref errors, model))
                    {
                        LogHandler.WriteServiceLog(GetUserId(), "Id" + model.Id + ",ReturnInspectionNum" + model.ReturnInspectionNum, "成功", "修改", "WMS_ReturnInspection");
                        return(Json(JsonHandler.CreateMessage(1, Resource.EditSucceed)));
                    }
                    else
                    {
                        string ErrorCol = errors.Error;
                        LogHandler.WriteServiceLog(GetUserId(), "Id" + model.Id + ",ReturnInspectionNum" + model.ReturnInspectionNum + "," + ErrorCol, "失败", "修改", "WMS_ReturnInspection");
                        return(Json(JsonHandler.CreateMessage(0, Resource.EditFail + ErrorCol)));
                    }
                }
                else
                {
                    return(Json(JsonHandler.CreateMessage(0, Resource.EditFail)));
                }
            }
        }
コード例 #3
0
ファイル: PartController.cs プロジェクト: zqs99/XDWMS-Ymnets
        public ActionResult Edit(long id)
        {
            WMS_PartModel entity = m_BLL.GetById(id);

            ViewBag.EditStatus = true;
            return(View(entity));
        }
コード例 #4
0
        public JsonResult Edit(WMS_PartModel model)
        {
            if (model.CustomerCode != null && model.CustomerCode.Last().ToString() != "/")
            {
                model.CustomerCode = model.CustomerCode + "/";
            }
            if (model.CustomerCode != null && model.CustomerCode.First().ToString() != "/")
            {
                model.CustomerCode = "/" + model.CustomerCode;
            }
            model.ModifyTime   = ResultHelper.NowTime;
            model.ModifyPerson = GetUserTrueName();

            if (model != null && ModelState.IsValid && model.StoreMan != null)
            {
                if (m_BLL.Edit(ref errors, model))
                {
                    LogHandler.WriteServiceLog(GetUserTrueName(), "Id" + model.Id + ",PartCode" + model.PartCode, "成功", "修改", "WMS_Part");
                    return(Json(JsonHandler.CreateMessage(1, Resource.EditSucceed)));
                }
                else
                {
                    string ErrorCol = errors.Error;
                    LogHandler.WriteServiceLog(GetUserTrueName(), "Id" + model.Id + ",PartCode" + model.PartCode + "," + ErrorCol, "失败", "修改", "WMS_Part");
                    return(Json(JsonHandler.CreateMessage(0, Resource.EditFail + ErrorCol)));
                }
            }
            else
            {
                return(Json(JsonHandler.CreateMessage(0, Resource.EditFail)));
            }
        }
コード例 #5
0
        public virtual WMS_PartModel GetById(object id)
        {
            if (IsExists(id))
            {
                WMS_Part      entity = m_Rep.GetById(id);
                WMS_PartModel model  = new WMS_PartModel();
                model.Id             = entity.Id;
                model.PartCode       = entity.PartCode;
                model.PartName       = entity.PartName;
                model.PartType       = entity.PartType;
                model.CustomerCode   = entity.CustomerCode;
                model.LogisticsCode  = entity.LogisticsCode;
                model.OtherCode      = entity.OtherCode;
                model.PCS            = entity.PCS;
                model.StoreMan       = entity.StoreMan;
                model.Status         = entity.Status;
                model.CreatePerson   = entity.CreatePerson;
                model.CreateTime     = entity.CreateTime;
                model.ModifyPerson   = entity.ModifyPerson;
                model.ModifyTime     = entity.ModifyTime;
                model.Unit           = entity.Unit;
                model.Volume         = entity.Volume;
                model.Remark         = entity.Remark;
                model.SafeStock      = entity.SafeStock;
                model.BelongSupplier = entity.BelongSupplier;
                model.BelongCustomer = entity.BelongCustomer;

                return(model);
            }
            else
            {
                return(null);
            }
        }
コード例 #6
0
 public JsonResult Create(WMS_PartModel 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 + ",PartCode" + model.PartCode, "成功", "创建", "WMS_Part");
             return(Json(JsonHandler.CreateMessage(1, Resource.InsertSucceed)));
         }
         else
         {
             //string ErrorCol = errors.Error;
             string ErrorCol = " :输入错误数据";
             LogHandler.WriteServiceLog(GetUserTrueName(), "Id" + model.Id + ",PartCode" + model.PartCode + "," + ErrorCol, "失败", "创建", "WMS_Part");
             return(Json(JsonHandler.CreateMessage(0, Resource.InsertFail + ErrorCol)));
         }
     }
     else
     {
         return(Json(JsonHandler.CreateMessage(0, Resource.InsertFail)));
     }
 }
コード例 #7
0
        public void AdditionalCheckExcelData(DBContainer db, ref WMS_PartModel model)
        {
            //获取物料ID
            if (!String.IsNullOrEmpty(model.PartCode))
            {
                var partCode = model.PartCode;
                Expression <Func <WMS_Part, bool> > exp = x => x.PartCode == partCode;

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

                var part = m_SysParamRep.GetSingleWhere(exp);
                if (part == null)
                {
                    throw new Exception("物料类型不存在!");
                }
            }
        }
コード例 #8
0
        public JsonResult Create(WMS_PartModel model)
        {
            if (model.CustomerCode != null && model.CustomerCode.Last().ToString() != ";")
            {
                model.CustomerCode = model.CustomerCode + ";";
            }
            if (model.CustomerCode != null && model.CustomerCode.First().ToString() != ";")
            {
                model.CustomerCode = ";" + model.CustomerCode;
            }
            if (model.BelongCustomer != null && model.BelongCustomer.Last().ToString() != ";")
            {
                model.BelongCustomer = model.BelongCustomer + ";";
            }
            if (model.BelongCustomer != null && model.BelongCustomer.First().ToString() != ";")
            {
                model.BelongCustomer = ";" + model.BelongCustomer;
            }
            if (model.BelongSupplier != null && model.BelongSupplier.Last().ToString() != ";")
            {
                model.BelongSupplier = model.BelongSupplier + ";";
            }
            if (model.BelongSupplier != null && model.BelongSupplier.First().ToString() != ";")
            {
                model.BelongSupplier = ";" + model.BelongSupplier;
            }
            model.CustomerCode   = model.CustomerCode.Replace(" ", "").Replace(";", ";");
            model.BelongCustomer = model.BelongCustomer.Replace(" ", "").Replace(";", ";");
            model.BelongSupplier = model.BelongSupplier.Replace(" ", "").Replace(";", ";");

            model.Id           = 0;
            model.CreateTime   = ResultHelper.NowTime;
            model.CreatePerson = GetUserTrueName();
            if (model != null && ModelState.IsValid && model.StoreMan != null)
            {
                if (m_BLL.Create(ref errors, model))
                {
                    LogHandler.WriteServiceLog(GetUserTrueName(), "Id" + model.Id + ",PartCode" + model.PartCode, "成功", "创建", "WMS_Part");
                    return(Json(JsonHandler.CreateMessage(1, Resource.InsertSucceed)));
                }
                else
                {
                    //string ErrorCol = errors.Error;
                    string ErrorCol = " :输入错误数据";
                    LogHandler.WriteServiceLog(GetUserTrueName(), "Id" + model.Id + ",PartCode" + model.PartCode + "," + ErrorCol, "失败", "创建", "WMS_Part");
                    return(Json(JsonHandler.CreateMessage(0, Resource.InsertFail + ErrorCol)));
                }
            }
            else
            {
                return(Json(JsonHandler.CreateMessage(0, Resource.InsertFail)));
            }
        }
コード例 #9
0
        public ActionResult Edit(long id)
        {
            ViewBag.Inv = new SelectList(_InvInfoBll.GetList(ref setNoPagerAscById, ""), "Id", "InvName");
            WMS_Feed_ListModel entity = m_BLL.GetById(id);
            //WMS_PartModel entity_p = m_PartBLL.GetById(entity.AssemblyPartId);
            //entity.AssemblyPartCode = entity_p.PartCode;
            WMS_PartModel entity_p1 = m_PartBLL.GetById(entity.SubAssemblyPartId);

            entity.SubAssemblyPartCode = entity_p1.PartCode;

            return(View(entity));
        }
コード例 #10
0
        public ActionResult Edit(long id)
        {
            WMS_AIModel entity = m_BLL.GetById(id);
            //给关联字段订单号赋值
            WMS_POModel entity_po = m_POBLL.GetById(entity.POId);

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

            entity.PartCode = entity_p.PartCode;
            return(View(entity));
        }
コード例 #11
0
        public void AdditionalCheckVolume(DBContainer db, ref WMS_PartModel model, ref List <WMS_Part> ts)
        {
            ////验证物料编码
            //if (!String.IsNullOrEmpty(model.PartCode))
            //{
            //    var partCode = model.PartCode;
            //    Expression<Func<WMS_Part, bool>> exp = x => x.PartCode == partCode;

            //    //var part = m_PartRep.GetSingleWhere(exp);
            //    var part = db.WMS_Part.FirstOrDefault(exp);
            //    if (part == null)
            //    {
            //        throw new Exception("物料编码不存在!");
            //    }
            //    else { model.Id = part.Id; }

            //}
            //else
            //{
            //    throw new Exception("物料编码不能为空!");
            //}

            //验证主机厂编码
            if (!String.IsNullOrEmpty(model.CustomerCode))
            {
                var             customerCode = model.CustomerCode;
                List <WMS_Part> list         = db.WMS_Part.Where(p => p.CustomerCode.Contains(customerCode)).ToList();

                //var part = m_PartRep.GetSingleWhere(exp);
                //var part = db.WMS_Part.FirstOrDefault(exp);
                if (list.Count() == 0)
                {
                    throw new Exception("主机厂编码不存在!");
                }
                else
                {
                    ts = list;
                }
            }
            else
            {
                throw new Exception("主机厂编码不能为空!");
            }

            //安全库存不能为空
            if (model.Volume == 0)
            {
                throw new Exception("每箱体积不能为空!");
            }
        }
コード例 #12
0
        public virtual bool Edit(ref ValidationErrors errors, WMS_PartModel model)
        {
            try
            {
                WMS_Part entity = m_Rep.GetById(model.Id);
                if (entity == null)
                {
                    errors.Add(Resource.Disable);
                    return(false);
                }
                entity.Id             = model.Id;
                entity.PartCode       = model.PartCode;
                entity.PartName       = model.PartName;
                entity.PartType       = model.PartType;
                entity.CustomerCode   = model.CustomerCode;
                entity.LogisticsCode  = model.LogisticsCode;
                entity.OtherCode      = model.OtherCode;
                entity.PCS            = model.PCS;
                entity.StoreMan       = model.StoreMan;
                entity.Status         = model.Status;
                entity.CreatePerson   = model.CreatePerson;
                entity.CreateTime     = model.CreateTime;
                entity.ModifyPerson   = model.ModifyPerson;
                entity.ModifyTime     = model.ModifyTime;
                entity.Unit           = model.Unit;
                entity.Volume         = model.Volume;
                entity.Remark         = model.Remark;
                entity.SafeStock      = model.SafeStock;
                entity.BelongCustomer = model.BelongCustomer;
                entity.BelongSupplier = model.BelongSupplier;



                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);
            }
        }
コード例 #13
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));
        }
コード例 #14
0
ファイル: POController.cs プロジェクト: zqs99/XDWMS-Ymnets
        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));
        }
コード例 #15
0
        public virtual bool Create(ref ValidationErrors errors, WMS_PartModel model)
        {
            try
            {
                WMS_Part entity = m_Rep.GetById(model.Id);
                if (entity != null)
                {
                    errors.Add(Resource.PrimaryRepeat);
                    return(false);
                }
                entity               = new WMS_Part();
                entity.Id            = model.Id;
                entity.PartCode      = model.PartCode;
                entity.PartName      = model.PartName;
                entity.PartType      = model.PartType;
                entity.CustomerCode  = model.CustomerCode;
                entity.LogisticsCode = model.LogisticsCode;
                entity.OtherCode     = model.OtherCode;
                entity.PCS           = model.PCS;
                entity.StoreMan      = model.StoreMan;
                entity.Status        = model.Status;
                entity.CreatePerson  = model.CreatePerson;
                entity.CreateTime    = model.CreateTime;
                entity.ModifyPerson  = model.ModifyPerson;
                entity.ModifyTime    = model.ModifyTime;
                entity.Unit          = model.Unit;
                entity.Volume        = model.Volume;
                entity.Remark        = model.Remark;


                if (m_Rep.Create(entity))
                {
                    return(true);
                }
                else
                {
                    errors.Add(Resource.InsertFail);
                    return(false);
                }
            }
            catch (Exception ex)
            {
                errors.Add(ex.Message);
                ExceptionHander.WriteException(ex);
                return(false);
            }
        }
コード例 #16
0
        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));
        }
コード例 #17
0
ファイル: PartController.cs プロジェクト: zqs99/XDWMS-Ymnets
        public ActionResult Details(long id)
        {
            WMS_PartModel entity = m_BLL.GetById(id);

            return(View(entity));
        }
コード例 #18
0
        /// <summary>
        /// 校验Excel数据,这个方法一般用于重写校验逻辑
        /// </summary>
        public virtual bool CheckImportData(string fileName, List <WMS_PartModel> list, ref ValidationErrors errors)
        {
            var targetFile = new FileInfo(fileName);

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

            var excelFile = new ExcelQueryFactory(fileName);

            //对应列头
            excelFile.AddMapping <WMS_PartModel>(x => x.PartCode, "物料编码");
            excelFile.AddMapping <WMS_PartModel>(x => x.PartName, "物料名称");
            excelFile.AddMapping <WMS_PartModel>(x => x.PartType, "物料类型");
            excelFile.AddMapping <WMS_PartModel>(x => x.CustomerCode, "客户编码");
            excelFile.AddMapping <WMS_PartModel>(x => x.LogisticsCode, "物流号");
            excelFile.AddMapping <WMS_PartModel>(x => x.OtherCode, "额外信息编码");
            excelFile.AddMapping <WMS_PartModel>(x => x.PCS, "每箱数量");
            excelFile.AddMapping <WMS_PartModel>(x => x.StoreMan, "保管员");
            excelFile.AddMapping <WMS_PartModel>(x => x.Status, "物料状态");
            excelFile.AddMapping <WMS_PartModel>(x => x.CreatePerson, "创建人");
            excelFile.AddMapping <WMS_PartModel>(x => x.CreateTime, "创建时间");
            excelFile.AddMapping <WMS_PartModel>(x => x.ModifyPerson, "修改人");
            excelFile.AddMapping <WMS_PartModel>(x => x.ModifyTime, "修改时间");
            excelFile.AddMapping <WMS_PartModel>(x => x.Unit, "单位");
            excelFile.AddMapping <WMS_PartModel>(x => x.Volume, "体积");
            excelFile.AddMapping <WMS_PartModel>(x => x.Remark, "说明");

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

            //检查数据正确性
            foreach (var row in excelContent)
            {
                var errorMessage = new StringBuilder();
                var entity       = new WMS_PartModel();
                entity.Id            = row.Id;
                entity.PartCode      = row.PartCode;
                entity.PartName      = row.PartName;
                entity.PartType      = row.PartType;
                entity.CustomerCode  = row.CustomerCode;
                entity.LogisticsCode = row.LogisticsCode;
                entity.OtherCode     = row.OtherCode;
                entity.PCS           = row.PCS;
                entity.StoreMan      = row.StoreMan;
                entity.Status        = row.Status;
                entity.CreatePerson  = row.CreatePerson;
                entity.CreateTime    = row.CreateTime;
                entity.ModifyPerson  = row.ModifyPerson;
                entity.ModifyTime    = row.ModifyTime;
                entity.Unit          = row.Unit;
                entity.Volume        = row.Volume;
                entity.Remark        = row.Remark;

                //=============================================================================
                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);
        }
コード例 #19
0
        public bool ImportStoreMan(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_PartModel>(x => x.PartCode, "物料编码(必输)");
                    excelFile.AddMapping <WMS_PartModel>(x => x.StoreMan, "保管员(必输)");


                    //SheetName,第一个Sheet
                    var excelContent = excelFile.Worksheet <WMS_PartModel>(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_PartModel();
                            model.Id = row.Id;
                            if (row.PartCode != null)
                            {
                                model.PartCode = row.PartCode.Replace(" ", "");
                            }
                            if (row.StoreMan != null)
                            {
                                model.StoreMan = row.StoreMan.Replace(" ", "");
                            }


                            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
                            {
                                AdditionalCheckStoreMan(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_Part entity = m_Rep.GetById(model.Id);
                            entity.Id = model.Id;
                            //entity.PartCode = model.PartCode;
                            entity.StoreMan     = model.StoreMan;
                            entity.ModifyPerson = oper;
                            entity.ModifyTime   = DateTime.Now;
                            m_Rep.Edit(entity);

                            //db.WMS_Part.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);
        }
コード例 #20
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_PartModel>(x => x.PartCode, "物料编码(必输)");
                    excelFile.AddMapping <WMS_PartModel>(x => x.PartName, "物料名称(必输)");
                    excelFile.AddMapping <WMS_PartModel>(x => x.PartType, "物料类型(必输)");
                    excelFile.AddMapping <WMS_PartModel>(x => x.CustomerCode, "主机厂编码");
                    excelFile.AddMapping <WMS_PartModel>(x => x.LogisticsCode, "物流号");
                    excelFile.AddMapping <WMS_PartModel>(x => x.OtherCode, "额外信息编码");
                    excelFile.AddMapping <WMS_PartModel>(x => x.PCS, "每箱数量");
                    excelFile.AddMapping <WMS_PartModel>(x => x.StoreMan, "保管员(必输)");
                    excelFile.AddMapping <WMS_PartModel>(x => x.Unit, "单位");
                    excelFile.AddMapping <WMS_PartModel>(x => x.Volume, "每箱体积");
                    excelFile.AddMapping <WMS_PartModel>(x => x.BelongSupplier, "所属供应商");
                    excelFile.AddMapping <WMS_PartModel>(x => x.BelongCustomer, "所属客户");
                    excelFile.AddMapping <WMS_PartModel>(x => x.Remark, "说明");


                    //SheetName,第一个Sheet
                    var excelContent = excelFile.Worksheet <WMS_PartModel>(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_PartModel();
                            model.Id = row.Id;
                            if (row.PartCode != null)
                            {
                                model.PartCode = row.PartCode.Replace(" ", "");
                            }

                            if (row.PartName != null)
                            {
                                model.PartName = row.PartName.Replace(" ", "");
                            }

                            if (row.PartType != null)
                            {
                                model.PartType = row.PartType.Replace(" ", "");
                            }

                            if (row.CustomerCode != null)
                            {
                                model.CustomerCode = row.CustomerCode.Replace(" ", "").Replace(";", ";");
                            }

                            //model.PartName = row.PartName.Replace(" ", "");
                            //model.PartType = row.PartType.Replace(" ", "");
                            //model.CustomerCode = row.CustomerCode.Replace(" ", "").Replace(";",";");
                            model.LogisticsCode = row.LogisticsCode;
                            model.OtherCode     = row.OtherCode;
                            model.PCS           = row.PCS;
                            model.StoreMan      = row.StoreMan.Replace(" ", "");
                            model.Unit          = row.Unit;
                            model.Volume        = row.Volume;
                            model.Remark        = row.Remark;
                            if (row.BelongCustomer != null)
                            {
                                model.BelongCustomer = row.BelongCustomer.Replace(" ", "").Replace(";", ";");
                            }

                            if (row.BelongSupplier != null)
                            {
                                model.BelongSupplier = row.BelongSupplier.Replace(" ", "").Replace(";", ";");
                            }

                            //model.BelongCustomer = row.BelongCustomer.Replace(" ", "").Replace(";", ";");
                            //model.BelongSupplier = row.BelongSupplier.Replace(" ", "").Replace(";", ";");

                            //model.CreatePerson = row.oper;
                            //model.CreateTime = row.CreateTime;
                            //model.ModifyPerson = row.oper;
                            //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_Part entity = new WMS_Part();
                            entity.Id            = model.Id;
                            entity.PartCode      = model.PartCode;
                            entity.PartName      = model.PartName;
                            entity.PartType      = model.PartType;
                            entity.CustomerCode  = ";" + model.CustomerCode + ";";
                            entity.LogisticsCode = model.LogisticsCode;
                            entity.OtherCode     = model.OtherCode;
                            entity.PCS           = model.PCS;
                            entity.StoreMan      = model.StoreMan;
                            entity.Status        = "有效";
                            entity.CreatePerson  = oper;
                            entity.CreateTime    = DateTime.Now;
                            entity.ModifyPerson  = oper;
                            entity.ModifyTime    = DateTime.Now;
                            entity.Unit          = model.Unit;
                            entity.Volume        = model.Volume;
                            entity.Remark        = model.Remark;
                            if (model.BelongCustomer != null)
                            {
                                entity.BelongCustomer = ";" + model.BelongCustomer + ";";
                            }
                            if (model.BelongSupplier != null)
                            {
                                entity.BelongSupplier = ";" + model.BelongSupplier + ";";
                            }

                            db.WMS_Part.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);
        }