using BLL; using Model; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Data; using System.Data.Linq.SqlClient; using System.Data.SqlClient; using System.Linq; using System.Reflection; namespace FineUIPro.Web.Customization.CNCCG.HSSE.Problem { public partial class ProblemReplyManagerEdit : PageBase { #region 定义项 /// /// 主键 /// public string ProNoticeId { get { return (string)ViewState["ProNoticeId"]; } set { ViewState["ProNoticeId"] = value; } } /// ///受检单位负责人签名附件路径 /// public string SignatureUrl { get { return (string)ViewState["SignatureUrl"]; } set { ViewState["SignatureUrl"] = value; } } /// /// 检查组签名附件路径 /// public string SignatureUrl1 { get { return (string)ViewState["SignatureUrl1"]; } set { ViewState["SignatureUrl1"] = value; } } /// /// 复查人签名附件路径 /// public string SignatureUrl2 { get { return (string)ViewState["SignatureUrl2"]; } set { ViewState["SignatureUrl2"] = value; } } /// /// 分管领导签名附件路径 /// public string SignatureUrl3 { get { return (string)ViewState["SignatureUrl3"]; } set { ViewState["SignatureUrl3"] = value; } } /// /// 类型 1查看 /// public string Types { get { return (string)ViewState["Types"]; } set { ViewState["Types"] = value; } } /// /// 定义集合 /// private static List details = new List(); #endregion protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { btnClose.OnClientClick = ActiveWindow.GetHideReference(); ProNoticeId = Request.Params["ProNoticeId"]; Types = Request.Params["Type"]; if (!string.IsNullOrEmpty(ProNoticeId)) { var model = Funs.DB.Problem_Notice.FirstOrDefault(x => x.ProNoticeId == ProNoticeId); if (model != null) { txtProjectName.Text = BLL.ProjectService.GetProjectByProjectId(model.ProjectId).ProjectName; //受检单位负责人签名 if (!string.IsNullOrEmpty(model.TestedUnitManSignature)) { this.SignatureUrl = model.TestedUnitManSignature; this.Image2.ImageUrl = "~/" + this.SignatureUrl; } txtTestedUnitManOpinions.Text = model.TestedUnitManOpinions; //复查人签名 if (!string.IsNullOrEmpty(model.ReviewSignature)) { this.SignatureUrl2 = model.ReviewSignature; this.Image3.ImageUrl = "~/" + this.SignatureUrl2; } txtReviewOpinions.Text = model.ReviewOpinions; //分管领导签名 if (!string.IsNullOrEmpty(model.LeaderSignature)) { this.SignatureUrl3 = model.LeaderSignature; this.Image4.ImageUrl = "~/" + this.SignatureUrl3; } txtLeaderOpinions.Text = model.LeaderOpinions; //检查组签名 if (!string.IsNullOrEmpty(model.InspectionUnitSignature)) { this.SignatureUrl1 = model.InspectionUnitSignature; this.Image1.ImageUrl = "~/" + this.SignatureUrl1; } txtInspectionUnitOpinions.Text = model.InspectionUnitOpinions; //根据状态隐藏字段 if (model.State=="3") { sjdwFr.Hidden = false; fileSignature.Hidden = true; txtTestedUnitManOpinions.Readonly = true; fcrFr.Hidden = false; } else if (model.State== "4") { sjdwFr.Hidden = false; fileSignature.Hidden = true; txtTestedUnitManOpinions.Readonly = true; fcrFr.Hidden = false; fileSignature2.Hidden = true; txtReviewOpinions.Readonly = true; ffgldFr.Hidden = false; } else if (model.State=="5") { sjdwFr.Hidden = false; fileSignature.Hidden = true; txtTestedUnitManOpinions.Readonly = true; fcrFr.Hidden = false; fileSignature2.Hidden = true; txtReviewOpinions.Readonly = true; ffgldFr.Hidden = false; fileSignature3.Hidden = true; txtLeaderOpinions.Readonly = true; jczFr.Hidden = false; } #region 加载检查项 var strSql = @"select F.ProNoticeCId,F.QueDescribe,F.ReSituation,F.QueType as QueTypeName,F.RiskLevel as RiskLevelName ,F.SortIndex from Problem_Notice_C F where ProNoticeId='" + model.ProNoticeId + "' order by SortIndex"; List listStr = new List(); SqlParameter[] parameter = listStr.ToArray(); DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter); Grid1.RecordCount = tb.Rows.Count; var table = this.GetPagedDataTable(Grid1, tb); details = GetList(table); Grid1.DataSource = table; Grid1.DataBind(); #endregion } } if (Types == "1") { btnSave.Hidden = true; btnSubmit.Hidden = true; fileSignature.Hidden = true; fileSignature1.Hidden = true; fileSignature2.Hidden = true; fileSignature3.Hidden = true; sjdwFr.Hidden = false; fcrFr.Hidden = false; ffgldFr.Hidden = false; jczFr.Hidden = false; } } } #region datable转换list public class ProblemNoticeItems { public string ProNoticeCId { get; set; } public string QueDescribe { get; set; } public string Requirements { get; set; } public string QueTypeName { get; set; } public string RiskLevelName { get; set; } public DateTime? CheckDatetime { get; set; } public string ReDay { get; set; } public int SortIndex { get; set; } } public List GetList(DataTable table) { List list = new List(); T t = default(T); PropertyInfo[] propertypes = null; string tempName = string.Empty; foreach (DataRow row in table.Rows) { t = Activator.CreateInstance(); propertypes = t.GetType().GetProperties(); foreach (PropertyInfo pro in propertypes) { tempName = pro.Name; if (table.Columns.Contains(tempName)) { object value = row[tempName]; if (!value.ToString().Equals("")) { pro.SetValue(t, value, null); } } } list.Add(t); } return list.Count == 0 ? null : list; } #endregion #region 上传签名 /// /// 受检单位负责人签名上传签名 /// /// /// protected void btnSignature_Click(object sender, EventArgs e) { if (fileSignature.HasFile) { string fileName = fileSignature.ShortFileName; if (!ValidateFileType(fileName)) { ShowNotify("无效的文件类型!", MessageBoxIcon.Warning); return; } this.SignatureUrl = UploadFileService.UploadAttachment(Funs.RootPath, this.fileSignature, this.SignatureUrl, UploadFileService.ProblemFilePath); this.Image2.ImageUrl = "~/" + this.SignatureUrl; } } /// /// 检查组签名上传签名 /// /// /// protected void btnSignature_Click1(object sender, EventArgs e) { if (fileSignature1.HasFile) { string fileName = fileSignature1.ShortFileName; if (!ValidateFileType(fileName)) { ShowNotify("无效的文件类型!", MessageBoxIcon.Warning); return; } this.SignatureUrl1 = UploadFileService.UploadAttachment(Funs.RootPath, this.fileSignature1, this.SignatureUrl1, UploadFileService.ProblemFilePath); this.Image1.ImageUrl = "~/" + this.SignatureUrl1; } } /// /// 复查人签名 /// /// /// protected void btnSignature_Click2(object sender, EventArgs e) { if (fileSignature2.HasFile) { string fileName = fileSignature2.ShortFileName; if (!ValidateFileType(fileName)) { ShowNotify("无效的文件类型!", MessageBoxIcon.Warning); return; } this.SignatureUrl2 = UploadFileService.UploadAttachment(Funs.RootPath, this.fileSignature2, this.SignatureUrl2, UploadFileService.ProblemFilePath); this.Image3.ImageUrl = "~/" + this.SignatureUrl2; } } /// /// 分管领导签名 /// /// /// protected void btnSignature_Click3(object sender, EventArgs e) { if (fileSignature3.HasFile) { string fileName = fileSignature3.ShortFileName; if (!ValidateFileType(fileName)) { ShowNotify("无效的文件类型!", MessageBoxIcon.Warning); return; } this.SignatureUrl3 = UploadFileService.UploadAttachment(Funs.RootPath, this.fileSignature3, this.SignatureUrl3, UploadFileService.ProblemFilePath); this.Image4.ImageUrl = "~/" + this.SignatureUrl3; } } #endregion #region 检查项 protected void Grid1_RowCommand(object sender, GridCommandEventArgs e) { string itemId = Grid1.DataKeys[e.RowIndex][0].ToString(); if (e.CommandName == "attchUrlSee") { PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("~/AttachFile/webuploader.aspx?toKeyId={0}&path=FileUpload/Problem&menuId={1}&type=-1", itemId, BLL.Const.ProblemNoticeManagerMenuId))); } else if (e.CommandName == "attchUrl") { if (Types == "1") { //整改后照片编辑 PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("~/AttachFile/webuploader.aspx?toKeyId={0}&path=FileUpload/Problem&menuId={1}&type=-1", itemId + "ZGH", BLL.Const.ProblemNoticeManagerMenuId))); } else { //整改后照片编辑 PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("~/AttachFile/webuploader.aspx?toKeyId={0}&path=FileUpload/Problem&menuId={1}&type=0", itemId + "ZGH", BLL.Const.ProblemNoticeManagerMenuId))); } } } #endregion #region 保存 /// /// 保存 /// protected void btnSave_Click(object sender, EventArgs e) { this.SaveData(Const.BtnSave); } /// /// 提交 /// /// /// protected void btnSubmit_Click(object sender, EventArgs e) { this.SaveData(Const.BtnSubmit); } /// /// 保存提交方法 /// /// private void SaveData(string type) { var newModel = Funs.DB.Problem_Notice.FirstOrDefault(x => x.ProNoticeId == ProNoticeId); Model.Problem_Notice model = new Model.Problem_Notice { State = newModel.State }; if (type == Const.BtnSubmit) { model.State =(Convert.ToInt32(newModel.State) + 1).ToString(); #region 根据状态判断签名是否上传 if (newModel.State=="2") { if (string.IsNullOrEmpty(this.SignatureUrl)) { ShowNotify("受检单位负责人签名不能为空!", MessageBoxIcon.Warning); return; } } else if (newModel.State == "3") { if (string.IsNullOrEmpty(this.SignatureUrl2)) { ShowNotify("复查人签名不能为空!", MessageBoxIcon.Warning); return; } } else if (newModel.State == "4") { if (string.IsNullOrEmpty(this.SignatureUrl3)) { ShowNotify("分管领导签名不能为空!", MessageBoxIcon.Warning); return; } } else if (newModel.State == "5") { if (string.IsNullOrEmpty(this.SignatureUrl1)) { ShowNotify("检查组签名不能为空!", MessageBoxIcon.Warning); return; } } #endregion } //受检单位负责人签名 if (!string.IsNullOrEmpty(this.SignatureUrl)) { model.TestedUnitManSignature = SignatureUrl; model.TestedUnitManDatetime = DateTime.Now; } model.TestedUnitManOpinions = txtTestedUnitManOpinions.Text; //复查人签名 if (!string.IsNullOrEmpty(this.SignatureUrl2)) { model.ReviewSignature = SignatureUrl2; model.ReviewDatetime = DateTime.Now; } model.ReviewOpinions = txtReviewOpinions.Text; //分管领导签名 if (!string.IsNullOrEmpty(this.SignatureUrl3)) { model.LeaderSignature = SignatureUrl3; model.LeaderDatetime = DateTime.Now; } model.LeaderOpinions = txtLeaderOpinions.Text; //检查组签名 if (!string.IsNullOrEmpty(this.SignatureUrl1)) { model.InspectionUnitSignature = SignatureUrl1; model.InspectionUnitDatetime = DateTime.Now; } model.InspectionUnitOpinions = txtInspectionUnitOpinions.Text; if (!string.IsNullOrEmpty(this.ProNoticeId)) { model.ProNoticeId = ProNoticeId; BLL.ProblemNoticeService.Reply(model); BLL.LogService.AddSys_Log(this.CurrUser, model.ProCode, model.ProNoticeId, BLL.Const.ProblemReplyManagerMenuId, BLL.Const.BtnModify); } else { ShowNotify("数据有误,请刷新页面", MessageBoxIcon.Error); } this.SaveDetail(model.ProNoticeId); if (type == Const.BtnSubmit) { ShowNotify("提交成功。", MessageBoxIcon.Success); } else { ShowNotify("保存成功。", MessageBoxIcon.Success); } PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference()); } /// /// 保存明细项 /// private void SaveDetail(string objId) { List detailLists = new List(); JArray teamGroupData = Grid1.GetMergedData(); foreach (JObject teamGroupRow in teamGroupData) { JObject values = teamGroupRow.Value("values"); int rowIndex = teamGroupRow.Value("index"); Model.Problem_Notice_C newDetail = new Model.Problem_Notice_C { //整改情况 ReSituation = values.Value("ReSituation"), ReSituationTime = DateTime.Now }; if (Grid1.Rows[rowIndex].DataKeys.Length > 0) { newDetail.ProNoticeCId = Grid1.Rows[rowIndex].DataKeys[0].ToString(); } //循环修改明细 BLL.ProblemNoticeService.UpdateDetail(newDetail); } } #endregion } }