/// <summary> /// 根据ID获得一个实体 /// </summary> /// <param name="id">id</param> /// <returns>实体</returns> public virtual MIS_PersonModel GetById(string id) { if (IsExist(id)) { MIS_Person entity = m_Rep.GetById(id); MIS_PersonModel model = new MIS_PersonModel(); model.Id = entity.Id; model.Name = entity.Name; model.Sex = entity.Sex; model.Age = entity.Age; model.IDCard = entity.IDCard; model.Phone = entity.Phone; model.Email = entity.Email; model.Address = entity.Address; model.CreateTime = entity.CreateTime; model.Region = entity.Region; model.Category = entity.Category; return(model); } else { return(null); } }
public ActionResult Edit(string id) { ViewBag.perm = GetPermission(); MIS_PersonModel entity = m_BLL.GetById(id); return(View(entity)); }
public ActionResult Details(string id) { ViewBag.perm = GetPermission(); MIS_PersonModel model = m_BLL.GetById(id); return(View(model)); }
/// <summary> /// 修改一个实体 /// </summary> /// <param name="errors">持久的错误信息</param> /// <param name="model">模型</param> /// <returns>是否成功</returns> public virtual bool Edit(ref ValidationErrors errors, MIS_PersonModel model) { try { MIS_Person entity = m_Rep.GetById(model.Id); if (entity == null) { errors.add(Suggestion.Disable); return(false); } entity.Id = model.Id; entity.Name = model.Name; entity.Sex = model.Sex; entity.Age = model.Age; entity.IDCard = model.IDCard; entity.Phone = model.Phone; entity.Email = model.Email; entity.Address = model.Address; entity.CreateTime = model.CreateTime; entity.Region = model.Region; entity.Category = model.Category; if (m_Rep.Edit(entity)) { return(true); } else { errors.add(Suggestion.EditFail); return(false); } } catch (Exception ex) { errors.add(ex.Message); ExceptionHandler.WriteException(ex); //ExceptionHander.WriteException(ex); return(false); } }
public JsonResult Edit(MIS_PersonModel model) { if (model != null && ModelState.IsValid) { if (m_BLL.Edit(ref errors, model)) { LogHandler.WriteServiceLog(GetUserId(), "Id" + model.Id, "成功", "修改", "MIS_Person"); return(Json(JsonHandler.CreateMessage(1, Suggestion.EditSucceed))); } else { string ErrorCol = errors.Error; LogHandler.WriteServiceLog(GetUserId(), "Id" + model.Id + "," + ErrorCol, "失败", "修改", "MIS_Person"); return(Json(JsonHandler.CreateMessage(0, Suggestion.EditFail + ErrorCol))); } } else { return(Json(JsonHandler.CreateMessage(0, Suggestion.EditFail))); } }
public bool CheckImportData(string fileName, List <MIS_PersonModel> personList, ref ValidationErrors errors) { try { var targetFile = new FileInfo(fileName); if (!targetFile.Exists) { errors.add("文件不存在"); return(false); } var excelFile = new ExcelQueryFactory(fileName); //对应表头 excelFile.AddMapping <MIS_PersonModel>(x => x.Name, "Name"); excelFile.AddMapping <MIS_PersonModel>(x => x.Sex, "Sex"); excelFile.AddMapping <MIS_PersonModel>(x => x.Age, "Age"); excelFile.AddMapping <MIS_PersonModel>(x => x.IDCard, "IDCard"); excelFile.AddMapping <MIS_PersonModel>(x => x.Phone, "Phone"); excelFile.AddMapping <MIS_PersonModel>(x => x.Email, "Email"); excelFile.AddMapping <MIS_PersonModel>(x => x.Address, "Address"); excelFile.AddMapping <MIS_PersonModel>(x => x.Region, "Region"); excelFile.AddMapping <MIS_PersonModel>(x => x.Category, "Category"); //sheetName var excelContent = excelFile.Worksheet <MIS_PersonModel>(0); int rowIndex = 1; //检查数据正确性 foreach (var row in excelContent) { var errorMessage = new StringBuilder(); var person = new MIS_PersonModel(); person.Id = row.Id; person.Name = row.Name; person.Sex = row.Sex; person.Age = row.Age; person.IDCard = row.IDCard; person.Phone = row.Phone; person.Email = row.Email; person.Address = row.Address; person.Region = row.Region; person.Category = row.Category; if (string.IsNullOrEmpty(person.Name)) { errorMessage.Append("Name - 不能为空. "); } if (string.IsNullOrWhiteSpace(row.IDCard)) { errorMessage.Append("IDCard - 不能为空. "); } if (errorMessage.Length > 0) { errors.add(string.Format("第{0}行发现错误:{1}{2}", rowIndex, errorMessage, "<br />")); } else { personList.Add(person); } rowIndex++; } if (errors.Count() > 0) { return(false); } else { return(true); } } catch (Exception ex) { errors.add("数据表列名不合法"); ExceptionHandler.WriteException(ex); return(false); } }