public virtual async Task <Spl_PersonModel> GetByIdAsync(object id) { if (IsExists(id)) { Spl_Person entity = await m_Rep.GetByIdAsync(id); Spl_PersonModel model = new Spl_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(); Spl_PersonModel entity = m_BLL.GetById(id); return(View(entity)); }
public virtual Spl_PersonModel GetById(string id) { if (IsExists(id)) { Spl_Person entity = m_Rep.GetById(id); Spl_PersonModel model = new Spl_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); } }
/// <summary> /// 校验Excel数据 /// </summary> public bool CheckImportBatchData(string fileName, List <Spl_PersonModel> personList, ref ValidationErrors errors) { var targetFile = new FileInfo(fileName); if (!targetFile.Exists) { errors.Add("导入的数据文件不存在"); return(false); } int rowIndex = 1; var excelFile = new ExcelQueryFactory(fileName); //获取所有的worksheet var sheetList = excelFile.GetWorksheetNames(); //检查数据正确性 foreach (var sheet in sheetList) { var errorMessage = new StringBuilder(); //获得sheet对应的数据 var data = excelFile.WorksheetNoHeader(sheet).ToList(); //判断信息是否齐全 if (data[1][2].Value.ToString() == "") { errorMessage.Append("姓名不能为空"); } var person = new Spl_PersonModel(); person.Id = ""; person.Name = data[1][2].Value.ToString(); person.Sex = data[2][2].Value.ToString(); person.Age = Convert.ToInt32(data[3][2].Value); person.IDCard = data[4][2].Value.ToString(); person.Phone = data[5][2].Value.ToString(); person.Email = data[6][2].Value.ToString(); person.Address = data[7][2].Value.ToString(); person.Region = data[8][2].Value.ToString(); person.Category = data[9][2].Value.ToString(); person.CreateTime = ResultHelper.NowTime; //集合错误 if (errorMessage.Length > 0) { errors.Add(string.Format( "在Sheet {0} 发现错误:{1}{2}", sheet, errorMessage, "<br/>")); } personList.Add(person); rowIndex += 1; } if (errors.Count > 0) { return(false); } return(true); }
public virtual async Task <Tuple <ValidationErrors, bool> > CreateAsync(Spl_PersonModel model) { ValidationErrors errors = new ValidationErrors(); try { Spl_Person entity = await m_Rep.GetByIdAsync(model.Id); if (entity != null) { errors.Add(Resource.PrimaryRepeat); return(new Tuple <ValidationErrors, bool>(errors, false)); } entity = new Spl_Person(); 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 (await m_Rep.CreateAsync(entity)) { return(new Tuple <ValidationErrors, bool>(errors, true)); } else { errors.Add(Resource.InsertFail); return(new Tuple <ValidationErrors, bool>(errors, false)); } } catch (Exception ex) { errors.Add(ex.Message); ExceptionHander.WriteException(ex); return(new Tuple <ValidationErrors, bool>(errors, false)); } }
public virtual bool Edit(ref ValidationErrors errors, Spl_PersonModel model) { try { Spl_Person entity = m_Rep.GetById(model.Id); if (entity == null) { errors.Add(Resource.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(Resource.NoDataChange); return(false); } } catch (Exception ex) { errors.Add(ex.Message); ExceptionHander.WriteException(ex); return(false); } }
public JsonResult Edit(Spl_PersonModel model) { if (model != null && ModelState.IsValid) { if (m_BLL.Edit(ref errors, model)) { LogHandler.WriteServiceLog(GetUserId(), "Id" + model.Id + ",Name" + model.Name, "成功", "修改", "Spl_Person"); return(Json(JsonHandler.CreateMessage(1, Resource.EditSucceed))); } else { string ErrorCol = errors.Error; LogHandler.WriteServiceLog(GetUserId(), "Id" + model.Id + ",Name" + model.Name + "," + ErrorCol, "失败", "修改", "Spl_Person"); return(Json(JsonHandler.CreateMessage(0, Resource.EditFail + ErrorCol))); } } else { return(Json(JsonHandler.CreateMessage(0, Resource.EditFail))); } }
public JsonResult Create(Spl_PersonModel model) { model.Id = ResultHelper.NewId; model.CreateTime = ResultHelper.NowTime; if (model != null && ModelState.IsValid) { if (m_BLL.Create(ref errors, model)) { LogHandler.WriteServiceLog(GetUserId(), "Id" + model.Id + ",Name" + model.Name, "成功", "创建", "Spl_Person"); return(Json(JsonHandler.CreateMessage(1, Resource.InsertSucceed))); } else { string ErrorCol = errors.Error; LogHandler.WriteServiceLog(GetUserId(), "Id" + model.Id + ",Name" + model.Name + "," + ErrorCol, "失败", "创建", "Spl_Person"); return(Json(JsonHandler.CreateMessage(0, Resource.InsertFail + ErrorCol))); } } else { return(Json(JsonHandler.CreateMessage(0, Resource.InsertFail))); } }
public JsonResult SaveBefor(string inserted) { var personList = JsonHandler.DeserializeJsonToList <Spl_PersonModel>(inserted); var personResultList = new List <Spl_PersonModel>(); //新加 if (personList != null && personList.Count != 0) { foreach (var model in personList) { Spl_PersonModel entity = new Spl_PersonModel(); entity.Id = ResultHelper.NewId; 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 = ResultHelper.NowTime; entity.Region = model.Region; entity.Category = model.Category; personResultList.Add(entity); } } try { m_BLL.SaveImportData(personResultList); LogHandler.WriteServiceLog(GetUserId(), "导入成功", "成功", "导入", "Spl_Person"); return(Json(JsonHandler.CreateMessage(1, Resource.InsertSucceed))); } catch (Exception ex) { LogHandler.WriteServiceLog(GetUserId(), ex.Message, "失败", "导入", "Spl_Person"); return(Json(JsonHandler.CreateMessage(0, Resource.InsertFail + ex.Message))); } }
/// <summary> /// 校验Excel数据 /// </summary> public override bool CheckImportData(string fileName, List <Spl_PersonModel> personList, ref ValidationErrors errors) { var targetFile = new FileInfo(fileName); if (!targetFile.Exists) { errors.Add("导入的数据文件不存在"); return(false); } var excelFile = new ExcelQueryFactory(fileName); //对应列头 excelFile.AddMapping <Spl_PersonModel>(x => x.Name, "Name"); excelFile.AddMapping <Spl_PersonModel>(x => x.Sex, "Sex"); excelFile.AddMapping <Spl_PersonModel>(x => x.Age, "Age"); excelFile.AddMapping <Spl_PersonModel>(x => x.IDCard, "IDCard"); excelFile.AddMapping <Spl_PersonModel>(x => x.Phone, "Phone"); excelFile.AddMapping <Spl_PersonModel>(x => x.Email, "Email"); excelFile.AddMapping <Spl_PersonModel>(x => x.Address, "Address"); excelFile.AddMapping <Spl_PersonModel>(x => x.Region, "Region"); excelFile.AddMapping <Spl_PersonModel>(x => x.Category, "Category"); //SheetName var excelContent = excelFile.Worksheet <Spl_PersonModel>(0); int rowIndex = 1; //检查数据正确性 foreach (var row in excelContent) { var errorMessage = new StringBuilder(); var person = new Spl_PersonModel(); person.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; person.CreateTime = ResultHelper.NowTime; if (string.IsNullOrWhiteSpace(row.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/>")); } personList.Add(person); rowIndex += 1; } if (errors.Count > 0) { return(false); } return(true); }
public ActionResult Edit(string id) { Spl_PersonModel entity = m_BLL.GetById(id); return(View(entity)); }
/// <summary> /// 校验Excel数据,这个方法一般用于重写校验逻辑 /// </summary> public virtual bool CheckImportData(string fileName, List <Spl_PersonModel> list, ref ValidationErrors errors) { var targetFile = new FileInfo(fileName); if (!targetFile.Exists) { errors.Add("导入的数据文件不存在"); return(false); } var excelFile = new ExcelQueryFactory(fileName); //对应列头 excelFile.AddMapping <Spl_PersonModel>(x => x.Name, "Name"); excelFile.AddMapping <Spl_PersonModel>(x => x.Sex, "Sex"); excelFile.AddMapping <Spl_PersonModel>(x => x.Age, "Age"); excelFile.AddMapping <Spl_PersonModel>(x => x.IDCard, "IDCard"); excelFile.AddMapping <Spl_PersonModel>(x => x.Phone, "Phone"); excelFile.AddMapping <Spl_PersonModel>(x => x.Email, "Email"); excelFile.AddMapping <Spl_PersonModel>(x => x.Address, "Address"); excelFile.AddMapping <Spl_PersonModel>(x => x.CreateTime, "CreateTime"); excelFile.AddMapping <Spl_PersonModel>(x => x.Region, "Region"); excelFile.AddMapping <Spl_PersonModel>(x => x.Category, "Category"); //SheetName var excelContent = excelFile.Worksheet <Spl_PersonModel>(0); int rowIndex = 1; //检查数据正确性 foreach (var row in excelContent) { var errorMessage = new StringBuilder(); var entity = new Spl_PersonModel(); entity.Id = row.Id; entity.Name = row.Name; entity.Sex = row.Sex; entity.Age = row.Age; entity.IDCard = row.IDCard; entity.Phone = row.Phone; entity.Email = row.Email; entity.Address = row.Address; entity.CreateTime = row.CreateTime; entity.Region = row.Region; entity.Category = row.Category; //============================================================================= 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); }