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; } } /// /// 定义集合 /// private static List constructionRiskControls = new List(); #endregion #region 加载页面 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.ProjectId = this.CurrUser.LoginProjectId; 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.ProjectId = constructionRisk.ProjectId; this.InitDropDownList(); 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.RiskLevel)) { drpRiskLevel.SelectedValue = constructionRisk.RiskLevel; } if (!string.IsNullOrEmpty(constructionRisk.RefLicense)) { drpRefLicense.SelectedValueArray = constructionRisk.RefLicense.Split(','); } if (!string.IsNullOrEmpty(constructionRisk.ConstructionContent)) { this.txtConstructionContent.Text = HttpUtility.HtmlDecode(constructionRisk.ConstructionContent); } if (!string.IsNullOrEmpty(constructionRisk.LicenseDes)) { this.txtLicenseDes.Text = HttpUtility.HtmlDecode(constructionRisk.LicenseDes); } if (!string.IsNullOrEmpty(constructionRisk.RiskLevel)) { this.drpRiskLevel.SelectedValueArray = constructionRisk.RiskLevel.Split(','); } constructionRiskControls = (from x in Funs.DB.HSSE_ConstructionRiskControl where x.ConstructionRiskId == this.ConstructionRiskId orderby x.ShowIndex select x).ToList(); } Grid1.DataSource = constructionRiskControls; Grid1.DataBind(); ///初始化审核菜单 this.ctlAuditFlow.MenuId = BLL.Const.ConstructionRiskMenuId; this.ctlAuditFlow.DataId = this.ConstructionRiskId; this.ctlAuditFlow.ProjectId = this.ProjectId; this.ctlAuditFlow.UnitId = this.CurrUser.UnitId; } } #endregion /// /// 初始化下拉框 /// private void InitDropDownList() { ///区域下拉框 BLL.UnitWorkService.InitUnitWorkDownList(this.drpWorkArea, this.ProjectId, true); drpRefLicense.DataValueField = "LicenseTypeName"; drpRefLicense.DataTextField = "LicenseTypeName"; drpRefLicense.DataSource = (from x in Funs.DB.Base_LicenseType orderby x.LicenseTypeCode select x).ToList(); drpRefLicense.DataBind(); UnitService.InitUnitByProjectIdUnitTypeDropDownList(this.drpUnit, this.ProjectId, Const.ProjectUnitType_2, false); } #region 提交按钮 /// /// 提交按钮 /// /// /// protected void btnSubmit_Click(object sender, EventArgs e) { if (this.ctlAuditFlow.NextStep == BLL.Const.State_1 && this.ctlAuditFlow.NextPerson == 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) { 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 ( drpRefLicense.SelectedValueArray!=null && drpRefLicense.SelectedValueArray.Count()>0) { newConstructionRisk.RefLicense = string.Join(",",drpRefLicense.SelectedValueArray); } 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()); newConstructionRisk.LicenseDes = HttpUtility.HtmlEncode(this.txtLicenseDes.Text); newConstructionRisk.ConstructionContent = HttpUtility.HtmlEncode(this.txtConstructionContent.Text); ////单据状态 newConstructionRisk.States = BLL.Const.State_0; if (type == BLL.Const.BtnSubmit) { newConstructionRisk.States = this.ctlAuditFlow.NextStep; } if (!string.IsNullOrEmpty(this.ConstructionRiskId)) { newConstructionRisk.ConstructionRiskId = this.ConstructionRiskId; BLL.ConstructionRiskListService.UpdateConstructionRisk(newConstructionRisk); BLL.LogService.AddSys_Log(this.CurrUser, newConstructionRisk.ConstructionRiskId, newConstructionRisk.ConstructionRiskId, BLL.Const.ProjectEnvironmentalRiskListMenuId, BLL.Const.BtnModify); } else { newConstructionRisk.ConstructionRiskId = SQLHelper.GetNewID(typeof(Model.Hazard_EnvironmentalRiskList)); this.ConstructionRiskId = newConstructionRisk.ConstructionRiskId; BLL.ConstructionRiskListService.AddConstructionRisk(newConstructionRisk); BLL.LogService.AddSys_Log(this.CurrUser, newConstructionRisk.ConstructionRiskId, newConstructionRisk.ConstructionRiskId, BLL.Const.ProjectEnvironmentalRiskListMenuId, BLL.Const.BtnAdd); } foreach(var item in constructionRiskControls) { item.ConstructionRiskId= newConstructionRisk.ConstructionRiskId; } BLL.ConstructionRiskListService.AddConstructionRiskControl(constructionRiskControls, this.ConstructionRiskId); ////保存流程审核数据 this.ctlAuditFlow.btnSaveData(this.ProjectId, BLL.Const.ProjectEnvironmentalRiskListMenuId, this.ConstructionRiskId, (type == BLL.Const.BtnSubmit ? true : false), this.txtConstructionContent.Text.Trim(), "../Hazard/EnvironmentalRiskListView.aspx?EnvironmentalRiskListId={0}"); } #region 关闭弹出窗 /// /// 关闭弹出窗 /// /// /// protected void Window1_Close(object sender, EventArgs e) { constructionRiskControls = (from x in Funs.DB.HSSE_ConstructionRiskControl where x.ConstructionRiskId == this.ConstructionRiskId orderby x.ShowIndex select x).ToList(); Grid1.DataSource = constructionRiskControls; Grid1.DataBind(); } #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.ConstructionRiskId = SQLHelper.GetNewID(typeof(Model.Hazard_EnvironmentalRiskList)); } PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("ConstructionRiskControlEdit.aspx?ConstructionRiskId=" + this.ConstructionRiskId, "添加 - "))); } } }