public virtual WMS_InvRecordModel GetById(object id)
        {
            if (IsExists(id))
            {
                WMS_InvRecord      entity = m_Rep.GetById(id);
                WMS_InvRecordModel model  = new WMS_InvRecordModel();
                model.Id          = entity.Id;
                model.PartId      = entity.PartId;
                model.QTY         = entity.QTY;
                model.InvId       = entity.InvId;
                model.SubInvId    = entity.SubInvId;
                model.BillId      = entity.BillId;
                model.SourceBill  = entity.SourceBill;
                model.OperateDate = entity.OperateDate;
                model.Lot         = entity.Lot;
                model.Type        = entity.Type;
                model.OperateMan  = entity.OperateMan;
                model.Stock_InvId = entity.Stock_InvId;
                model.StockStatus = entity.StockStatus;

                return(model);
            }
            else
            {
                return(null);
            }
        }
        public virtual bool Create(ref ValidationErrors errors, WMS_InvRecordModel model)
        {
            try
            {
                WMS_InvRecord entity = m_Rep.GetById(model.Id);
                if (entity != null)
                {
                    errors.Add(Resource.PrimaryRepeat);
                    return(false);
                }
                entity             = new WMS_InvRecord();
                entity.Id          = model.Id;
                entity.PartId      = model.PartId;
                entity.QTY         = model.QTY;
                entity.InvId       = model.InvId;
                entity.SubInvId    = model.SubInvId;
                entity.BillId      = model.BillId;
                entity.SourceBill  = model.SourceBill;
                entity.OperateDate = model.OperateDate;
                entity.Lot         = model.Lot;
                entity.Type        = model.Type;
                entity.OperateMan  = model.OperateMan;
                entity.Stock_InvId = model.Stock_InvId;
                entity.StockStatus = model.StockStatus;


                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);
            }
        }
Example #3
0
 public JsonResult Edit(WMS_InvRecordModel model)
 {
     if (model != null && ModelState.IsValid)
     {
         if (m_BLL.Edit(ref errors, model))
         {
             LogHandler.WriteServiceLog(GetUserId(), "Id" + model.Id + ",PartId" + model.PartId, "成功", "修改", "WMS_InvRecord");
             return(Json(JsonHandler.CreateMessage(1, Resource.EditSucceed)));
         }
         else
         {
             string ErrorCol = errors.Error;
             LogHandler.WriteServiceLog(GetUserId(), "Id" + model.Id + ",PartId" + model.PartId + "," + ErrorCol, "失败", "修改", "WMS_InvRecord");
             return(Json(JsonHandler.CreateMessage(0, Resource.EditFail + ErrorCol)));
         }
     }
     else
     {
         return(Json(JsonHandler.CreateMessage(0, Resource.EditFail)));
     }
 }
Example #4
0
 public JsonResult Create(WMS_InvRecordModel model)
 {
     model.Id          = 0;
     model.OperateDate = ResultHelper.NowTime;
     if (model != null && ModelState.IsValid)
     {
         if (m_BLL.Create(ref errors, model))
         {
             LogHandler.WriteServiceLog(GetUserId(), "Id" + model.Id + ",PartId" + model.PartId, "成功", "创建", "WMS_InvRecord");
             return(Json(JsonHandler.CreateMessage(1, Resource.InsertSucceed)));
         }
         else
         {
             string ErrorCol = errors.Error;
             LogHandler.WriteServiceLog(GetUserId(), "Id" + model.Id + ",PartId" + model.PartId + "," + ErrorCol, "失败", "创建", "WMS_InvRecord");
             return(Json(JsonHandler.CreateMessage(0, Resource.InsertFail + ErrorCol)));
         }
     }
     else
     {
         return(Json(JsonHandler.CreateMessage(0, Resource.InsertFail)));
     }
 }
        /// <summary>
        /// 校验Excel数据,这个方法一般用于重写校验逻辑
        /// </summary>
        public virtual bool CheckImportData(string fileName, List <WMS_InvRecordModel> list, ref ValidationErrors errors)
        {
            var targetFile = new FileInfo(fileName);

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

            var excelFile = new ExcelQueryFactory(fileName);

            //对应列头
            excelFile.AddMapping <WMS_InvRecordModel>(x => x.PartId, "物料编码");
            excelFile.AddMapping <WMS_InvRecordModel>(x => x.QTY, "数量");
            excelFile.AddMapping <WMS_InvRecordModel>(x => x.InvId, "库房编码");
            excelFile.AddMapping <WMS_InvRecordModel>(x => x.SubInvId, "SubInvId");
            excelFile.AddMapping <WMS_InvRecordModel>(x => x.BillId, "单据ID");
            excelFile.AddMapping <WMS_InvRecordModel>(x => x.SourceBill, "单据来源");
            excelFile.AddMapping <WMS_InvRecordModel>(x => x.OperateDate, "操作时间");
            excelFile.AddMapping <WMS_InvRecordModel>(x => x.Lot, "Lot");
            excelFile.AddMapping <WMS_InvRecordModel>(x => x.Type, "出入库类型");
            excelFile.AddMapping <WMS_InvRecordModel>(x => x.OperateMan, "操作人");
            excelFile.AddMapping <WMS_InvRecordModel>(x => x.Stock_InvId, "备料库存");
            excelFile.AddMapping <WMS_InvRecordModel>(x => x.StockStatus, "备料状态:1-不适用(直接修改库存现有量);2-已备料;3-无效备料(取消备料后将2改成3);4-取消备料(当前操作是取消备料)");

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

            //检查数据正确性
            foreach (var row in excelContent)
            {
                var errorMessage = new StringBuilder();
                var entity       = new WMS_InvRecordModel();
                entity.Id          = row.Id;
                entity.PartId      = row.PartId;
                entity.QTY         = row.QTY;
                entity.InvId       = row.InvId;
                entity.SubInvId    = row.SubInvId;
                entity.BillId      = row.BillId;
                entity.SourceBill  = row.SourceBill;
                entity.OperateDate = row.OperateDate;
                entity.Lot         = row.Lot;
                entity.Type        = row.Type;
                entity.OperateMan  = row.OperateMan;
                entity.Stock_InvId = row.Stock_InvId;
                entity.StockStatus = row.StockStatus;

                //=============================================================================
                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);
        }
