Esempio n. 1
0
        public virtual WMS_ReportParamModel GetById(object id)
        {
            if (IsExists(id))
            {
                WMS_ReportParam      entity = m_Rep.GetById(id);
                WMS_ReportParamModel model  = new WMS_ReportParamModel();
                model.Id           = entity.Id;
                model.ParamCode    = entity.ParamCode;
                model.ReportId     = entity.ReportId;
                model.InputNo      = entity.InputNo;
                model.ParamName    = entity.ParamName;
                model.ShowName     = entity.ShowName;
                model.ParamType    = entity.ParamType;
                model.ParamData    = entity.ParamData;
                model.DefaultValue = entity.DefaultValue;
                model.ParamElement = entity.ParamElement;
                model.Remark       = entity.Remark;
                model.CreatePerson = entity.CreatePerson;
                model.CreateTime   = entity.CreateTime;
                model.ModifyPerson = entity.ModifyPerson;
                model.ModifyTime   = entity.ModifyTime;

                return(model);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 2
0
 public ActionResult Create()
 {
     ViewBag.Report        = new SelectList(m_ReportBLL.GetList(ref setNoPagerAscById, ""), "Id", "ReportName");
     ViewBag.ParamTypes    = new SelectList(WMS_ReportParamModel.GetParamType(), "TypeCode", "TypeName");
     ViewBag.ParamElements = new SelectList(WMS_ReportParamModel.GetParamElement(), "ElementCode", "ElementName");
     return(View());
 }
Esempio n. 3
0
        public ActionResult Edit(long id)
        {
            ViewBag.ParamTypes    = new SelectList(WMS_ReportParamModel.GetParamType(), "TypeCode", "TypeName");
            ViewBag.ParamElements = new SelectList(WMS_ReportParamModel.GetParamElement(), "ElementCode", "ElementName");
            WMS_ReportParamModel entity = m_BLL.GetById(id);

            ViewBag.Report = new SelectList(m_ReportBLL.GetList(ref setNoPagerAscById, ""), "Id", "ReportName", entity.ReportId);
            return(View(entity));
        }
Esempio n. 4
0
        public virtual bool Edit(ref ValidationErrors errors, WMS_ReportParamModel model)
        {
            try
            {
                WMS_ReportParam entity = m_Rep.GetById(model.Id);
                if (entity == null)
                {
                    errors.Add(Resource.Disable);
                    return(false);
                }
                entity.Id           = model.Id;
                entity.ParamCode    = model.ParamCode;
                entity.ReportId     = model.ReportId;
                entity.InputNo      = model.InputNo;
                entity.ParamName    = model.ParamName;
                entity.ShowName     = model.ShowName;
                entity.ParamType    = model.ParamType;
                entity.ParamData    = model.ParamData;
                entity.DefaultValue = model.DefaultValue;
                entity.ParamElement = model.ParamElement;
                entity.Remark       = model.Remark;
                entity.CreatePerson = model.CreatePerson;
                entity.CreateTime   = model.CreateTime;
                entity.ModifyPerson = model.ModifyPerson;
                entity.ModifyTime   = model.ModifyTime;



                if (m_Rep.Edit(entity))
                {
                    return(true);
                }
                else
                {
                    errors.Add(Resource.NoDataChange);
                    return(false);
                }
            }
            catch (Exception ex)
            {
                errors.Add(ex.Message);
                ExceptionHander.WriteException(ex);
                return(false);
            }
        }
Esempio n. 5
0
 public JsonResult Edit(WMS_ReportParamModel model)
 {
     if (model != null && ModelState.IsValid)
     {
         if (m_BLL.Edit(ref errors, model))
         {
             LogHandler.WriteServiceLog(GetUserId(), "Id" + model.Id + ",ParamCode" + model.ParamCode, "成功", "修改", "WMS_ReportParam");
             return(Json(JsonHandler.CreateMessage(1, Resource.EditSucceed)));
         }
         else
         {
             string ErrorCol = errors.Error;
             LogHandler.WriteServiceLog(GetUserId(), "Id" + model.Id + ",ParamCode" + model.ParamCode + "," + ErrorCol, "失败", "修改", "WMS_ReportParam");
             return(Json(JsonHandler.CreateMessage(0, Resource.EditFail + ErrorCol)));
         }
     }
     else
     {
         return(Json(JsonHandler.CreateMessage(0, Resource.EditFail)));
     }
 }
Esempio n. 6
0
 public ActionResult Index()
 {
     ViewBag.ParamTypes    = new SelectList(WMS_ReportParamModel.GetParamType(), "TypeCode", "TypeName");
     ViewBag.ParamElements = new SelectList(WMS_ReportParamModel.GetParamElement(), "ElementCode", "ElementName");
     return(View());
 }
Esempio n. 7
0
        public ActionResult Details(long id)
        {
            WMS_ReportParamModel entity = m_BLL.GetById(id);

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

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

            var excelFile = new ExcelQueryFactory(fileName);

            //对应列头
            excelFile.AddMapping <WMS_ReportParamModel>(x => x.ParamCode, "参数代码");
            excelFile.AddMapping <WMS_ReportParamModel>(x => x.ReportId, "报表ID");
            excelFile.AddMapping <WMS_ReportParamModel>(x => x.InputNo, "InputNo");
            excelFile.AddMapping <WMS_ReportParamModel>(x => x.ParamName, "参数名");
            excelFile.AddMapping <WMS_ReportParamModel>(x => x.ShowName, "显示名称");
            excelFile.AddMapping <WMS_ReportParamModel>(x => x.ParamType, "参数类型:varchar、int、datetime");
            excelFile.AddMapping <WMS_ReportParamModel>(x => x.ParamData, "可选值");
            excelFile.AddMapping <WMS_ReportParamModel>(x => x.DefaultValue, "默认值");
            excelFile.AddMapping <WMS_ReportParamModel>(x => x.ParamElement, "显示元素:文本框、下拉框、日期框等");
            excelFile.AddMapping <WMS_ReportParamModel>(x => x.Remark, "备注");
            excelFile.AddMapping <WMS_ReportParamModel>(x => x.CreatePerson, "创建人");
            excelFile.AddMapping <WMS_ReportParamModel>(x => x.CreateTime, "创建时间");
            excelFile.AddMapping <WMS_ReportParamModel>(x => x.ModifyPerson, "修改人");
            excelFile.AddMapping <WMS_ReportParamModel>(x => x.ModifyTime, "修改时间");

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

            //检查数据正确性
            foreach (var row in excelContent)
            {
                var errorMessage = new StringBuilder();
                var entity       = new WMS_ReportParamModel();
                entity.Id           = row.Id;
                entity.ParamCode    = row.ParamCode;
                entity.ReportId     = row.ReportId;
                entity.InputNo      = row.InputNo;
                entity.ParamName    = row.ParamName;
                entity.ShowName     = row.ShowName;
                entity.ParamType    = row.ParamType;
                entity.ParamData    = row.ParamData;
                entity.DefaultValue = row.DefaultValue;
                entity.ParamElement = row.ParamElement;
                entity.Remark       = row.Remark;
                entity.CreatePerson = row.CreatePerson;
                entity.CreateTime   = row.CreateTime;
                entity.ModifyPerson = row.ModifyPerson;
                entity.ModifyTime   = row.ModifyTime;

                //=============================================================================
                if (errorMessage.Length > 0)
                {
                    errors.Add(string.Format(
                                   "第 {0} 列发现错误:{1}{2}",
                                   rowIndex,
                                   errorMessage,
                                   "<br/>"));
                }
                list.Add(entity);
                rowIndex += 1;
            }
            if (errors.Count > 0)
            {
                return(false);
            }
            return(true);
        }
Esempio 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_ReportParamModel>(x => x.ParamCode, "参数代码");
                    excelFile.AddMapping <WMS_ReportParamModel>(x => x.ReportId, "报表ID");
                    excelFile.AddMapping <WMS_ReportParamModel>(x => x.InputNo, "");
                    excelFile.AddMapping <WMS_ReportParamModel>(x => x.ParamName, "参数名");
                    excelFile.AddMapping <WMS_ReportParamModel>(x => x.ShowName, "显示名称");
                    excelFile.AddMapping <WMS_ReportParamModel>(x => x.ParamType, "参数类型:varchar、int、datetime");
                    excelFile.AddMapping <WMS_ReportParamModel>(x => x.ParamData, "可选值");
                    excelFile.AddMapping <WMS_ReportParamModel>(x => x.DefaultValue, "默认值");
                    excelFile.AddMapping <WMS_ReportParamModel>(x => x.ParamElement, "显示元素:文本框、下拉框、日期框等");
                    excelFile.AddMapping <WMS_ReportParamModel>(x => x.Remark, "备注");
                    excelFile.AddMapping <WMS_ReportParamModel>(x => x.CreatePerson, "创建人");
                    excelFile.AddMapping <WMS_ReportParamModel>(x => x.CreateTime, "创建时间");
                    excelFile.AddMapping <WMS_ReportParamModel>(x => x.ModifyPerson, "修改人");
                    excelFile.AddMapping <WMS_ReportParamModel>(x => x.ModifyTime, "修改时间");

                    //SheetName,第一个Sheet
                    var excelContent = excelFile.Worksheet <WMS_ReportParamModel>(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_ReportParamModel();
                            model.Id           = row.Id;
                            model.ParamCode    = row.ParamCode;
                            model.ReportId     = row.ReportId;
                            model.InputNo      = row.InputNo;
                            model.ParamName    = row.ParamName;
                            model.ShowName     = row.ShowName;
                            model.ParamType    = row.ParamType;
                            model.ParamData    = row.ParamData;
                            model.DefaultValue = row.DefaultValue;
                            model.ParamElement = row.ParamElement;
                            model.Remark       = row.Remark;
                            model.CreatePerson = row.CreatePerson;
                            model.CreateTime   = row.CreateTime;
                            model.ModifyPerson = row.ModifyPerson;
                            model.ModifyTime   = row.ModifyTime;

                            if (!String.IsNullOrEmpty(errorMessage))
                            {
                                rtn = false;
                                errors.Add(string.Format("第 {0} 列发现错误:{1}{2}", rowIndex, errorMessage, "<br/>"));
                                wws.Cell(rowIndex + 1, excelFile.GetColumnNames("Sheet1").Count()).Value = errorMessage;
                                continue;
                            }

                            //执行额外的数据校验
                            try
                            {
                                AdditionalCheckExcelData(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_ReportParam entity = new WMS_ReportParam();
                            entity.Id           = model.Id;
                            entity.ParamCode    = model.ParamCode;
                            entity.ReportId     = model.ReportId;
                            entity.InputNo      = model.InputNo;
                            entity.ParamName    = model.ParamName;
                            entity.ShowName     = model.ShowName;
                            entity.ParamType    = model.ParamType;
                            entity.ParamData    = model.ParamData;
                            entity.DefaultValue = model.DefaultValue;
                            entity.ParamElement = model.ParamElement;
                            entity.Remark       = model.Remark;
                            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_ReportParam.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);
        }
Esempio n. 10
0
 public void AdditionalCheckExcelData(ref WMS_ReportParamModel model)
 {
 }