using BLL; using Model; using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Data.SqlClient; using System.Linq; namespace FineUIPro.Web.HSSE.Hazard { public partial class ConstructionRisk : PageBase { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { GetButtonPower();//权限设置 this.InitTreeMenu();//加载树 } } #region 加载树施工单位 /// /// 加载树 /// private void InitTreeMenu() { this.tvControlItem.Nodes.Clear(); List units = null; var user = Person_PersonsService.GetPerson_PersonsById(this.CurrUser.PersonId); if (!string.IsNullOrEmpty(user.UnitId)) { var projectUnit = BLL.ProjectUnitService.GetProjectUnitByUnitIdProjectId(this.CurrUser.LoginProjectId, user.UnitId); if (projectUnit != null) { if (projectUnit.UnitType == BLL.Const.ProjectUnitType_1 || projectUnit.UnitType == BLL.Const.ProjectUnitType_3 || projectUnit.UnitType == BLL.Const.ProjectUnitType_4) { var ids = Funs.DB.HSSE_ConstructionRisk.Select(x=>x.UnitId).Distinct().ToList(); units = (from x in Funs.DB.Base_Unit where ids.Contains(x.UnitId) select x).OrderBy(x => x.UnitCode).ToList(); } else { units = (from x in Funs.DB.Base_Unit where x.UnitId == this.CurrUser.UnitId select x).ToList(); } } } else if (user.UnitId == Const.UnitId_SEDIN || user.PersonId == Const.hfnbdId) { var ids = Funs.DB.HSSE_ConstructionRisk.Select(x => x.UnitId).Distinct().ToList(); units = (from x in Funs.DB.Base_Unit where ids.Contains(x.UnitId) select x).OrderBy(x => x.UnitCode).ToList(); } if (units != null && units.Count > 0) { foreach (var unit in units) { TreeNode rootNode = new TreeNode(); rootNode.Text = unit.UnitName; rootNode.NodeID = unit.UnitId; rootNode.ToolTip = "单位"; rootNode.Expanded = false; this.tvControlItem.Nodes.Add(rootNode); this.BindNodes(rootNode); } } } #endregion #region 关闭弹出窗口及刷新页面 /// /// 关闭弹出窗口 /// /// /// protected void Window1_Close(object sender, WindowCloseEventArgs e) { this.InitTreeMenu(); this.BindGrid(); } protected void Window2_Close(object sender, WindowCloseEventArgs e) { if (hdState.Text == "A") { var ids = Grid1.SelectedRowID.Split('|'); if (ids.Length > 1) { hdState.Text = ""; PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("../Check/RectifyNoticesAdd.aspx?ControlId={0}", ids[1], "编辑 - "))); } } else if (hdState.Text == "B") { var ids = Grid1.SelectedRowID.Split('|'); if (ids.Length > 1) { hdState.Text = ""; PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("../HiddenInspection/HiddenRectificationAdd.aspx?ControlId={0}", ids[1], "编辑 - "))); } } this.InitTreeMenu(); this.BindGrid(); } #endregion #region 页索引改变事件 /// /// 页索引改变事件 /// /// /// protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e) { Grid1.PageIndex = e.NewPageIndex; BindGrid(); } #endregion #region 删除 /// /// 删除 /// /// /// /// /// 右键删除明细 /// /// /// protected void btnMenuDelete_Click(object sender, EventArgs e) { if (Grid1.SelectedRowIndexArray.Length == 0) { Alert.ShowInTop("请选择一条记录!", MessageBoxIcon.Warning); return; } foreach (int rowIndex in Grid1.SelectedRowIndexArray) { string rowID = Grid1.DataKeys[rowIndex][0].ToString(); var ids =rowID.Split('|'); if (ids.Length >= 1) { var list = Funs.DB.HSSE_ConstructionRiskControl.Where(x => x.ConstructionRiskId == ids[0]).ToList(); Funs.DB.HSSE_ConstructionRiskControl.DeleteAllOnSubmit(list); var constructionRisk = Funs.DB.HSSE_ConstructionRisk.Where(x => x.ConstructionRiskId == ids[0]).FirstOrDefault(); Funs.DB.HSSE_ConstructionRisk.DeleteOnSubmit(constructionRisk); Funs.DB.SubmitChanges(); } } ShowNotify("删除成功!", MessageBoxIcon.Success); this.InitTreeMenu(); this.BindGrid(); } #endregion /// /// 数据绑定 /// private void BindGrid() { if (this.tvControlItem.SelectedNode != null && this.tvControlItem.SelectedNode.NodeID.Contains("|")) { var ids = this.tvControlItem.SelectedNode.NodeID.Split('|'); string strSql = @"select c.UnitWorkName, '' Id,* ,b.CheckResult,(CASE WHEN a.States = " + BLL.Const.State_3 + " THEN '审核/审批完成' when a.States = " + BLL.Const.State_0 + " OR a.States IS NULL THEN '待提交' WHEN a.States = " + BLL.Const.State_2 + " THEN '待总包安全经理审核' ELSE '待['+OperateUser.PersonName+']办理' END) AS FlowOperateName" + @" from [dbo].[HSSE_ConstructionRisk] a left join [dbo].[HSSE_ConstructionRiskControl] b on a.ConstructionRiskId =b.ConstructionRiskId left join WBS_UnitWork c on a.WorkAreaId = c.UnitWorkId LEFT JOIN Sys_FlowOperate AS FlowOperate ON a.ConstructionRiskId=FlowOperate.DataId AND FlowOperate.IsClosed <> 1 LEFT JOIN Person_Persons AS OperateUser ON FlowOperate.OperaterId=OperateUser.PersonId where a.UnitId=@UnitId and a.DateWeek=@DateWeek order by a.[ConstructionContent],b.[ShowIndex]"; List listStr = new List(); listStr.Add(new SqlParameter("@UnitId", ids[0])); listStr.Add(new SqlParameter("@DateWeek", ids[1])); SqlParameter[] parameter = listStr.ToArray(); DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter); foreach (DataRow row in tb.Rows) { row["Id"] = row["ConstructionRiskId"] + "|" + row["ControlId"]; } Grid1.DataSource = tb; Grid1.DataBind(); } else { Grid1.DataSource = null; Grid1.DataBind(); } } #region 绑定树节点 /// /// 绑定树节点 /// /// private void BindNodes(TreeNode node) { var DateWeek = (from x in Funs.DB.HSSE_ConstructionRisk where x.ProjectId == this.CurrUser.LoginProjectId && x.UnitId == node.NodeID select x.DateWeek).OrderByDescending(x=>x).ToList(); foreach (var d in DateWeek) { TreeNode newNode = new TreeNode(); newNode.Text = d; //string.Format("{0:yyyy-MM-dd}", d.AssessmentDate); newNode.NodeID = node.NodeID + "|" + d; newNode.EnableClickEvent = true; newNode.ToolTip = "标签"; node.Nodes.Add(newNode); } } #endregion #region 获取按钮权限 private void GetButtonPower() { if (Request.Params["value"] == "0") { return; } var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.PersonId, BLL.Const.ConstructionRiskMenuId); if (buttonList.Count() > 0) { if (buttonList.Contains(BLL.Const.BtnIn)) { this.btnImport.Hidden = false; this.btnNew.Hidden = false; } if (buttonList.Contains(BLL.Const.BtnDelete)) { this.btnMenuDelete.Hidden = false; } if (buttonList.Contains(BLL.Const.BtnAuditing)) { this.btnMenuDelete.Hidden = false; } } } #endregion #region 导入 /// /// 导入按钮 /// /// /// protected void btnImport_Click(object sender, EventArgs e) { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("ConstructionRiskDataIn.aspx", "导入 - "))); } #endregion #region 导入 /// /// 导入按钮 /// /// /// protected void btnNew_Click(object sender, EventArgs e) { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("ConstructionRiskEdit.aspx", "添加 - "))); } #endregion protected void btnAudit_Click(object sender, EventArgs e) { //if (Grid1.SelectedRowIndexArray.Length == 0) //{ // Alert.ShowInTop("请选择一条记录!", MessageBoxIcon.Warning); // return; //} //foreach (int rowIndex in Grid1.SelectedRowIndexArray) //{ // string rowID = Grid1.DataKeys[rowIndex][0].ToString(); // var ids = rowID.Split('|'); // if (ids.Length >= 1) // { // var r = Funs.DB.HSSE_ConstructionRisk.FirstOrDefault(x => x.ConstructionRiskId == ids[0]); // if (r != null && r.States == "2") // { // r.States = "3"; // } // } //} var r = Funs.DB.HSSE_ConstructionRisk.Where(x => x.ProjectId==this.CurrUser.LoginProjectId && x.States == "2"); foreach (var item in r) { item.States = "3"; } Funs.DB.SubmitChanges(); BindGrid(); } #region 点击TreeView /// /// 点击TreeView /// /// /// protected void tvControlItem_NodeCommand111(object sender, TreeCommandEventArgs e) { BindGrid(); } #endregion protected void btnMenuCheck_Click(object sender, EventArgs e) { var ids = Grid1.SelectedRowID.Split('|'); if (ids.Length > 1) { hdState.Text = ""; PageContext.RegisterStartupScript(Window2.GetSaveStateReference(hdState.ClientID) + Window2.GetShowReference(String.Format("ConstructionRiskControlCheck.aspx?ControlId={0}", ids[1], "编辑 - "))); } } protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e) { var ids = Grid1.SelectedRowID.Split('|'); PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("ConstructionRiskEdit.aspx?ConstructionRiskId={0}", ids[0], "编辑 - "))); } } }