Beispiel #1
0
        public virtual WMS_POModel GetById(object id)
        {
            if (IsExists(id))
            {
                WMS_PO      entity = m_Rep.GetById(id);
                WMS_POModel model  = new WMS_POModel();
                model.Id           = entity.Id;
                model.PO           = entity.PO;
                model.PODate       = entity.PODate;
                model.SupplierId   = entity.SupplierId;
                model.PartId       = entity.PartId;
                model.QTY          = entity.QTY;
                model.PlanDate     = entity.PlanDate;
                model.POType       = entity.POType;
                model.Status       = entity.Status;
                model.Remark       = entity.Remark;
                model.Attr1        = entity.Attr1;
                model.Attr2        = entity.Attr2;
                model.Attr3        = entity.Attr3;
                model.Attr4        = entity.Attr4;
                model.Attr5        = entity.Attr5;
                model.CreatePerson = entity.CreatePerson;
                model.CreateTime   = entity.CreateTime;
                model.ModifyPerson = entity.ModifyPerson;
                model.ModifyTime   = entity.ModifyTime;

                return(model);
            }
            else
            {
                return(null);
            }
        }
Beispiel #2
0
        public ActionResult Create()
        {
            ViewBag.Supplier = new SelectList(m_SupplierBLL.GetList(ref setNoPagerAscById, ""), "Id", "SupplierShortName");

            WMS_POModel model = new WMS_POModel()
            {
                PO = "PO" + DateTime.Now.ToString("yyyyMMddHHmmssff"),
            };

            return(View(model));
            //return View();
        }
        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));
        }
Beispiel #4
0
        public virtual bool Edit(ref ValidationErrors errors, WMS_POModel model)
        {
            try
            {
                WMS_PO entity = m_Rep.GetById(model.Id);
                if (entity == null)
                {
                    errors.Add(Resource.Disable);
                    return(false);
                }
                entity.Id           = model.Id;
                entity.PO           = model.PO;
                entity.PODate       = model.PODate;
                entity.SupplierId   = model.SupplierId;
                entity.PartId       = model.PartId;
                entity.QTY          = model.QTY;
                entity.PlanDate     = model.PlanDate;
                entity.POType       = model.POType;
                entity.Status       = model.Status;
                entity.Remark       = model.Remark;
                entity.Attr1        = model.Attr1;
                entity.Attr2        = model.Attr2;
                entity.Attr3        = model.Attr3;
                entity.Attr4        = model.Attr4;
                entity.Attr5        = model.Attr5;
                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);
            }
        }
Beispiel #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));
        }
Beispiel #6
0
 public JsonResult Edit(WMS_POModel model)
 {
     model.ModifyTime   = ResultHelper.NowTime;
     model.ModifyPerson = GetUserTrueName();
     if (model != null && ModelState.IsValid)
     {
         if (m_BLL.Edit(ref errors, model))
         {
             LogHandler.WriteServiceLog(GetUserTrueName(), "Id" + model.Id + ",PO" + model.PO, "成功", "修改", "WMS_PO");
             return(Json(JsonHandler.CreateMessage(1, Resource.EditSucceed)));
         }
         else
         {
             string ErrorCol = errors.Error;
             LogHandler.WriteServiceLog(GetUserTrueName(), "Id" + model.Id + ",PO" + model.PO + "," + ErrorCol, "失败", "修改", "WMS_PO");
             return(Json(JsonHandler.CreateMessage(0, Resource.EditFail + ErrorCol)));
         }
     }
     else
     {
         return(Json(JsonHandler.CreateMessage(0, Resource.EditFail)));
     }
 }
        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_POModel>(x => x.PO, "采购订单(必输)");
                    excelFile.AddMapping <WMS_POModel>(x => x.PODate, "采购日期(必输格式:YYYY-MM-DD)");
                    excelFile.AddMapping <WMS_POModel>(x => x.SupplierShortName, "供应商简称(必输)");
                    excelFile.AddMapping <WMS_POModel>(x => x.PartCode, "物料编码(必输)");
                    excelFile.AddMapping <WMS_POModel>(x => x.QTY, "数量(必输)");
                    excelFile.AddMapping <WMS_POModel>(x => x.PlanDate, "计划到货日期");
                    excelFile.AddMapping <WMS_POModel>(x => x.POType, "采购订单类型");
                    //excelFile.AddMapping<WMS_POModel>(x => x.Status, "状态");
                    excelFile.AddMapping <WMS_POModel>(x => x.Remark, "说明");
                    //excelFile.AddMapping<WMS_POModel>(x => x.Attr1, "");
                    //excelFile.AddMapping<WMS_POModel>(x => x.Attr2, "");
                    //excelFile.AddMapping<WMS_POModel>(x => x.Attr3, "");
                    //excelFile.AddMapping<WMS_POModel>(x => x.Attr4, "");
                    //excelFile.AddMapping<WMS_POModel>(x => x.Attr5, "");
                    //excelFile.AddMapping<WMS_POModel>(x => x.CreatePerson, "创建人");
                    //excelFile.AddMapping<WMS_POModel>(x => x.CreateTime, "创建时间");
                    //excelFile.AddMapping<WMS_POModel>(x => x.ModifyPerson, "修改人");
                    //excelFile.AddMapping<WMS_POModel>(x => x.ModifyTime, "修改时间");

                    //SheetName,第一个Sheet
                    var excelContent = excelFile.Worksheet <WMS_POModel>(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_POModel();
                            model.Id                = row.Id;
                            model.PO                = row.PO;
                            model.PODate            = row.PODate;
                            model.SupplierShortName = row.SupplierShortName;
                            model.PartCode          = row.PartCode;
                            model.QTY               = row.QTY;
                            model.PlanDate          = row.PlanDate;
                            model.POType            = row.POType;
                            model.Status            = "有效";
                            model.Remark            = row.Remark;
                            //model.Attr1 = row.Attr1;
                            //model.Attr2 = row.Attr2;
                            //model.Attr3 = row.Attr3;
                            //model.Attr4 = row.Attr4;
                            //model.Attr5 = row.Attr5;
                            //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_PO entity = new WMS_PO();
                            entity.Id           = model.Id;
                            entity.PO           = model.PO;
                            entity.PODate       = model.PODate;
                            entity.SupplierId   = model.SupplierId;
                            entity.PartId       = model.PartId;
                            entity.QTY          = model.QTY;
                            entity.PlanDate     = model.PlanDate;
                            entity.POType       = model.POType;
                            entity.Status       = "有效";
                            entity.Remark       = model.Remark;
                            entity.Attr1        = model.Attr1;
                            entity.Attr2        = model.Attr2;
                            entity.Attr3        = model.Attr3;
                            entity.Attr4        = model.Attr4;
                            entity.Attr5        = model.Attr5;
                            entity.CreatePerson = oper;
                            entity.CreateTime   = DateTime.Now;
                            entity.ModifyPerson = oper;
                            entity.ModifyTime   = DateTime.Now;

                            db.WMS_PO.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);
        }
        private void AdditionalCheckExcelData(DBContainer db, ref WMS_POModel 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
                {
                    model.PartId = part.Id;
                }
            }
            else
            {
                throw new Exception("物料编码不能为空!");
            }

            //获取代理商ID
            if (!String.IsNullOrEmpty(model.SupplierShortName))
            {
                var supplierShortName = model.SupplierShortName;
                Expression <Func <WMS_Supplier, bool> > exp = x => x.SupplierShortName == supplierShortName;

                //var supplier = m_SupplierRep.GetSingleWhere(exp);
                var supplier = db.WMS_Supplier.FirstOrDefault(exp);
                if (supplier == null)
                {
                    throw new Exception("供应商简称不存在!");
                }
                else
                {
                    model.SupplierId = supplier.Id;
                }
            }
            else
            {
                throw new Exception("供应商简称不能为空!");
            }

            //校验订单号与物料
            if (!String.IsNullOrEmpty(model.PO))
            {
                var partId = model.PartId;
                var po     = model.PO;
                Expression <Func <WMS_PO, bool> > exp = x => x.PartId == partId && x.PO == po;

                //var part = m_PORep.GetSingleWhere(exp);
                var part = db.WMS_PO.FirstOrDefault(exp);
                if (part != null)
                {
                    throw new Exception("订单号与物料编码重复!");
                }
            }
            else
            {
                throw new Exception("订单号不能为空!");
            }
            //校验订单号与供应商
            if (!String.IsNullOrEmpty(model.PO))
            {
                var supplierId = model.SupplierId;
                var po         = model.PO;
                Expression <Func <WMS_PO, bool> > exp = x => x.PO == po && x.SupplierId != supplierId;

                //var result = m_PORep.GetSingleWhere(exp);
                var result = db.WMS_PO.FirstOrDefault(exp);
                if (result != null)
                {
                    throw new Exception("同订单存在不同供应商!");
                }
            }
            //采购日期不能为空
            if (String.IsNullOrEmpty(model.PODate.ToString()))
            {
                throw new Exception("采购日期不能为空!");
            }
            //采购数量不能为空
            if (model.QTY == 0)
            {
                throw new Exception("采购数量不能为空!");
            }
            //采购订单类型判断
            if (!String.IsNullOrEmpty(model.POType))
            {
                var potype = model.POType;
                Expression <Func <SysParam, bool> > exp = x => x.ParamName == potype && x.TypeCode == "POType";

                var part = m_SysParamRep.GetSingleWhere(exp);
                if (part == null)
                {
                    throw new Exception("采购订单类型不存在!");
                }
            }
            //else { throw new Exception("采购订单类型不能为空!"); }
        }
Beispiel #9
0
        public ActionResult Details(long id)
        {
            WMS_POModel entity = m_BLL.GetById(id);

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

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

            var excelFile = new ExcelQueryFactory(fileName);

            //对应列头
            excelFile.AddMapping <WMS_POModel>(x => x.PO, "采购订单");
            excelFile.AddMapping <WMS_POModel>(x => x.PODate, "采购日期");
            excelFile.AddMapping <WMS_POModel>(x => x.SupplierId, "供应商ID");
            excelFile.AddMapping <WMS_POModel>(x => x.PartId, "物料ID");
            excelFile.AddMapping <WMS_POModel>(x => x.QTY, "数量");
            excelFile.AddMapping <WMS_POModel>(x => x.PlanDate, "计划到货日期");
            excelFile.AddMapping <WMS_POModel>(x => x.POType, "采购订单类型");
            excelFile.AddMapping <WMS_POModel>(x => x.Status, "状态");
            excelFile.AddMapping <WMS_POModel>(x => x.Remark, "说明");
            excelFile.AddMapping <WMS_POModel>(x => x.Attr1, "Attr1");
            excelFile.AddMapping <WMS_POModel>(x => x.Attr2, "Attr2");
            excelFile.AddMapping <WMS_POModel>(x => x.Attr3, "Attr3");
            excelFile.AddMapping <WMS_POModel>(x => x.Attr4, "Attr4");
            excelFile.AddMapping <WMS_POModel>(x => x.Attr5, "Attr5");
            excelFile.AddMapping <WMS_POModel>(x => x.CreatePerson, "创建人");
            excelFile.AddMapping <WMS_POModel>(x => x.CreateTime, "创建时间");
            excelFile.AddMapping <WMS_POModel>(x => x.ModifyPerson, "修改人");
            excelFile.AddMapping <WMS_POModel>(x => x.ModifyTime, "修改时间");

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

            //检查数据正确性
            foreach (var row in excelContent)
            {
                var errorMessage = new StringBuilder();
                var entity       = new WMS_POModel();
                entity.Id           = row.Id;
                entity.PO           = row.PO;
                entity.PODate       = row.PODate;
                entity.SupplierId   = row.SupplierId;
                entity.PartId       = row.PartId;
                entity.QTY          = row.QTY;
                entity.PlanDate     = row.PlanDate;
                entity.POType       = row.POType;
                entity.Status       = row.Status;
                entity.Remark       = row.Remark;
                entity.Attr1        = row.Attr1;
                entity.Attr2        = row.Attr2;
                entity.Attr3        = row.Attr3;
                entity.Attr4        = row.Attr4;
                entity.Attr5        = row.Attr5;
                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);
        }