260 lines
9.2 KiB
C#
260 lines
9.2 KiB
C#
namespace FineUIPro.Web.ProjectData
|
|
{
|
|
using BLL;
|
|
using Newtonsoft.Json.Linq;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Data.SqlClient;
|
|
using System.Linq;
|
|
|
|
public partial class ProjectUserSelect : PageBase
|
|
{
|
|
/// <summary>
|
|
/// 定义项
|
|
/// </summary>
|
|
public string ProjectId
|
|
{
|
|
get
|
|
{
|
|
return (string)ViewState["ProjectId"];
|
|
}
|
|
set
|
|
{
|
|
ViewState["ProjectId"] = value;
|
|
}
|
|
}
|
|
|
|
#region 加载
|
|
/// <summary>
|
|
/// 加载页面
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if (!IsPostBack)
|
|
{
|
|
Funs.DropDownPageSize(this.ddlPageSize);
|
|
this.ProjectId = Request.QueryString["ProjectId"];
|
|
BLL.UnitService.InitUnitDropDownList(this.drpUnit, this.ProjectId, false);
|
|
if (!string.IsNullOrEmpty(this.CurrUser.UnitId))
|
|
{
|
|
this.drpUnit.SelectedValue = this.CurrUser.UnitId;
|
|
}
|
|
RoleService.InitRoleDropDownList(this.drpRoleIds, null, false, true);
|
|
// 绑定表格
|
|
this.BindGrid();
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// 绑定数据
|
|
/// </summary>
|
|
private void BindGrid()
|
|
{
|
|
if (!string.IsNullOrEmpty(this.ProjectId))
|
|
{
|
|
string strSql = @"SELECT Persons.PersonId,Persons.CardNo,Persons.PersonName,U.UnitName,IdentityCard,RoleIds
|
|
FROM SitePerson_Person AS Persons
|
|
LEFT JOIN Base_Unit AS U ON Persons.UnitId=U.UnitId
|
|
WHERE Persons.ProjectId =@ProjectId AND Persons.RoleIds is null ";
|
|
List<SqlParameter> listStr = new List<SqlParameter>
|
|
{
|
|
new SqlParameter("@ProjectId", this.ProjectId),
|
|
new SqlParameter("@UnitId", this.drpUnit.SelectedValue),
|
|
new SqlParameter("@PersonId", BLL.Const.sysglyId)
|
|
};
|
|
if (!string.IsNullOrEmpty(this.txtUserName.Text.Trim()))
|
|
{
|
|
strSql += " AND Persons.PersonName LIKE @PersonName";
|
|
listStr.Add(new SqlParameter("@PersonName", "%" + this.txtUserName.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();
|
|
}
|
|
}
|
|
|
|
#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
|
|
|
|
/// <summary>
|
|
/// 确定按钮事件
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void btnSure_Click(object sender, EventArgs e)
|
|
{
|
|
if (Grid1.SelectedRowIndexArray.Length == 0)
|
|
{
|
|
Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning);
|
|
return;
|
|
}
|
|
|
|
foreach (int rowIndex in Grid1.SelectedRowIndexArray)
|
|
{
|
|
string roleIds = getRoleId(Grid1.DataKeys[rowIndex][0].ToString());
|
|
if (string.IsNullOrEmpty(roleIds))
|
|
{
|
|
Alert.ShowInTop("请先选中项目角色!", MessageBoxIcon.Warning);
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
this.SaveData(Grid1.DataKeys[rowIndex][0].ToString(), roleIds);
|
|
}
|
|
}
|
|
|
|
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
|
|
}
|
|
|
|
protected string getRoleId(string id)
|
|
{
|
|
string RoleIds = string.Empty;
|
|
JArray teamGroupData = Grid1.GetMergedData();
|
|
if (teamGroupData != null)
|
|
{
|
|
foreach (JObject teamGroupRow in teamGroupData)
|
|
{
|
|
JObject values = teamGroupRow.Value<JObject>("values");
|
|
string PersonId = values.Value<string>("PersonId");
|
|
if (PersonId == id)
|
|
{
|
|
string[] strs = values.Value<string>("RoleIds").Split(',');
|
|
string handleStep = string.Empty;
|
|
foreach (var item in strs)
|
|
{
|
|
var getRole = Funs.DB.Sys_Role.FirstOrDefault(x => x.RoleId == item);
|
|
if (getRole != null)
|
|
{
|
|
RoleIds += getRole.RoleId + ",";
|
|
}
|
|
}
|
|
if (!string.IsNullOrEmpty(handleStep))
|
|
{
|
|
RoleIds = RoleIds.Substring(0, handleStep.LastIndexOf(","));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return RoleIds;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 双击事件
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e)
|
|
{
|
|
if (Grid1.SelectedRowIndexArray.Length == 0)
|
|
{
|
|
Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning);
|
|
return;
|
|
}
|
|
string roleIds = getRoleId(Grid1.SelectedRowID);
|
|
string info = string.Empty;
|
|
if (string.IsNullOrEmpty(roleIds))
|
|
{
|
|
Alert.ShowInTop("请先选中项目角色!", MessageBoxIcon.Warning);
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
this.SaveData(Grid1.SelectedRowID, roleIds);
|
|
}
|
|
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
|
|
}
|
|
|
|
/// <summary>
|
|
/// 保存数据
|
|
/// </summary>
|
|
/// <param name="userId"></param>
|
|
private void SaveData(string userId, string roleIds)
|
|
{
|
|
var projectUser = BLL.SitePerson_PersonService.GetSitePersonByProjectIdPersonId(this.ProjectId, userId);
|
|
var user = BLL.Person_PersonsService.GetPerson_PersonsById(userId);
|
|
if (user != null)
|
|
{
|
|
if (projectUser == null)
|
|
{
|
|
Model.SitePerson_Person newProjectUser = new Model.SitePerson_Person
|
|
{
|
|
ProjectId = this.ProjectId,
|
|
SitePersonId = SQLHelper.GetNewID(),
|
|
PersonId = userId,
|
|
IdentityCard = user.IdentityCard,
|
|
PersonName = user.PersonName,
|
|
UnitId = user.UnitId,
|
|
RoleIds = roleIds ?? user.RoleIds,
|
|
States = Const.State_1,
|
|
};
|
|
BLL.SitePerson_PersonService.AddSitePerson(newProjectUser);
|
|
|
|
Model.Sys_RoleItem roleItem = new Model.Sys_RoleItem
|
|
{
|
|
ProjectId = this.ProjectId,
|
|
UserId = userId,
|
|
RoleId = roleIds ?? user.RoleIds,
|
|
IntoDate = DateTime.Now
|
|
};
|
|
BLL.RoleItemService.AddRoleItem(roleItem);
|
|
}
|
|
else
|
|
{
|
|
projectUser.RoleIds = roleIds ?? user.RoleIds;
|
|
Funs.DB.SubmitChanges();
|
|
}
|
|
}
|
|
}
|
|
|
|
protected void btnNew_Click(object sender, EventArgs e)
|
|
{
|
|
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("../Person/ProjectPersonEdit.aspx?ProjectId={0}", this.ProjectId, "新增 - ")));
|
|
}
|
|
|
|
protected void btSearch_Click(object sender, EventArgs e)
|
|
{
|
|
this.BindGrid();
|
|
}
|
|
}
|
|
} |