398 lines
16 KiB
C#
398 lines
16 KiB
C#
using BLL;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Data.SqlClient;
|
|
using System.Linq;
|
|
using System.Web.UI.WebControls;
|
|
|
|
namespace FineUIPro.Web.CQMS.WBS.Control
|
|
{
|
|
public partial class DivisionDivideAndCrop : PageBase
|
|
{
|
|
#region 定义变量
|
|
/// <summary>
|
|
/// 被选择项列表
|
|
/// </summary>
|
|
public List<string> SelectedList
|
|
{
|
|
get
|
|
{
|
|
return (List<string>)ViewState["SelectedList"];
|
|
}
|
|
set
|
|
{
|
|
ViewState["SelectedList"] = value;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 未被选择项列表
|
|
/// </summary>
|
|
public List<string> NoSelectedList
|
|
{
|
|
get
|
|
{
|
|
return (List<string>)ViewState["NoSelectedList"];
|
|
}
|
|
set
|
|
{
|
|
ViewState["NoSelectedList"] = value;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 加载
|
|
/// <summary>
|
|
/// 加载页面
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if (!IsPostBack)
|
|
{
|
|
this.SelectedList = new List<string>();
|
|
this.NoSelectedList = new List<string>();
|
|
GetButtonPower();
|
|
InitTreeMenu();
|
|
BindGrid();
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 加载树
|
|
/// <summary>
|
|
/// 加载树
|
|
/// </summary>
|
|
private void InitTreeMenu()
|
|
{
|
|
this.trUnitWork.Nodes.Clear();
|
|
this.trUnitWork.ShowBorder = false;
|
|
this.trUnitWork.ShowHeader = false;
|
|
this.trUnitWork.EnableIcons = true;
|
|
this.trUnitWork.AutoScroll = true;
|
|
this.trUnitWork.EnableSingleClickExpand = true;
|
|
List<Model.WBS_UnitWork> supUnitWorkList = BLL.UnitWorkService.GetUnitWorkLists(this.CurrUser.LoginProjectId);
|
|
if (supUnitWorkList.Count() > 0)
|
|
{
|
|
foreach (var item in supUnitWorkList)
|
|
{
|
|
TreeNode node = new TreeNode();
|
|
node.Text = item.UnitWorkName;
|
|
node.NodeID = item.UnitWorkId;
|
|
node.CommandName = "supUnitWork";
|
|
node.EnableClickEvent = true;
|
|
node.EnableExpandEvent = true;
|
|
this.trUnitWork.Nodes.Add(node);
|
|
TreeNode emptyNode = new TreeNode();
|
|
emptyNode.Text = "";
|
|
emptyNode.NodeID = "";
|
|
node.Nodes.Add(emptyNode);
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 展开树
|
|
/// <summary>
|
|
/// 展开树
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void trUnitWork_NodeExpand(object sender, TreeNodeEventArgs e)
|
|
{
|
|
e.Node.Nodes.Clear();
|
|
if (e.Node.CommandName == "supUnitWork") //展开单位工程节点
|
|
{
|
|
var unitWorks = from x in Funs.DB.WBS_UnitWork
|
|
where x.SuperUnitWork == e.Node.NodeID
|
|
orderby x.UnitWorkCode
|
|
select x;
|
|
foreach (var unitWork in unitWorks)
|
|
{
|
|
TreeNode newNode = new TreeNode();
|
|
newNode.Text = unitWork.UnitWorkName;
|
|
newNode.NodeID = unitWork.UnitWorkId;
|
|
newNode.CommandName = "unitWork";
|
|
newNode.EnableExpandEvent = true;
|
|
newNode.EnableClickEvent = true;
|
|
e.Node.Nodes.Add(newNode);
|
|
var installation3s = from x in Funs.DB.WBS_UnitWork where x.SuperUnitWork == unitWork.UnitWorkId orderby x.UnitWorkCode select x;
|
|
if (installation3s.Count() > 0)
|
|
{
|
|
TreeNode emptyNode = new TreeNode();
|
|
emptyNode.Text = "";
|
|
emptyNode.NodeID = "";
|
|
newNode.Nodes.Add(emptyNode);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 节点选择事件
|
|
/// <summary>
|
|
/// tv节点选中事件
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void trUnitWork_NodeCommand(object sender, TreeCommandEventArgs e)
|
|
{
|
|
for (int i = 0; i < this.Grid1.Rows.Count; i++)
|
|
{
|
|
if (this.Grid1.SelectedRowIDArray.Contains(this.Grid1.Rows[i].RowID))
|
|
{
|
|
SelectedList.Add(this.Grid1.Rows[i].RowID);
|
|
}
|
|
else
|
|
{
|
|
NoSelectedList.Add(this.Grid1.Rows[i].RowID);
|
|
}
|
|
}
|
|
BindGrid();
|
|
}
|
|
#endregion
|
|
|
|
#region 数据绑定和事件
|
|
/// <summary>
|
|
/// 数据绑定
|
|
/// </summary>
|
|
public void BindGrid()
|
|
{
|
|
string strSql = @"select * from(select a.DivisionId,a.ProjectId,a.ParentId,a.DivisionLevel,a.BranchEngineeringCode,a.BranchEngineeringName,a.SubBranchEngineeringName,a.ProEngineeringCode,a.ProEngineeringName,a.ProEngineeringNum,a.Remark,a.AddUser,a.OperateTime,a.Sort,a.Status from Division_SubProjects as a where isnull(a.ProjectId,'')='' ";
|
|
string strSql1 = @"select a.DivisionId,a.ProjectId,a.ParentId,a.DivisionLevel,a.BranchEngineeringCode,a.BranchEngineeringName,a.SubBranchEngineeringName,a.ProEngineeringCode,a.ProEngineeringName,a.ProEngineeringNum,a.Remark,a.AddUser,a.OperateTime,a.Sort,a.Status from Division_SubProjects as a inner join Base_Project as b on a.ProjectId=b.ProjectId where a.ProjectId=@ProjectId ";
|
|
List<SqlParameter> listStr = new List<SqlParameter>();
|
|
listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId));
|
|
SqlParameter[] parameter = listStr.ToArray();
|
|
var zxsql = strSql + " union all " + strSql1 + " ) as t order by t.BranchEngineeringCode,t.Sort,t.DivisionLevel,t.ProEngineeringNum asc";
|
|
DataTable tb = SQLHelper.GetDataTableRunText(zxsql, parameter);
|
|
Grid1.DataSource = tb;
|
|
Grid1.DataBind();
|
|
|
|
var selectIds = (from x in Funs.DB.WBS_DivisionDivide where x.UnitWorkId == this.trUnitWork.SelectedNodeID select x.DivisionId).ToList();
|
|
if (selectIds.Count() > 0)
|
|
{
|
|
this.Grid1.SelectedRowIDArray = selectIds.ToArray();
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 保存
|
|
/// <summary>
|
|
/// 保存按钮
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void btnSave_Click(object sender, EventArgs e)
|
|
{
|
|
if (!string.IsNullOrEmpty(this.trUnitWork.SelectedNodeID))
|
|
{
|
|
SelectedList.Clear();
|
|
NoSelectedList.Clear();
|
|
for (int i = 0; i < this.Grid1.Rows.Count; i++)
|
|
{
|
|
if (this.Grid1.SelectedRowIDArray.Contains(this.Grid1.Rows[i].RowID))
|
|
{
|
|
SelectedList.Add(this.Grid1.Rows[i].RowID);
|
|
}
|
|
else
|
|
{
|
|
NoSelectedList.Add(this.Grid1.Rows[i].RowID);
|
|
}
|
|
}
|
|
foreach (var item in SelectedList.Distinct())
|
|
{
|
|
Model.WBS_DivisionDivide divisionDivide = BLL.DivisionDivideService.GetDivisionDivideByDivisionId(this.trUnitWork.SelectedNodeID, item);
|
|
if (divisionDivide == null)
|
|
{
|
|
Model.WBS_DivisionDivide newdivisiondivide = new Model.WBS_DivisionDivide();
|
|
newdivisiondivide.DivisionDivideId = SQLHelper.GetNewID(typeof(Model.WBS_DivisionDivide));
|
|
newdivisiondivide.ProjectId = this.CurrUser.LoginProjectId;
|
|
newdivisiondivide.UnitWorkId = this.trUnitWork.SelectedNodeID;
|
|
newdivisiondivide.DivisionId = item;
|
|
BLL.DivisionDivideService.AddDivisionDivide(newdivisiondivide);
|
|
}
|
|
}
|
|
NoSelectedList = NoSelectedList.Distinct().ToList();
|
|
var q = NoSelectedList.Distinct().ToList();
|
|
foreach (var item in q)
|
|
{
|
|
foreach (var i in SelectedList.Distinct())
|
|
{
|
|
if (item == i)
|
|
{
|
|
NoSelectedList.Remove(item);
|
|
}
|
|
}
|
|
}
|
|
foreach (var item in NoSelectedList)
|
|
{
|
|
Model.WBS_DivisionDivide divisionDivide = BLL.DivisionDivideService.GetDivisionDivideByDivisionId(this.trUnitWork.SelectedNodeID,item);
|
|
if (divisionDivide != null)
|
|
{
|
|
BLL.DivisionDivideService.DeleteDivisionDivideByDivisionId(item);
|
|
}
|
|
}
|
|
ShowNotify("保存成功!", MessageBoxIcon.Success);
|
|
}
|
|
else
|
|
{
|
|
Alert.ShowInTop("请先选择单位工程/子单位工程!", MessageBoxIcon.Warning);
|
|
return;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 导入
|
|
/// <summary>
|
|
/// 导入
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void btnImport_Click(object sender, EventArgs e)
|
|
{
|
|
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("DivisionDivideAndCropDataIn.aspx", "导入 - ")));
|
|
}
|
|
#endregion
|
|
|
|
#region 拷贝
|
|
/// <summary>
|
|
/// 拷贝
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void btnCopy_Click(object sender, EventArgs e)
|
|
{
|
|
bool isOk = false;
|
|
if (!string.IsNullOrEmpty(this.trUnitWork.SelectedNodeID))
|
|
{
|
|
var unitwork = BLL.UnitWorkService.GetUnitWorkByUnitWorkId(this.trUnitWork.SelectedNodeID);
|
|
if (unitwork != null)
|
|
{
|
|
Model.WBS_UnitWork newSupUnitWork = new Model.WBS_UnitWork();
|
|
newSupUnitWork.UnitWorkId = SQLHelper.GetNewID(typeof(Model.WBS_UnitWork));
|
|
newSupUnitWork.UnitWorkCode = unitwork.UnitWorkCode;
|
|
newSupUnitWork.UnitWorkName = unitwork.UnitWorkName;
|
|
newSupUnitWork.ProjectId = this.CurrUser.LoginProjectId;
|
|
newSupUnitWork.SuperUnitWork = unitwork.SuperUnitWork;
|
|
BLL.UnitWorkService.AddUnitWork(newSupUnitWork);
|
|
isOk = true;
|
|
|
|
var divisionDivides = BLL.DivisionDivideService.GetDivisionDivideByUnitWorkId(this.trUnitWork.SelectedNodeID);
|
|
if (divisionDivides != null)
|
|
{
|
|
foreach (var item in divisionDivides)
|
|
{
|
|
Model.WBS_DivisionDivide newDivisionDivide = new Model.WBS_DivisionDivide();
|
|
newDivisionDivide.DivisionDivideId = SQLHelper.GetNewID(typeof(Model.WBS_DivisionDivide));
|
|
newDivisionDivide.ProjectId = this.CurrUser.LoginProjectId;
|
|
newDivisionDivide.UnitWorkId = newSupUnitWork.UnitWorkId;
|
|
newDivisionDivide.DivisionId = item.DivisionId;
|
|
BLL.DivisionDivideService.AddDivisionDivide(newDivisionDivide);
|
|
isOk = true;
|
|
}
|
|
}
|
|
|
|
var unitworkList = BLL.UnitWorkService.GetUnitWorksBySupUnitWork(this.trUnitWork.SelectedNodeID);
|
|
if (unitworkList.Count() > 0)
|
|
{
|
|
foreach (var item in unitworkList)
|
|
{
|
|
Model.WBS_UnitWork newUnitWork = new Model.WBS_UnitWork();
|
|
newUnitWork.UnitWorkId = SQLHelper.GetNewID(typeof(Model.WBS_UnitWork));
|
|
newUnitWork.UnitWorkCode = item.UnitWorkCode;
|
|
newUnitWork.UnitWorkName = item.UnitWorkName;
|
|
newUnitWork.ProjectId = this.CurrUser.LoginProjectId;
|
|
newUnitWork.SuperUnitWork = newSupUnitWork.UnitWorkId;
|
|
BLL.UnitWorkService.AddUnitWork(newUnitWork);
|
|
isOk = true;
|
|
|
|
var divisionDivideLists = BLL.DivisionDivideService.GetDivisionDivideByUnitWorkId(item.UnitWorkId);
|
|
if (divisionDivideLists != null)
|
|
{
|
|
foreach (var divis in divisionDivideLists)
|
|
{
|
|
Model.WBS_DivisionDivide newDivisionDivide = new Model.WBS_DivisionDivide();
|
|
newDivisionDivide.DivisionDivideId = SQLHelper.GetNewID(typeof(Model.WBS_DivisionDivide));
|
|
newDivisionDivide.ProjectId = this.CurrUser.LoginProjectId;
|
|
newDivisionDivide.UnitWorkId = newUnitWork.UnitWorkId;
|
|
newDivisionDivide.DivisionId = divis.DivisionId;
|
|
BLL.DivisionDivideService.AddDivisionDivide(newDivisionDivide);
|
|
isOk = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (isOk)
|
|
{
|
|
ShowNotify("拷贝成功!", MessageBoxIcon.Success);
|
|
}
|
|
else
|
|
{
|
|
ShowNotify("拷贝失败!", MessageBoxIcon.Success);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 修改
|
|
/// <summary>
|
|
/// 修改
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void btnEdit_Click(object sender, EventArgs e)
|
|
{
|
|
if (!string.IsNullOrEmpty(this.trUnitWork.SelectedNodeID))
|
|
{
|
|
var unitWork = BLL.UnitWorkService.GetUnitWorkByUnitWorkId(this.trUnitWork.SelectedNodeID);
|
|
if (unitWork != null)
|
|
{
|
|
PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("../../../ProjectData/UnitWorkEdit.aspx?Id={0}&&SuperId={1}", this.trUnitWork.SelectedNode.NodeID, unitWork.SuperUnitWork, "编辑 - ")));
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 关闭弹出窗体
|
|
/// <summary>
|
|
/// 关闭弹出窗体
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void Window2_Close(object sender, WindowCloseEventArgs e)
|
|
{
|
|
InitTreeMenu();
|
|
}
|
|
#endregion
|
|
|
|
#region 获取按钮权限
|
|
/// <summary>
|
|
/// 获取按钮权限
|
|
/// </summary>
|
|
/// <param name="button"></param>
|
|
/// <returns></returns>
|
|
private void GetButtonPower()
|
|
{
|
|
if (Request.Params["value"] == "0")
|
|
{
|
|
return;
|
|
}
|
|
var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.DivisionDivideAndCropMenuId);
|
|
if (buttonList.Count() > 0)
|
|
{
|
|
if (buttonList.Contains(BLL.Const.BtnSave))
|
|
{
|
|
this.btnSave.Hidden = false;
|
|
this.btnImport.Hidden = false;
|
|
this.btnCopy.Hidden = false;
|
|
this.btnEdit.Hidden = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
} |