using BLL; using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace FineUIPro.Web.HSSE.Hazard { public partial class ConstructionRiskEdit : PageBase { #region 定义变量 /// /// 主键 /// public string ConstructionRiskId { get { return (string)ViewState["ConstructionRiskId"]; } set { ViewState["ConstructionRiskId"] = value; } } /// /// 项目主键 /// public string ProjectId { get { return (string)ViewState["ProjectId"]; } set { ViewState["ProjectId"] = value; } } /// /// 办理类型 /// public string State { get { return (string)ViewState["State"]; } set { ViewState["State"] = value; } } /// /// 定义集合 /// private static List constructionRiskControls = new List(); #endregion #region 加载页面 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.ProjectId = this.CurrUser.LoginProjectId; this.drpHandleType.DataTextField = "Text"; this.drpHandleType.DataValueField = "Value"; this.HideOptions.Hidden = true; this.rblIsAgree.Hidden = true; this.drpHandleMan.DataTextField = "PersonName"; this.drpHandleMan.DataValueField = "PersonId"; this.InitDropDownList(); this.btnClose.OnClientClick = ActiveWindow.GetHideReference(); constructionRiskControls.Clear(); this.ConstructionRiskId = Request.Params["ConstructionRiskId"]; var constructionRisk = Funs.DB.HSSE_ConstructionRisk.FirstOrDefault(x => x.ConstructionRiskId == this.ConstructionRiskId); if (constructionRisk != null) { this.hdConstructionRiskId.Text = this.ConstructionRiskId; this.ProjectId = constructionRisk.ProjectId; this.dpDateA.Text = string.Format("{0:yyyy-MM-dd}", constructionRisk.DateA); this.dpDateZ.Text = string.Format("{0:yyyy-MM-dd}", constructionRisk.DateZ); if (!string.IsNullOrEmpty(constructionRisk.WorkAreaId)) { drpWorkArea.SelectedValue = constructionRisk.WorkAreaId; } if (!string.IsNullOrEmpty(constructionRisk.UnitId)) { drpUnit.SelectedValue = constructionRisk.UnitId; } if (!string.IsNullOrEmpty(constructionRisk.RefLicense)) { drpRefLicense.SelectedValueArray = constructionRisk.RefLicense.Split(','); this.drpRiskLevel.DataSource = BLL.ConstructionRiskListService.RiskLevelList2(); this.drpRiskLevel.DataBind(); Funs.FineUIPleaseSelect(this.drpRiskLevel); } if (!string.IsNullOrEmpty(constructionRisk.RiskLevel)) { drpRiskLevel.SelectedValue = constructionRisk.RiskLevel; } if (!string.IsNullOrEmpty(constructionRisk.ConstructionContent)) { this.txtConstructionContent.Text = HttpUtility.HtmlDecode(constructionRisk.ConstructionContent); } this.hdConstructionContentId.Text = constructionRisk.ConstructionContentId; if (!string.IsNullOrEmpty(constructionRisk.RiskLevel)) { this.drpRiskLevel.SelectedValueArray = constructionRisk.RiskLevel.Split(','); } if (!string.IsNullOrEmpty(constructionRisk.LicenseDes)) { this.drpLicenseDes.SelectedValueArray = constructionRisk.LicenseDes.Split(','); } this.hdCoordinate.Text = constructionRisk.Coordinate; constructionRiskControls = (from x in Funs.DB.HSSE_ConstructionRiskControl where x.ConstructionRiskId == this.ConstructionRiskId orderby x.ShowIndex select x).ToList(); gvApprove.DataSource = BLL.ConstructionRiskApproveService.getListData(this.ConstructionRiskId); gvApprove.DataBind(); if (!string.IsNullOrEmpty(constructionRisk.States)) { State = constructionRisk.States; } else { State = BLL.Const.ConstructionRisk_Compile; this.HideOptions.Hidden = true; this.rblIsAgree.Hidden = true; } if (State != BLL.Const.ConstructionRisk_Complete.ToString()) { drpHandleType.DataSource = BLL.ConstructionRiskListService.GetDHandleTypeByState(State); drpHandleType.DataBind(); } if (State == BLL.Const.ConstructionRisk_Compile || State == BLL.Const.ConstructionRisk_ReCompile) { this.HideOptions.Visible = false; this.rblIsAgree.Visible = false; this.drpHandleMan.Enabled = true; } else { this.HideOptions.Hidden = false; this.rblIsAgree.Hidden = false; } if (State == Const.ConstructionRisk_Audit2) { this.drpHandleMan.Enabled = false; } if (State == BLL.Const.ConstructionRisk_Complete || !string.IsNullOrEmpty(Request.Params["see"])) { this.btnSave.Visible = false; this.btnSubmit.Visible = false; this.next.Hidden = true; } } else { drpHandleType.DataSource = BLL.ConstructionRiskListService.GetDHandleTypeByState(BLL.Const.ConstructionRisk_Compile); drpHandleType.DataBind(); this.drpUnit.SelectedValue = this.CurrUser.UnitId; } drpHandleType_SelectedIndexChanged(null, null); Grid1.DataSource = constructionRiskControls; Grid1.DataBind(); } } #endregion /// /// 初始化下拉框 /// private void InitDropDownList() { ///区域下拉框 UnitWorkService.InitUnitWorkDownList(this.drpWorkArea, this.CurrUser.LoginProjectId, true); drpRefLicense.DataValueField = "LicenseTypeName"; drpRefLicense.DataTextField = "LicenseTypeName"; drpRefLicense.DataSource = (from x in Funs.DB.Base_LicenseType orderby x.LicenseTypeCode select x).ToList(); drpRefLicense.DataBind(); Funs.FineUIPleaseSelect(this.drpRefLicense); this.drpRiskLevel.DataTextField = "Text"; this.drpRiskLevel.DataValueField = "Value"; this.drpRiskLevel.DataSource = BLL.ConstructionRiskListService.RiskLevelList(); this.drpRiskLevel.DataBind(); Funs.FineUIPleaseSelect(this.drpRiskLevel); Funs.FineUIPleaseSelect(this.drpLicenseDes); UnitService.InitUnitByProjectIdUnitTypeDropDownList(this.drpUnit, this.ProjectId, Const.ProjectUnitType_2, false); } #region 提交按钮 /// /// 提交按钮 /// /// /// protected void btnSubmit_Click(object sender, EventArgs e) { if (this.drpWorkArea.SelectedValue == BLL.Const._Null) { ShowNotify("请选择主项!", MessageBoxIcon.Warning); return; } if (this.drpRiskLevel.SelectedValue == BLL.Const._Null) { ShowNotify("请选择风险等级!", MessageBoxIcon.Warning); return; } if (string.IsNullOrEmpty(this.txtConstructionContent.Text.Trim())) { ShowNotify("请选择施工内容!", MessageBoxIcon.Warning); return; } if (this.drpLicenseDes.SelectedValueArray.Length == 1 && this.drpLicenseDes.SelectedValue == BLL.Const._Null) { ShowNotify("请选择作业风险描述!", MessageBoxIcon.Warning); return; } this.SaveData(BLL.Const.BtnSubmit); PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference()); } #endregion #region 保存按钮 /// /// 保存按钮 /// /// /// protected void btnSave_Click(object sender, EventArgs e) { if (this.drpWorkArea.SelectedValue == BLL.Const._Null) { ShowNotify("请选择主项!", MessageBoxIcon.Warning); return; } if (this.drpRiskLevel.SelectedValue == BLL.Const._Null) { ShowNotify("请选择风险等级!", MessageBoxIcon.Warning); return; } if (string.IsNullOrEmpty(this.txtConstructionContent.Text.Trim())) { ShowNotify("请选择施工内容!", MessageBoxIcon.Warning); return; } if (this.drpLicenseDes.SelectedValueArray.Length == 1 && this.drpLicenseDes.SelectedValue == BLL.Const._Null) { ShowNotify("请选择作业风险描述!", MessageBoxIcon.Warning); return; } this.SaveData(BLL.Const.BtnSave); PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference()); } #endregion /// /// 保存数据 /// /// private void SaveData(string type) { Model.HSSE_ConstructionRisk newConstructionRisk = new Model.HSSE_ConstructionRisk { ProjectId = this.ProjectId, }; if (this.dpDateA.SelectedDate.HasValue) { newConstructionRisk.DateWeek = this.dpDateA.SelectedDate.Value.Year + "年" + Funs.GetWeekOfYear(this.dpDateA.SelectedDate.Value) + "周"; } if (this.drpWorkArea.SelectedValue != BLL.Const._Null) { newConstructionRisk.WorkAreaId = this.drpWorkArea.SelectedValue; } if (this.drpRiskLevel.SelectedValue != BLL.Const._Null) { newConstructionRisk.RiskLevel = drpRiskLevel.SelectedValue; } if (this.drpRefLicense.SelectedValueArray.Length == 1 && this.drpRefLicense.SelectedValue == BLL.Const._Null) { } else { string refLicense = string.Empty; foreach (var item in this.drpRefLicense.SelectedItemArray) { if (item.Value != BLL.Const._Null) { refLicense += item.Value + ","; } } if (!string.IsNullOrEmpty(refLicense)) { refLicense = refLicense.Substring(0, refLicense.Length - 1); } newConstructionRisk.RefLicense = refLicense; } if (this.drpUnit.SelectedValue != BLL.Const._Null) { newConstructionRisk.UnitId = drpUnit.SelectedValue; } newConstructionRisk.DateA = Funs.GetNewDateTime(this.dpDateA.Text.Trim()); newConstructionRisk.DateZ = Funs.GetNewDateTime(this.dpDateZ.Text.Trim()); if (this.drpLicenseDes.SelectedValueArray.Length == 1 && this.drpLicenseDes.SelectedValue == BLL.Const._Null) { } else { string licenseDes = string.Empty; foreach (var item in this.drpLicenseDes.SelectedItemArray) { if (item.Value != BLL.Const._Null) { licenseDes += item.Value + ","; } } if (!string.IsNullOrEmpty(licenseDes)) { licenseDes = licenseDes.Substring(0, licenseDes.Length - 1); } newConstructionRisk.LicenseDes = licenseDes; } newConstructionRisk.ConstructionContent = HttpUtility.HtmlEncode(this.txtConstructionContent.Text); newConstructionRisk.ConstructionContentId = this.hdConstructionContentId.Text; newConstructionRisk.Coordinate = this.hdCoordinate.Text; ////单据状态 newConstructionRisk.States = BLL.Const.State_0; //if (type == BLL.Const.BtnSubmit) //{ // newConstructionRisk.States = this.ctlAuditFlow.NextStep; //} if (type == BLL.Const.BtnSubmit) { newConstructionRisk.States = this.drpHandleType.SelectedValue; } else { Model.HSSE_ConstructionRisk ConstructionRisk1 = BLL.ConstructionRiskListService.GetConstructionRisk(ConstructionRiskId); if (ConstructionRisk1 != null) { if (string.IsNullOrEmpty(ConstructionRisk1.States)) { newConstructionRisk.States = BLL.Const.ConstructionRisk_Compile; } else { newConstructionRisk.States = ConstructionRisk1.States; } } else { newConstructionRisk.States = BLL.Const.ConstructionRisk_Compile; } } if (!string.IsNullOrEmpty(this.ConstructionRiskId)) { newConstructionRisk.ConstructionRiskId = this.ConstructionRiskId; BLL.ConstructionRiskListService.UpdateConstructionRisk(newConstructionRisk); if (type == BLL.Const.BtnSubmit) { Model.HSSE_ConstructionRiskApprove approve1 = BLL.ConstructionRiskApproveService.GetConstructionRiskApproveByConstructionRiskId(ConstructionRiskId); approve1.ApproveDate = DateTime.Now; approve1.ApproveIdea = this.txtOpinions.Text.Trim(); approve1.IsAgree = Convert.ToBoolean(this.rblIsAgree.SelectedValue); BLL.ConstructionRiskApproveService.UpdateConstructionRiskApprove(approve1); if (this.drpHandleMan.SelectedValue != BLL.Const._Null) { Model.HSSE_ConstructionRiskApprove approve = new Model.HSSE_ConstructionRiskApprove(); approve.ConstructionRiskId = newConstructionRisk.ConstructionRiskId; approve.ApproveMan = this.drpHandleMan.SelectedValue; approve.ApproveType = this.drpHandleType.SelectedValue; BLL.ConstructionRiskApproveService.AddConstructionRiskApprove(approve); } } BLL.LogService.AddSys_Log(this.CurrUser, newConstructionRisk.ConstructionRiskId, newConstructionRisk.ConstructionRiskId, BLL.Const.ConstructionRiskMenuId, BLL.Const.BtnModify); } else { if (string.IsNullOrEmpty(this.hdConstructionRiskId.Text)) { newConstructionRisk.ConstructionRiskId = SQLHelper.GetNewID(typeof(Model.Hazard_EnvironmentalRiskList)); } else { newConstructionRisk.ConstructionRiskId = this.hdConstructionRiskId.Text; } this.ConstructionRiskId = newConstructionRisk.ConstructionRiskId; BLL.ConstructionRiskListService.AddConstructionRisk(newConstructionRisk); if (type == BLL.Const.BtnSubmit) { Model.HSSE_ConstructionRiskApprove approve1 = new Model.HSSE_ConstructionRiskApprove(); approve1.ConstructionRiskId = newConstructionRisk.ConstructionRiskId; approve1.ApproveMan = this.CurrUser.UserId; approve1.ApproveType = BLL.Const.ConstructionRisk_Compile; approve1.ApproveDate = DateTime.Now; BLL.ConstructionRiskApproveService.AddConstructionRiskApprove(approve1); Model.HSSE_ConstructionRiskApprove approve = new Model.HSSE_ConstructionRiskApprove(); approve.ConstructionRiskId = newConstructionRisk.ConstructionRiskId; if (this.drpHandleMan.SelectedValue != BLL.Const._Null) { approve.ApproveMan = this.drpHandleMan.SelectedValue; } approve.ApproveType = this.drpHandleType.SelectedValue; BLL.ConstructionRiskApproveService.AddConstructionRiskApprove(approve); } else { Model.HSSE_ConstructionRiskApprove approve1 = new Model.HSSE_ConstructionRiskApprove(); approve1.ConstructionRiskId = newConstructionRisk.ConstructionRiskId; approve1.ApproveMan = this.CurrUser.UserId; approve1.ApproveType = BLL.Const.ConstructionRisk_Compile; BLL.ConstructionRiskApproveService.AddConstructionRiskApprove(approve1); } BLL.LogService.AddSys_Log(this.CurrUser, newConstructionRisk.ConstructionRiskId, newConstructionRisk.ConstructionRiskId, BLL.Const.ConstructionRiskMenuId, BLL.Const.BtnAdd); } foreach (var item in constructionRiskControls) { item.ConstructionRiskId = newConstructionRisk.ConstructionRiskId; } BLL.ConstructionRiskListService.AddConstructionRiskControl(constructionRiskControls, this.ConstructionRiskId); } #region 关闭弹出窗 /// /// 关闭弹出窗 /// /// /// protected void Window1_Close(object sender, EventArgs e) { constructionRiskControls = (from x in Funs.DB.HSSE_ConstructionRiskControl where x.ConstructionRiskId == this.hdConstructionRiskId.Text orderby x.ShowIndex select x).ToList(); Grid1.DataSource = constructionRiskControls; Grid1.DataBind(); } /// /// 关闭弹出窗 /// /// /// protected void Window2_Close(object sender, EventArgs e) { } #endregion #region Grid双击事件 /// /// Grid行双击事件 /// /// /// protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e) { btnMenuEdit_Click(null, null); } #endregion #region 编辑 /// /// 编辑按钮 /// /// /// protected void btnMenuEdit_Click(object sender, EventArgs e) { if (Grid1.SelectedRowIndexArray.Length == 0) { Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning); return; } string rowID = Grid1.SelectedRowID; PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("ConstructionRiskControlEdit.aspx?ConstructionRiskId={0}&ControlId={1}", ConstructionRiskId, rowID, "编辑 - "))); } #endregion #region 删除 /// /// 批量删除 /// /// /// protected void btnMenuDelete_Click(object sender, EventArgs e) { if (Grid1.SelectedRowIndexArray.Length > 0) { foreach (int rowIndex in Grid1.SelectedRowIndexArray) { string rowID = Grid1.DataKeys[rowIndex][0].ToString(); var constructionRiskControl = Funs.DB.HSSE_ConstructionRiskControl.FirstOrDefault(x => x.ControlId == rowID); Funs.DB.HSSE_ConstructionRiskControl.DeleteOnSubmit(constructionRiskControl); Funs.DB.SubmitChanges(); } constructionRiskControls = (from x in Funs.DB.HSSE_ConstructionRiskControl where x.ConstructionRiskId == this.ConstructionRiskId orderby x.ShowIndex select x).ToList(); Grid1.DataSource = constructionRiskControls; Grid1.DataBind(); ShowNotify("删除数据成功!(表格数据已重新绑定)"); } } #endregion #region 区域选择框事件 /// /// 区域选择框事件 /// /// /// protected void dpDateA_SelectedIndexChanged(object sender, EventArgs e) { } #endregion protected void btnAdd_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(this.ConstructionRiskId)) { this.hdConstructionRiskId.Text = SQLHelper.GetNewID(typeof(Model.Hazard_EnvironmentalRiskList)); } PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("ConstructionRiskControlEdit.aspx?ConstructionRiskId=" + this.hdConstructionRiskId.Text, "添加 - "))); } protected void btnMap_Click(object sender, EventArgs e) { string window = String.Format("LocationSelect.aspx?ConstructionRiskId=" + this.ConstructionRiskId); PageContext.RegisterStartupScript(Window2.GetSaveStateReference(hdCoordinate.ClientID) + Window2.GetShowReference(window)); //PageContext.RegisterStartupScript(Window2.GetShowReference()); } protected void drpRefLicense_SelectedIndexChanged(object sender, EventArgs e) { if (this.drpRefLicense.SelectedValueArray.Length == 1 && this.drpRefLicense.SelectedValue == BLL.Const._Null) { this.drpRiskLevel.DataSource = BLL.ConstructionRiskListService.RiskLevelList(); } else { this.drpRiskLevel.DataSource = BLL.ConstructionRiskListService.RiskLevelList2(); } this.drpRiskLevel.DataBind(); Funs.FineUIPleaseSelect(this.drpRiskLevel); this.drpRiskLevel.SelectedValue = BLL.Const._Null; } #region 选择施工内容 /// /// 选择施工内容 /// /// /// protected void btnNew_Click(object sender, EventArgs e) { if (this.drpWorkArea.SelectedValue == BLL.Const._Null) { Alert.ShowInTop("请先选择单位工程!", MessageBoxIcon.Warning); return; } string window = String.Format("ShowWBS.aspx?WorkAreaId={0}", this.drpWorkArea.SelectedValue, "查找 - "); PageContext.RegisterStartupScript(Window3.GetSaveStateReference(hdConstructionContentId.ClientID) + Window3.GetShowReference(window)); } #endregion #region 关闭弹出窗口 /// /// 关闭弹出窗口 /// /// /// protected void Window3_Close(object sender, WindowCloseEventArgs e) { if (!string.IsNullOrEmpty(hdConstructionContentId.Text)) { var c = BLL.BreakdownProjectService.GetBreakdownProjectById(hdConstructionContentId.Text); if (c != null) { this.txtConstructionContent.Text = c.BreakdownName; } } } #endregion protected void rblIsAgree_SelectedIndexChanged(object sender, EventArgs e) { this.drpHandleMan.Enabled = true; string State = BLL.ConstructionRiskListService.GetConstructionRisk(this.ConstructionRiskId).States; if (this.rblIsAgree.SelectedValue.Equals("true")) { if (State == Const.ConstructionRisk_Audit1) { this.drpHandleMan.Items.Clear(); UserService.Init2(drpHandleMan, this.CurrUser.LoginProjectId, false); } if (State == Const.ConstructionRisk_Audit2) { this.drpHandleMan.Items.Clear(); Funs.FineUIPleaseSelect(this.drpHandleMan); this.drpHandleMan.Enabled = false; } this.drpHandleType.SelectedIndex = 0; this.drpHandleMan.SelectedIndex = 0; } else { this.drpHandleMan.Items.Clear(); this.drpHandleType.SelectedIndex = 1; ListItem item = new ListItem(); var user = BLL.UserService.GetUserByUserId(BLL.ConstructionRiskApproveService.GetComplie(this.ConstructionRiskId).ApproveMan); item.Value = user.UserId; item.Text = user.UserName; this.drpHandleMan.Items.Add(item); this.drpHandleMan.SelectedIndex = 0; } } protected void drpHandleType_SelectedIndexChanged(object sender, EventArgs e) { this.drpHandleMan.Items.Clear(); Funs.FineUIPleaseSelect(this.drpHandleMan); if (this.drpHandleType.SelectedValue == BLL.Const.ConstructionRisk_Audit3) { this.drpHandleMan.Enabled = false; } else if (this.drpHandleType.SelectedValue == BLL.Const.ConstructionRisk_ReCompile) { this.drpHandleMan.Enabled = true; string userId = (from x in Funs.DB.HSSE_ConstructionRiskApprove where x.ConstructionRiskId == ConstructionRiskId && x.ApproveType == BLL.Const.ConstructionRisk_Compile select x.ApproveMan).First(); ListItem lis = new ListItem(BLL.UserService.GetUserNameByUserId(userId), userId); this.drpHandleMan.Items.Add(lis); this.drpHandleMan.SelectedIndex = 0; } else { this.drpHandleMan.Enabled = true; UserService.Init2(drpHandleMan, this.CurrUser.LoginProjectId, false); this.drpHandleMan.SelectedIndex = 0; } } } }