public bool SaveItemForm(string keyValue, CheckItemsEntity entity) { try { service.SaveItemForm(keyValue, entity); return(true); } catch (Exception ex) { return(false); } }
public ActionResult SaveItemForm(string keyValue, CheckItemsEntity entity) { try { var user = OperatorProvider.Provider.Current(); saftycheckdatabll.SaveItemForm(keyValue, entity); return(Success("操作成功。")); } catch (Exception ex) { return(Error(ex.Message)); } }
public void SaveItemForm(string keyValue, CheckItemsEntity entity) { if (!string.IsNullOrEmpty(keyValue)) { entity.Id = keyValue; CheckItemsEntity se = DbFactory.Base().FindEntity <CheckItemsEntity>(keyValue); if (se == null) { entity.Create(); DbFactory.Base().Insert <CheckItemsEntity>(entity); } else { entity.Modify(keyValue); DbFactory.Base().Update <CheckItemsEntity>(entity); } } else { entity.Create(); DbFactory.Base().Insert <CheckItemsEntity>(entity); } }
public string ImportData(string checkId) { try { int error = 0; string message = "请选择格式正确的文件再导入!"; StringBuilder falseMessage = new StringBuilder(); 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)); Workbook wb = new Aspose.Cells.Workbook(); wb.Open(Server.MapPath("~/Resource/temp/" + fileName)); Aspose.Cells.Cells cells = wb.Worksheets[0].Cells; DataTable dt = cells.ExportDataTable(1, 0, cells.MaxDataRow, cells.MaxColumn + 1, true); int success = dt.Rows.Count - 1; var user = OperatorProvider.Provider.Current(); DepartmentBLL deptBll = new DepartmentBLL(); List <CheckItemsEntity> list = new List <CheckItemsEntity>(); List <int> lstRowIndex = new List <int>(); for (int i = 0; i < dt.Rows.Count; i++) { string itemName = dt.Rows[i][1].ToString().Trim(); //治理措施 string measures = dt.Rows[i][2].ToString().Trim(); //治理措施 string dutyDept = dt.Rows[i][3].ToString().Trim(); //责任单位 string dutyUser = dt.Rows[i][4].ToString().Trim(); //责任人 string planDate = dt.Rows[i][5].ToString().Trim(); //计划完成时间 string realityDate = dt.Rows[i][6].ToString().Trim(); //实际完成时间 string checkDept = dt.Rows[i][7].ToString().Trim(); //验收单位 string checkUser = dt.Rows[i][8].ToString().Trim(); //验收人 string result = dt.Rows[i][9].ToString().Trim(); //整改结果 string remark = dt.Rows[i][10].ToString().Trim(); //备注 string dutyDeptCode = ""; string dutyDeptId = ""; string dutyUserId = ""; string checkDeptId = ""; string checkUserId = ""; if (string.IsNullOrWhiteSpace(itemName)) { if (!lstRowIndex.Contains(i + 2)) { lstRowIndex.Add(i + 2); } falseMessage.AppendFormat("</br>第{0}行问题项目不能为空!", i + 1); error++; continue; } if (!string.IsNullOrWhiteSpace(planDate)) { DateTime time = new DateTime(); if (!DateTime.TryParse(planDate, out time)) { if (!lstRowIndex.Contains(i + 2)) { lstRowIndex.Add(i + 2); } falseMessage.AppendFormat("</br>第{0}行计划完成时间格式不正确!", i + 1); error++; continue; } } if (!string.IsNullOrWhiteSpace(realityDate)) { DateTime time = new DateTime(); if (!DateTime.TryParse(realityDate, out time)) { if (!lstRowIndex.Contains(i + 2)) { lstRowIndex.Add(i + 2); } falseMessage.AppendFormat("</br>第{0}行实际完成时间格式不正确!", i + 1); error++; continue; } } DataTable dtCount = deptBll.GetDataTable(string.Format("select count(1) from jt_checkitems where CheckId='{4}' and ItemName='{0}' and Measures='{1}' and DutyUser='******' and DeptName='{3}'", itemName, measures, dutyUser, dutyDept, checkId)); if (dtCount.Rows[0][0].ToInt() > 0) { if (!lstRowIndex.Contains(i + 2)) { lstRowIndex.Add(i + 2); } falseMessage.AppendFormat("</br>第{0}行记录已存在,无法导入!", i + 1); error++; continue; } if (!string.IsNullOrWhiteSpace(dutyDept)) { DataTable dtDept = deptBll.GetDataTable(string.Format("select departmentid,encode from base_department where fullname='{0}'", dutyDept)); if (dtDept.Rows.Count == 0) { //falseMessage.AppendFormat("</br>第{0}行责任单位与系统不匹配!", i + 2); //error++; //continue; } else { dutyDeptCode = dtDept.Rows[0][1].ToString(); dutyDeptId = dtDept.Rows[0][0].ToString(); } } if (!string.IsNullOrWhiteSpace(dutyUser)) { if (!string.IsNullOrWhiteSpace(dutyDeptId)) { DataTable dtUser = deptBll.GetDataTable(string.Format("select userid from base_user where organizeid='{2}' and realname='{0}' and departmentid='{1}' ", dutyUser, dutyDeptId, user.OrganizeId)); if (dtUser.Rows.Count == 0) { //falseMessage.AppendFormat("</br>第{0}行责任人与系统不匹配!", i + 2); //error++; //continue; } else { dutyUserId = dtUser.Rows[0][0].ToString(); } } else { DataTable dtUser = deptBll.GetDataTable(string.Format("select userid from base_user where organizeid='{1}' and realname='{0}' ", dutyUser, user.OrganizeId)); if (dtUser.Rows.Count == 0) { //falseMessage.AppendFormat("</br>第{0}行责任人与系统不匹配!", i + 2); //error++; //continue; } else { dutyUserId = dtUser.Rows[0][0].ToString(); } } } if (!string.IsNullOrWhiteSpace(checkDept)) { DataTable dtDept = deptBll.GetDataTable(string.Format("select departmentid,encode from base_department where fullname='{0}'", checkDept)); if (dtDept.Rows.Count == 0) { //falseMessage.AppendFormat("</br>第{0}行验收单位与系统不匹配!", i + 2); //error++; //continue; } else { checkDeptId = dtDept.Rows[0][0].ToString(); } } if (!string.IsNullOrWhiteSpace(checkUser)) { if (!string.IsNullOrWhiteSpace(checkDeptId)) { DataTable dtUser = deptBll.GetDataTable(string.Format("select userid from v_userinfo where organizeid='{2}' and realname='{0}' and departmentid='{1}' ", checkUser, checkDeptId, user.OrganizeId)); if (dtUser.Rows.Count == 0) { //falseMessage.AppendFormat("</br>第{0}行验收人与系统不匹配!", i + 2); //error++; //continue; } else { checkDeptId = dtUser.Rows[0][0].ToString(); } } else { DataTable dtUser = deptBll.GetDataTable(string.Format("select userid from v_userinfo where organizeid='{1}' and realname='{0}' ", checkUser, user.OrganizeId)); if (dtUser.Rows.Count == 0) { //falseMessage.AppendFormat("</br>第{0}行验收人与系统不匹配!", i + 2); //error++; //continue; } else { checkUserId = dtUser.Rows[0][0].ToString(); } } } result = string.IsNullOrWhiteSpace(result) ? "未完成" : result; CheckItemsEntity entity = new CheckItemsEntity { IsSend = 0, Id = Guid.NewGuid().ToString(), ItemName = itemName, Measures = measures, CheckUser = checkUser, CheckUserId = checkUserId, DutyUser = dutyUser, DutyUserId = dutyUserId, DeptCode = dutyDeptCode, DeptName = dutyDept, PlanDate = string.IsNullOrWhiteSpace(planDate) ?null:planDate.ToDateOrNull(), RealityDate = string.IsNullOrWhiteSpace(realityDate)?null:realityDate.ToDateOrNull(), CreateTime = DateTime.Now, CreateUserId = user.UserId, Remark = remark, Result = result, CheckId = checkId, SortCode = i }; bool res = saftycheckdatabll.SaveItemForm("", entity); if (res) { } else { falseMessage.AppendFormat("</br>第{0}行导入失败!", i + 1); error++; continue; //falseMessage.AppendFormat("</br>导入失败!!"); //error = dt.Rows.Count; } } count = dt.Rows.Count; message = "共有" + count + "条记录,成功导入" + (count - error) + "条,失败" + error + "条"; message += "</br>" + falseMessage; if (lstRowIndex.Count > 0) { foreach (int rowIndex in lstRowIndex) { Style style = wb.Styles[wb.Styles.Add()]; style.ForegroundColor = System.Drawing.Color.Red; style.BackgroundColor = System.Drawing.Color.Red; style.Pattern = BackgroundType.Solid; cells.Rows[rowIndex].ApplyStyle(style, new StyleFlag() { All = true }); } wb.Save(Server.MapPath("~/Resource/temp/" + fileName)); message += "<br /><a href='../../Resource/temp/" + fileName + "' target='_blank'>下载附件,查看详情</a>"; } } return(message); } catch (Exception ex) { return(ex.Message); } }
public ActionResult GetItemFormJson(string keyValue) { CheckItemsEntity data = saftycheckdatabll.GetItemEntity(keyValue); return(ToJsonResult(data)); }