using System; using System.Data; using System.Data.OracleClient; using System.Text; using System.Windows.Forms; using DevComponents.DotNetBar; namespace Cyberpipe { public partial class FrmRoleRescManager : Office2007Form { public static bool IS_OPEN; public FrmRoleRescManager() { InitializeComponent(); } private void FrmRoleRescManager_Load(object sender, EventArgs e) { IS_OPEN = true; initForm(""); initCombox(); if (Utility.userRole.IndexOf("角色授权") == -1) { btn_ok.Visible = false; } } private void FrmRoleRescManager_FormClosing(object sender, FormClosingEventArgs e) { IS_OPEN = false; } private void initCombox() { string sql = "select nt from casic_userroletest where sysname='GHFX' order by nt"; using (OracleDataReader reader = OracleUtils.ExecuteReader(OracleUtils.ConnectionString, CommandType.Text, sql)) { while (reader.Read()) { combo_role.Items.Add(reader[0]); } } } private void initForm(string role) { try { listBox_left.Items.Clear(); listBox_right.Items.Clear(); string gid; string sql; if (String.IsNullOrEmpty(role)) { gid = ""; } else { sql = "select gid from casic_userroletest where nt='" + role + "' and sysname='GHFX'"; gid = OracleUtils.ExecuteScalar(OracleUtils.ConnectionString, CommandType.Text, sql).ToString(); } StringBuilder where = new StringBuilder(); if (!String.IsNullOrEmpty(gid)) { where.Append("'"); foreach (string str in gid.Split(',')) { where.Append(str).Append("','"); listBox_right.Items.Add(str); } where.Remove(where.Length - 2, 2); } if (where.Length > 0) { sql = "select resc from casic_userresctest where resc not in (" + where + ") and sysname='GHFX'"; } else { sql = "select resc from casic_userresctest where sysname='GHFX'"; } using (OracleDataReader reader = OracleUtils.ExecuteReader(OracleUtils.ConnectionString, CommandType.Text, sql)) { while (reader.Read()) { listBox_left.Items.Add(reader[0]); } } } catch (Exception ex) { MessageBox.Show("表单初始化失败:" + ex, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void combo_role_SelectedIndexChanged(object sender, EventArgs e) { initForm(combo_role.Text.Trim()); } private void btn_left_all_Click(object sender, EventArgs e) { foreach (Object obj in listBox_left.Items) { listBox_right.Items.Add(obj); } listBox_left.Items.Clear(); } private void btn_left_Click(object sender, EventArgs e) { if (listBox_left.SelectedItem!=null) { listBox_right.Items.Add(listBox_left.SelectedItem); } listBox_left.Items.Remove(listBox_left.SelectedItem); } private void btn_right_Click(object sender, EventArgs e) { if (listBox_right.SelectedItem != null) { listBox_left.Items.Add(listBox_right.SelectedItem); } listBox_right.Items.Remove(listBox_right.SelectedItem); } private void btn_right_all_Click(object sender, EventArgs e) { foreach (Object obj in listBox_right.Items) { listBox_left.Items.Add(obj); } listBox_right.Items.Clear(); } private void btn_ok_Click(object sender, EventArgs e) { try { if (String.IsNullOrEmpty(combo_role.Text.Trim())) { MessageBox.Show("角色不能为空!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); combo_role.Focus(); return; } if (listBox_right.Items.Count <= 0) { MessageBox.Show("请选资源不能为空!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } StringBuilder gid = new StringBuilder(); foreach (string str in listBox_right.Items) { gid.Append(str).Append(","); } gid.Remove(gid.Length - 1, 1); string sql = "update casic_userroletest set gid='" + gid + "' where nt='" + combo_role.Text.Trim() + "' and sysname='GHFX'"; OracleUtils.ExecuteNonQuery(OracleUtils.ConnectionString, CommandType.Text, sql); MessageBox.Show("授权成功!", "结果", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show("授权失败:" + ex, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }