189 lines
6.1 KiB
C#
189 lines
6.1 KiB
C#
using DevExpress.Skins;
|
||
using DevExpress.XtraEditors;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Data;
|
||
using System.Windows.Forms;
|
||
|
||
namespace HL_FristAidPlatform_Public
|
||
{
|
||
public partial class Form_SelectUser : XtraForm
|
||
{
|
||
#region 变量
|
||
|
||
/// <summary>
|
||
/// 当前选择的用户名集合
|
||
/// </summary>
|
||
public string SelUserNameS = string.Empty;
|
||
|
||
/// <summary>
|
||
/// 当前选择的用户ID集合
|
||
/// </summary>
|
||
public string SelUserIDS = string.Empty;
|
||
|
||
#endregion 变量
|
||
|
||
public Form_SelectUser()
|
||
{
|
||
InitializeComponent();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 窗体加载
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void Form_SelectUser_Load(object sender, EventArgs e)
|
||
{
|
||
BindData();
|
||
BindUser();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 绑定科室
|
||
/// </summary>
|
||
private void BindData()
|
||
{
|
||
try
|
||
{
|
||
string Url = string.Format("/api/admin/T_SYS_Departments/GetListByHospitalGuid?hospitalGuid={0}", Information.Hospital.GUID);
|
||
DataTable DepartmentsDT = DBHelpClass.Get(Url);
|
||
|
||
Skin skin = GridSkins.GetSkin(treeList_Department.LookAndFeel);
|
||
skin.Properties[GridSkins.OptShowTreeLine] = true;
|
||
|
||
treeList_Department.DataSource = DepartmentsDT;
|
||
treeList_Department.KeyFieldName = "ID";//是节点id
|
||
treeList_Department.ParentFieldName = "ParentID";//是父节点id
|
||
treeList_Department.ExpandAll();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
PublicClass.WriteErrorLog(this.Text, "绑定科室:\r\n" + ex);
|
||
}
|
||
}
|
||
|
||
#region 树事件
|
||
|
||
private void treeList_Department_AfterCheckNode(object sender, DevExpress.XtraTreeList.NodeEventArgs e)
|
||
{
|
||
SetCheckedChildNodes(e.Node, e.Node.CheckState);
|
||
SetCheckedParentNodes(e.Node, e.Node.CheckState);
|
||
}
|
||
|
||
private void treeList_Department_BeforeCheckNode(object sender, DevExpress.XtraTreeList.CheckNodeEventArgs e)
|
||
{
|
||
e.State = (e.PrevState == CheckState.Checked ? CheckState.Unchecked : CheckState.Checked);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 设置子节点的状态
|
||
/// </summary>
|
||
/// <param name="node"></param>
|
||
/// <param name="check"></param>
|
||
private void SetCheckedChildNodes(DevExpress.XtraTreeList.Nodes.TreeListNode node, CheckState check)
|
||
{
|
||
for (int i = 0; i < node.Nodes.Count; i++)
|
||
{
|
||
node.Nodes[i].CheckState = check;
|
||
SetCheckedChildNodes(node.Nodes[i], check);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 设置父节点的状态
|
||
/// </summary>
|
||
/// <param name="node"></param>
|
||
/// <param name="check"></param>
|
||
private void SetCheckedParentNodes(DevExpress.XtraTreeList.Nodes.TreeListNode node, CheckState check)
|
||
{
|
||
if (node.ParentNode != null)
|
||
{
|
||
bool b = false;
|
||
CheckState state;
|
||
for (int i = 0; i < node.ParentNode.Nodes.Count; i++)
|
||
{
|
||
state = (CheckState)node.ParentNode.Nodes[i].CheckState;
|
||
if (!check.Equals(state))
|
||
{
|
||
b = !b;
|
||
break;
|
||
}
|
||
}
|
||
node.ParentNode.CheckState = b ? CheckState.Indeterminate : check;
|
||
SetCheckedParentNodes(node.ParentNode, check);
|
||
}
|
||
}
|
||
|
||
#endregion 树事件
|
||
|
||
/// <summary>
|
||
/// 绑定用户
|
||
/// </summary>
|
||
private void BindUser()
|
||
{
|
||
try
|
||
{
|
||
List<string> list = PublicClass.FindOrigin(treeList_Department, "ID");
|
||
string whereStr = "";
|
||
foreach (string str in list)
|
||
{
|
||
whereStr += str + "&";
|
||
}
|
||
DataTable ResultDT = DBHelpClass.Get(string.Format("/api/admin/T_SYS_User/GetList?departmentsIds={0}&keyWord={1}", whereStr, txt_Key.Text.ToString().Trim()));
|
||
grid_User.DataSource = ResultDT;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
PublicClass.WriteErrorLog(this.Text, "绑定用户:\r\n" + ex);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 查询事件
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void btn_Select_Click(object sender, EventArgs e)
|
||
{
|
||
BindUser();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 确认选择
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void btn_Sure_Click(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
int[] rownumber = grv_User.GetSelectedRows();//获取选中行号;
|
||
SelUserIDS = string.Empty;
|
||
SelUserNameS = string.Empty;
|
||
|
||
foreach (int i in rownumber)
|
||
{
|
||
//根据行号获取相应行的数据;
|
||
SelUserIDS += grv_User.GetRowCellValue(i, "ID").ToString() + ",";
|
||
SelUserNameS += grv_User.GetRowCellValue(i, "FullName").ToString() + ";";
|
||
}
|
||
|
||
if (!string.IsNullOrEmpty(SelUserIDS))
|
||
{
|
||
SelUserIDS = SelUserIDS.Substring(0, SelUserIDS.Length - 1);
|
||
DialogResult = DialogResult.OK;
|
||
Close();
|
||
}
|
||
else
|
||
{
|
||
XtraMessageBox.Show("请先勾选您要选择的用户!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
PublicClass.WriteErrorLog(this.Text, "确认选择:\r\n" + ex);
|
||
}
|
||
}
|
||
}
|
||
} |