Example #6
0
        public ActionResult Details(long id)
        {
            WMS_InvRecordModel entity = m_BLL.GetById(id);

            return(View(entity));
        }
Example #7
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_InvRecordModel>(x => x.PartId, "物料编码");
                    excelFile.AddMapping <WMS_InvRecordModel>(x => x.QTY, "数量");
                    excelFile.AddMapping <WMS_InvRecordModel>(x => x.InvId, "库房编码");
                    excelFile.AddMapping <WMS_InvRecordModel>(x => x.SubInvId, "");
                    excelFile.AddMapping <WMS_InvRecordModel>(x => x.BillId, "单据ID");
                    excelFile.AddMapping <WMS_InvRecordModel>(x => x.SourceBill, "单据来源");
                    excelFile.AddMapping <WMS_InvRecordModel>(x => x.OperateDate, "操作时间");
                    excelFile.AddMapping <WMS_InvRecordModel>(x => x.Lot, "");
                    excelFile.AddMapping <WMS_InvRecordModel>(x => x.Type, "出入库类型");
                    excelFile.AddMapping <WMS_InvRecordModel>(x => x.OperateMan, "操作人");
                    excelFile.AddMapping <WMS_InvRecordModel>(x => x.Stock_InvId, "备料库存");
                    excelFile.AddMapping <WMS_InvRecordModel>(x => x.StockStatus, "备料状态:1-不适用(直接修改库存现有量);2-已备料;3-无效备料(取消备料后将2改成3);4-取消备料(当前操作是取消备料)");

                    //SheetName,第一个Sheet
                    var excelContent = excelFile.Worksheet <WMS_InvRecordModel>(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_InvRecordModel();
                            model.Id          = row.Id;
                            model.PartId      = row.PartId;
                            model.QTY         = row.QTY;
                            model.InvId       = row.InvId;
                            model.SubInvId    = row.SubInvId;
                            model.BillId      = row.BillId;
                            model.SourceBill  = row.SourceBill;
                            model.OperateDate = row.OperateDate;
                            model.Lot         = row.Lot;
                            model.Type        = row.Type;
                            model.OperateMan  = row.OperateMan;
                            model.Stock_InvId = row.Stock_InvId;
                            model.StockStatus = row.StockStatus;

                            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(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_InvRecord entity = new WMS_InvRecord();
                            entity.Id          = model.Id;
                            entity.PartId      = model.PartId;
                            entity.QTY         = model.QTY;
                            entity.InvId       = model.InvId;
                            entity.SubInvId    = model.SubInvId;
                            entity.BillId      = model.BillId;
                            entity.SourceBill  = model.SourceBill;
                            entity.OperateDate = model.OperateDate;
                            entity.Lot         = model.Lot;
                            entity.Type        = model.Type;
                            entity.OperateMan  = model.OperateMan;
                            entity.Stock_InvId = model.Stock_InvId;
                            entity.StockStatus = model.StockStatus;


                            db.WMS_InvRecord.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);
        }
Example #8
0
 public void AdditionalCheckExcelData(ref WMS_InvRecordModel model)
 {
 }