using BLL;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Web.UI.WebControls;
namespace FineUIPro.Web.CQMS.WBS
{
public partial class ControlItemAndCycleShow : PageBase
{
#region 页面加载
///
/// 页面加载
///
///
///
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
InitTreeMenu();
}
}
#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;
TreeNode rootNode1 = new TreeNode();
rootNode1.Text = "建筑工程";
rootNode1.NodeID = "1";
rootNode1.CommandName = "ProjectType";
rootNode1.EnableExpandEvent = true;
rootNode1.EnableClickEvent = true;
this.trWBS.Nodes.Add(rootNode1);
TreeNode emptyNode = new TreeNode();
emptyNode.Text = "";
emptyNode.NodeID = "";
rootNode1.Nodes.Add(emptyNode);
//this.GetNodes(rootNode1.Nodes, rootNode1.NodeID);
TreeNode rootNode2 = new TreeNode();
rootNode2.Text = "安装工程";
rootNode2.NodeID = "2";
rootNode2.CommandName = "ProjectType";
rootNode2.EnableExpandEvent = true;
rootNode2.EnableClickEvent = true;
this.trWBS.Nodes.Add(rootNode2);
rootNode2.Nodes.Add(emptyNode);
//this.GetNodes(rootNode2.Nodes, rootNode2.NodeID);
}
#region 遍历节点方法
///
/// 遍历节点方法
///
/// 节点集合
/// 父节点
private void GetNodes(TreeNodeCollection nodes, string parentId)
{
List workPackages = new List();
if (parentId.Length == 1) //工程类型节点
{
workPackages = (from x in Funs.DB.WBS_WorkPackageProject
where x.SuperWorkPack == null && x.ProjectId == this.CurrUser.LoginProjectId && x.ProjectType == parentId
orderby x.PackageCode ascending
select x).ToList();
}
else
{
workPackages = (from x in Funs.DB.WBS_WorkPackageProject
where x.SuperWorkPack == parentId && x.ProjectId == this.CurrUser.LoginProjectId
orderby x.PackageCode ascending
select x).ToList();
}
foreach (var q in workPackages)
{
TreeNode newNode = new TreeNode();
newNode.Text = q.PackageContent;
newNode.NodeID = q.WorkPackageCode;
newNode.CommandName = "WorkPackage";
newNode.EnableClickEvent = true;
nodes.Add(newNode);
}
for (int i = 0; i < nodes.Count; i++)
{
GetNodes(nodes[i].Nodes, nodes[i].NodeID);
}
}
#endregion
#endregion
#region 展开树
///
/// 展开树
///
///
///
protected void trWBS_NodeExpand(object sender, TreeNodeEventArgs e)
{
e.Node.Nodes.Clear();
if (e.Node.CommandName == "ProjectType") //展开工程类型
{
var trUnitWork = from x in Funs.DB.WBS_UnitWork
where x.ProjectId == this.CurrUser.LoginProjectId && x.SuperUnitWork == null && x.ProjectType == e.Node.NodeID
select x;
trUnitWork = trUnitWork.OrderBy(x => x.UnitWorkCode);
if (trUnitWork.Count() > 0)
{
foreach (var trUnitWorkItem in trUnitWork)
{
TreeNode newNode = new TreeNode();
newNode.Text = trUnitWorkItem.UnitWorkCode + "-" + trUnitWorkItem.UnitWorkName;
newNode.NodeID = trUnitWorkItem.UnitWorkId;
newNode.CommandName = "UnitWork";
newNode.EnableExpandEvent = true;
newNode.EnableClickEvent = true;
e.Node.Nodes.Add(newNode);
if (BLL.WorkPackageService.GetWorkPackages1ByUnitWorkId(trUnitWorkItem.UnitWorkId.ToString()) != null)
{
TreeNode temp = new TreeNode();
temp.Text = "temp";
temp.NodeID = "temp";
newNode.Nodes.Add(temp);
}
}
}
}
else if (e.Node.CommandName == "UnitWork") //展开单位工程节点
{
var workPackages = from x in Funs.DB.WBS_WorkPackage where x.UnitWorkId == e.NodeID && x.SuperWorkPack == null && x.IsApprove == true orderby x.WorkPackageCode select x;
foreach (var workPackage in workPackages)
{
TreeNode newNode = new TreeNode();
newNode.Text = workPackage.PackageContent;
newNode.NodeID = workPackage.WorkPackageId;
newNode.CommandName = "WorkPackage";
newNode.EnableExpandEvent = true;
newNode.EnableClickEvent = true;
e.Node.Nodes.Add(newNode);
var childWorkPackages = from x in Funs.DB.WBS_WorkPackage where x.SuperWorkPackageId == workPackage.WorkPackageId && x.IsApprove == true select x;
if (childWorkPackages.Count() > 0)
{
TreeNode emptyNode = new TreeNode();
emptyNode.Text = "";
emptyNode.NodeID = "";
newNode.Nodes.Add(emptyNode);
}
}
}
else if (e.Node.CommandName == "WorkPackage") //展开工作包节点
{
var workPackages = from x in Funs.DB.WBS_WorkPackage where x.SuperWorkPackageId == e.Node.NodeID && x.IsApprove == true orderby x.WorkPackageCode, x.WorkPackageId select x;
if (workPackages.Count() > 0) //存在子单位工程
{
foreach (var workPackage in workPackages)
{
TreeNode newNode = new TreeNode();
newNode.Text = workPackage.PackageContent;
newNode.NodeID = workPackage.WorkPackageId;
newNode.CommandName = "WorkPackage";
newNode.EnableExpandEvent = true;
newNode.EnableClickEvent = true;
e.Node.Nodes.Add(newNode);
var childWorkPackages = from x in Funs.DB.WBS_WorkPackage where x.SuperWorkPackageId == workPackage.WorkPackageId && x.IsApprove == true select x;
if (childWorkPackages.Count() > 0)
{
TreeNode emptyNode = new TreeNode();
emptyNode.Text = "";
emptyNode.NodeID = "";
newNode.Nodes.Add(emptyNode);
}
}
}
}
}
#endregion
///
/// 发起设计交底(树节点)
///
///
///
protected void btnMenuAddTechnicalDisclose_Click(object sender, EventArgs e)
{
if (this.trWBS.SelectedNode != null)
{
if (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.PersonId, BLL.Const.CQMSTechnicalDiscloseMenuId, BLL.Const.BtnAdd))
{
if (this.trWBS.SelectedNode.CommandName == "WorkPackage")
{
var childWorkPackages = from x in Funs.DB.WBS_WorkPackage where x.SuperWorkPackageId == this.trWBS.SelectedNodeID && x.IsApprove == true select x;
if (childWorkPackages.Count() == 0) //末级节点
{
var oldTechnicalDisclose = BLL.CQMS_TechnicalDiscloseService.GetTechnicalDiscloseByDataId(this.trWBS.SelectedNodeID);
if (oldTechnicalDisclose == null)
{
var unitWork = (from x in Funs.DB.WBS_UnitWork
join y in Funs.DB.WBS_WorkPackage on x.UnitWorkId equals y.UnitWorkId
where y.WorkPackageId == this.trWBS.SelectedNodeID
select x).FirstOrDefault();
Model.Technical_TechnicalDisclose technicalDisclose = new Model.Technical_TechnicalDisclose();
technicalDisclose.TechnicalDiscloseId = SQLHelper.GetNewID();
technicalDisclose.ProjectId = this.CurrUser.LoginProjectId;
if (unitWork != null)
{
technicalDisclose.UnitId = unitWork.UnitId;
technicalDisclose.UnitWorkId = unitWork.UnitWorkId;
}
technicalDisclose.DataId = this.trWBS.SelectedNodeID;
technicalDisclose.DiscloseName = this.trWBS.SelectedNode.Text;
technicalDisclose.State = "0"; //未交底
technicalDisclose.CompileMan = this.CurrUser.PersonId;
technicalDisclose.CompileDate = DateTime.Now;
BLL.CQMS_TechnicalDiscloseService.AddTechnicalDisclose(technicalDisclose);
ShowNotify("发起成功!", MessageBoxIcon.Success);
}
else
{
ShowNotify("该节点已发起设计交底!", MessageBoxIcon.Warning);
}
}
else
{
ShowNotify("请选择末级节点发起设计交底!", MessageBoxIcon.Warning);
}
}
else
{
ShowNotify("请选择末级节点发起设计交底!", MessageBoxIcon.Warning);
}
}
else
{
ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
}
}
else
{
ShowNotify("请选择树节点!", MessageBoxIcon.Warning);
}
}
///
/// 发起设计交底(表格节点)
///
///
///
protected void btnMenuAddTechnicalDisclose2_Click(object sender, EventArgs e)
{
if (this.trWBS.SelectedNode != null)
{
if (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.PersonId, BLL.Const.CQMSTechnicalDiscloseMenuId, BLL.Const.BtnAdd))
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning);
return;
}
string id = Grid1.SelectedRowID;
var oldTechnicalDisclose = BLL.CQMS_TechnicalDiscloseService.GetTechnicalDiscloseByDataId(id);
if (oldTechnicalDisclose == null)
{
var unitWork = (from x in Funs.DB.WBS_UnitWork
join y in Funs.DB.WBS_WorkPackage on x.UnitWorkId equals y.UnitWorkId
where y.WorkPackageId == this.trWBS.SelectedNodeID
select x).FirstOrDefault();
var controlItemAndCycle = BLL.ControlItemAndCycleService.GetControlItemAndCycleById(id);
Model.Technical_TechnicalDisclose technicalDisclose = new Model.Technical_TechnicalDisclose();
technicalDisclose.TechnicalDiscloseId = SQLHelper.GetNewID();
technicalDisclose.ProjectId = this.CurrUser.LoginProjectId;
if (unitWork != null)
{
technicalDisclose.UnitId = unitWork.UnitId;
technicalDisclose.UnitWorkId = unitWork.UnitWorkId;
}
technicalDisclose.DataId = id;
technicalDisclose.DiscloseName = controlItemAndCycle.ControlItemContent;
technicalDisclose.State = "0"; //未交底
technicalDisclose.CompileMan = this.CurrUser.PersonId;
technicalDisclose.CompileDate = DateTime.Now;
BLL.CQMS_TechnicalDiscloseService.AddTechnicalDisclose(technicalDisclose);
ShowNotify("发起成功!", MessageBoxIcon.Success);
}
else
{
ShowNotify("该节点已发起设计交底!", MessageBoxIcon.Warning);
}
}
else
{
ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
}
}
else
{
ShowNotify("请选择树节点!", MessageBoxIcon.Warning);
}
}
///
/// 展开全部
///
///
///
protected void btnMenuMore_Click(object sender, EventArgs e)
{
if (this.trWBS.SelectedNode != null)
{
if (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.PersonId, BLL.Const.ControlItemAndCycleMenuId, BLL.Const.BtnAdd))
{
if (this.trWBS.SelectedNode.CommandName != "ProjectType") //非工程类型节点可以增加
{
Model.WBS_UnitWork unitWork = BLL.UnitWorkService.GetUnitWorkByUnitWorkId(this.trWBS.SelectedNodeID);
if (unitWork != null) //单位工程节点
{
this.trWBS.SelectedNode.Expanded = true;
this.trWBS.SelectedNode.Nodes.Clear();
var workPackages = from x in Funs.DB.WBS_WorkPackage where x.UnitWorkId == this.trWBS.SelectedNodeID && x.SuperWorkPack == null && x.IsApprove == true orderby x.WorkPackageCode select x;
foreach (var workPackage in workPackages)
{
TreeNode newNode = new TreeNode();
newNode.Text = workPackage.PackageContent;
newNode.NodeID = workPackage.WorkPackageId;
newNode.CommandName = "WorkPackage";
newNode.EnableExpandEvent = true;
newNode.EnableClickEvent = true;
this.trWBS.SelectedNode.Nodes.Add(newNode);
var childWorkPackages = from x in Funs.DB.WBS_WorkPackage where x.SuperWorkPackageId == workPackage.WorkPackageId && x.IsApprove == true select x;
if (childWorkPackages.Count() > 0)
{
newNode.Expanded = true;
ExpandWorkPackage(newNode.Nodes, newNode.NodeID);
}
}
}
else
{
this.trWBS.SelectedNode.Expanded = true;
this.trWBS.SelectedNode.Nodes.Clear();
ExpandWorkPackage(this.trWBS.SelectedNode.Nodes, this.trWBS.SelectedNodeID);
}
}
else
{
ShowNotify("请选择单位工程节点展开!", MessageBoxIcon.Warning);
}
}
else
{
ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
}
}
else
{
ShowNotify("请选择树节点!", MessageBoxIcon.Warning);
}
}
///
/// 展开子级分部分项节点
///
///
///
private void ExpandWorkPackage(TreeNodeCollection nodes, string parentId)
{
var workPackages = from x in Funs.DB.WBS_WorkPackage where x.SuperWorkPackageId == parentId && x.IsApprove == true orderby x.WorkPackageCode select x;
if (workPackages.Count() > 0) //存在子单位工程
{
foreach (var workPackage in workPackages)
{
TreeNode newNode = new TreeNode();
newNode.Text = workPackage.PackageContent;
newNode.NodeID = workPackage.WorkPackageId;
newNode.CommandName = "WorkPackage";
newNode.EnableExpandEvent = true;
newNode.EnableClickEvent = true;
nodes.Add(newNode);
var childWorkPackages = from x in Funs.DB.WBS_WorkPackage where x.SuperWorkPackageId == workPackage.WorkPackageId && x.IsApprove == true select x;
if (childWorkPackages.Count() > 0)
{
newNode.Expanded = true;
ExpandWorkPackage(newNode.Nodes, newNode.NodeID);
}
}
}
}
#region Tree点击事件
///
/// Tree点击事件
///
///
///
protected void trWBS_NodeCommand(object sender, TreeCommandEventArgs e)
{
BindGrid();
}
#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()
{
string strSql = @"SELECT ControlItemAndCycleId,ControlItemAndCycleCode,InitControlItemCode,ControlItemContent,ControlPoint,ControlItemDef,HGForms,SHForms,Standard,ClauseNo,CheckNum"
+ @" FROM WBS_ControlItemAndCycle ";
List listStr = new List();
strSql += " where WorkPackageId = @WorkPackageId and IsApprove=1 ";
listStr.Add(new SqlParameter("@WorkPackageId", this.trWBS.SelectedNodeID));
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
Grid1.RecordCount = tb.Rows.Count;
tb = GetFilteredTable(Grid1.FilteredData, tb);
var table = this.GetPagedDataTable(Grid1, tb);
Grid1.DataSource = table;
Grid1.DataBind();
Model.WBS_WorkPackage workPackage = BLL.WorkPackageService.GetWorkPackageByWorkPackageId(this.trWBS.SelectedNodeID);
if (workPackage != null)
{
if (workPackage.ProjectType == "1") //建筑工程
{
this.Grid1.Columns[4].HeaderText = "对应的建筑资料表格";
this.Grid1.Columns[5].Hidden = true;
}
else //安装工程
{
this.Grid1.Columns[4].HeaderText = "对应的化工资料表格";
this.Grid1.Columns[5].Hidden = false;
}
}
//for (int i = 0; i < this.Grid1.Rows.Count; i++)
//{
// Model.WBS_ControlItemAndCycle c = BLL.ControlItemAndCycleService.GetControlItemAndCycleById(this.Grid1.Rows[i].RowID.ToString());
// Model.WBS_ControlItemProject cp = BLL.ControlItemProjectService.GetControlItemProjectByCode(this.Grid1.Rows[i].DataKeys[1].ToString(), this.CurrUser.LoginProjectId);
// if (c != null)
// {
// if (!string.IsNullOrEmpty(cp.HGForms))
// {
// string[] hGForms = cp.HGForms.Split(',');
// AspNet.CheckBoxList cblHGForms = (AspNet.CheckBoxList)(this.Grid1.Rows[i].FindControl("cblHGForms"));
// cblHGForms.Items.Clear();
// foreach (var hGForm in hGForms) //加载项目基础库的表格数据
// {
// AspNet.ListItem li = new AspNet.ListItem();
// li.Text = hGForm;
// li.Value = hGForm;
// cblHGForms.Items.Add(li);
// }
// for (int j = 0; j < cblHGForms.Items.Count; j++)
// {
// if (c.HGForms.Contains(cblHGForms.Items[j].Value)) //项目中包含的表格选中
// {
// cblHGForms.Items[j].Selected = true;
// }
// }
// }
// if (!string.IsNullOrEmpty(cp.SHForms))
// {
// string[] sHForms = cp.SHForms.Split(',');
// AspNet.CheckBoxList cblSHForms = (AspNet.CheckBoxList)(this.Grid1.Rows[i].FindControl("cblSHForms"));
// cblSHForms.Items.Clear();
// foreach (var sHForm in sHForms) //加载项目基础库的表格数据
// {
// AspNet.ListItem li = new AspNet.ListItem();
// li.Text = sHForm;
// li.Value = sHForm;
// cblSHForms.Items.Add(li);
// }
// for (int j = 0; j < cblSHForms.Items.Count; j++)
// {
// if (c.SHForms.Contains(cblSHForms.Items[j].Value)) //项目中包含的表格选中
// {
// cblSHForms.Items[j].Selected = true;
// }
// }
// }
// }
//}
}
#endregion
//
//获取文本
//
//
//
public static string ConvertText(object Str)
{
string s = string.Empty;
if (Str != null)
{
string[] strs = Str.ToString().Split(',');
foreach (var item in strs)
{
s += item + "
";
}
if (!string.IsNullOrEmpty(s))
{
s = s.Substring(0, s.Length - 5);
}
}
return s;
}
///
/// 生成项目WBS编码
///
///
///
protected void btnCreateCode_Click(object sender, EventArgs e)
{
Model.SGGLDB db = Funs.DB;
string projectRealCode = BLL.ProjectService.GetProjectRealCodeByProjectId(this.CurrUser.LoginProjectId);
var unitWorks = from x in db.WBS_UnitWork where x.ProjectId == this.CurrUser.LoginProjectId orderby x.UnitWorkCode select x;
var workPackages = (from x in db.WBS_WorkPackage where x.ProjectId == this.CurrUser.LoginProjectId && x.IsApprove == true select x).ToList();
var controlItemAndCycles = (from x in db.WBS_ControlItemAndCycle where x.ProjectId == this.CurrUser.LoginProjectId && x.IsApprove == true select x).ToList();
foreach (var unitWork in unitWorks)
{
unitWork.WBSCode = projectRealCode + unitWork.UnitWorkCode;
var workPackage1s = workPackages.Where(x => x.UnitWorkId == unitWork.UnitWorkId && x.SuperWorkPack == null).OrderBy(x => x.WorkPackageCode);
foreach (var workPackage1 in workPackage1s)
{
if (!workPackage1.PackageContent.Contains("-"))
{
workPackage1.WBSCode = projectRealCode + unitWork.UnitWorkCode + unitWork.ProjectType + workPackage1.PackageCode;
}
else
{
workPackage1.WBSCode = projectRealCode + unitWork.UnitWorkCode + unitWork.ProjectType + workPackage1.PackageCode + workPackage1.WorkPackageCode.Substring(workPackage1.WorkPackageCode.Length - 2, 2);
}
UpdateWBSCode(db, workPackages, workPackage1.WorkPackageId, workPackage1.WBSCode, controlItemAndCycles);
}
}
db.SubmitChanges();
ShowNotify("生成成功!", MessageBoxIcon.Success);
}
private void UpdateWBSCode(Model.SGGLDB db, List workPackages, string workPackageId, string wbsCode, List controlItemAndCycles)
{
var childWorkPackages = workPackages.Where(x => x.SuperWorkPackageId == workPackageId);
if (childWorkPackages.Count() > 0)
{
foreach (var childWorkPackage in childWorkPackages)
{
if (!childWorkPackage.PackageContent.Contains("-"))
{
childWorkPackage.WBSCode = wbsCode + childWorkPackage.PackageCode;
}
else
{
childWorkPackage.WBSCode = wbsCode + childWorkPackage.PackageCode + childWorkPackage.WorkPackageCode.Substring(childWorkPackage.WorkPackageCode.Length - 2, 2);
}
UpdateWBSCode(db, workPackages, childWorkPackage.WorkPackageId, childWorkPackage.WBSCode, controlItemAndCycles);
}
}
else
{
var controlItemAndCycleItems = controlItemAndCycles.Where(x => x.WorkPackageId == workPackageId);
foreach (var controlItemAndCycleItem in controlItemAndCycleItems)
{
controlItemAndCycleItem.WBSCode = wbsCode + controlItemAndCycleItem.InitControlItemCode.Substring(controlItemAndCycleItem.InitControlItemCode.Length - 2, 2);
}
}
}
#region 下载WBS编码规则文件
///
/// 下载WBS编码规则文件按钮
///
///
///
protected void btnFile_Click(object sender, EventArgs e)
{
PageContext.RegisterStartupScript(Confirm.GetShowReference("确定下载WBS编码规则文件吗?", String.Empty, MessageBoxIcon.Question, PageManager1.GetCustomEventReference(false, "Confirm_OK"), PageManager1.GetCustomEventReference("Confirm_Cancel")));
}
///
/// 下载导入模板
///
///
///
protected void PageManager1_CustomEvent(object sender, CustomEventArgs e)
{
if (e.EventArgument == "Confirm_OK")
{
string rootPath = Server.MapPath("~/");
string filePath = Const.WBSCodeTemplateUrl;
string uploadfilepath = rootPath + filePath;
string fileName = Path.GetFileName(filePath);
FileInfo info = new FileInfo(uploadfilepath);
long fileSize = info.Length;
Response.ClearContent();
Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
Response.ContentType = "excel/plain";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.AddHeader("Content-Length", fileSize.ToString().Trim());
Response.TransmitFile(uploadfilepath, 0, fileSize);
Response.End();
}
}
#endregion
}
}