123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Linq;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using DevExpress.XtraEditors;
- using SIMDP.Model;
- using SIMDP.BLL;
- using DevExpress.XtraTreeList.Nodes;
- using ProjectBase.Data.Logs;
- using System.Data.Common;
- using ProjectBase.Data.Encrypt;
- using ProjectBase.Data.BaseDAL;
- using SIMDP.Util;
- namespace SIMDP
- {
- public partial class FormEditAuthoryUser : DevExpress.XtraEditors.XtraForm
- {
- //BlAuthoryGroup blGroup = new BlAuthoryGroup();
- //BlAuthoryRole blRole = new BlAuthoryRole();
- //BlUserRole blUserRole = new BlUserRole();
- //BlAuthoryUser blUser = new BlAuthoryUser();
- List<MoAuthoryRole> roleList = new List<MoAuthoryRole>();
- DbTransaction trans;
- bool flag;
- private MoAuthoryUser authoryUser = new MoAuthoryUser();
- private List<string> listCheckedID = new List<string>();//用户角色控件选择局ID集合
- private List<string> listCheckedName = new List<string>();//用户角色控件选择局Name集合
- private string displayText = null; //用户角色控件显示的文本
- /// <summary>
- /// 定义一个委托
- /// </summary>
- public delegate void save();
- /// <summary>
- /// 定义一个事件,数据添加和修改成功后刷新
- /// </summary>
- public event save saveData;
- /// <summary>
- /// 性别的字典表
- /// </summary>
- private Dictionary<string, string> Dic_Sex
- {
- get
- {
- Dictionary<string, string> sex = new Dictionary<string, string>();
- sex.Add("1", "男");
- sex.Add("0", "女");
- return sex;
- }
- }
- /// <summary>
- /// 状态的字典表
- /// </summary>
- private Dictionary<string, string> Dic_Status
- {
- get
- {
- Dictionary<string, string> status = new Dictionary<string, string>();
- status.Add("0", "停用");
- status.Add("1", "启用");
- return status;
- }
- }
- /// <summary>
- /// 构造函数
- /// </summary>
- /// <param name="moAuthory">为null时表示添加操作,不为null时表示修改操作</param>
- public FormEditAuthoryUser(MoAuthoryUser moAuthory)
- {
- InitializeComponent();
- authoryUser = moAuthory;
- InitControls(moAuthory);
- }
- private void InitControls(MoAuthoryUser moAuthory)
- {
- //文本框--密码
- //this.txt_PassWord.Properties.NullValuePromptShowForEmptyValue = true;
- //this.txt_PassWord.Properties.NullValuePrompt = "请输入密码";
- this.txt_PassWord.Enabled = false;
- //下拉框--性别
- BindingSource bsSex = new BindingSource();
- bsSex.DataSource = Dic_Sex;
- this.lookUp_Sex.Properties.DataSource = bsSex;
- this.lookUp_Sex.Properties.ValueMember = "Key";
- this.lookUp_Sex.Properties.DisplayMember = "Value";
- //下拉框--状态
- BindingSource bsStatus = new BindingSource();
- bsStatus.DataSource = Dic_Status;
- this.lookUp_Status.Properties.DataSource = bsStatus;
- this.lookUp_Status.Properties.ValueMember = "Key";
- this.lookUp_Status.Properties.DisplayMember = "Value";
- #region 初始化用户组控件
- DataTable dt = new DataTable();
- dt.Columns.Add("ImageIndex", typeof(int));
- dt.Columns.Add("GroupID", typeof(string));
- dt.Columns.Add("GroupPID", typeof(string));
- dt.Columns.Add("GroupName", typeof(string));
- List<MoAuthoryGroup> list = BLLFactory<BlAuthoryGroup>.Instance.GetAll();
- DataRow dr = null;
- foreach (MoAuthoryGroup info in list)
- {
- if (info.GroupId.Substring(0, 1).Equals("1") || info.GroupId.Substring(0, 1).Equals("2"))
- {
- dr = dt.NewRow();
- dr["ImageIndex"] = 0;
- dr["GroupID"] = info.GroupId;
- dr["GroupPID"] = info.ParentGroupId;
- dr["GroupName"] = info.GroupName;
- dt.Rows.Add(dr);
- }
- }
- //设置图形序号
- //this.treeListLookUpEdit1TreeList.SelectImageList = this.imageList2;
- //this.treeListLookUpEdit1TreeList.StateImageList = this.imageList2;
- this.treeLookUp_Group.Properties.TreeList.KeyFieldName = "GroupID";
- this.treeLookUp_Group.Properties.TreeList.ParentFieldName = "GroupPID";
- this.treeLookUp_Group.Properties.DataSource = dt;
- this.treeLookUp_Group.Properties.ValueMember = "GroupID";
- this.treeLookUp_Group.Properties.DisplayMember = "GroupName";
- this.treeLookUp_Group.Properties.NullValuePrompt = "请选择公司";
- this.treeLookUp_Group.Properties.NullValuePromptShowForEmptyValue = true;
- this.treeLookUp_Group.EditValueChanged += new EventHandler(treeLookUp_Group_EditValueChanged);
- #endregion
- if (moAuthory == null)
- {
- this.btn_Save.Enabled = false;
- this.lookUp_Sex.Properties.NullText = "请您选择";
- this.lookUp_Status.Properties.NullText = "请您选择";
- this.treeLookUp_Group.EditValue = "0";
- this.treeLookUp_Role.EditValue = "0";
- this.treeLookUp_Part.EditValue = "0";
- this.txt_PassWord.Text = "000000";
- return;
- }
- this.btn_Add.Enabled = false;
- this.lookUp_Sex.EditValue = moAuthory.UserSex;
- this.lookUp_Status.EditValue = moAuthory.UserStatus;
- if (moAuthory.GroupId.Substring(0,1).Equals("1") || moAuthory.GroupId.Substring(0, 1).Equals("2"))
- {
- this.treeLookUp_Group.EditValue = moAuthory.GroupId;
- }
- else
- {
- MoAuthoryGroup group = new MoAuthoryGroup();
- group = BLLFactory<BlAuthoryGroup>.Instance.FindByID(moAuthory.GroupId);
- this.treeLookUp_Group.EditValue = group.ParentGroupId;
- this.treeLookUp_Part.EditValue = moAuthory.GroupId;
- }
- this.txt_Account.Text = moAuthory.LoginAccount;
- this.txt_CardId.Text = moAuthory.CardId;
- this.txt_Email.Text = moAuthory.UserEmail;
- this.txt_Mobile.Text = moAuthory.UserMobile;
- this.txt_Name.Text = moAuthory.UserName;
- this.txt_PassWord.Text = EncodeHelper.DecryptString(moAuthory.LoginPasswd, true);
- List<MoUserRole> userRoleList = BLLFactory<BlUserRole>.Instance.Find(string.Format(" user_id = '{0}'", txt_Account.Text));
- DefaultChecked(userRoleList);
- }
-
- /// <summary>
- /// 用户角色控件复选框默认选中情况
- /// </summary>
- /// <param name="rid"></param>
- private void DefaultChecked(List<MoUserRole> role)
- {
- this.listCheckedID.Clear();
- this.listCheckedName.Clear();
- foreach (MoUserRole item in role)
- {
- listCheckedID.Add(item.RoleId);
- foreach (MoAuthoryRole mo in roleList)
- {
- if (mo.RoleId == item.RoleId)
- {
- listCheckedName.Add(mo.RoleName);
- }
- }
- }
- if (this.treeLookUp_Role.Properties.TreeList.Nodes.Count > 0)
- {
- foreach (TreeListNode nd in treeLookUp_Role.Properties.TreeList.Nodes)
- {
- for (int i = 0; i < listCheckedID.Count; i++)
- {
- string checkedkeyid = listCheckedID[i];
- if (treeLookUp_Role.Properties.TreeList.FindNodeByKeyID(checkedkeyid) != null)
- {
- treeLookUp_Role.Properties.TreeList.FindNodeByKeyID(checkedkeyid).Checked = true;
- }
- }
- }
- }
- displayText = null;
- foreach (string name in listCheckedName)
- {
- displayText += name + ",";
- }
- this.treeLookUp_Role.Text = displayText;
- }
- /// <summary>
- /// 获取用户角色控件复选框已经勾选的ID和Name集合
- /// </summary>
- private void GetSelectedRoleIDandName()
- {
- this.listCheckedID.Clear();
- this.listCheckedName.Clear();
- if (this.treeLookUp_Role.Properties.TreeList.Nodes.Count > 0)
- {
- foreach (TreeListNode root in this.treeLookUp_Role.Properties.TreeList.Nodes)
- {
- GetCheckedKeyID(root);
- }
- }
- displayText = null;
- foreach (string name in listCheckedName)
- {
- displayText += name + ",";
- }
- }
- /// <summary>
- /// 获取用户角色控件复选框已经勾选的ID和Name集合
- /// </summary>
- /// <param name="parentNode">父级节点</param>
- private void GetCheckedKeyID(TreeListNode parentNode)
- {
- //if (parentNode.Nodes.Count == 0) //本项目只有根节点,此部分不需要
- //{
- // return;//递归终止
- //}
- if (parentNode.CheckState != CheckState.Unchecked)
- {
- DataRowView drv = this.treeLookUp_Role.Properties.TreeList.GetDataRecordByNode(parentNode) as DataRowView;
- if (drv != null)
- {
- string KeyFieldName = drv["RoleId"].ToString();
- string DisplayMember = drv["RoleName"].ToString();
- if (!listCheckedID.Contains(KeyFieldName))
- {
- listCheckedID.Add(KeyFieldName);
- }
- if (!listCheckedName.Contains(DisplayMember))
- {
- listCheckedName.Add(DisplayMember);
- }
- }
- }
- //foreach (TreeListNode node in parentNode.Nodes) //本项目只有根节点,此部分不需要
- //{
- // if (node.CheckState != CheckState.Unchecked)
- // {
- // DataRowView drv = this.treeLookUp_Role.Properties.TreeList.GetDataRecordByNode(node) as DataRowView;//关键代码,就是不知道是这样获取数据而纠结了很久(鬼知道可以转换为DataRowView啊)
- // if (drv != null)
- // {
- // string KeyFieldName = drv["RoleId"].ToString();
- // string DisplayMember = drv["RoleName"].ToString();
- // listCheckedID.Add(KeyFieldName);
- // listCheckedName.Add(DisplayMember);
- // }
- // }
- // GetCheckedKeyID(node);
- //}
- }
- private void btn_Cancel_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- private void treeLookUp_Role_Closed(object sender, DevExpress.XtraEditors.Controls.ClosedEventArgs e)
- {
- this.treeLookUp_Role.Properties.NullText = displayText;
- }
- private void treeLookUp_Role_CustomDisplayText(object sender, DevExpress.XtraEditors.Controls.CustomDisplayTextEventArgs e)
- {
- e.DisplayText = displayText;
- }
- private void btn_Add_Click(object sender, EventArgs e)
- {
- if (string.IsNullOrEmpty(txt_Account.Text))
- {
- DevExpress.XtraEditors.XtraMessageBox.Show("请输入登录账号", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- if (string.IsNullOrEmpty(txt_Name.Text))
- {
- DevExpress.XtraEditors.XtraMessageBox.Show("请输入用户名", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- if (string.IsNullOrEmpty(txt_PassWord.Text))
- {
- DevExpress.XtraEditors.XtraMessageBox.Show("请输入登录密码", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- //if (txt_PassWord.Text.Trim().Length != 6)
- //{
- // DevExpress.XtraEditors.XtraMessageBox.Show("请输入六位登录密码", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- // return;
- //}
- if (string.IsNullOrEmpty(treeLookUp_Group.Text))
- {
- DevExpress.XtraEditors.XtraMessageBox.Show("请输入所属公司", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- if (treeLookUp_Group.Text == treeLookUp_Part.Text)
- {
- DevExpress.XtraEditors.XtraMessageBox.Show("请正确选择公司和部门", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- if (string.IsNullOrEmpty(txt_Mobile.Text))
- {
- DevExpress.XtraEditors.XtraMessageBox.Show("请输入手机号", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- if (string.IsNullOrEmpty(txt_Email.Text))
- {
- DevExpress.XtraEditors.XtraMessageBox.Show("请输入邮箱", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- if (string.IsNullOrEmpty(treeLookUp_Role.Text))
- {
- DevExpress.XtraEditors.XtraMessageBox.Show("请输入角色", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- if (lookUp_Status.Text == "请您选择")
- {
- DevExpress.XtraEditors.XtraMessageBox.Show("请输入状态", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- MoAuthoryUser user = new MoAuthoryUser();
- user.LoginAccount = txt_Account.Text;
- user.LoginPasswd = EncodeHelper.EncryptString(txt_PassWord.Text);
- user.UserName = txt_Name.Text;
- user.UserMobile = txt_Mobile.Text;
- user.UserEmail = txt_Email.Text;
- user.UserTime = DateTime.Now;
- if (string.IsNullOrEmpty(this.treeLookUp_Part.Text) || this.treeLookUp_Part.Text == "无")
- {
- user.GroupId = treeLookUp_Group.EditValue.ToString();
- }
- else
- {
- user.GroupId = treeLookUp_Part.EditValue.ToString();
- }
- user.UserStatus = Convert.ToInt32(lookUp_Status.EditValue);
- if (lookUp_Sex.Text != "请您选择")
- {
- user.UserSex = Convert.ToInt32(lookUp_Sex.EditValue);
- }
- //user.UserSex = Convert.ToInt32(lookUp_Status.EditValue);
- user.CardId = txt_CardId.Text;
- List<MoUserRole> insert = new List<MoUserRole>();
- foreach (string item in listCheckedID)
- {
- insert.Add(new MoUserRole { UserId = txt_Account.Text, RoleId = item });
- }
- using (trans = BLLFactory<BlAuthoryUser>.Instance.CreateTransaction())
- {
- try
- {
- flag = BLLFactory<BlAuthoryUser>.Instance.Insert(user, trans);
- foreach (MoUserRole item in insert)
- {
- if (flag)
- {
- flag = BLLFactory<BlUserRole>.Instance.Insert(item, trans);
- }
- }
- trans.Commit();
- }
- catch (Exception ex)
- {
- trans.Rollback();
- DevExpress.XtraEditors.XtraMessageBox.Show("添加失败。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- LogHelper.log.Error(string.Format("添加数据库authory_user和user_role出现错误:{0}", ex));
- }
- }
- trans.Dispose();
- if (flag)
- {
- DevExpress.XtraEditors.XtraMessageBox.Show("添加成功。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- saveData();
- this.Close();
- }
- }
- private void btn_Save_Click(object sender, EventArgs e)
- {
- if (string.IsNullOrEmpty(txt_Account.Text))
- {
- DevExpress.XtraEditors.XtraMessageBox.Show("请输入登录账号", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- if (string.IsNullOrEmpty(txt_Name.Text))
- {
- DevExpress.XtraEditors.XtraMessageBox.Show("请输入用户名", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- if (string.IsNullOrEmpty(txt_PassWord.Text))
- {
- DevExpress.XtraEditors.XtraMessageBox.Show("请输入登录密码", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- if (txt_PassWord.Text.Trim().Length != 6)
- {
- DevExpress.XtraEditors.XtraMessageBox.Show("请输入六位登录密码", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- if (string.IsNullOrEmpty(treeLookUp_Group.Text))
- {
- DevExpress.XtraEditors.XtraMessageBox.Show("请输入所属公司", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- if (treeLookUp_Group.Text == treeLookUp_Part.Text)
- {
- DevExpress.XtraEditors.XtraMessageBox.Show("请正确选择公司和部门", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- if (string.IsNullOrEmpty(txt_Mobile.Text))
- {
- DevExpress.XtraEditors.XtraMessageBox.Show("请输入手机号", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- if (string.IsNullOrEmpty(txt_Email.Text))
- {
- DevExpress.XtraEditors.XtraMessageBox.Show("请输入邮箱", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- if (string.IsNullOrEmpty(treeLookUp_Role.Text))
- {
- DevExpress.XtraEditors.XtraMessageBox.Show("请输入角色", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- if (lookUp_Status.Text == "请您选择")
- {
- DevExpress.XtraEditors.XtraMessageBox.Show("请输入状态", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- authoryUser.LoginAccount = txt_Account.Text;
- authoryUser.LoginPasswd = EncodeHelper.EncryptString(txt_PassWord.Text);
- authoryUser.UserName = txt_Name.Text;
- authoryUser.UserMobile = txt_Mobile.Text;
- authoryUser.UserEmail = txt_Email.Text;
- if (string.IsNullOrEmpty(this.treeLookUp_Part.Text) || this.treeLookUp_Part.Text == "无")
- {
- authoryUser.GroupId = treeLookUp_Group.EditValue.ToString();
- }
- else
- {
- authoryUser.GroupId = treeLookUp_Part.EditValue.ToString();
- }
- authoryUser.UserStatus = Convert.ToInt32(lookUp_Status.EditValue) ;
- authoryUser.UserSex = Convert.ToInt32(lookUp_Sex.EditValue);
- authoryUser.CardId = txt_CardId.Text;
- List<MoUserRole> upDate = new List<MoUserRole>();
- foreach (string item in listCheckedID)
- {
- upDate.Add(new MoUserRole { UserId = txt_Account.Text, RoleId = item });
- }
- using (trans = BLLFactory<BlAuthoryUser>.Instance.CreateTransaction())
- {
- try
- {
- flag = BLLFactory<BlAuthoryUser>.Instance.Update(authoryUser, authoryUser.LoginAccount, trans);
- if (flag)
- {
- flag = BLLFactory<BlUserRole>.Instance.Delete(authoryUser.LoginAccount, SysEnvironment.CurrentLoginID, trans);
- }
- foreach (MoUserRole item in upDate)
- {
- if (flag)
- {
- flag = BLLFactory<BlUserRole>.Instance.Insert(item,trans);
- }
- }
- trans.Commit();
- }
- catch (Exception ex)
- {
- trans.Rollback();
- DevExpress.XtraEditors.XtraMessageBox.Show("修改失败。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- LogHelper.log.Error(string.Format("修改数据库authory_user和user_role出现错误:{0}", ex));
- }
- }
- trans.Dispose();
- if (flag)
- {
- DevExpress.XtraEditors.XtraMessageBox.Show("修改成功。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- saveData();
- this.Close();
- }
- }
- private void treeLookUp_Group_EditValueChanged(object sender, EventArgs e)
- {
- if (!string.IsNullOrEmpty(this.treeLookUp_Group.EditValue.ToString()))
- {
- if (this.treeLookUp_Group.EditValue.ToString() == "1000" || this.treeLookUp_Group.EditValue.ToString() == "0")
- {
- InitTreePart(null);
- InitTreeRole(null);
- return;
- }
- InitTreePart(this.treeLookUp_Group.EditValue.ToString());
- InitTreeRole(this.treeLookUp_Group.EditValue.ToString());
- }
- }
- /// <summary>
- /// 部门控件
- /// </summary>
- /// <param name="id">所选的组织id</param>
- private void InitTreePart(string id)
- {
- DataTable dt = new DataTable();
- dt.Columns.Add("ImageIndex", typeof(int));
- dt.Columns.Add("GroupID", typeof(string));
- dt.Columns.Add("GroupPID", typeof(string));
- dt.Columns.Add("GroupName", typeof(string));
- List<MoAuthoryGroup> list = new List<MoAuthoryGroup>();
- if (id == null)
- {
- list = BLLFactory<BlAuthoryGroup>.Instance.GetAll();
- }
- else
- {
- list = BLLFactory<BlAuthoryGroup>.Instance.Find(string.Format(" group_id = '{0}' OR parent_group_id = '{1}'",id,id));
- }
-
- DataRow dr = null;
- foreach (MoAuthoryGroup info in list)
- {
- dr = dt.NewRow();
- dr["ImageIndex"] = 0;
- dr["GroupID"] = info.GroupId;
- dr["GroupPID"] = info.ParentGroupId;
- dr["GroupName"] = info.GroupName;
- dt.Rows.Add(dr);
- }
- //增加一行空的
- dr = dt.NewRow();
- dr["GroupID"] = "0"; //使用0代替-1,避免出现节点的嵌套显示,因为-1已经作为了一般节点的顶级标识
- dr["GroupPID"] = "-1";
- dr["GroupName"] = "无";
- dt.Rows.InsertAt(dr, 0);
- //设置图形序号
- //this.treeListLookUpEdit1TreeList.SelectImageList = this.imageList2;
- //this.treeListLookUpEdit1TreeList.StateImageList = this.imageList2;
- this.treeLookUp_Part.Properties.TreeList.KeyFieldName = "GroupID";
- this.treeLookUp_Part.Properties.TreeList.ParentFieldName = "GroupPID";
- this.treeLookUp_Part.Properties.DataSource = dt;
- this.treeLookUp_Part.Properties.ValueMember = "GroupID";
- this.treeLookUp_Part.Properties.DisplayMember = "GroupName";
- this.treeLookUp_Part.Text = "";
- this.treeLookUp_Part.Properties.NullText = "";
- this.treeLookUp_Part.Properties.NullValuePrompt = "请选择部门";
- this.treeLookUp_Part.Properties.NullValuePromptShowForEmptyValue = true;
- }
- /// <summary>
- /// 角色控件
- /// </summary>
- /// <param name="id">所选的组织id</param>
- private void InitTreeRole(string id)
- {
- DataTable data = new DataTable();
- data.Columns.Add("ImageIndex", typeof(int));
- data.Columns.Add("RoleId", typeof(string));
- data.Columns.Add("ParentRoleId", typeof(string));
- data.Columns.Add("RoleName", typeof(string));
- if (id == null)
- {
- roleList = BLLFactory<BlAuthoryRole>.Instance.GetAll();
- }
- else
- {
- string sql = " role_id in (SELECT b.role_id from group_role b where group_id = '"+ id +"')";
- roleList = BLLFactory<BlAuthoryRole>.Instance.Find(sql);
- }
-
- DataRow dataRow = null;
- foreach (MoAuthoryRole info in roleList)
- {
- dataRow = data.NewRow();
- dataRow["ImageIndex"] = 0;
- dataRow["RoleId"] = info.RoleId;
- //dataRow["ParentRoleId"] = null;
- dataRow["RoleName"] = info.RoleName;
- data.Rows.Add(dataRow);
- }
- //设置图形序号
- //this.treeListLookUpEdit1TreeList.SelectImageList = this.imageList2;
- //this.treeListLookUpEdit1TreeList.StateImageList = this.imageList2;
- this.treeLookUp_Role.Properties.TreeList.OptionsView.ShowCheckBoxes = true; //设置带有复选框
- //this.treeLookUp_Role.Properties.TreeList.OptionsBehavior.AllowIndeterminateCheckState = true; //设置复选框有三个状态
- this.treeLookUp_Role.Properties.TreeList.KeyFieldName = "RoleId";
- //this.treeLookUp_Role.Properties.TreeList.ParentFieldName = "ParentRoleId";
- this.treeLookUp_Role.Properties.DataSource = data;
- this.treeLookUp_Role.Properties.ValueMember = "RoleId";
- this.treeLookUp_Role.Properties.DisplayMember = "RoleName";
- this.treeLookUp_Role.Text = "";
- this.treeLookUp_Part.Properties.NullText = "";
- this.treeLookUp_Role.Properties.NullValuePrompt = "请选择角色";
- this.treeLookUp_Role.Properties.NullValuePromptShowForEmptyValue = true;
- displayText = null;
- this.treeLookUp_Role.Properties.TreeList.AfterCheckNode += (s, a) =>
- {
- a.Node.Selected = true;
- // txtRole.RefreshEditValue();
- // txtRole.ForceClosePopup();
- GetSelectedRoleIDandName();
- };
- }
- }
- }
|