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.ZHGL.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"]; menuPower(ProNoticeId); if (!string.IsNullOrEmpty(ProNoticeId)) { var model = Funs.DB.Problem_Notice.FirstOrDefault(x => x.ProNoticeId == ProNoticeId); if (model != null) { if (model.ProType == "2") { txtProjectName.Text = BLL.UnitService.GetUnitByUnitId(model.ProjectId).UnitName; } else { txtProjectName.Text = BLL.ProjectService.GetProjectByProjectId(model.ProjectId).ProjectName; } #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 #region 加载审批记录 DataTable approveData = BLL.ProblemNoticeApprove.GetAllApproveData(ProNoticeId+"reply"); Grid_ApproveLog.DataSource = approveData; Grid_ApproveLog.DataBind(); #endregion } } //if (Types == "1") //{ // btnSave.Hidden = true; // btnSubmit.Hidden = true; //} } } private void menuPower(string ProNoticeId) { if (string.IsNullOrEmpty(ProNoticeId)) { Form_Approve.Hidden = true; } else { var model = ProblemNoticeService.GetProblemNoticeById(ProNoticeId); var approvelist = ProblemNoticeApprove.GetProblem_NoticeApproveByParentId(ProNoticeId+"reply"); var thisApprovemodel = approvelist?.Where(x => x.ApproveMan == this.CurrUser.UserId).FirstOrDefault(); if (model.State == "0" && (model.CreateUser == this.CurrUser.UserId || this.CurrUser.UserId == Const.hfnbdId || this.CurrUser.UserId == Const.sysglyId)) { Form_Approve.Hidden = true; } else if (model.State == "2" && thisApprovemodel != null) { btnSave.Hidden = true; } else { Form_Approve.Hidden = true; btnSave.Hidden = true; btnSubmit.Hidden = true; } } } #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 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); // 如果实体对象为空,说明数据有误 if (newModel == null) { ShowNotify("数据有误,请刷新页面", MessageBoxIcon.Error); return; } this.SaveDetail(); if (type == Const.BtnSubmit) { ProblemNoticeService.ReplyApprove(ProNoticeId, this.CurrUser.UserId, Boolean.Parse(rblIsAgree.SelectedValue), txtApproveIdea.Text); BLL.LogService.AddSys_Log(this.CurrUser, newModel.ProCode, newModel.ProNoticeId, BLL.Const.ProblemReplyManagerMenuId, BLL.Const.BtnModify); ShowNotify("回复成功。", MessageBoxIcon.Success); } else { ShowNotify("保存成功。", MessageBoxIcon.Success); } PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference()); } /// /// 保存明细项 /// private void SaveDetail() { 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 } }