389 lines
13 KiB
C#
389 lines
13 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Data;
|
|||
|
using System.Data.SqlClient;
|
|||
|
using System.Web;
|
|||
|
using System.Web.UI;
|
|||
|
using System.Web.UI.WebControls;
|
|||
|
using BLL;
|
|||
|
|
|||
|
namespace FineUIPro.Web.common.ProjectSet
|
|||
|
{
|
|||
|
public partial class SelectUnit : PageBase
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// 项目id
|
|||
|
/// </summary>
|
|||
|
public string ProjectId
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
return (string)ViewState["ProjectId"];
|
|||
|
}
|
|||
|
set
|
|||
|
{
|
|||
|
ViewState["ProjectId"] = value;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
protected void Page_Load(object sender, EventArgs e)
|
|||
|
{
|
|||
|
// 表头过滤
|
|||
|
FilterDataRowItem = FilterDataRowItemImplement;
|
|||
|
|
|||
|
if (!IsPostBack)
|
|||
|
{
|
|||
|
this.ProjectId = Request.Params["projectId"];
|
|||
|
//ddlPageSize.SelectedValue = Grid1.PageSize.ToString();
|
|||
|
|
|||
|
InitTreeMenu();//加载树
|
|||
|
|
|||
|
//BindGrid();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void BindGrid()
|
|||
|
{
|
|||
|
string strSql = @"select u.UnitId,u.UnitCode,u.UnitName
|
|||
|
from dbo.Base_Unit u
|
|||
|
where IsSubUnit=@IsSubUnit";
|
|||
|
|
|||
|
List<SqlParameter> parms = new List<SqlParameter>();
|
|||
|
|
|||
|
if (this.tvUnit.SelectedNode == null)
|
|||
|
{
|
|||
|
parms.Add(new SqlParameter("@IsSubUnit", true));
|
|||
|
}
|
|||
|
|
|||
|
else
|
|||
|
{
|
|||
|
parms.Add(new SqlParameter("@IsSubUnit", Convert.ToBoolean(this.tvUnit.SelectedNode.NodeID)));
|
|||
|
//if (this.tvUnit.SelectedNode.NodeID == "true")
|
|||
|
//{
|
|||
|
// strSql += " and r.PropertyId=@PropertyId ";
|
|||
|
// parms.Add(new SqlParameter("@PropertyId", Const.PropertyId_2));
|
|||
|
//}
|
|||
|
//else
|
|||
|
//{
|
|||
|
// strSql += " or IsSubUnit is null";
|
|||
|
//}
|
|||
|
|
|||
|
strSql += " order by UnitCode";
|
|||
|
}
|
|||
|
SqlParameter[] parameter = parms.ToArray();
|
|||
|
|
|||
|
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
|
|||
|
//Grid1.Items.Clear();
|
|||
|
Grid1.RecordCount = tb.Rows.Count;
|
|||
|
tb = GetFilteredTable(Grid1.FilteredData, tb);
|
|||
|
var table = this.GetPagedDataTable(Grid1, tb);
|
|||
|
|
|||
|
Grid1.DataSource = tb;
|
|||
|
Grid1.DataBind();
|
|||
|
|
|||
|
bool type = false;
|
|||
|
if (tvUnit.SelectedNodeID == "true")
|
|||
|
{
|
|||
|
type = true; // 本部单位
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
type = false; // 外部单位
|
|||
|
}
|
|||
|
var pro = BLL.Project_UnitService.GetProjectUnitList(this.ProjectId, type);
|
|||
|
if (pro.Count() > 0)
|
|||
|
{
|
|||
|
string[] arr = new string[pro.Count()];
|
|||
|
int i = 0;
|
|||
|
foreach (var q in pro)
|
|||
|
{
|
|||
|
arr[i] = q.UnitId;
|
|||
|
i++;
|
|||
|
}
|
|||
|
Grid1.SelectedRowIDArray = arr;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
#region 表头过滤
|
|||
|
protected void Grid1_FilterChange(object sender, EventArgs e)
|
|||
|
{
|
|||
|
BindGrid();
|
|||
|
}
|
|||
|
|
|||
|
private bool FilterDataRowItemImplement(object sourceObj, string fillteredOperator, object fillteredObj, string column)
|
|||
|
{
|
|||
|
bool valid = false;
|
|||
|
if (column == "UnitCode")
|
|||
|
{
|
|||
|
string sourceValue = sourceObj.ToString();
|
|||
|
string fillteredValue = fillteredObj.ToString();
|
|||
|
if (fillteredOperator == "equal")
|
|||
|
{
|
|||
|
if (sourceValue == fillteredValue)
|
|||
|
{
|
|||
|
valid = true;
|
|||
|
}
|
|||
|
}
|
|||
|
else if (fillteredOperator == "contain")
|
|||
|
{
|
|||
|
if (sourceValue.Contains(fillteredValue))
|
|||
|
{
|
|||
|
valid = true;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
else if (column == "UnitName")
|
|||
|
{
|
|||
|
string sourceValue = sourceObj.ToString();
|
|||
|
string fillteredValue = fillteredObj.ToString();
|
|||
|
if (fillteredOperator == "equal")
|
|||
|
{
|
|||
|
if (sourceValue == fillteredValue)
|
|||
|
{
|
|||
|
valid = true;
|
|||
|
}
|
|||
|
}
|
|||
|
else if (fillteredOperator == "contain")
|
|||
|
{
|
|||
|
if (sourceValue.Contains(fillteredValue))
|
|||
|
{
|
|||
|
valid = true;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
return valid;
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region
|
|||
|
/// <summary>
|
|||
|
/// 加载树
|
|||
|
/// </summary>
|
|||
|
private void InitTreeMenu()
|
|||
|
{
|
|||
|
this.tvUnit .Nodes.Clear();
|
|||
|
TreeNode rootNode = new TreeNode();
|
|||
|
rootNode.Text = "单位性质";
|
|||
|
rootNode.NodeID = null;
|
|||
|
rootNode.Expanded = true;
|
|||
|
this.tvUnit.Nodes.Add(rootNode);
|
|||
|
TreeNode tn = new TreeNode();
|
|||
|
tn.Text = "外部单位";
|
|||
|
tn.NodeID = "false";
|
|||
|
tn.EnableClickEvent = true;
|
|||
|
tn.Expanded = true;
|
|||
|
rootNode.Nodes.Add(tn);
|
|||
|
TreeNode tn1 = new TreeNode();
|
|||
|
tn1.Text = "内部单位";
|
|||
|
tn1.NodeID = "true";
|
|||
|
tn1.Expanded = true;
|
|||
|
tn1.EnableClickEvent = true;
|
|||
|
rootNode.Nodes.Add(tn1);
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region 点击TreeView
|
|||
|
/// <summary>
|
|||
|
/// 点击TreeView
|
|||
|
/// </summary>
|
|||
|
/// <param name="sender"></param>
|
|||
|
/// <param name="e"></param>
|
|||
|
protected void tvUnit_NodeCommand(object sender, TreeCommandEventArgs e)
|
|||
|
{
|
|||
|
if (!string.IsNullOrEmpty(this.tvUnit.SelectedNode.NodeID))
|
|||
|
{
|
|||
|
BindGrid();
|
|||
|
}
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
protected void btnEdit_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.ProjectUnitMenuId, Const.BtnSave))
|
|||
|
{
|
|||
|
string type = string.Empty;
|
|||
|
string coutValue = IsSave();
|
|||
|
|
|||
|
if (!string.IsNullOrEmpty(coutValue))
|
|||
|
{
|
|||
|
ShowNotify(coutValue + "请选择单位类型!");
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
BLL.Project_UnitService.DeleteProject_UnitByProjectId(this.ProjectId, Convert.ToBoolean(tvUnit.SelectedNodeID));
|
|||
|
//int[] selections = Grid1.SelectedRowIndexArray;
|
|||
|
string[] selectRowId = Grid1.SelectedRowIDArray;
|
|||
|
int n = 0;
|
|||
|
int j = 0;
|
|||
|
int[] selections = new int[selectRowId.Count()];
|
|||
|
foreach (GridRow row in Grid1.Rows)
|
|||
|
{
|
|||
|
if (selectRowId.Contains(row.DataKeys[0]))
|
|||
|
{
|
|||
|
selections[n] = j;
|
|||
|
n++;
|
|||
|
}
|
|||
|
j++;
|
|||
|
}
|
|||
|
|
|||
|
var select = selections.Distinct();
|
|||
|
foreach (int i in select)
|
|||
|
{
|
|||
|
string unitType = string.Empty;
|
|||
|
//System.Web.UI.WebControls.DropDownList ddlUnitType = (System.Web.UI.WebControls.DropDownList)Grid1.Rows[i].FindControl("ddlUnitType");
|
|||
|
System.Web.UI.WebControls.CheckBoxList cblUnitType = (System.Web.UI.WebControls.CheckBoxList)Grid1.Rows[i].FindControl("cblUnitType");
|
|||
|
Model.Project_Unit newUnit = new Model.Project_Unit();
|
|||
|
newUnit.ProjectId = this.ProjectId;
|
|||
|
newUnit.UnitId = Grid1.DataKeys[i][0].ToString();
|
|||
|
if (!string.IsNullOrEmpty(cblUnitType.SelectedValue))
|
|||
|
{
|
|||
|
foreach (System.Web.UI.WebControls.ListItem item in cblUnitType.Items)
|
|||
|
{
|
|||
|
if (item.Selected)
|
|||
|
{
|
|||
|
unitType += item.Value + ",";
|
|||
|
}
|
|||
|
}
|
|||
|
if (!string.IsNullOrEmpty(unitType))
|
|||
|
{
|
|||
|
unitType = unitType.Substring(0, unitType.LastIndexOf(","));
|
|||
|
newUnit.UnitType = unitType;
|
|||
|
newUnit.InTime = System.DateTime.Now;
|
|||
|
BLL.Project_UnitService.AddProject_Unit(newUnit);
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
ShowNotify("您没有这个权限,请与管理员联系!");
|
|||
|
}
|
|||
|
}
|
|||
|
#region 页索引改变事件
|
|||
|
/// <summary>
|
|||
|
/// 页索引改变事件
|
|||
|
/// </summary>
|
|||
|
/// <param name="sender"></param>
|
|||
|
/// <param name="e"></param>
|
|||
|
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
|
|||
|
{
|
|||
|
//Grid1.PageIndex = e.NewPageIndex;
|
|||
|
//BindGrid();
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region 排序
|
|||
|
/// <summary>
|
|||
|
/// 排序
|
|||
|
/// </summary>
|
|||
|
/// <param name="sender"></param>
|
|||
|
/// <param name="e"></param>
|
|||
|
protected void Grid1_Sort(object sender, 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 ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
|
|||
|
{
|
|||
|
//Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
|
|||
|
//BindGrid();
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
protected void Grid1_RowDataBound(object sender, GridRowEventArgs e)
|
|||
|
{
|
|||
|
System.Web.UI.WebControls.CheckBoxList cblUnitType = (System.Web.UI.WebControls.CheckBoxList)Grid1.Rows[e.RowIndex].FindControl("cblUnitType");
|
|||
|
|
|||
|
if (this.tvUnit.SelectedNodeID == "true")
|
|||
|
{
|
|||
|
cblUnitType.DataTextField = "Text";
|
|||
|
cblUnitType.DataValueField = "Value";
|
|||
|
cblUnitType.DataSource = BLL.DropListService.UnitTypeSubSearchList();
|
|||
|
cblUnitType.DataBind();
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
cblUnitType.DataTextField = "Text";
|
|||
|
cblUnitType.DataValueField = "Value";
|
|||
|
cblUnitType.DataSource = BLL.DropListService.UnitTypeNotSubSearchList();
|
|||
|
cblUnitType.DataBind();
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
var pUnit = BLL.Project_UnitService.GetProject_UnitByProjectIdUnitId(this.ProjectId, e.RowID);
|
|||
|
if (pUnit != null)
|
|||
|
{
|
|||
|
// 单位类型下拉框
|
|||
|
if (!string.IsNullOrEmpty(pUnit.UnitType))
|
|||
|
{
|
|||
|
List<string> unitTypeList = pUnit.UnitType.Split(',').ToList();
|
|||
|
foreach (var type in unitTypeList)
|
|||
|
{
|
|||
|
for (int i = 0; i < cblUnitType.Items.Count; i++)
|
|||
|
{
|
|||
|
if (cblUnitType.Items[i].Value == type)
|
|||
|
{
|
|||
|
cblUnitType.Items[i].Selected = true;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
#region 验证是否选择单位类型
|
|||
|
/// <summary>
|
|||
|
/// 验证是否选择单位类型
|
|||
|
/// </summary>
|
|||
|
/// <returns></returns>
|
|||
|
protected string IsSave()
|
|||
|
{
|
|||
|
string coutValue = string.Empty;
|
|||
|
//int[] selections = Grid1.SelectedRowIndexArray;//注意超过20行属性用不了
|
|||
|
string[] selectRowId = Grid1.SelectedRowIDArray;
|
|||
|
int i = 0;
|
|||
|
int j = 0;
|
|||
|
int[] selections = new int[selectRowId.Count()];
|
|||
|
foreach (GridRow row in Grid1.Rows)
|
|||
|
{
|
|||
|
if (selectRowId.Contains(row.DataKeys[0]))
|
|||
|
{
|
|||
|
selections[i] = j;
|
|||
|
i++;
|
|||
|
}
|
|||
|
j++;
|
|||
|
}
|
|||
|
|
|||
|
foreach (int n in selections)
|
|||
|
{
|
|||
|
//System.Web.UI.WebControls.DropDownList drpUnitType = (System.Web.UI.WebControls.DropDownList)Grid1.Rows[n].FindControl("ddlUnitType");
|
|||
|
|
|||
|
System.Web.UI.WebControls.CheckBoxList cblUnitType = (System.Web.UI.WebControls.CheckBoxList)Grid1.Rows[n].FindControl("cblUnitType");
|
|||
|
if (string.IsNullOrEmpty(cblUnitType.SelectedValue))
|
|||
|
{
|
|||
|
coutValue += "第" + (n + 1).ToString() + "行;";
|
|||
|
}
|
|||
|
}
|
|||
|
return coutValue;
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
}
|
|||
|
}
|