xinjiang/SGGL/FineUIPro.Web/HSSE/Epidemic/PersonList.aspx.cs

437 lines
16 KiB
C#
Raw Permalink Normal View History

2024-11-19 09:45:27 +08:00
using BLL;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using AspNet = System.Web.UI.WebControls;
namespace FineUIPro.Web.HSSE.Epidemic
{
public partial class PersonList : PageBase
{
#region
/// <summary>
/// 人员主键
/// </summary>
public string PersonId
{
get
{
return (string)ViewState["PersonId"];
}
set
{
ViewState["PersonId"] = value;
}
}
/// <summary>
/// 项目id
/// </summary>
public string ProjectId
{
get
{
return (string)ViewState["ProjectId"];
}
set
{
ViewState["ProjectId"] = value;
}
}
#endregion
#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 = this.CurrUser.LoginProjectId;
if (!string.IsNullOrEmpty(Request.Params["projectId"]) && Request.Params["projectId"] != this.ProjectId)
{
this.ProjectId = Request.Params["projectId"];
}
////权限按钮方法
this.GetButtonPower();
this.ddlPageSize.SelectedValue = this.Grid1.PageSize.ToString();
BLL.WorkPostService.InitWorkPostDropDownList(this.drpPost, true);
this.InitTreeMenu();//加载树
}
}
/// <summary>
/// 加载树
/// </summary>
private void InitTreeMenu()
{
this.tvProjectAndUnit.Nodes.Clear();
var project = BLL.ProjectService.GetProjectByProjectId(this.ProjectId);
if (project != null)
{
var personLists = BLL.PersonService.GetPersonList(project.ProjectId);
TreeNode rootNode = new TreeNode();
rootNode = new TreeNode
{
Text = project.ProjectName,
NodeID = project.ProjectId
};
if (personLists.Count() > 0)
{
var personIn = personLists.Where(x => x.ProjectId == this.CurrUser.LoginProjectId && x.IsUsed == true
&& x.InTime <= DateTime.Now && (!x.OutTime.HasValue || x.OutTime > DateTime.Now)).ToList();
rootNode.ToolTip = "当前项目人员总数:" + personLists.Count() + ";在场人员数:" + personIn.Count() + ";离场人员数:" + (personLists.Count() - personIn.Count());
}
else
{
rootNode.ToolTip = "当前项目人员总数0";
}
rootNode.Expanded = true;
this.tvProjectAndUnit.Nodes.Add(rootNode);
GetUnitLists(rootNode.Nodes, this.ProjectId, personLists);
}
}
/// <summary>
/// 加载单位
/// </summary>
/// <param name="nodes"></param>
/// <param name="parentId"></param>
private void GetUnitLists(TreeNodeCollection nodes, string parentId, List<Model.SitePerson_Person> personLists)
{
List<Model.Base_Unit> unitLists = BLL.UnitService.GetUnitByProjectIdList(parentId);
if (unitLists.Count() > 0)
{
if (BLL.ProjectUnitService.GetProjectUnitTypeByProjectIdUnitId(parentId, this.CurrUser.UnitId))
{
unitLists = unitLists.Where(x => x.UnitId == this.CurrUser.UnitId).ToList();
}
//添加其他单位/无单位人员
Model.Base_Unit otherUnit = new Model.Base_Unit
{
UnitId = "0",
UnitName = "其他"
};
unitLists.Add(otherUnit);
TreeNode newNode = null;
foreach (var q in unitLists)
{
newNode = new TreeNode
{
Text = q.UnitName,
NodeID = q.UnitId + "|" + parentId,
ToolTip = q.UnitName
};
if (personLists.Count() > 0)
{
var personUnitLists = personLists.Where(x => x.UnitId == q.UnitId);
if (q.UnitId == "0")
{
personUnitLists = personLists.Where(x => x.UnitId == null);
}
if (personUnitLists.Count() > 0)
{
var personIn = personUnitLists.Where(x => x.InTime <= System.DateTime.Now && x.IsUsed == true
&& (!x.OutTime.HasValue || x.OutTime >= System.DateTime.Now));
newNode.ToolTip = q.UnitName + "人员总数:" + personUnitLists.Count() + ";在场人员数:" + personIn.Count() + ";离场人员数:" + (personUnitLists.Count() - personIn.Count());
}
else
{
newNode.ToolTip = q.UnitName + "人员总数0";
}
}
else
{
newNode.ToolTip = q.UnitName + "人员总数0";
}
newNode.EnableClickEvent = true;
nodes.Add(newNode);
}
}
}
/// <summary>
/// 绑定数据
/// </summary>
private void BindGrid()
{
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
{
if (this.tvProjectAndUnit != null && !string.IsNullOrEmpty(this.tvProjectAndUnit.SelectedNodeID))
{
string id = this.tvProjectAndUnit.SelectedNodeID;
string unitId = string.Empty;
string projectId = string.Empty;
var str = id.Split('|');
if (str.Count() > 1)
{
unitId = str[0];
projectId = str[1];
}
string strSql = "select * from View_SitePerson_Person Where ProjectId=@ProjectId ";
List<SqlParameter> listStr = new List<SqlParameter>
{
new SqlParameter("@ProjectId", this.ProjectId)
};
if (!string.IsNullOrEmpty(unitId) && unitId != "0")
{
strSql += " AND UnitId =@UnitId ";
listStr.Add(new SqlParameter("@UnitId", unitId));
}
else
{
strSql += " AND UnitId IS NULL";
}
if (drpIsUsedName.SelectedValue == "是")
{
strSql += " AND IsUsed = @IsUsed";
listStr.Add(new SqlParameter("@IsUsed", "1"));
}
else
{
strSql += " AND IsUsed = @IsUsed";
listStr.Add(new SqlParameter("@IsUsed", "0"));
}
if (!string.IsNullOrEmpty(this.txtPersonName.Text.Trim()))
{
strSql += " AND PersonName LIKE @PersonName";
listStr.Add(new SqlParameter("@PersonName", "%" + this.txtPersonName.Text.Trim() + "%"));
}
if (!string.IsNullOrEmpty(this.txtCardNo.Text.Trim()))
{
strSql += " AND CardNo LIKE @CardNo";
listStr.Add(new SqlParameter("@CardNo", "%" + this.txtCardNo.Text.Trim() + "%"));
}
if (!string.IsNullOrEmpty(this.txtIdentityCard.Text.Trim()))
{
strSql += " AND IdentityCard LIKE @IdentityCard";
listStr.Add(new SqlParameter("@IdentityCard", "%" + this.txtIdentityCard.Text.Trim() + "%"));
}
if (!string.IsNullOrEmpty(this.drpTreamGroup.SelectedValue) && this.drpTreamGroup.SelectedValue != BLL.Const._Null)
{
strSql += " AND TeamGroupId = @TeamGroupId";
listStr.Add(new SqlParameter("@TeamGroupId", this.drpTreamGroup.SelectedValue));
}
if (this.drpPost.SelectedItemArray.Count() > 1 || (this.drpPost.SelectedValue != BLL.Const._Null && this.drpPost.SelectedItemArray.Count() == 1))
{
strSql += " AND (1=2 ";
int i = 0;
foreach (var item in this.drpPost.SelectedValueArray)
{
if (!string.IsNullOrEmpty(item) && item != BLL.Const._Null)
{
strSql += " OR WorkPostId = @WorkPostId" + i.ToString();
listStr.Add(new SqlParameter("@WorkPostId" + i.ToString(), item));
}
i++;
}
strSql += ")";
}
if (this.ckIdCardInfoNotOK.Checked)
{
strSql += " AND (IdcardType is null or IdentityCard is null or PhotoUrl is null or (select count(*) from AttachFile where ToKeyId=PersonId+'#1')=0 or (select count(*) from AttachFile where ToKeyId=PersonId+'#5')=0)";
}
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();
for (int i = 0; i < Grid1.Rows.Count; i++)
{
string personId = Grid1.Rows[i].DataKeys[0].ToString();
var isNull = from x in db.EduTrain_TrainRecordDetail
join y in db.EduTrain_TrainRecord on x.TrainingId equals y.TrainingId
where y.ProjectId == this.ProjectId && x.PersonId == personId
select x;
//if (isNull.Count() == 0) ////未参加过培训的人员
//{
// Grid1.Rows[i].RowCssClass = "Red";
//}
}
}
}
}
#endregion
#region TreeView
/// <summary>
/// 点击TreeView
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void tvProjectAndUnit_NodeCommand(object sender, TreeCommandEventArgs e)
{
this.drpTreamGroup.Items.Clear();
if (this.tvProjectAndUnit.SelectedNodeID.Contains("|"))
{
string id = this.tvProjectAndUnit.SelectedNodeID;
string unitId = string.Empty;
string projectId = string.Empty;
var str = id.Split('|');
if (str.Count() > 1)
{
unitId = str[0];
projectId = str[1];
}
BLL.TeamGroupService.InitTeamGroupProjectUnitDropDownList(this.drpTreamGroup, projectId, unitId, true);
BindGrid();
}
}
#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();
}
#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
#region
/// <summary>
/// 右键编辑事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuEdit_Click(object sender, EventArgs e)
{
this.EditData();
}
/// <summary>
/// 编辑
/// </summary>
private void EditData()
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning);
return;
}
this.PersonId = Grid1.SelectedRowID;
string id = this.tvProjectAndUnit.SelectedNodeID;
string[] str = id.Split('|');
if (str.Count() > 1)
{
string unitId = id.Split('|')[0];
string projectId = id.Split('|')[1];
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("PersonListEdit.aspx?PersonId={0}&&ProjectId={1}&&UnitId={2}", this.PersonId, projectId, unitId, "编辑 - ")));
}
}
/// <summary>
/// Grid双击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e)
{
this.EditData();
}
#endregion
#region
/// <summary>
/// 关闭弹出窗口
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Window1_Close(object sender, WindowCloseEventArgs e)
{
BindGrid();
}
#endregion
#region
/// <summary>
/// 判断按钮权限
/// </summary>
private void GetButtonPower()
{
if (Request.Params["value"] == "0")
{
return;
}
var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.PersonListMenuId);
if (buttonList.Count() > 0)
{
}
}
#endregion
#region
/// <summary>
/// 查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void TextBox_TextChanged(object sender, EventArgs e)
{
this.BindGrid();
}
#endregion
}
}