/// <summary> /// 保存表单(新增、修改) /// </summary> /// <param name="keyValue">主键值</param> /// <param name="entity">实体对象</param> /// <returns></returns> public void SaveForm(string keyValue, KeyPartEntity entity) { try { service.SaveForm(keyValue, entity); } catch (Exception) { throw; } }
public void SavePartEntity(PatrolRecordEntity entity) { try { //更新主表下次巡查时间、最近巡查时间 IRepository db = new RepositoryFactory().BaseRepository(); KeyPartEntity ke = db.FindEntity <KeyPartEntity>(entity.MainId); if (ke != null) { ke.LatelyPatrolDate = entity.PatrolDate; if (entity.PatrolPeriod != null) { ke.NextPatrolDate = entity.PatrolDate.Value.AddDays(entity.PatrolPeriod.Value); } else { ke.NextPatrolDate = entity.NextPatrolDate; } db.Update <KeyPartEntity>(ke); } } catch { } }
public object SaveKeyPart() { try { string res = ctx.Request["json"]; dynamic dy = JsonConvert.DeserializeObject <ExpandoObject>(res); string userId = dy.userid; //当前用户ID OperatorProvider.AppUserId = userId; //设置当前用户 Operator curUser = OperatorProvider.Provider.Current(); string keyValue = dy.data.Id; string str = JsonConvert.SerializeObject(dy.data); KeyPartEntity entity = JsonConvert.DeserializeObject <KeyPartEntity>(str); //HttpFileCollection files = ctx.Request.Files;//上传的文件 keypartbll.SaveForm(keyValue, entity); } catch (Exception) { return(new { code = -1, count = 0, info = "保存失败" }); } return(new { code = 0, count = 0, info = "保存成功" }); }
//[AjaxOnly] //[HandlerAuthorize(PermissionMode.Ignore)] // [ValidateAntiForgeryToken] public string ImportGenericFirefighting() { if (OperatorProvider.Provider.Current().IsSystem) { return("超级管理员无此操作权限"); } string orgId = OperatorProvider.Provider.Current().OrganizeId;//所属公司 int error = 0; string message = "请选择格式正确的文件再导入!"; string falseMessage = ""; int count = HttpContext.Request.Files.Count; if (count > 0) { HttpPostedFileBase file = HttpContext.Request.Files[0]; if (string.IsNullOrEmpty(file.FileName)) { return(message); } if (!(file.FileName.Substring(file.FileName.IndexOf('.')).Contains("xls") || file.FileName.Substring(file.FileName.IndexOf('.')).Contains("xlsx"))) { return(message); } string fileName = DateTime.Now.ToString("yyyyMMddHHmmss") + System.IO.Path.GetExtension(file.FileName); file.SaveAs(Server.MapPath("~/Resource/temp/" + fileName)); DataTable dt = ExcelHelper.ExcelImport(Server.MapPath("~/Resource/temp/" + fileName)); int order = 1; string orgid = OperatorProvider.Provider.Current().OrganizeId; for (int i = 0; i < dt.Rows.Count; i++) { KeyPartEntity item = new KeyPartEntity(); order = i + 1; #region 重点防火部位名称 string partname = dt.Rows[i][0].ToString(); if (!string.IsNullOrEmpty(partname)) { item.PartName = partname; item.PartNo = partname; //var data = new DataItemCache().ToItemValue("PartName", partname); //if (data != null && !string.IsNullOrEmpty(data)) // item.PartNo = data; //else //{ // falseMessage += string.Format(@"第{0}行导入失败,重点防火部位名称不存在!</br>", order); // error++; // continue; //} } else { falseMessage += string.Format(@"第{0}行导入失败,重点防火部位名称不能为空!</br>", order); error++; continue; } #endregion #region 所在位置 string district = dt.Rows[i][1].ToString(); if (!string.IsNullOrEmpty(district)) { var disItem = new DistrictBLL().GetListForCon(x => x.DistrictName == district && x.OrganizeId == orgid).FirstOrDefault(); if (disItem != null) { item.DistrictId = disItem.DistrictID; item.DistrictCode = disItem.DistrictCode; item.District = district; } else { falseMessage += string.Format(@"第{0}行导入失败,所在位置不存在!</br>", order); error++; continue; } } else { falseMessage += string.Format(@"第{0}行导入失败,所在位置不能为空!</br>", order); error++; continue; } #endregion #region 责任部门 string dutydept = dt.Rows[i][2].ToString(); if (!string.IsNullOrEmpty(dutydept)) { var data = departBLL.GetList().FirstOrDefault(e => e.FullName == dutydept && e.OrganizeId == orgid); if (data != null) { item.DutyDept = dutydept; item.DutyDeptCode = data.EnCode; } else { falseMessage += string.Format(@"第{0}行导入失败,责任部门不存在!</br>", order); error++; continue; } } else { falseMessage += string.Format(@"第{0}行导入失败,责任部门不能为空!</br>", order); error++; continue; } #endregion #region 责任人 string dutyUser = dt.Rows[i][3].ToString(); if (!string.IsNullOrEmpty(dutyUser)) { var userEntity = userBLL.GetListForCon(x => x.RealName == dutyUser && x.OrganizeId == orgid).FirstOrDefault(); if (userEntity != null) { item.DutyUserId = userEntity.UserId; item.DutyUser = dutyUser; } else { falseMessage += string.Format(@"第{0}行导入失败,责任人不存在!</br>", order); error++; continue; } } else { falseMessage += string.Format(@"第{0}行导入失败,责任人不能为空!</br>", order); error++; continue; } #endregion #region 责任人电话 string dutyTel = dt.Rows[i][4].ToString(); if (!string.IsNullOrEmpty(dutyTel)) { item.DutyTel = dutyTel; } #endregion #region 建筑结构 string structure = dt.Rows[i][5].ToString(); if (!string.IsNullOrEmpty(structure)) { item.Structure = structure; var data = new DataItemCache().ToItemValue("Structure", structure); if (data != null && !string.IsNullOrEmpty(data)) { item.Structure = data; } else { falseMessage += string.Format(@"第{0}行导入失败,建筑结构不存在!</br>", order); error++; continue; } } //else //{ // falseMessage += string.Format(@"第{0}行导入失败,建筑结构不能为空!</br>", order); // error++; // continue; //} #endregion #region 建筑面积(m2) string acreage = dt.Rows[i][6].ToString(); int tempAcreage; if (!string.IsNullOrEmpty(acreage)) { if (int.TryParse(acreage, out tempAcreage)) { item.Acreage = tempAcreage; } else { falseMessage += string.Format(@"第{0}行导入失败,建筑面积(m2)必须为数字!</br>", order); error++; continue; } } //else //{ // falseMessage += string.Format(@"第{0}行导入失败,建筑面积(m2)不能为空!</br>", order); // error++; // continue; //} #endregion #region 主要存储物品 string storegoods = dt.Rows[i][7].ToString(); if (!string.IsNullOrEmpty(storegoods)) { item.StoreGoods = storegoods; } #endregion #region 主要灭火器装备 string outfireequip = dt.Rows[i][8].ToString(); if (!string.IsNullOrEmpty(outfireequip)) { item.OutfireEquip = outfireequip; } else { falseMessage += string.Format(@"第{0}行导入失败,主要灭火器装备不能为空!</br>", order); error++; continue; } #endregion #region 重点防火部位人数 string peoplenum = dt.Rows[i][9].ToString(); int tempPeopleNum; if (!string.IsNullOrEmpty(peoplenum)) { if (int.TryParse(peoplenum, out tempPeopleNum)) { item.PeopleNum = tempPeopleNum; } else { falseMessage += string.Format(@"第{0}行导入失败,重点防火部位人数必须为数字!</br>", order); error++; continue; } } #endregion #region 动火级别 string rank = dt.Rows[i][10].ToString(); if (!string.IsNullOrEmpty(rank)) { if (rank == "一级动火区域") { item.Rank = 1; } else if (rank == "二级动火区域") { item.Rank = 2; } else { falseMessage += string.Format(@"第{0}行导入失败,动火级别不存在!</br>", order); error++; continue; } } else { falseMessage += string.Format(@"第{0}行导入失败,动火级别不能为空!</br>", order); error++; continue; } #endregion #region 最近巡查日期(年月日) string latelypatroldate = dt.Rows[i][11].ToString(); DateTime tempLatelyPatrolDate; if (!string.IsNullOrEmpty(latelypatroldate)) { if (DateTime.TryParse(latelypatroldate, out tempLatelyPatrolDate)) { item.LatelyPatrolDate = tempLatelyPatrolDate; } else { falseMessage += string.Format(@"第{0}行导入失败,最近巡查日期不对!</br>", order); error++; continue; } } #endregion #region 巡查周期(天) string patrolperiod = dt.Rows[i][12].ToString(); int tempPatrolPeriod; if (!string.IsNullOrEmpty(patrolperiod)) { if (int.TryParse(patrolperiod, out tempPatrolPeriod)) { item.PatrolPeriod = tempPatrolPeriod; } else { falseMessage += string.Format(@"第{0}行导入失败,巡查周期(天)必须为数字!</br>", order); error++; continue; } } #endregion #region 次巡查日期 string nextpatroldate = dt.Rows[i][13].ToString(); DateTime tempNextPatrolDate; if (!string.IsNullOrEmpty(nextpatroldate)) { if (DateTime.TryParse(nextpatroldate, out tempNextPatrolDate)) { item.NextPatrolDate = tempNextPatrolDate; } else { falseMessage += string.Format(@"第{0}行导入失败,下次巡查日期不对!</br>", order); error++; continue; } } else { falseMessage += string.Format(@"第{0}行导入失败,下次巡查日期不能为空!</br>", order); error++; continue; } #endregion #region 使用状态 string employstate = dt.Rows[i][14].ToString(); if (!string.IsNullOrEmpty(employstate)) { if (employstate == "在用") { item.EmployState = 0; } else if (employstate == "停用") { item.EmployState = 1; } else if (employstate == "其他") { item.EmployState = 2; } else { falseMessage += string.Format(@"第{0}行导入失败,使用状态不存在!</br>", order); error++; continue; } } else { falseMessage += string.Format(@"第{0}行导入失败,使用状态不能为空!</br>", order); error++; continue; } #endregion #region 火灾危险性分析 string analyze = dt.Rows[i][15].ToString(); if (!string.IsNullOrEmpty(analyze)) { item.Analyze = analyze; } else { falseMessage += string.Format(@"第{0}行导入失败,火灾危险性分析不能为空!</br>", order); error++; continue; } #endregion #region 防火措施 string measure = dt.Rows[i][16].ToString(); if (!string.IsNullOrEmpty(measure)) { item.Measure = measure; } else { falseMessage += string.Format(@"第{0}行导入失败,防火措施不能为空!</br>", order); error++; continue; } #endregion //管理要求 string require = dt.Rows[i][17].ToString(); if (!string.IsNullOrEmpty(require)) { item.Require = require; } //备注 string remark = dt.Rows[i][18].ToString(); if (!string.IsNullOrEmpty(remark)) { item.Remark = remark; } try { keypartbll.SaveForm("", item); } catch { error++; } } count = dt.Rows.Count; message = "共有" + count + "条记录,成功导入" + (count - error) + "条,失败" + error + "条"; message += "</br>" + falseMessage; } return(message); }
public ActionResult SaveForm(string keyValue, KeyPartEntity entity) { keypartbll.SaveForm(keyValue, entity); return(Success("操作成功。")); }