using System; using System.Collections.Generic; using System.Linq; using System.Text; using BLL; using Newtonsoft.Json.Linq; using AspNet = System.Web.UI.WebControls; namespace FineUIPro.Web.DCGL.ServerCheck { public partial class CheckRectifyEdit : PageBase { private static string proType; /// /// 主键 /// public string CheckRectifyId { get { return (string)ViewState["CheckRectifyId"]; } set { ViewState["CheckRectifyId"] = value; } } /// /// 集团服务器路径 /// public string CNCECPath = BLL.Funs.CNCECPath; //public string CNCECPath = "https://qhse.cncecoa.com/QHSE/"; /// /// 定义集合 /// private static List CheckRectifyItems = new List(); protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.GetButtonPower(); this.CheckRectifyId = Request.Params["CheckRectifyId"]; proType = Request.Params["proType"] ?? string.Empty; if (!string.IsNullOrEmpty(this.CheckRectifyId)) { var rectify = Funs.DB.DCGL_Check_CheckRectify.FirstOrDefault(x => x.CheckRectifyId == this.CheckRectifyId); if (rectify != null) { var unit = BLL.UnitService.GetUnitByUnitId(rectify.UnitId); if (unit != null) { this.lbUnitName.Text = unit.UnitName; } this.lbProjectName.Text = rectify.ProjectName; this.lbCheckRectifyCode.Text = rectify.CheckRectifyCode; if (!string.IsNullOrEmpty(rectify.IssueMan)) { this.txtIssueMan.Text = rectify.IssueMan; } if (rectify.IssueDate.HasValue) { this.txtIssueDate.Text = string.Format("{0:yyyy-MM-dd}", rectify.IssueDate); } if (rectify.HandleState == BLL.Const.State_3) { this.btnSave.Hidden = true; this.btnSaveUp.Hidden = true; } CheckRectifyItems = (from x in Funs.DB.View_DCGL_CheckRectifyListFromSUB where x.CheckRectifyId == this.CheckRectifyId orderby x.SortIndex select x).ToList(); Grid1.DataSource = CheckRectifyItems; Grid1.DataBind(); //if (CheckRectifyItems.FirstOrDefault(x => x.DangerPoint.Length > 1) == null) //{ //this.Grid1.Columns[1].Hidden = true; //this.Grid1.Columns[2].Hidden = true; //} } } } } /// /// 获取整改前图片(放于Img中) /// /// /// protected string ConvertImageUrlByImage(object id) { string url = string.Empty; if (id != null) { var attachFile = Funs.DB.AttachFile.FirstOrDefault(x => x.ToKeyId == id.ToString()); if (attachFile != null) { CNCECPath = !string.IsNullOrWhiteSpace(CNCECPath) ? CNCECPath : "https://qhse.cncecoa.com/QHSE/"; url = BLL.UploadAttachmentService.ShowImage(CNCECPath, attachFile.AttachUrl); } } return url; } /// /// 保存按钮 /// /// /// protected void btnSave_Click(object sender, EventArgs e) { this.SavaData(BLL.Const.BtnSave); } /// /// 保存并提交 /// /// /// protected void btnSaveUp_Click(object sender, EventArgs e) { this.SavaData(BLL.Const.BtnSaveUp); } /// /// 保存数据方法 /// /// private void SavaData(string type) { jerqueSaveList(); foreach (var item in CheckRectifyItems) { var newCheckNoticeItem = BLL.DCGLCheckNoticeItemService.GetCheckNoticeItemByCheckNoticeItemId(item.NoticeItemId); if (newCheckNoticeItem != null) { newCheckNoticeItem.Situation = item.Situation; BLL.DCGLCheckNoticeItemService.UpdateCheckNoticeItem(newCheckNoticeItem); } var newCheckRectifyItem = BLL.DCGLCheckRectifyItemService.GetCheckRectifyItemByCheckRectifyItemId(item.CheckRectifyItemId); if (newCheckRectifyItem != null) { newCheckRectifyItem.RealEndDate = item.RealEndDate; newCheckRectifyItem.OrderEndPerson = item.OrderEndPerson; //newCheckRectifyItem.Verification = item.Verification; BLL.DCGLCheckRectifyItemService.UpdateCheckRectifyItem(newCheckRectifyItem); } } var newCheckRectify = BLL.DCGLCheckRectifyService.GetCheckRectifyByCheckRectifyId(this.CheckRectifyId); if (newCheckRectify != null && newCheckRectify.HandleState != BLL.Const.State_3) { newCheckRectify.HandleState = BLL.Const.State_2; //待上报 BLL.DCGLCheckRectifyService.UpdateCheckRectify(newCheckRectify); } if (type == BLL.Const.BtnSaveUp) { //string code = CNCECHSSEGetWebService.UpReportDCGlCheck_CheckRectify(newCheckRectify.CheckRectifyId, this.CurrUser); string code = CNCECHSSEGetWebService.UpDCGlCheck_CheckRectify(newCheckRectify.CheckRectifyId, this.CurrUser); if (code == "1") { ShowNotify("同步成功!", MessageBoxIcon.Success); PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference()); return; } else { Alert.ShowInParent("同步异常,请退出后重试!", MessageBoxIcon.Error); } } BLL.LogService.AddSys_Log(this.CurrUser, string.Empty, string.Empty, BLL.Const.DCGLCheckRectifyMenuId, BLL.Const.BtnModify); PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference()); } /// /// 保存集合 /// private void jerqueSaveList() { JArray mergedData = Grid1.GetMergedData(); foreach (JObject mergedRow in mergedData) { string status = mergedRow.Value("status"); JObject values = mergedRow.Value("values"); string checkRectifyItemId = values.Value("CheckRectifyItemId").ToString(); var item = CheckRectifyItems.FirstOrDefault(e => e.CheckRectifyItemId == checkRectifyItemId); if (item != null) { item.OrderEndPerson = values.Value("OrderEndPerson").ToString(); item.RealEndDate = Funs.GetNewDateTime(values.Value("RealEndDate").ToString()); //item.Verification = values.Value("Verification").ToString(); item.Situation = values.Value("Situation").ToString(); } } } #region 权限设置 /// /// 权限按钮设置 /// private void GetButtonPower() { var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.DCGLCheckRectifyMenuId); if (buttonList.Count() > 0) { if (buttonList.Contains(BLL.Const.BtnSave)) { this.btnSave.Hidden = false; if (proType == "1") { this.btnSaveUp.Hidden = true; } else { this.btnSaveUp.Hidden = false; } } } } #endregion #region 关闭按钮事件 /// /// 关闭按钮事件 /// /// /// protected void btnClose_Click(object sender, EventArgs e) { PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference()); } #endregion #region 导出 /// /// 导出按钮 /// /// /// protected void btnOutExcel_Click(object sender, EventArgs e) { Response.ClearContent(); var unitProjectName = $"{this.lbUnitName.Text}{this.lbProjectName.Text}"; string filename = Funs.GetNewFileName(); Response.AddHeader("content-disposition", "attachment; filename=" + System.Web.HttpUtility.UrlEncode(unitProjectName + "隐患问题表" + filename, System.Text.Encoding.UTF8) + ".xls"); Response.ContentType = "application/excel"; Response.ContentEncoding = System.Text.Encoding.UTF8; this.Grid1.PageSize = this.Grid1.RecordCount; //this.BindGrid(); Response.Write(GetGridTableHtml(Grid1)); Response.End(); } /// /// 导出方法 /// /// /// private string GetGridTableHtml(Grid grid) { StringBuilder sb = new StringBuilder(); sb.Append(""); sb.Append(""); sb.Append(""); foreach (GridColumn column in grid.Columns) { if (column.ColumnID != "ckbIsSelected" && column.ColumnID != "Punish" && column.ColumnID != "Del" && column.ColumnID != "CheckRectifyItemId") { sb.AppendFormat("", column.HeaderText); } } sb.Append(""); foreach (GridRow row in grid.Rows) { sb.Append(""); foreach (GridColumn column in grid.Columns) { if (column.ColumnID != "ckbIsSelected" && column.ColumnID != "Punish" && column.ColumnID != "Del" && column.ColumnID != "CheckRectifyItemId") { string html = row.Values[column.ColumnIndex].ToString(); if (column.ColumnID == "tfPageIndex") { html = (row.FindControl("lblPageIndex") as AspNet.Label).Text; } if (column.ColumnID == "tfRiskExists") { html = (row.FindControl("lbRiskExists") as AspNet.Label).Text; } if (column.ColumnID == "tfImageUrl1") { html = (row.FindControl("lbImageUrl1") as AspNet.Label).Text; } sb.AppendFormat("", html); } } sb.Append(""); } sb.Append("
{0}
{0}
"); return sb.ToString(); } #endregion } }