using BLL; using Model; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; using System.Web; namespace FineUIPro.Web.OfficeCheck.Check { public partial class RectifyEdit : PageBase { #region 定义项 /// /// 检查Id /// public string CheckNoticeId { get { return (string)ViewState["CheckNoticeId"]; } set { ViewState["CheckNoticeId"] = value; } } /// /// 定义集合 /// public static List rectifyItemLists = new List(); #endregion #region 加载 /// /// 加载 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string type = Request.Params["type"]; if (type == "1") { this.btnSave.Hidden = true; this.btnAdd.Hidden = true; this.btnSubmit.Hidden = true; this.Grid1.Columns[11].Hidden = true; } this.CheckNoticeId = Request.Params["CheckNoticeId"]; var getRectify = ProjectSupervision_RectifyService.GetRectifyByCheckNoticeId(this.CheckNoticeId); if (getRectify != null) { SetDrop(getRectify.ProjectId); this.hdRectifyNoticesId.Text = getRectify.RectifyId; if (!string.IsNullOrEmpty(getRectify.ProjectId)) { this.drpProjectId.SelectedValue = getRectify.ProjectId; } if (!string.IsNullOrEmpty(getRectify.CheckManIds)) { this.drpCheckMan.SelectedValueArray = getRectify.CheckManIds.Split(','); } this.txtCheckPerson.Text = getRectify.CheckManNames; this.txtRectifyNoticesCode.Text = getRectify.RectifyCode; this.txtCheckedDate.Text = getRectify.CheckedDate.ToString(); //if (!string.IsNullOrEmpty(getRectify.HiddenHazardType)) //{ // this.drpHiddenHazardType.SelectedValue = getRectify.HiddenHazardType; //} if (!string.IsNullOrEmpty(getRectify.SignPerson)) { this.drpSignPerson.SelectedValue = getRectify.SignPerson; } if (getRectify.States == Const.State_1 || getRectify.States == Const.State_2) { this.btnSure.Hidden = false; } } else { var getCheckNotice = CheckNoticeService.GetCheckNoticeById(this.CheckNoticeId); if (getCheckNotice != null) { SetDrop(getCheckNotice.SubjectProjectId); if (!string.IsNullOrEmpty(getCheckNotice.SubjectProjectId)) { this.drpProjectId.SelectedValue = getCheckNotice.SubjectProjectId; } if (!string.IsNullOrEmpty(getCheckNotice.CheckTeamLeader)) { this.drpCheckMan.SelectedValueArray = getCheckNotice.CheckTeamLeader.Split(','); } var getTeam = CheckTeamService.GetCheckTeamListByCheckNoticeId(this.CheckNoticeId); foreach (var item in getTeam) { this.txtCheckPerson.Text += item.UserName + "、"; } string perfix = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + "-"; this.txtRectifyNoticesCode.Text = BLL.SQLHelper.RunProcNewId("SpGetNewCode3", "dbo.ProjectSupervision_Rectify", "RectifyCode", perfix); } this.txtCheckedDate.Text = string.Format("{0:yyyy-MM-dd}", DateTime.Now); } BindGrid(); rectifyItemLists.Clear(); } } private void SetDrop(string projectId) { //受检项目 BLL.ProjectService.InitAllProjectDropDownList(this.drpProjectId, true); this.drpProjectId.SelectedValue = projectId; ///安全经理 BLL.Person_PersonsService.InitFlowOperateControlUserDropDownList(this.drpSignPerson, projectId, Const.UnitId_SEDIN, true); ///检察人员 BLL.Person_PersonsService.InitUserUnitIdDepartIdDropDownList(this.drpCheckMan, Const.UnitId_SEDIN, string.Empty, true); } /// /// 绑定明细 /// public void BindGrid() { string strSql = string.Empty; List listStr = new List(); if (Funs.DB.ProjectSupervision_RectifyItem.FirstOrDefault(x => x.RectifyId == this.hdRectifyNoticesId.Text) != null) { strSql = @"select RectifyItemId,WrongContent,Requirement,LimitTime,RectifyResults,IsRectify,HiddenHazardType ,null as CheckReportItemId, RectifyItemId AS FileUrlId from ProjectSupervision_RectifyItem where RectifyId = @RectifyId"; listStr.Add(new SqlParameter("@RectifyId", this.hdRectifyNoticesId.Text)); } else { strSql = @"select newid() as RectifyItemId,UnConformItem as WrongContent,null as Requirement,null as LimitTime, null as RectifyResults,0 as IsRectify ,'1' as HiddenHazardType,item.CheckReportItemId,item.CheckReportItemId AS FileUrlId from ProjectSupervision_CheckReportItem as item left join ProjectSupervision_CheckReport as Report on item.CheckReportId=Report.CheckReportId where Report.CheckNoticeId = @CheckNoticeId"; listStr.Add(new SqlParameter("@CheckNoticeId", this.CheckNoticeId)); } SqlParameter[] parameter = listStr.ToArray(); DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter); var table = this.GetPagedDataTable(Grid1, tb); Grid1.DataSource = table; Grid1.DataBind(); } #endregion #region 添加按钮 protected void btnAdd_Click(object sender, EventArgs e) { addViewTestPlanTrainingList(); Model.ProjectSupervision_RectifyItem notice = new Model.ProjectSupervision_RectifyItem(); notice.RectifyItemId = SQLHelper.GetNewID(); rectifyItemLists.Add(notice); //将gd数据保存在list中 Grid1.DataSource = rectifyItemLists; Grid1.DataBind(); } private void addViewTestPlanTrainingList() { rectifyItemLists.Clear(); var data = Grid1.GetMergedData(); if (data != null) { foreach (JObject mergedRow in Grid1.GetMergedData()) { int i = mergedRow.Value("index"); JObject values = mergedRow.Value("values"); string wrongContent = values.Value("WrongContent"); string rectifyNoticesItemId = values.Value("RectifyItemId"); string requirement = values.Value("Requirement"); string rectifyResults = values.Value("RectifyResults"); TextBox txtlimitTim = (TextBox)Grid1.Rows[i].FindControl("txtLimitTimes"); var item = new ProjectSupervision_RectifyItem(); item.RectifyItemId = rectifyNoticesItemId; item.RectifyId = hdRectifyNoticesId.Text.Trim(); item.WrongContent = wrongContent; item.Requirement = requirement; item.LimitTime = Funs.GetNewDateTime(txtlimitTim.Text); item.RectifyResults = rectifyResults; DropDownList drpIsRect = (DropDownList)Grid1.Rows[i].FindControl("drpIsRectify"); item.IsRectify = Convert.ToBoolean(drpIsRect.SelectedValue); DropDownList drpHiddenHazardType = (DropDownList)Grid1.Rows[i].FindControl("drpHiddenHazardTypeify"); item.HiddenHazardType = drpHiddenHazardType.SelectedValue; rectifyItemLists.Add(item); } } } #endregion #region 整改单明细数据验证 ///// ///// 整改单明细数据验证 ///// ///// //private bool validate() //{ // bool res = false; // string err = string.Empty; // foreach (JObject mergedRow in Grid1.GetMergedData()) // { // int i = mergedRow.Value("index"); // JObject values = mergedRow.Value("values"); // string WrongContent = values.Value("WrongContent"); // string Requirement = values.Value("Requirement"); // if (string.IsNullOrWhiteSpace(WrongContent) || string.IsNullOrWhiteSpace(Requirement)) // { // err += "第" + (i + 1).ToString() + "行:"; // if (string.IsNullOrWhiteSpace(WrongContent)) // { // err += "请输入具体位置及隐患内容,"; // } // if (string.IsNullOrWhiteSpace(Requirement)) // { // err += "请输入整改要求,"; // } // err = err.Substring(0, err.LastIndexOf(",")); // err += "!"; // } // } // if (Grid1.Rows.Count > 0) // { // if (!string.IsNullOrWhiteSpace(err)) // { // Alert.ShowInTop(err, MessageBoxIcon.Warning); // } // else // { // res = true; // } // } // else // { // Alert.ShowInTop("请整改单内容!", MessageBoxIcon.Warning); // } // return res; //} #endregion #region Grid行点击事件 protected void Grid1_RowCommand(object sender, GridCommandEventArgs e) { string itemId = Grid1.DataKeys[e.RowIndex][0].ToString(); if (e.CommandName == "AttachUrl") { if (Funs.DB.ProjectSupervision_RectifyItem.FirstOrDefault(x => x.RectifyItemId == itemId) != null) { PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("~/AttachFile/webuploader.aspx?toKeyId={0}&path=FileUpload/Rectify&menuId={1}&type=0&strParam=1", itemId, BLL.Const.CheckInfoMenuId))); } else { string checkReportItemId = Grid1.Rows[e.RowIndex].Values[12].ToString(); PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("~/AttachFile/webuploader.aspx?toKeyId={0}&path=FileUpload/Rectify&menuId={1}&type=0&strParam=1", checkReportItemId, BLL.Const.CheckInfoMenuId))); } } if (e.CommandName == "delete") { rectifyItemLists.Remove(rectifyItemLists.FirstOrDefault(p => p.RectifyItemId == itemId)); Grid1.DataSource = rectifyItemLists; Grid1.DataBind(); } if (e.CommandName == "ReAttachUrl") { PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("~/AttachFile/webuploader.aspx?toKeyId={0}&path=FileUpload/Rectify&menuId={1}&type=0&strParam=2", itemId, BLL.Const.CheckInfoMenuId))); } } #endregion #region Grid行绑定事件 protected void Grid1_RowDataBound(object sender, GridRowEventArgs e) { //DataRowView row = e.DataItem as DataRowView; for (int i = 0; i < this.Grid1.Rows.Count; i++) { System.Web.UI.WebControls.DropDownList drpIsRectify = (System.Web.UI.WebControls.DropDownList)(this.Grid1.Rows[i].FindControl("drpIsRectify")); HiddenField hdIsRectify = (HiddenField)(this.Grid1.Rows[i].FindControl("hdIsRectify")); if (!string.IsNullOrEmpty(hdIsRectify.Text)) { if (hdIsRectify.Text == "True") { drpIsRectify.SelectedValue = "true"; } else { drpIsRectify.SelectedValue = "false"; } } System.Web.UI.WebControls.DropDownList drpHiddenHazardType = (System.Web.UI.WebControls.DropDownList)(this.Grid1.Rows[i].FindControl("drpHiddenHazardType")); HiddenField hdHiddenHazardType = (HiddenField)(this.Grid1.Rows[i].FindControl("hdHiddenHazardType")); if (!string.IsNullOrEmpty(hdHiddenHazardType.Text)) { drpHiddenHazardType.SelectedValue = hdHiddenHazardType.Text; } } } #endregion #region 时间转换 /// /// 时间转换 /// /// /// public string ConvertDate(object date) { if (!Convert.IsDBNull(date)) { return string.Format("{0:yyyy-MM-dd}", Convert.ToDateTime(date)); } else { return null; } } #endregion #region 保存 protected void btnSave_Click(object sender, EventArgs e) { SaveRectifyNotices("save"); } /// /// 提交 /// /// /// protected void btnSubmit_Click(object sender, EventArgs e) { SaveRectifyNotices("submit"); } /// /// 保存方法 /// /// private void SaveRectifyNotices(string saveType) { if (this.drpSignPerson.SelectedValue == BLL.Const._Null) { Alert.ShowInTop("项目安全经理不能为空!", MessageBoxIcon.Warning); return; } Model.ProjectSupervision_Rectify Notices = new Model.ProjectSupervision_Rectify(); Notices.RectifyCode = this.txtRectifyNoticesCode.Text.Trim(); if (this.drpProjectId.SelectedValue != BLL.Const._Null) { Notices.ProjectId = this.drpProjectId.SelectedValue; } if (this.drpCheckMan.SelectedValue != BLL.Const._Null) { string str = GetStringByArray(this.drpCheckMan.SelectedValueArray); Notices.CheckManIds = str; } if (!string.IsNullOrEmpty(txtCheckPerson.Text)) { Notices.CheckManNames = txtCheckPerson.Text; } if (!string.IsNullOrEmpty(this.txtCheckedDate.Text.Trim())) { Notices.CheckedDate = Convert.ToDateTime(this.txtCheckedDate.Text.Trim()); } //if (this.drpHiddenHazardType.SelectedValue != BLL.Const._Null) //{ // Notices.HiddenHazardType = this.drpHiddenHazardType.SelectedValue; //} if (this.drpSignPerson.SelectedValue != BLL.Const._Null) { Notices.SignPerson = this.drpSignPerson.SelectedValue; } if (saveType == "submit") { Notices.States = BLL.Const.State_1; } else { Notices.States = BLL.Const.State_0; } if (!string.IsNullOrEmpty(this.hdRectifyNoticesId.Text)) { Notices.RectifyId = this.hdRectifyNoticesId.Text; ProjectSupervision_RectifyService.UpdateRectify(Notices); } else { Notices.CheckNoticeId = this.CheckNoticeId; Notices.RectifyId = SQLHelper.GetNewID(typeof(Model.ProjectSupervision_Rectify)); ProjectSupervision_RectifyService.AddRectify(Notices); this.hdRectifyNoticesId.Text = Notices.RectifyId; } saveNoticesItemDetail();//增加明细 ShowNotify("保存成功!", MessageBoxIcon.Success); PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference()); } /// /// 保存明细 /// public void saveNoticesItemDetail() { int j = 0; var data = Grid1.GetMergedData(); if (data != null) { foreach (JObject mergedRow in Grid1.GetMergedData()) { int i = mergedRow.Value("index"); JObject values = mergedRow.Value("values"); string wrongContent = values.Value("WrongContent"); string rectifyNoticesItemId = values.Value("RectifyItemId"); string requirement = values.Value("Requirement"); string rectifyResults = values.Value("RectifyResults"); System.Web.UI.WebControls.TextBox txtlimitTim = (System.Web.UI.WebControls.TextBox)Grid1.Rows[i].FindControl("txtLimitTimes"); System.Web.UI.WebControls.DropDownList drpIsRect = (System.Web.UI.WebControls.DropDownList)Grid1.Rows[i].FindControl("drpIsRectify"); System.Web.UI.WebControls.DropDownList drpHiddenHazardType = (System.Web.UI.WebControls.DropDownList)Grid1.Rows[i].FindControl("drpHiddenHazardType"); string limitTime = txtlimitTim.Text.Trim(); Model.ProjectSupervision_RectifyItem rectifyNoticesItem = Funs.DB.ProjectSupervision_RectifyItem.FirstOrDefault(e => e.RectifyItemId == rectifyNoticesItemId); if (rectifyNoticesItem != null) { rectifyNoticesItem.RectifyItemId = rectifyNoticesItemId; rectifyNoticesItem.RectifyId = this.hdRectifyNoticesId.Text.Trim(); rectifyNoticesItem.WrongContent = wrongContent.Trim(); rectifyNoticesItem.Requirement = requirement.Trim(); rectifyNoticesItem.LimitTime = Funs.GetNewDateTime(limitTime); rectifyNoticesItem.RectifyResults = rectifyResults.Trim(); rectifyNoticesItem.HiddenHazardType = drpHiddenHazardType.SelectedValue; rectifyNoticesItem.IsRectify = Convert.ToBoolean(drpIsRect.SelectedValue); Funs.DB.SubmitChanges(); if (rectifyNoticesItem.IsRectify == true) { j++; } } else { var item = new ProjectSupervision_RectifyItem(); item.RectifyItemId = rectifyNoticesItemId; item.RectifyId = this.hdRectifyNoticesId.Text.Trim(); item.WrongContent = wrongContent.Trim(); item.Requirement = requirement.Trim(); item.LimitTime = Funs.GetNewDateTime(limitTime); item.RectifyResults = rectifyResults.Trim(); item.HiddenHazardType = drpHiddenHazardType.SelectedValue; item.IsRectify = Convert.ToBoolean(drpIsRect.SelectedValue); Funs.DB.ProjectSupervision_RectifyItem.InsertOnSubmit(item); Funs.DB.SubmitChanges(); string hdCheckReportItemId = values.Value("CheckReportItemId"); var getAtt = Funs.DB.AttachFile.FirstOrDefault(x => x.ToKeyId == hdCheckReportItemId + "#1"); if (getAtt != null) { UploadFileService.SaveAttachUrl(getAtt.AttachSource, getAtt.AttachUrl, BLL.Const.CheckInfoMenuId, item.RectifyItemId + "#1"); } } } if (j == data.Count) { var re = BLL.ProjectSupervision_RectifyService.GetRectifyById(this.hdRectifyNoticesId.Text.Trim()); if (re != null) { re.States = BLL.Const.State_3; BLL.ProjectSupervision_RectifyService.UpdateRectify(re); } } } } #endregion #region 格式化字符串 private string GetStringByArray(string[] array) { string str = string.Empty; foreach (var item in array) { if (item != BLL.Const._Null) { str += item + ","; } } if (!string.IsNullOrEmpty(str)) { str = str.Substring(0, str.LastIndexOf(",")); } return str; } #endregion #region DropDownList下拉选择 protected void drpCheckMan_SelectedIndexChanged(object sender, EventArgs e) { string[] array = this.drpCheckMan.SelectedValueArray; List str = new List(); foreach (var item in array) { if (item != BLL.Const._Null) { str.Add(item); } } this.drpCheckMan.SelectedValueArray = str.ToArray(); } #endregion protected void btnSure_Click(object sender, EventArgs e) { var getRectify = ProjectSupervision_RectifyService.GetRectifyByCheckNoticeId(this.CheckNoticeId); if (getRectify != null) { saveNoticesItemDetail();//增加明细 ShowNotify("保存成功!", MessageBoxIcon.Success); PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference()); } } /// /// 获取整改前图片(放于Img中) /// /// /// protected string ConvertImageUrlByImage(object FileUrlId) { string url = string.Empty; if (FileUrlId != null) { var RectifyNoticesItem = BLL.AttachFileService.GetAttachFileByToKeyId(FileUrlId.ToString() + "#1"); if (RectifyNoticesItem != null) { url = HttpUtility.HtmlDecode(BLL.UploadAttachmentService.ShowImage("../../", RectifyNoticesItem.AttachUrl)); } } return url; } /// /// 获取整改后图片 /// /// /// protected string ConvertImageUrlByImage2(object FileUrlId) { string url = string.Empty; if (FileUrlId != null) { var RectifyNoticesItem = BLL.AttachFileService.GetAttachFileByToKeyId(FileUrlId.ToString() + "#2"); if (RectifyNoticesItem != null) { url = BLL.UploadAttachmentService.ShowImage("../../", RectifyNoticesItem.AttachUrl); } } return url; } } }