using BLL; using System; using System.Collections.Generic; using System.Data; using System.Linq; namespace FineUIPro.Web.JDGL.WBS { public partial class WBSSet : PageBase { #region 定义项 private static TreeNode node; private static string type; private static TreeNode delNode; private static string operating = null; #endregion #region 页面加载 /// /// 页面加载 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { GetButtonPower(); InitTreeMenu(); } } #endregion #region 获取按钮权限 /// /// 获取按钮权限 /// /// /// private void GetButtonPower() { if (Request.Params["value"] == "0") { return; } var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.WBSSetMenuId); if (buttonList.Count() > 0) { if (buttonList.Contains(BLL.Const.BtnAdd)) { this.btnMenuAdd.Hidden = false; } if (buttonList.Contains(BLL.Const.BtnModify)) { this.btnMenuEdit.Hidden = false; } if (buttonList.Contains(BLL.Const.BtnDelete)) { this.btnMenuDelete.Hidden = false; } } } #endregion #region 加载树 /// /// 加载树 /// private void InitTreeMenu() { this.trWBS.Nodes.Clear(); this.trWBS.ShowBorder = false; this.trWBS.ShowHeader = false; this.trWBS.EnableIcons = true; this.trWBS.AutoScroll = true; this.trWBS.EnableSingleClickExpand = true; var cnProfessions = from x in Funs.DB.WBS_CnProfessionInit orderby x.SortIndex select x; foreach (var cnProfession in cnProfessions) { TreeNode rootNode = new TreeNode(); rootNode.Text = cnProfession.CnProfessionName; rootNode.NodeID = cnProfession.CnProfessionId.ToString(); rootNode.CommandName = "cnProfession"; rootNode.EnableExpandEvent = true; rootNode.EnableClickEvent = true; this.trWBS.Nodes.Add(rootNode); TreeNode emptyNode = new TreeNode(); emptyNode.Text = ""; emptyNode.NodeID = ""; rootNode.Nodes.Add(emptyNode); } } #endregion #region 展开树 /// /// 展开树 /// /// /// protected void trWBS_NodeExpand(object sender, TreeNodeEventArgs e) { e.Node.Nodes.Clear(); if (e.Node.CommandName == "cnProfession") //展开专业节点 { var unitProjects = from x in Funs.DB.Wbs_UnitProjectInit where x.CnProfessionId == Convert.ToInt32(e.Node.NodeID) && x.SuperUnitProject == null orderby x.SortIndex select x; foreach (var unitProject in unitProjects) { TreeNode newNode = new TreeNode(); newNode.Text = unitProject.UnitProjectName; newNode.NodeID = unitProject.UnitProjectCode; newNode.CommandName = "unitProject"; newNode.EnableExpandEvent = true; newNode.EnableClickEvent = true; e.Node.Nodes.Add(newNode); TreeNode emptyNode = new TreeNode(); emptyNode.Text = ""; emptyNode.NodeID = ""; newNode.Nodes.Add(emptyNode); } } else if (e.Node.CommandName == "unitProject") //展开单位工程节点 { var childUnitProjects = from x in Funs.DB.Wbs_UnitProjectInit where x.SuperUnitProject == e.Node.NodeID orderby x.UnitProjectCode select x; if (childUnitProjects.Count() > 0) //存在子单位工程 { foreach (var childUnitProject in childUnitProjects) { TreeNode newNode = new TreeNode(); newNode.Text = childUnitProject.UnitProjectName; newNode.NodeID = childUnitProject.UnitProjectCode; newNode.CommandName = "childUnitProject"; newNode.EnableExpandEvent = true; newNode.EnableClickEvent = true; e.Node.Nodes.Add(newNode); TreeNode emptyNode = new TreeNode(); emptyNode.Text = ""; emptyNode.NodeID = ""; newNode.Nodes.Add(emptyNode); } } else //不存在子单位工程,加载分部工程 { var wbsSet1s = from x in Funs.DB.WBS_WbsSetInit where x.UnitProjectCode == e.Node.NodeID && x.SuperWbsSetCode == null orderby x.WbsSetCode select x; if (wbsSet1s.Count() > 0) { foreach (var wbsSet1 in wbsSet1s) { TreeNode newNode = new TreeNode(); newNode.Text = wbsSet1.WbsSetName; newNode.NodeID = wbsSet1.WbsSetCode; newNode.CommandName = "wbsSet"; newNode.EnableExpandEvent = true; newNode.EnableClickEvent = true; e.Node.Nodes.Add(newNode); TreeNode emptyNode = new TreeNode(); emptyNode.Text = ""; emptyNode.NodeID = ""; newNode.Nodes.Add(emptyNode); } } else { var wbsSet3s = from x in Funs.DB.WBS_WbsSetInit where x.UnitProjectCode == e.Node.NodeID && x.SuperWbsSetCode == null orderby x.WbsSetCode select x; if (wbsSet3s.Count() > 0) { foreach (var wbsSet3 in wbsSet3s) { TreeNode newNode = new TreeNode(); newNode.Text = wbsSet3.WbsSetName; newNode.NodeID = wbsSet3.WbsSetCode; newNode.CommandName = "wbsSet"; newNode.EnableExpandEvent = true; newNode.EnableClickEvent = true; e.Node.Nodes.Add(newNode); var childWbsSets = BLL.WbsSetInitService.GetWbsSetInitsBySuperWbsSetCode(wbsSet3.WbsSetCode); if (childWbsSets.Count() > 0) { TreeNode emptyNode = new TreeNode(); emptyNode.Text = ""; emptyNode.NodeID = ""; newNode.Nodes.Add(emptyNode); } } } else { var wbsSet4s = from x in Funs.DB.WBS_WbsSetInit where x.UnitProjectCode == e.Node.NodeID && x.SuperWbsSetCode == null orderby x.WbsSetCode select x; if (wbsSet4s.Count() > 0) { foreach (var wbsSet4 in wbsSet4s) { TreeNode newNode = new TreeNode(); newNode.Text = wbsSet4.WbsSetName; newNode.NodeID = wbsSet4.WbsSetCode; newNode.CommandName = "wbsSet"; newNode.EnableExpandEvent = true; newNode.EnableClickEvent = true; e.Node.Nodes.Add(newNode); } } } } } } else if (e.Node.CommandName == "childUnitProject") //展开子单位工程节点 { var wbsSet1s = from x in Funs.DB.WBS_WbsSetInit where x.UnitProjectCode == e.Node.NodeID && x.SuperWbsSetCode == null orderby x.WbsSetCode select x; foreach (var wbsSet1 in wbsSet1s) { TreeNode newNode = new TreeNode(); newNode.Text = wbsSet1.WbsSetName; newNode.NodeID = wbsSet1.WbsSetCode; newNode.CommandName = "wbsSet"; newNode.EnableExpandEvent = true; newNode.EnableClickEvent = true; e.Node.Nodes.Add(newNode); var childWbsSets = BLL.WbsSetInitService.GetWbsSetInitsBySuperWbsSetCode(wbsSet1.WbsSetCode); if (childWbsSets.Count > 0) { TreeNode emptyNode = new TreeNode(); emptyNode.Text = ""; emptyNode.NodeID = ""; newNode.Nodes.Add(emptyNode); } } } else if (e.Node.CommandName == "wbsSet") //展开分部/子分部/分项/子分项工程节点 { var childWbsSets = BLL.WbsSetInitService.GetWbsSetInitsBySuperWbsSetCode(e.Node.NodeID); foreach (var wbsSet in childWbsSets) { TreeNode newNode = new TreeNode(); newNode.Text = wbsSet.WbsSetName; newNode.NodeID = wbsSet.WbsSetCode; newNode.CommandName = "wbsSet"; newNode.EnableExpandEvent = true; newNode.EnableClickEvent = true; e.Node.Nodes.Add(newNode); var childWbsSets2 = BLL.WbsSetInitService.GetWbsSetInitsBySuperWbsSetCode(newNode.NodeID); if (childWbsSets2.Count() > 0) { TreeNode emptyNode = new TreeNode(); emptyNode.Text = ""; emptyNode.NodeID = ""; newNode.Nodes.Add(emptyNode); } } } } #endregion #region Tree点击事件 /// /// Tree点击事件 /// /// /// protected void trWBS_NodeCommand(object sender, TreeCommandEventArgs e) { if (this.Grid1.Rows.Count > 0) { SaveData(); } BindGrid(); } #endregion #region 保存方法 /// /// 保存方法 /// private void SaveData() { //string rowId = this.Grid1.Rows[0].RowID; //string type = this.Grid1.Rows[0].Values[4].ToString(); //if (type == "unitProject") //{ // Model.Wbs_UnitProjectInit unitProject = BLL.UnitProjectInitService.GetUnitProjectInitByUnitProjectCode(rowId); // if (unitProject != null) // { // BLL.UnitProjectInitService.UpdateUnitProjectInit(unitProject); // } //} //else if (type == "wbsSet") //{ // Model.WBS_WbsSetInit wbsSet = BLL.WbsSetInitService.GetWbsSetInitByWbsSetCode(rowId); // if (wbsSet != null) // { // var childWbsSets = BLL.WbsSetInitService.GetWbsSetInitsBySuperWbsSetCode(this.trWBS.SelectedNodeID); // //wbsSet.StartDate = Convert.ToDateTime(this.Grid1.Rows[0].Values[2].ToString()); // //wbsSet.EndDate = Convert.ToDateTime(this.Grid1.Rows[0].Values[3].ToString()); // BLL.WbsSetInitService.UpdateWbsSetInit(wbsSet); // } //} } #endregion #region 修改关闭窗口 /// /// 关闭窗口 /// /// /// protected void Window1_Close(object sender, WindowCloseEventArgs e) { ShowNotify("修改成功!", MessageBoxIcon.Success); getWBSSet(); } #endregion #region 拷贝关闭窗口 /// /// 拷贝关闭窗口 /// /// /// protected void Window2_Close(object sender, WindowCloseEventArgs e) { ShowNotify("增加成功!", MessageBoxIcon.Success); getWBSSet(); } #endregion #region 右键增加、修改、删除方法 /// /// 右键修改事件 /// /// /// protected void btnMenuEdit_Click(object sender, EventArgs e) { if (this.trWBS.SelectedNode != null) { if (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.WBSSetMenuId, BLL.Const.BtnModify)) { type = this.trWBS.SelectedNode.CommandName; if (type.Equals("cnProfession")) { ShowNotify("专业不允许修改!", MessageBoxIcon.Warning); } else { this.hdSelectId.Text = this.trWBS.SelectedNodeID; node = trWBS.SelectedNode; operating = "modify"; PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("WBSSetEdit.aspx?operating=modify&Id={0}&Type={1}", this.trWBS.SelectedNodeID, this.trWBS.SelectedNode.CommandName, "编辑 - "))); } } else { ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); } } else { ShowNotify("请选择树节点!", MessageBoxIcon.Warning); } } /// /// 增加 /// /// /// protected void btnMenuAdd_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(trWBS.SelectedNodeID)) { if (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.WBSSetMenuId, BLL.Const.BtnAdd)) { //if (this.trWBS.SelectedNode.CommandName != "cnProfession") //非专业节点可以增加 //{ type = this.trWBS.SelectedNode.CommandName; this.hdSelectId.Text = this.trWBS.SelectedNodeID; node = trWBS.SelectedNode; operating = "add"; string openUrl = String.Format("WBSSetEdit.aspx?operating=add&Id={0}&Type={1}", trWBS.SelectedNodeID, trWBS.SelectedNode.CommandName, "拷贝 - "); PageContext.RegisterStartupScript(Window2.GetSaveStateReference(hdSelectId.ClientID) + Window2.GetShowReference(openUrl)); //PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("WBSSetCopy.aspx?Id={0}&Type={1}", this.trWBS.SelectedNode.NodeID, this.trWBS.SelectedNode.CommandName, "拷贝 - "))); //} //else //{ // ShowNotify("专业节点无法增加!", MessageBoxIcon.Warning); //} } else { ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); } } else { ShowNotify("请选择树节点!", MessageBoxIcon.Warning); } } /// /// 右键删除事件 /// /// /// protected void btnMenuDelete_Click(object sender, EventArgs e) { if (this.trWBS.SelectedNode != null) { if (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.WBSSetMenuId, BLL.Const.BtnDelete)) { if (this.trWBS.SelectedNode.CommandName != "cnProfession") //非专业节点可以删除 { var strId = trWBS.SelectedNode.NodeID.Split('-'); if (strId.Count() == 2) { delNode = trWBS.SelectedNode; } else { node = trWBS.SelectedNode; } DeleteData(); } else { ShowNotify("专业节点无法删除!", MessageBoxIcon.Warning); } } else { ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); } } else { ShowNotify("请选择树节点!", MessageBoxIcon.Warning); } } /// /// 删除方法 /// private void DeleteData() { string id = this.trWBS.SelectedNodeID; if (this.trWBS.SelectedNode.CommandName == "unitProject") { Model.Wbs_UnitProjectInit unitProject = BLL.UnitProjectInitService.GetUnitProjectInitByUnitProjectCode(id); if (unitProject != null) { if (unitProject.IsIn == true) { ShowNotify("内置项无法删除!", MessageBoxIcon.Warning); return; } else { List childUnitProjects = BLL.UnitProjectInitService.GetUnitProjectInitsBySuperUnitProject(id); if (childUnitProjects.Count > 0) //存在子单位工程 { this.hdSelectId.Text = unitProject.CnProfessionId.ToString(); foreach (var childUnitProject in childUnitProjects) { BLL.WbsSetInitService.DeleteWbsSetInitByUnitProjectCode(childUnitProject.UnitProjectCode); } BLL.UnitProjectInitService.DeleteUnitProjectInitBySuperUnitProject(id); BLL.UnitProjectInitService.DeleteUnitProjectInit(id); } else { this.hdSelectId.Text = unitProject.CnProfessionId.ToString(); BLL.WbsSetInitService.DeleteWbsSetInitByUnitProjectCode(id); BLL.UnitProjectInitService.DeleteUnitProjectInit(id); } } } } else if (this.trWBS.SelectedNode.CommandName == "childUnitProject") { Model.Wbs_UnitProjectInit childUnitProject = BLL.UnitProjectInitService.GetUnitProjectInitByUnitProjectCode(id); if (childUnitProject != null) { if (childUnitProject.IsIn == true) { ShowNotify("内置项无法删除!", MessageBoxIcon.Warning); return; } else { this.hdSelectId.Text = childUnitProject.SuperUnitProject; BLL.WbsSetInitService.DeleteWbsSetInitByUnitProjectCode(id); BLL.UnitProjectInitService.DeleteUnitProjectInit(id); } } } else if (this.trWBS.SelectedNode.CommandName == "wbsSet") { Model.WBS_WbsSetInit wbsSet = BLL.WbsSetInitService.GetWbsSetInitByWbsSetCode(id); if (wbsSet != null) { if (wbsSet.IsIn == true) { ShowNotify("内置项无法删除!", MessageBoxIcon.Warning); return; } else { List childWbsSet1s = BLL.WbsSetInitService.GetWbsSetInitsBySuperWbsSetCode(id); Model.WBS_WbsSetInit set = BLL.WbsSetInitService.GetWbsSetInitByWbsSetCode(id); if (set != null) { if (!string.IsNullOrEmpty(set.SuperWbsSetCode)) { this.hdSelectId.Text = wbsSet.SuperWbsSetCode; } else { this.hdSelectId.Text = wbsSet.UnitProjectCode; } } foreach (var childWbsSet1 in childWbsSet1s) { List childWbsSet2s = BLL.WbsSetInitService.GetWbsSetInitsBySuperWbsSetCode(childWbsSet1.WbsSetCode); foreach (var childWbsSet2 in childWbsSet2s)//3 { List childWbsSet3s = BLL.WbsSetInitService.GetWbsSetInitsBySuperWbsSetCode(childWbsSet2.WbsSetCode); foreach (var childWbsSet3 in childWbsSet3s) { BLL.WbsSetInitService.DeleteWbsSetInit(childWbsSet3.WbsSetCode); } BLL.WbsSetInitService.DeleteWbsSetInit(childWbsSet2.WbsSetCode); } BLL.WbsSetInitService.DeleteWbsSetInit(childWbsSet1.WbsSetCode); } BLL.WbsSetInitService.DeleteWbsSetInit(id); } } } BLL.LogService.AddSys_Log(this.CurrUser, id, id, BLL.Const.WBSSetMenuId, "删除WBS库单位、分部、分项工程!"); ShowNotify("删除成功!", MessageBoxIcon.Success); getWBSSet(); } #endregion #region 保存事件 /// /// 保存事件 /// /// /// protected void btnSave_Click(object sender, EventArgs e) { if (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.WBSSetMenuId, BLL.Const.BtnSave)) { if (this.Grid1.Rows.Count > 0) { SaveData(); Alert.ShowInTop("保存成功!", MessageBoxIcon.Success); } else { Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning); return; } } else { ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); } } #endregion #region 绑定数据 /// /// 绑定数据 /// /// /// protected void Grid1_FilterChange(object sender, EventArgs e) { BindGrid(); } protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e) { Grid1.PageIndex = e.NewPageIndex; BindGrid(); } /// /// Grid1排序 /// /// /// protected void Grid1_Sort(object sender, GridSortEventArgs e) { Grid1.SortDirection = e.SortDirection; Grid1.SortField = e.SortField; BindGrid(); } /// /// 分页下拉选择事件 /// /// /// protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e) { Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue); BindGrid(); } /// /// 加载Grid /// private void BindGrid() { this.Grid1.Columns[2].Hidden = true; this.Grid1.Columns[3].Hidden = true; this.Grid1.Columns[4].Hidden = true; List items = new List(); if (this.trWBS.SelectedNode != null) { if (this.trWBS.SelectedNode.CommandName == "cnProfession") { Model.WBS_CnProfessionInit cnProfession = BLL.CnProfessionInitService.GetCnProfessionInitByCnProfessionId(this.trWBS.SelectedNode.NodeID); Model.WBSSetInitItem item = new Model.WBSSetInitItem(); if (cnProfession != null) { item.Code = this.trWBS.SelectedNode.NodeID; item.Name = cnProfession.CnProfessionName; item.Type = "cnProfession"; items.Add(item); } } else if (this.trWBS.SelectedNode.CommandName == "unitProject" || this.trWBS.SelectedNode.CommandName == "childUnitProject") { this.Grid1.Columns[4].Hidden = false; Model.Wbs_UnitProjectInit unitProject = BLL.UnitProjectInitService.GetUnitProjectInitByUnitProjectCode(this.trWBS.SelectedNode.NodeID); Model.WBSSetInitItem item = new Model.WBSSetInitItem(); if (unitProject != null) { item.Code = this.trWBS.SelectedNode.NodeID; item.Name = unitProject.UnitProjectName; item.Remark = unitProject.Remark; item.Type = "unitProject"; items.Add(item); } } else if (this.trWBS.SelectedNode.CommandName == "wbsSet") { this.Grid1.Columns[4].Hidden = false; Model.WBS_WbsSetInit wbsSet = BLL.WbsSetInitService.GetWbsSetInitByWbsSetCode(this.trWBS.SelectedNode.NodeID); var childWbsSets = BLL.WbsSetInitService.GetWbsSetInitsBySuperWbsSetCode(this.trWBS.SelectedNode.NodeID); if (childWbsSets.Count == 0) { this.Grid1.Columns[2].Hidden = false; this.Grid1.Columns[3].Hidden = false; } Model.WBSSetInitItem item = new Model.WBSSetInitItem(); if (wbsSet != null) { item.Code = this.trWBS.SelectedNode.NodeID; item.Name = wbsSet.WbsSetName; item.Type = "wbsSet"; item.ControlPoint = wbsSet.ControlPoint; item.ControlItemDef = wbsSet.ControlItemDef; item.Remark = wbsSet.Remark; items.Add(item); } } this.Grid1.DataSource = items; this.Grid1.DataBind(); } } #endregion #region 判断字符串是否可以转化为数字 /// /// 判断字符串是否可以转化为数字 /// /// 要检查的字符串 /// true:可以转换为数字;false:不是数字 public bool IsNumberic(string str) { double vsNum; bool isNum; isNum = double.TryParse(str, System.Globalization.NumberStyles.Float, System.Globalization.NumberFormatInfo.InvariantInfo, out vsNum); return isNum; } #endregion #region 根据所给Id定位到对应具体的专业、单位工程、子单位工程、分部、子分部、分项、子分项 /// /// 根据所给Id定位到对应具体的专业、单位工程、子单位工程、分部、子分部、分项、子分项 /// private void getWBSSet() { string CnProfessionCode = string.Empty; string UnitProjectCode = string.Empty; string childUnitProjectCode = string.Empty; string CnProfessionId = String.Empty; string wbsSetParentCode1 = string.Empty; string wbsSetParentCode2 = string.Empty; string wbsSetParentCode3 = string.Empty; //if (type.Equals("unitProject")) //{ // this.hdSelectId.Text = node.ParentNode.NodeID; // if (!operating.Equals("add")) // { // this.hdSelectId.Text = node.ParentNode.NodeID; // } //} //else //{ // if (type.Equals("cnProfession") && operating.Equals("add")) // { // this.hdSelectId.Text = node.NodeID; // } // else // { // this.hdSelectId.Text = node.ParentNode.NodeID; // } //} Model.WBS_CnProfessionInit cnPro = BLL.CnProfessionInitService.GetCnProfessionInitByCnProfessionId(this.hdSelectId.Text); Model.Wbs_UnitProjectInit UnitProject = BLL.UnitProjectInitService.GetUnitProjectInitByUnitProjectCode(this.hdSelectId.Text); Model.WBS_WbsSetInit wbsSetParm = BLL.WbsSetInitService.GetWbsSetInitByWbsSetCode(this.hdSelectId.Text); if (UnitProject != null) { if (string.IsNullOrEmpty(UnitProject.SuperUnitProject)) { UnitProjectCode = UnitProject.UnitProjectCode; } else { childUnitProjectCode = UnitProject.UnitProjectCode; UnitProjectCode = UnitProject.SuperUnitProject; } Model.WBS_CnProfessionInit cn = BLL.CnProfessionInitService.GetCnProfessionInitByCnProfessionId(UnitProject.CnProfessionId.ToString()); if (cn != null) { if (type == "cnProfession" || type == "unitProject" || type == "wbsSet") { CnProfessionCode = cn.CnProfessionId.ToString(); } else { CnProfessionCode = cn.CnProfessionCode; } } } else if (wbsSetParm != null) { Model.WBS_CnProfessionInit cn = BLL.CnProfessionInitService.GetCnProfessionInitByCnProfessionId(wbsSetParm.CnProfessionId.ToString()); CnProfessionCode = wbsSetParm.CnProfessionId.ToString(); Model.Wbs_UnitProjectInit unitpro = BLL.UnitProjectInitService.GetUnitProjectInitByUnitProjectCode(wbsSetParm.UnitProjectCode); if (string.IsNullOrEmpty(unitpro.SuperUnitProject)) { UnitProjectCode = unitpro.UnitProjectCode; } else { childUnitProjectCode = unitpro.UnitProjectCode; UnitProjectCode = unitpro.SuperUnitProject; } if (!string.IsNullOrEmpty(wbsSetParm.SuperWbsSetCode)) { wbsSetParentCode1 = wbsSetParm.SuperWbsSetCode; Model.WBS_WbsSetInit wbsSetParent1 = BLL.WbsSetInitService.GetWbsSetInitByWbsSetCode(wbsSetParentCode1); if (wbsSetParent1 != null) { if (!string.IsNullOrEmpty(wbsSetParent1.SuperWbsSetCode)) { wbsSetParentCode2 = wbsSetParent1.SuperWbsSetCode; Model.WBS_WbsSetInit wbsSetParent2 = BLL.WbsSetInitService.GetWbsSetInitByWbsSetCode(wbsSetParentCode2); if (wbsSetParent2 != null) { if (!string.IsNullOrEmpty(wbsSetParent2.SuperWbsSetCode)) { wbsSetParentCode3 = wbsSetParent2.SuperWbsSetCode; } } } } } } if (delNode != null) { if (delNode.ParentNode != null) { CnProfessionCode = cnPro.CnProfessionId.ToString(); } } this.trWBS.Nodes.Clear(); this.trWBS.ShowBorder = false; this.trWBS.ShowHeader = false; this.trWBS.EnableIcons = true; this.trWBS.AutoScroll = true; this.trWBS.EnableSingleClickExpand = true; var cnProfessions = from x in Funs.DB.WBS_CnProfessionInit orderby x.SortIndex select x; foreach (var cnProfession in cnProfessions) { TreeNode newCnProfessionNode = new TreeNode(); newCnProfessionNode.Text = cnProfession.CnProfessionName; newCnProfessionNode.NodeID = cnProfession.CnProfessionId.ToString(); if (delNode != null) { if (delNode.ParentNode.NodeID == newCnProfessionNode.NodeID) { newCnProfessionNode.Expanded = true; } } else { if (node.NodeID == newCnProfessionNode.NodeID) { newCnProfessionNode.Expanded = true; } } newCnProfessionNode.CommandName = "cnProfession"; newCnProfessionNode.ToolTip = cnProfession.CnProfessionCode; newCnProfessionNode.EnableExpandEvent = true; newCnProfessionNode.EnableClickEvent = true; this.trWBS.Nodes.Add(newCnProfessionNode); if (!string.IsNullOrEmpty(UnitProjectCode) || delNode != null) { //加载专业下的单位工程 if (cnProfession.CnProfessionId.ToString().Equals(CnProfessionCode)) { newCnProfessionNode.Expanded = true; var UnitProjects = from x in Funs.DB.Wbs_UnitProjectInit where x.CnProfessionId.ToString() == CnProfessionCode && x.SuperUnitProject == null orderby x.UnitProjectCode select x; foreach (var unitProject in UnitProjects) { TreeNode newNodeUnitPorject = new TreeNode(); newNodeUnitPorject.Text = unitProject.UnitProjectName; newNodeUnitPorject.NodeID = unitProject.UnitProjectCode; newNodeUnitPorject.CommandName = "unitProject"; newNodeUnitPorject.EnableExpandEvent = true; newNodeUnitPorject.EnableClickEvent = true; newCnProfessionNode.Expanded = true; newCnProfessionNode.Nodes.Add(newNodeUnitPorject); if (unitProject.UnitProjectCode != UnitProjectCode) { TreeNode emptyNode = new TreeNode(); emptyNode.Text = ""; emptyNode.NodeID = ""; newNodeUnitPorject.Nodes.Add(emptyNode); } else { if (!string.IsNullOrEmpty(childUnitProjectCode))//存在子单位工程 { newNodeUnitPorject.Expanded = true; var childUnitProjects = BLL.UnitProjectInitService.GetUnitProjectInitsBySuperUnitProject(newNodeUnitPorject.NodeID); foreach (var childUnitProject in childUnitProjects) { TreeNode newChildUnitProjectNode = new TreeNode(); newChildUnitProjectNode.Text = childUnitProject.UnitProjectName; newChildUnitProjectNode.NodeID = childUnitProject.UnitProjectCode; newChildUnitProjectNode.CommandName = "childUnitProject"; newChildUnitProjectNode.ToolTip = childUnitProject.UnitProjectCode; newChildUnitProjectNode.EnableExpandEvent = true; newChildUnitProjectNode.EnableClickEvent = true; newNodeUnitPorject.Nodes.Add(newChildUnitProjectNode); if (wbsSetParm != null) { if (wbsSetParm.UnitProjectCode != childUnitProject.UnitProjectCode) { TreeNode emptyNode = new TreeNode(); emptyNode.Text = ""; emptyNode.NodeID = ""; newChildUnitProjectNode.Nodes.Add(emptyNode); } else { newChildUnitProjectNode.Expanded = true; var wbsSet1s = from x in Funs.DB.WBS_WbsSetInit where x.Flag == 1 && x.UnitProjectCode == wbsSetParm.UnitProjectCode orderby x.WbsSetCode select x; foreach (var wbsSet1 in wbsSet1s) { TreeNode newwbsSet1Node = new TreeNode(); newwbsSet1Node.Text = wbsSet1.WbsSetName; newwbsSet1Node.NodeID = wbsSet1.WbsSetCode; newwbsSet1Node.CommandName = "wbsSet"; newwbsSet1Node.ToolTip = wbsSet1.WbsSetCode; newwbsSet1Node.EnableExpandEvent = true; newwbsSet1Node.EnableClickEvent = true; newChildUnitProjectNode.Nodes.Add(newwbsSet1Node); var childWbsSets2 = BLL.WbsSetInitService.GetWbsSetInitsBySuperWbsSetCode(newwbsSet1Node.NodeID); if (childWbsSets2.Count() > 0) { if (BLL.WbsSetInitService.IsExitWbsSetById2(wbsSet1.WbsSetCode, wbsSetParm.WbsSetCode)) { newwbsSet1Node.Expanded = true; foreach (var wbsSet2 in childWbsSets2) { TreeNode newwbsSet2Node = new TreeNode(); newwbsSet2Node.Text = wbsSet2.WbsSetName; newwbsSet2Node.NodeID = wbsSet2.WbsSetCode; newwbsSet2Node.CommandName = "wbsSet"; newwbsSet2Node.ToolTip = wbsSet2.WbsSetCode; newwbsSet2Node.EnableExpandEvent = true; newwbsSet2Node.EnableClickEvent = true; newwbsSet1Node.Nodes.Add(newwbsSet2Node); var childWbsSets3 = BLL.WbsSetInitService.GetWbsSetInitsBySuperWbsSetCode(newwbsSet2Node.NodeID); if (BLL.WbsSetInitService.IsExitWbsSetById2(wbsSet2.WbsSetCode, wbsSetParm.WbsSetCode)) { newwbsSet2Node.Expanded = true; if (childWbsSets3.Count() > 0) { foreach (var wbsSet3 in childWbsSets3) { TreeNode newwbsSet3Node = new TreeNode(); newwbsSet3Node.Text = wbsSet3.WbsSetName; newwbsSet3Node.NodeID = wbsSet3.WbsSetCode; newwbsSet3Node.CommandName = "wbsSet"; newwbsSet3Node.ToolTip = wbsSet3.WbsSetCode; newwbsSet3Node.EnableExpandEvent = true; newwbsSet3Node.EnableClickEvent = true; newwbsSet2Node.Nodes.Add(newwbsSet3Node); var childWbsSets4 = BLL.WbsSetInitService.GetWbsSetInitsBySuperWbsSetCode(newwbsSet3Node.NodeID); if (BLL.WbsSetInitService.IsExitWbsSetById2(wbsSet3.WbsSetCode, wbsSetParm.WbsSetCode)) { newwbsSet3Node.Expanded = true; if (childWbsSets4.Count() > 0) { foreach (var wbsSet4 in childWbsSets4) { TreeNode newwbsSet4Node = new TreeNode(); newwbsSet4Node.Text = wbsSet4.WbsSetName; newwbsSet4Node.NodeID = wbsSet4.WbsSetCode; newwbsSet4Node.CommandName = "wbsSet"; newwbsSet4Node.ToolTip = wbsSet4.WbsSetCode; newwbsSet4Node.EnableExpandEvent = true; newwbsSet4Node.EnableClickEvent = true; newwbsSet3Node.Nodes.Add(newwbsSet4Node); } } } else { if (childWbsSets4.Count() > 0) { TreeNode emptyNode = new TreeNode(); emptyNode.Text = ""; emptyNode.NodeID = ""; newwbsSet3Node.Nodes.Add(emptyNode); } } } } } else { if (childWbsSets3.Count() > 0) { TreeNode emptyNode = new TreeNode(); emptyNode.Text = ""; emptyNode.NodeID = ""; newwbsSet2Node.Nodes.Add(emptyNode); } } } } else { TreeNode emptyNode = new TreeNode(); emptyNode.Text = ""; emptyNode.NodeID = ""; newwbsSet1Node.Nodes.Add(emptyNode); } } } } } else { TreeNode emptyNode = new TreeNode(); emptyNode.Text = ""; emptyNode.NodeID = ""; newChildUnitProjectNode.Nodes.Add(emptyNode); } } } else { #region 不存在子单位工程 if (wbsSetParm != null) { if (wbsSetParm.UnitProjectCode != UnitProjectCode) { TreeNode emptyNode = new TreeNode(); emptyNode.Text = ""; emptyNode.NodeID = ""; newNodeUnitPorject.Nodes.Add(emptyNode); } else { newNodeUnitPorject.Expanded = true; var wbsSet1s = from x in Funs.DB.WBS_WbsSetInit where x.Flag == 1 && x.UnitProjectCode == UnitProjectCode orderby x.WbsSetCode select x; foreach (var wbsSet1 in wbsSet1s) { TreeNode newwbsSet1Node = new TreeNode(); newwbsSet1Node.Text = wbsSet1.WbsSetName; newwbsSet1Node.NodeID = wbsSet1.WbsSetCode; newwbsSet1Node.CommandName = "wbsSet"; newwbsSet1Node.ToolTip = wbsSet1.WbsSetCode; newwbsSet1Node.EnableExpandEvent = true; newwbsSet1Node.EnableClickEvent = true; newNodeUnitPorject.Nodes.Add(newwbsSet1Node); var childWbsSets2 = BLL.WbsSetInitService.GetWbsSetInitsBySuperWbsSetCode(newwbsSet1Node.NodeID); if (childWbsSets2.Count() > 0) { if (BLL.WbsSetInitService.IsExitWbsSetById2(wbsSet1.WbsSetCode, wbsSetParm.WbsSetCode)) { foreach (var wbsSet2 in childWbsSets2) { if (wbsSet1.WbsSetCode == wbsSet2.SuperWbsSetCode) { newwbsSet1Node.Expanded = true; } TreeNode newwbsSet2Node = new TreeNode(); newwbsSet2Node.Text = wbsSet2.WbsSetName; newwbsSet2Node.NodeID = wbsSet2.WbsSetCode; newwbsSet2Node.CommandName = "wbsSet"; newwbsSet2Node.ToolTip = wbsSet2.WbsSetCode; newwbsSet2Node.EnableExpandEvent = true; newwbsSet2Node.EnableClickEvent = true; newwbsSet1Node.Nodes.Add(newwbsSet2Node); var childWbsSets3 = BLL.WbsSetInitService.GetWbsSetInitsBySuperWbsSetCode(newwbsSet2Node.NodeID); if (BLL.WbsSetInitService.IsExitWbsSetById2(wbsSet2.WbsSetCode, wbsSetParm.WbsSetCode)) { newwbsSet2Node.Expanded = true; if (childWbsSets3.Count() > 0) { foreach (var wbsSet3 in childWbsSets3) { TreeNode newwbsSet3Node = new TreeNode(); newwbsSet3Node.Text = wbsSet3.WbsSetName; newwbsSet3Node.NodeID = wbsSet3.WbsSetCode; newwbsSet3Node.CommandName = "wbsSet"; newwbsSet3Node.ToolTip = wbsSet3.WbsSetCode; newwbsSet3Node.EnableExpandEvent = true; newwbsSet3Node.EnableClickEvent = true; newwbsSet2Node.Nodes.Add(newwbsSet3Node); var childWbsSets4 = BLL.WbsSetInitService.GetWbsSetInitsBySuperWbsSetCode(newwbsSet3Node.NodeID); if (BLL.WbsSetInitService.IsExitWbsSetById2(wbsSet3.WbsSetCode, wbsSetParm.WbsSetCode)) { newwbsSet3Node.Expanded = true; if (childWbsSets4.Count() > 0) { foreach (var wbsSet4 in childWbsSets4) { TreeNode newwbsSet4Node = new TreeNode(); newwbsSet4Node.Text = wbsSet4.WbsSetName; newwbsSet4Node.NodeID = wbsSet4.WbsSetCode; newwbsSet4Node.CommandName = "wbsSet"; newwbsSet4Node.ToolTip = wbsSet4.WbsSetCode; newwbsSet4Node.EnableExpandEvent = true; newwbsSet4Node.EnableClickEvent = true; newwbsSet3Node.Nodes.Add(newwbsSet4Node); } } } else { if (childWbsSets4.Count() > 0) { TreeNode emptyNode = new TreeNode(); emptyNode.Text = ""; emptyNode.NodeID = ""; newwbsSet3Node.Nodes.Add(emptyNode); } } } } } else { if (childWbsSets3.Count() > 0) { TreeNode emptyNode = new TreeNode(); emptyNode.Text = ""; emptyNode.NodeID = ""; newwbsSet2Node.Nodes.Add(emptyNode); } } } } else { TreeNode emptyNode = new TreeNode(); emptyNode.Text = ""; emptyNode.NodeID = ""; newwbsSet1Node.Nodes.Add(emptyNode); } } } } } else { TreeNode emptyNode = new TreeNode(); emptyNode.Text = ""; emptyNode.NodeID = ""; newNodeUnitPorject.Nodes.Add(emptyNode); } #endregion } } } } else { TreeNode emptyNode = new TreeNode(); emptyNode.Text = ""; emptyNode.NodeID = ""; newCnProfessionNode.Nodes.Add(emptyNode); } } else { TreeNode emptyNode = new TreeNode(); emptyNode.Text = ""; emptyNode.NodeID = ""; newCnProfessionNode.Nodes.Add(emptyNode); } } if (delNode != null) { if (!string.IsNullOrEmpty(delNode.ParentNode.NodeID)) { if (type == "cnProfession" || type == "unitProject") { this.hdSelectId.Text = delNode.ParentNode.NodeID; delNode.ParentNode.Expanded = true; } } } delNode = null; this.trWBS.SelectedNodeID = this.hdSelectId.Text; BindGrid(); } #endregion } }