private void JurisdictionSettings_Load(object sender, EventArgs e) { try { _mManageRights = Dbhelper.Db.FirstDefault <CbManageRights>(" And UserId=" + _mManageInfo.ID); PropertyInfo[] pinfo = typeof(CbManageRights).GetProperties(BindingFlags.Public | BindingFlags.DeclaredOnly | BindingFlags.Instance); foreach (PropertyInfo item in pinfo) { if (!tv_DataList.Nodes.ContainsKey(item.Name)) { continue; } TreeNode node = tv_DataList.Nodes[item.Name]; node.Checked = Utils.StrToBool(item.GetValue(_mManageRights, null), false); } GetSelectedState(); } catch (Exception ex) { CustomExceptionHandler.GetExceptionMessage(ex); MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void Btn_Enter_Click(object sender, EventArgs e) { string account = tb_Accounts.Text.Trim(); string name = tb_Name.Text.Trim(); string password = tb_Password.Text.Trim(); string confirmpassword = tb_ConfirmPassword.Text.Trim(); int index = cb_ManageType.SelectedIndex; if (account.Length == 0) { //l_AccountsTitle.Text = "帐号不能为空"; l_AccountsTitle.ForeColor = Color.Red; tb_Accounts.Focus(); return; } if (account.Length < 6) { MessageBox.Show("帐号长度不能小于 6 位,请重新输入。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); tb_Accounts.Focus(); tb_Accounts.SelectionStart = tb_Accounts.TextLength; return; } if (name.Length == 0) { //l_NameTitle.Text = "用户名称不能为空"; l_NameTitle.ForeColor = Color.Red; tb_Name.Focus(); return; } if (password.Length == 0) { //l_PasswordTitle.Text = "密码不能为空"; l_PasswordTitle.ForeColor = Color.Red; tb_Password.Focus(); return; } if (password.Length < 6) { MessageBox.Show("密码长度不能小于 6 位,请重新输入。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); tb_Password.Focus(); tb_Password.SelectionStart = tb_Password.TextLength; return; } if (confirmpassword.Length == 0) { //l_ConfrimTitle.Text = "确认密码不能为空"; l_ConfrimTitle.ForeColor = Color.Red; tb_ConfirmPassword.Focus(); return; } if (confirmpassword.Length < 6) { MessageBox.Show("确认密码长度不能小于 6 位,请重新输入。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); tb_ConfirmPassword.Focus(); tb_ConfirmPassword.SelectionStart = tb_ConfirmPassword.TextLength; return; } if (password != confirmpassword) { MessageBox.Show("密码与确认密码不一致,请重新输入。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); tb_ConfirmPassword.Focus(); tb_ConfirmPassword.SelectionStart = tb_ConfirmPassword.TextLength; return; } try { int count = Dbhelper.Db.GetCount <CbManageInfo>("ManageName", string.Format(" and ManageName='{0}' ", account)); if (count > 0) { MessageBox.Show(string.Format("{0} 已经存在", account), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); tb_Accounts.Focus(); tb_Accounts.SelectionStart = tb_Accounts.TextLength; return; } CbManageInfo mManageInfo = new CbManageInfo() { ManageName = account, ManagePwd = password, ManageType = index + 1, UserName = name }; mManageInfo.ID = Dbhelper.Db.Insert <CbManageInfo>(mManageInfo); //添加权限 CbManageRights mManageRights = new CbManageRights() { UserID = mManageInfo.ID }; PropertyInfo[] pinfos = typeof(CbManageRights).GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly); foreach (PropertyInfo item in pinfos) { if (item.PropertyType == typeof(Boolean)) { item.SetValue(mManageRights, true, null); } } Dbhelper.Db.Insert <CbManageRights>(mManageRights); this.DialogResult = DialogResult.OK; } catch (Exception ex) { CustomExceptionHandler.GetExceptionMessage(ex); MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } }