Exemplo n.º 1
0
        public JsonResult Edit(WMS_Sale_OrderModel model)
        {
            List <WMS_Sale_OrderModel> list = m_BLL.GetListByWhere(ref setNoPagerAscById, "Id = " + model.Id + " &&ConfirmStatus = \"已确认\"");

            if (list.Count() > 0)
            {
                return(Json(JsonHandler.CreateMessage(0, "已确认单据不能修改")));
            }
            else
            {
                if (model != null && ModelState.IsValid)
                {
                    if (m_BLL.Edit(ref errors, model))
                    {
                        LogHandler.WriteServiceLog(GetUserTrueName(), "Id" + model.Id + ",SaleBillNum" + model.SaleBillNum, "成功", "修改", "WMS_Sale_Order");
                        return(Json(JsonHandler.CreateMessage(1, Resource.EditSucceed)));
                    }
                    else
                    {
                        string ErrorCol = errors.Error;
                        LogHandler.WriteServiceLog(GetUserTrueName(), "Id" + model.Id + ",SaleBillNum" + model.SaleBillNum + "," + ErrorCol, "失败", "修改", "WMS_Sale_Order");
                        return(Json(JsonHandler.CreateMessage(0, Resource.EditFail + ErrorCol)));
                    }
                }
                else
                {
                    return(Json(JsonHandler.CreateMessage(0, Resource.EditFail)));
                }
            }
        }
Exemplo n.º 2
0
 public JsonResult Create(WMS_Sale_OrderModel model)
 {
     model.Id            = 0;
     model.CreatePerson  = GetUserTrueName();
     model.CreateTime    = ResultHelper.NowTime;
     model.PrintStaus    = "未打印";
     model.ConfirmStatus = "未确认";
     if (model.Lot == "[空]")
     {
         model.Lot = "";
     }
     if (model.Lot == "" || model.Lot == null || !DateTimeHelper.CheckYearMonth(model.Lot))
     {
         return(Json(JsonHandler.CreateMessage(0, "批次录入不符合规范")));
     }
     if (model != null && ModelState.IsValid && model.Lot != null)
     {
         if (m_BLL.Create(ref errors, model))
         {
             LogHandler.WriteServiceLog(GetUserTrueName(), "Id" + model.Id + ",SaleBillNum" + model.SaleBillNum, "成功", "创建", "WMS_Sale_Order");
             return(Json(JsonHandler.CreateMessage(1, Resource.InsertSucceed)));
         }
         else
         {
             string ErrorCol = errors.Error;
             LogHandler.WriteServiceLog(GetUserTrueName(), "Id" + model.Id + ",SaleBillNum" + model.SaleBillNum + "," + ErrorCol, "失败", "创建", "WMS_Sale_Order");
             return(Json(JsonHandler.CreateMessage(0, Resource.InsertFail + ErrorCol)));
         }
     }
     else
     {
         return(Json(JsonHandler.CreateMessage(0, Resource.InsertFail)));
     }
 }
Exemplo n.º 3
0
        public virtual bool Edit(ref ValidationErrors errors, WMS_Sale_OrderModel model)
        {
            try
            {
                WMS_Sale_Order entity = m_Rep.GetById(model.Id);
                if (entity == null)
                {
                    errors.Add(Resource.Disable);
                    return(false);
                }
                entity.Id               = model.Id;
                entity.SaleBillNum      = model.SaleBillNum;
                entity.SellBillNum      = model.SellBillNum;
                entity.PlanDeliveryDate = model.PlanDeliveryDate;
                entity.CustomerId       = model.CustomerId;
                entity.PartId           = model.PartId;
                entity.Qty              = model.Qty;
                entity.BoxQty           = model.BoxQty;
                entity.InvId            = model.InvId;
                entity.SubInvId         = model.SubInvId;
                entity.Lot              = model.Lot;
                entity.Remark           = model.Remark;
                entity.PrintStaus       = model.PrintStaus;
                entity.PrintDate        = model.PrintDate;
                entity.PrintMan         = model.PrintMan;
                entity.ConfirmStatus    = model.ConfirmStatus;
                entity.ConfirmMan       = model.ConfirmMan;
                entity.ConfirmDate      = model.ConfirmDate;
                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;
                entity.ConfirmMessage   = model.ConfirmMessage;
                entity.Volume           = model.Volume;



                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);
            }
        }
Exemplo n.º 4
0
        public ActionResult Create()
        {
            ViewBag.Inv = new SelectList(_InvInfoBll.GetList(ref setNoPagerAscById, ""), "Id", "InvName");
            WMS_Sale_OrderModel model = new WMS_Sale_OrderModel()
            {
                SaleBillNum = "XS" + DateTime.Now.ToString("yyyyMMddHHmmssff"),
                SellBillNum = "XS" + DateTime.Now.ToString("yyyyMMddHHmmssff"),
            };

            return(View(model));
        }
Exemplo n.º 5
0
        public ActionResult Delete(long id)
        {
            List <WMS_Sale_OrderModel> list = m_BLL.GetListByWhere(ref setNoPagerAscById, "Id = " + id + " &&ConfirmStatus = \"已确认\"");

            if (list.Count() > 0)
            {
                return(Json(JsonHandler.CreateMessage(0, "已确认单据不能删除")));
            }
            else
            {
                if (id != 0)
                {
                    WMS_Sale_OrderModel model = m_BLL.GetById(id);
                    model.ModifyTime   = ResultHelper.NowTime;
                    model.ModifyPerson = GetUserTrueName();
                    model.PrintStaus   = "已失效";
                    if (model != null && ModelState.IsValid)
                    {
                        if (m_BLL.Edit(ref errors, model))
                        {
                            LogHandler.WriteServiceLog(GetUserTrueName(), "Id" + model.Id + ",SaleBillNum" + model.SaleBillNum, "成功", "修改", "WMS_Sale_Order");
                            return(Json(JsonHandler.CreateMessage(1, Resource.EditSucceed)));
                        }
                        else
                        {
                            string ErrorCol = errors.Error;
                            LogHandler.WriteServiceLog(GetUserTrueName(), "Id" + model.Id + ",SaleBillNum" + model.SaleBillNum + "," + ErrorCol, "失败", "修改", "WMS_Sale_Order");
                            return(Json(JsonHandler.CreateMessage(0, Resource.EditFail + ErrorCol)));
                        }
                    }
                    else
                    {
                        return(Json(JsonHandler.CreateMessage(0, Resource.EditFail)));
                    }
                    //if (m_BLL.Delete(ref errors, id))
                    //{
                    //    LogHandler.WriteServiceLog(GetUserTrueName(), "Id:" + id, "成功", "删除", "WMS_Sale_Order");
                    //    return Json(JsonHandler.CreateMessage(1, Resource.DeleteSucceed));
                    //}
                    //else
                    //{
                    //    string ErrorCol = errors.Error;
                    //    LogHandler.WriteServiceLog(GetUserTrueName(), "Id" + id + "," + ErrorCol, "失败", "删除", "WMS_Sale_Order");
                    //    return Json(JsonHandler.CreateMessage(0, Resource.DeleteFail + ErrorCol));
                    //}
                }
                else
                {
                    return(Json(JsonHandler.CreateMessage(0, Resource.DeleteFail)));
                }
            }
        }
Exemplo n.º 6
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));
        }
Exemplo n.º 7
0
        public virtual WMS_Sale_OrderModel GetById(object id)
        {
            if (IsExists(id))
            {
                WMS_Sale_Order      entity = m_Rep.GetById(id);
                WMS_Sale_OrderModel model  = new WMS_Sale_OrderModel();
                model.Id               = entity.Id;
                model.SaleBillNum      = entity.SaleBillNum;
                model.SellBillNum      = entity.SellBillNum;
                model.PlanDeliveryDate = entity.PlanDeliveryDate;
                model.CustomerId       = entity.CustomerId;
                model.PartId           = entity.PartId;
                model.Qty              = entity.Qty;
                model.BoxQty           = entity.BoxQty;
                model.InvId            = entity.InvId;
                model.SubInvId         = entity.SubInvId;
                model.Lot              = entity.Lot;
                model.Remark           = entity.Remark;
                model.PrintStaus       = entity.PrintStaus;
                model.PrintDate        = entity.PrintDate;
                model.PrintMan         = entity.PrintMan;
                model.ConfirmStatus    = entity.ConfirmStatus;
                model.ConfirmMan       = entity.ConfirmMan;
                model.ConfirmDate      = entity.ConfirmDate;
                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;
                model.ConfirmMessage   = entity.ConfirmMessage;
                model.Volume           = entity.Volume;

                return(model);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 8
0
        public ActionResult Details(long id)
        {
            WMS_Sale_OrderModel entity = m_BLL.GetById(id);

            return(View(entity));
        }
Exemplo n.º 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_Sale_OrderModel>(x => x.SaleBillNum, "销售单号(业务)(必输)");
                    //excelFile.AddMapping<WMS_Sale_OrderModel>(x => x.SellBillNum, "销售单号(系统)");
                    excelFile.AddMapping <WMS_Sale_OrderModel>(x => x.PlanDeliveryDate, "要求到货日期");
                    excelFile.AddMapping <WMS_Sale_OrderModel>(x => x.CustomerShortName, "客户名称(必输)");
                    excelFile.AddMapping <WMS_Sale_OrderModel>(x => x.PartCode, "物料编码(必输)");
                    excelFile.AddMapping <WMS_Sale_OrderModel>(x => x.Qty, "数量(必输)");
                    excelFile.AddMapping <WMS_Sale_OrderModel>(x => x.BoxQty, "箱数");
                    excelFile.AddMapping <WMS_Sale_OrderModel>(x => x.InvName, "库房");
                    //excelFile.AddMapping<WMS_Sale_OrderModel>(x => x.SubInvId, "子库存");
                    excelFile.AddMapping <WMS_Sale_OrderModel>(x => x.Lot, "批次号(格式:YYYY-MM-DD)");
                    excelFile.AddMapping <WMS_Sale_OrderModel>(x => x.Volume, "体积");
                    excelFile.AddMapping <WMS_Sale_OrderModel>(x => x.Remark, "备注");
                    //excelFile.AddMapping<WMS_Sale_OrderModel>(x => x.PrintStaus, "打印状态");
                    //excelFile.AddMapping<WMS_Sale_OrderModel>(x => x.PrintDate, "打印日期");
                    //excelFile.AddMapping<WMS_Sale_OrderModel>(x => x.PrintMan, "打印人");
                    //excelFile.AddMapping<WMS_Sale_OrderModel>(x => x.ConfirmStatus, "确认状态");
                    //excelFile.AddMapping<WMS_Sale_OrderModel>(x => x.ConfirmMan, "确认人");
                    //excelFile.AddMapping<WMS_Sale_OrderModel>(x => x.ConfirmDate, "确认时间");
                    //excelFile.AddMapping<WMS_Sale_OrderModel>(x => x.Attr1, "");
                    //excelFile.AddMapping<WMS_Sale_OrderModel>(x => x.Attr2, "");
                    //excelFile.AddMapping<WMS_Sale_OrderModel>(x => x.Attr3, "");
                    //excelFile.AddMapping<WMS_Sale_OrderModel>(x => x.Attr4, "");
                    //excelFile.AddMapping<WMS_Sale_OrderModel>(x => x.Attr5, "");
                    //excelFile.AddMapping<WMS_Sale_OrderModel>(x => x.CreatePerson, "创建人");
                    //excelFile.AddMapping<WMS_Sale_OrderModel>(x => x.CreateTime, "创建时间");
                    //excelFile.AddMapping<WMS_Sale_OrderModel>(x => x.ModifyPerson, "修改人");
                    //excelFile.AddMapping<WMS_Sale_OrderModel>(x => x.ModifyTime, "修改时间");

                    //SheetName,第一个Sheet
                    var excelContent = excelFile.Worksheet <WMS_Sale_OrderModel>(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_Sale_OrderModel();
                            model.Id          = row.Id;
                            model.SaleBillNum = row.SaleBillNum;
                            //model.SellBillNum = row.SellBillNum;
                            model.PlanDeliveryDate  = row.PlanDeliveryDate;
                            model.CustomerShortName = row.CustomerShortName;
                            model.PartCode          = row.PartCode;
                            model.Qty     = row.Qty;
                            model.BoxQty  = row.BoxQty;
                            model.InvName = row.InvName;
                            //model.SubInvId = row.SubInvId;
                            model.Lot    = row.Lot;
                            model.Volume = row.Volume;
                            model.Remark = row.Remark;
                            //model.PrintStaus = row.PrintStaus;
                            //model.PrintDate = row.PrintDate;
                            //model.PrintMan = row.PrintMan;
                            //model.ConfirmStatus = row.ConfirmStatus;
                            //model.ConfirmMan = row.ConfirmMan;
                            //model.ConfirmDate = row.ConfirmDate;
                            //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_Sale_Order entity = new WMS_Sale_Order();
                            entity.Id          = model.Id;
                            entity.SaleBillNum = model.SaleBillNum;
                            //entity.SellBillNum = "XS" + DateTime.Now.ToString("yyyyMMddHHmmssff");打印时生成
                            entity.PlanDeliveryDate = model.PlanDeliveryDate;
                            entity.CustomerId       = model.CustomerId;
                            entity.PartId           = model.PartId;
                            entity.Qty        = model.Qty;
                            entity.BoxQty     = model.BoxQty;
                            entity.InvId      = model.InvId;
                            entity.SubInvId   = model.SubInvId;
                            entity.Lot        = model.Lot;
                            entity.Remark     = model.Remark;
                            entity.Volume     = model.Volume;
                            entity.PrintStaus = "未打印";
                            //entity.PrintDate = model.PrintDate;
                            //entity.PrintMan = model.PrintMan;
                            entity.ConfirmStatus = "未确认";
                            //entity.ConfirmMan = model.ConfirmMan;
                            //entity.ConfirmDate = model.ConfirmDate;
                            //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;
                            entity.CreatePerson = oper;
                            entity.CreateTime   = DateTime.Now;
                            entity.ModifyPerson = oper;
                            entity.ModifyTime   = DateTime.Now;

                            db.WMS_Sale_Order.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);
        }
Exemplo n.º 10
0
        public void AdditionalCheckExcelData(DBContainer db, ref WMS_Sale_OrderModel 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;
                    int partId = part.Id;
                    if (!String.IsNullOrEmpty(model.SaleBillNum))
                    {
                        var saleBillNum = model.SaleBillNum;
                        Expression <Func <WMS_Sale_Order, bool> > exp1 = x => x.PartId == partId && x.SaleBillNum == saleBillNum;
                        var part1 = db.WMS_Sale_Order.FirstOrDefault(exp1);
                        if (part1 != null)
                        {
                            throw new Exception("销售单号与物料编码重复!");
                        }
                    }
                }
            }
            else
            {
                throw new Exception("物料编码不能为空!");
            }
            //设定箱数的默认值
            //if (model.BoxQty == null) { model.BoxQty = 0; }

            //获取客户ID
            if (!String.IsNullOrEmpty(model.CustomerShortName))
            {
                var customerShortName = model.CustomerShortName;
                Expression <Func <WMS_Customer, bool> > exp = x => x.CustomerName == customerShortName;

                //var part = m_PartRep.GetSingleWhere(exp);
                var customer = db.WMS_Customer.FirstOrDefault(exp);
                if (customer == null)
                {
                    throw new Exception("客户不存在!");
                }
                else
                {
                    model.CustomerId = customer.Id;
                }
            }
            else
            {
                throw new Exception("客户简称不能为空!");
            }

            //获取库房ID
            if (!String.IsNullOrEmpty(model.PartCode))
            {
                var invName = "主仓库";
                Expression <Func <WMS_InvInfo, bool> > exp = x => x.InvName == invName;

                //var supplier = m_SupplierRep.GetSingleWhere(exp);
                var invInfo = db.WMS_InvInfo.FirstOrDefault(exp);
                if (invInfo == null)
                {
                    throw new Exception("库房不存在!");
                }
                else
                {
                    model.InvId = invInfo.Id;
                }
            }
            //else
            //{
            //    throw new Exception("库房不能为空!");
            //}
            //校验批次号,没有批次号自动赋值为当前月
            if (!String.IsNullOrEmpty(model.Lot))
            {
                if (!DateTimeHelper.CheckYearMonth(model.Lot))
                {
                    throw new Exception("批次号不合符规范!");
                }
            }
            //销售单号不能为空
            if (String.IsNullOrEmpty(model.SaleBillNum))
            {
                throw new Exception("销售单号不能为空!");
            }
            //数量不能为空
            if (model.Qty == 0)
            {
                throw new Exception("数量不能为空!");
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// 校验Excel数据,这个方法一般用于重写校验逻辑
        /// </summary>
        public virtual bool CheckImportData(string fileName, List <WMS_Sale_OrderModel> list, ref ValidationErrors errors)
        {
            var targetFile = new FileInfo(fileName);

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

            var excelFile = new ExcelQueryFactory(fileName);

            //对应列头
            excelFile.AddMapping <WMS_Sale_OrderModel>(x => x.SaleBillNum, "销售单号(业务)");
            excelFile.AddMapping <WMS_Sale_OrderModel>(x => x.SellBillNum, "销售单号(系统)");
            excelFile.AddMapping <WMS_Sale_OrderModel>(x => x.PlanDeliveryDate, "计划发货日期");
            excelFile.AddMapping <WMS_Sale_OrderModel>(x => x.CustomerId, "客户");
            excelFile.AddMapping <WMS_Sale_OrderModel>(x => x.PartId, "物料Id");
            excelFile.AddMapping <WMS_Sale_OrderModel>(x => x.Qty, "数量");
            excelFile.AddMapping <WMS_Sale_OrderModel>(x => x.BoxQty, "箱数");
            excelFile.AddMapping <WMS_Sale_OrderModel>(x => x.InvId, "库存");
            excelFile.AddMapping <WMS_Sale_OrderModel>(x => x.SubInvId, "子库存");
            excelFile.AddMapping <WMS_Sale_OrderModel>(x => x.Lot, "批次号:YYYYMM");
            excelFile.AddMapping <WMS_Sale_OrderModel>(x => x.Remark, "备注");
            excelFile.AddMapping <WMS_Sale_OrderModel>(x => x.PrintStaus, "打印状态");
            excelFile.AddMapping <WMS_Sale_OrderModel>(x => x.PrintDate, "打印日期");
            excelFile.AddMapping <WMS_Sale_OrderModel>(x => x.PrintMan, "打印人");
            excelFile.AddMapping <WMS_Sale_OrderModel>(x => x.ConfirmStatus, "确认状态");
            excelFile.AddMapping <WMS_Sale_OrderModel>(x => x.ConfirmMan, "确认人");
            excelFile.AddMapping <WMS_Sale_OrderModel>(x => x.ConfirmDate, "确认时间");
            excelFile.AddMapping <WMS_Sale_OrderModel>(x => x.Attr1, "Attr1");
            excelFile.AddMapping <WMS_Sale_OrderModel>(x => x.Attr2, "Attr2");
            excelFile.AddMapping <WMS_Sale_OrderModel>(x => x.Attr3, "Attr3");
            excelFile.AddMapping <WMS_Sale_OrderModel>(x => x.Attr4, "Attr4");
            excelFile.AddMapping <WMS_Sale_OrderModel>(x => x.Attr5, "Attr5");
            excelFile.AddMapping <WMS_Sale_OrderModel>(x => x.CreatePerson, "创建人");
            excelFile.AddMapping <WMS_Sale_OrderModel>(x => x.CreateTime, "创建时间");
            excelFile.AddMapping <WMS_Sale_OrderModel>(x => x.ModifyPerson, "修改人");
            excelFile.AddMapping <WMS_Sale_OrderModel>(x => x.ModifyTime, "修改时间");
            excelFile.AddMapping <WMS_Sale_OrderModel>(x => x.ConfirmMessage, "ConfirmMessage");

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

            //检查数据正确性
            foreach (var row in excelContent)
            {
                var errorMessage = new StringBuilder();
                var entity       = new WMS_Sale_OrderModel();
                entity.Id               = row.Id;
                entity.SaleBillNum      = row.SaleBillNum;
                entity.SellBillNum      = row.SellBillNum;
                entity.PlanDeliveryDate = row.PlanDeliveryDate;
                entity.CustomerId       = row.CustomerId;
                entity.PartId           = row.PartId;
                entity.Qty              = row.Qty;
                entity.BoxQty           = row.BoxQty;
                entity.InvId            = row.InvId;
                entity.SubInvId         = row.SubInvId;
                entity.Lot              = row.Lot;
                entity.Remark           = row.Remark;
                entity.PrintStaus       = row.PrintStaus;
                entity.PrintDate        = row.PrintDate;
                entity.PrintMan         = row.PrintMan;
                entity.ConfirmStatus    = row.ConfirmStatus;
                entity.ConfirmMan       = row.ConfirmMan;
                entity.ConfirmDate      = row.ConfirmDate;
                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;
                entity.ConfirmMessage   = row.ConfirmMessage;

                //=============================================================================
                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);
        }
Exemplo n.º 12
0
        public void AdditionalCheckExcelData(DBContainer db, ref WMS_Sale_OrderModel 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("物料编码不能为空!");
            }
            //设定箱数的默认值
            //if (model.BoxQty == null) { model.BoxQty = 0; }

            //获取客户ID
            if (!String.IsNullOrEmpty(model.CustomerShortName))
            {
                var customerShortName = model.CustomerShortName;
                Expression <Func <WMS_Customer, bool> > exp = x => x.CustomerShortName == customerShortName;

                //var part = m_PartRep.GetSingleWhere(exp);
                var customer = db.WMS_Customer.FirstOrDefault(exp);
                if (customer == null)
                {
                    throw new Exception("客户不存在!");
                }
                else
                {
                    model.CustomerId = customer.Id;
                }
            }
            else
            {
                throw new Exception("客户简称不能为空!");
            }

            //获取库房ID
            if (!String.IsNullOrEmpty(model.InvName))
            {
                var invName = model.InvName;
                Expression <Func <WMS_InvInfo, bool> > exp = x => x.InvName == invName;

                //var supplier = m_SupplierRep.GetSingleWhere(exp);
                var invInfo = db.WMS_InvInfo.FirstOrDefault(exp);
                if (invInfo == null)
                {
                    throw new Exception("库房不存在!");
                }
                else
                {
                    model.InvId = invInfo.Id;
                }
            }
            else
            {
                throw new Exception("库房不能为空!");
            }
            //校验批次号
            if (String.IsNullOrEmpty(model.Lot))
            {
                throw new Exception("批次号不能为空!");
            }
        }