337 lines
13 KiB
C#
337 lines
13 KiB
C#
using BLL;
|
|
using Newtonsoft.Json.Linq;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Data.SqlClient;
|
|
using System.Linq;
|
|
using System.Web.UI.WebControls;
|
|
using AspNet = System.Web.UI.WebControls;
|
|
|
|
namespace FineUIPro.Web.CQMS.ProcessControl
|
|
{
|
|
public partial class ShowUnitWork : PageBase
|
|
{
|
|
/// <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;
|
|
}
|
|
}
|
|
|
|
#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>();
|
|
string cnProfessionalId = Request.Params["CNPrefessionalId"];
|
|
if (!string.IsNullOrEmpty(cnProfessionalId))
|
|
{
|
|
InitTreeMenu(cnProfessionalId);
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 加载树
|
|
/// </summary>
|
|
/// <param name="cnProfessionalId"></param>
|
|
private void InitTreeMenu(string cnProfessionalId)
|
|
{
|
|
this.tvControlItem.Nodes.Clear();
|
|
this.tvControlItem.ShowHeader = false;
|
|
this.tvControlItem.ShowBorder = false;
|
|
this.tvControlItem.EnableIcons = true;
|
|
this.tvControlItem.AutoScroll = true;
|
|
this.tvControlItem.EnableSingleClickExpand = true;
|
|
|
|
var unitWorks = from x in Funs.DB.WBS_UnitWork where x.ProjectId == this.CurrUser.LoginProjectId orderby x.UnitWorkCode select x;
|
|
if (unitWorks.Count() > 0)
|
|
{
|
|
foreach (var q in unitWorks)
|
|
{
|
|
TreeNode rootNode = new TreeNode();
|
|
rootNode.Text = q.UnitWorkName;
|
|
rootNode.NodeID = q.UnitWorkId;
|
|
rootNode.EnableExpandEvent = true;
|
|
rootNode.EnableClickEvent = true;
|
|
rootNode.Expanded = true;
|
|
rootNode.CommandName = "单位工程";
|
|
this.tvControlItem.Nodes.Add(rootNode);
|
|
|
|
var divisions = (from x in BLL.Funs.DB.WBS_DivisionProject
|
|
where x.CNProfessionalId == cnProfessionalId && x.ProjectId == this.CurrUser.LoginProjectId && x.SuperDivisionId == null && x.UnitWorkId == q.UnitWorkId && x.IsSelected == true
|
|
orderby x.SortIndex
|
|
select x).ToList();
|
|
Model.Base_CNProfessional cNProfessional = new Model.Base_CNProfessional();
|
|
if (divisions.Count() == 0 && cnProfessionalId == BLL.Const.CNProfessionalCVId)
|
|
{
|
|
cNProfessional = (from x in BLL.Funs.DB.Base_CNProfessional where x.CNProfessionalId == BLL.Const.CNProfessionalConstructId orderby x.SortIndex select x).FirstOrDefault();
|
|
}
|
|
else
|
|
{
|
|
cNProfessional = (from x in BLL.Funs.DB.Base_CNProfessional where x.CNProfessionalId == cnProfessionalId orderby x.SortIndex select x).FirstOrDefault();
|
|
}
|
|
if (cNProfessional != null)
|
|
{
|
|
TreeNode newNode = new TreeNode();
|
|
newNode.Text = cNProfessional.ProfessionalName;
|
|
newNode.NodeID = cNProfessional.CNProfessionalId+"|"+ q.UnitWorkId;
|
|
newNode.CommandName = "专业";
|
|
newNode.EnableExpandEvent = true;
|
|
newNode.EnableClickEvent = true;
|
|
newNode.Expanded = true;
|
|
rootNode.Nodes.Add(newNode);
|
|
|
|
this.GetNodes(newNode.Nodes, cNProfessional.CNProfessionalId, newNode, q.UnitWorkId);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 遍历节点
|
|
/// <summary>
|
|
/// 遍历节点
|
|
/// </summary>
|
|
/// <param name="nodes"></param>
|
|
/// <param name="parentId"></param>
|
|
/// <param name="node"></param>
|
|
/// <param name="unitWorkId"></param>
|
|
private void GetNodes(TreeNodeCollection nodes, string parentId, TreeNode node, string unitWorkId)
|
|
{
|
|
if (!string.IsNullOrEmpty(unitWorkId))
|
|
{
|
|
var divisions = (from x in BLL.Funs.DB.WBS_DivisionProject
|
|
where x.CNProfessionalId == parentId && x.ProjectId == this.CurrUser.LoginProjectId && x.SuperDivisionId == null && x.UnitWorkId == unitWorkId && x.IsSelected == true
|
|
orderby x.SortIndex
|
|
select x).ToList();
|
|
foreach (var q in divisions)
|
|
{
|
|
TreeNode newNode = new TreeNode();
|
|
newNode.Text = q.DivisionName;
|
|
newNode.NodeID = q.DivisionProjectId;
|
|
newNode.EnableExpandEvent = true;
|
|
newNode.EnableClickEvent = true;
|
|
newNode.Expanded = true;
|
|
node.Nodes.Add(newNode);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
var childDivisions = (from x in BLL.Funs.DB.WBS_DivisionProject
|
|
where x.SuperDivisionId == parentId && x.ProjectId == this.CurrUser.LoginProjectId
|
|
&& x.IsSelected == true
|
|
orderby x.SortIndex
|
|
select x).ToList();
|
|
foreach (var q in childDivisions)
|
|
{
|
|
TreeNode newNode = new TreeNode();
|
|
newNode.Text = q.DivisionName;
|
|
newNode.NodeID = q.DivisionProjectId;
|
|
newNode.EnableExpandEvent = true;
|
|
newNode.EnableClickEvent = true;
|
|
newNode.Expanded = true;
|
|
nodes.Add(newNode);
|
|
}
|
|
}
|
|
for (int i = 0; i < nodes.Count; i++)
|
|
{
|
|
GetNodes(nodes[i].Nodes, nodes[i].NodeID, nodes[i], string.Empty);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 点击树节点
|
|
/// <summary>
|
|
/// 点击树节点
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void tvControlItem_NodeCommand(object sender, TreeCommandEventArgs e)
|
|
{
|
|
this.hdDivisionProjectId.Text = this.tvControlItem.SelectedNode.NodeID;
|
|
foreach (JObject mergedRow in Grid1.GetMergedData())
|
|
{
|
|
JObject values = mergedRow.Value<JObject>("values");
|
|
int i = mergedRow.Value<int>("index");
|
|
AspNet.CheckBox ckb = (AspNet.CheckBox)(this.Grid1.Rows[i].FindControl("cbSelect"));
|
|
if (ckb.Checked)
|
|
{
|
|
SelectedList.Add(this.Grid1.Rows[i].RowID);
|
|
}
|
|
else
|
|
{
|
|
NoSelectedList.Add(this.Grid1.Rows[i].RowID);
|
|
}
|
|
}
|
|
BindGrid();
|
|
}
|
|
#endregion
|
|
|
|
#region 数据绑定
|
|
/// <summary>
|
|
/// 绑定数据
|
|
/// </summary>
|
|
private void BindGrid()
|
|
{
|
|
string strSql = @"SELECT V.BreakdownProjectId,
|
|
V.ProjectId,
|
|
V.BreakdownCode,
|
|
V.BreakdownName,
|
|
V.DivisionProjectId,
|
|
V.Basis,
|
|
V.CheckPoints,
|
|
V.RecordAndCode,
|
|
V.Class,
|
|
V.SortIndex,
|
|
V.Remark,
|
|
V.AttachUrl,
|
|
V.IsAcceptance,
|
|
V.FenBao,
|
|
V.WuHuan,
|
|
V.JianLi,
|
|
V.YeZhu,
|
|
V.IsSelected"
|
|
+ @" FROM View_WBS_BreakdownProject AS V "
|
|
+ @" WHERE V.ProjectId=@ProjectId AND V.DivisionProjectId=@divisionProjectId";
|
|
List<SqlParameter> listStr = new List<SqlParameter>();
|
|
listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId));
|
|
listStr.Add(new SqlParameter("@divisionProjectId", this.hdDivisionProjectId.Text.Trim()));
|
|
SqlParameter[] parameter = listStr.ToArray();
|
|
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
|
|
Grid1.RecordCount = tb.Rows.Count;
|
|
var table = this.GetPagedDataTable(Grid1, tb);
|
|
Grid1.DataSource = table;
|
|
Grid1.DataBind();
|
|
}
|
|
#endregion
|
|
|
|
#region 分页
|
|
/// <summary>
|
|
/// 分页
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
|
|
{
|
|
Grid1.PageIndex = e.NewPageIndex;
|
|
BindGrid();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 下拉框分页
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
|
|
BindGrid();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 排序
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void Grid1_Sort(object sender, FineUIPro.GridSortEventArgs e)
|
|
{
|
|
Grid1.SortDirection = e.SortDirection;
|
|
Grid1.SortField = e.SortField;
|
|
BindGrid();
|
|
}
|
|
#endregion
|
|
|
|
#region 确定
|
|
/// <summary>
|
|
/// 确定按钮
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void btnSure_Click(object sender, EventArgs e)
|
|
{
|
|
string ids = string.Empty;
|
|
bool res = false;
|
|
foreach (JObject mergedRow in Grid1.GetMergedData())
|
|
{
|
|
JObject values = mergedRow.Value<JObject>("values");
|
|
int i = mergedRow.Value<int>("index");
|
|
AspNet.CheckBox ckb = (AspNet.CheckBox)(this.Grid1.Rows[i].FindControl("cbSelect"));
|
|
if (ckb.Checked)
|
|
{
|
|
res = true;
|
|
break;
|
|
}
|
|
}
|
|
if (SelectedList.Count == 0 && !res)
|
|
{
|
|
Alert.ShowInTop("没有选中任何项!", MessageBoxIcon.Warning);
|
|
return;
|
|
}
|
|
foreach (JObject mergedRow in Grid1.GetMergedData())
|
|
{
|
|
JObject values = mergedRow.Value<JObject>("values");
|
|
int i = mergedRow.Value<int>("index");
|
|
AspNet.CheckBox ckb = (AspNet.CheckBox)(this.Grid1.Rows[i].FindControl("cbSelect"));
|
|
if (ckb.Checked)
|
|
{
|
|
SelectedList.Add(this.Grid1.Rows[i].RowID);
|
|
}
|
|
else
|
|
{
|
|
if (SelectedList.Contains(this.Grid1.Rows[i].RowID))
|
|
{
|
|
SelectedList.Remove(this.Grid1.Rows[i].RowID);
|
|
}
|
|
NoSelectedList.Add(this.Grid1.Rows[i].RowID);
|
|
}
|
|
}
|
|
foreach (var item in SelectedList.Distinct())
|
|
{
|
|
ids += item + ",";
|
|
}
|
|
if (!string.IsNullOrEmpty(ids))
|
|
{
|
|
ids = ids.Substring(0, ids.LastIndexOf(","));
|
|
}
|
|
|
|
string scripts = String.Format("F.getActiveWindow().window.reloadGrid('{0}');", ids);
|
|
PageContext.RegisterStartupScript(scripts + ActiveWindow.GetHidePostBackReference());
|
|
|
|
//PageContext.RegisterStartupScript(ActiveWindow.GetWriteBackValueReference(ids)
|
|
// + ActiveWindow.GetHidePostBackReference());
|
|
}
|
|
#endregion
|
|
}
|
|
} |