using System; using System.Data; using System.Data.OracleClient; using System.Windows.Forms; using DevComponents.DotNetBar; namespace Cyberpipe { public partial class FrmUserRole : Office2007Form { public static bool IS_OPEN; public FrmUserRole() { InitializeComponent(); } private void FrmUserRole_Load(object sender, EventArgs e) { IS_OPEN = true; reloadGrid(-1); initCombox(); if (Utility.isNeedLogin && !Utility.userRole.Contains("用户授权")) { btn_ok.Visible = false; } } private void initCombox() { string sql = "select username from casic_userinfotest where sysname='GHFX'"; using (OracleDataReader reader = OracleUtils.ExecuteReader(OracleUtils.ConnectionString, CommandType.Text, sql)) { while (reader.Read()) { combo_user.Items.Add(reader[0]); } } } private void FrmUserRole_FormClosing(object sender, FormClosingEventArgs e) { IS_OPEN = false; } private void reloadGrid(int id) { string sql = "select id,nt,case id " + "when "+id+" then " + "'Y'" + " else " + "'N'" + " end as chk from casic_userroletest where sysname='GHFX'"; DataTable table = OracleUtils.ExecuteDataset(OracleUtils.ConnectionString, CommandType.Text, sql).Tables[0]; dataGridViewX1.DataSource = table; } private void dataGridViewX1_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex < 0 || e.ColumnIndex < 0) { return; } for (int i = 0; i < dataGridViewX1.Rows.Count;i++ ) { dataGridViewX1.Rows[i].Cells["chk"].Value = "N"; } dataGridViewX1.Rows[e.RowIndex].Cells["chk"].Value = "Y"; } private void btn_ok_Click(object sender, EventArgs e) { try { if (String.IsNullOrEmpty(combo_user.Text.Trim())) { MessageBox.Show("请选择要授权的用户!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); combo_user.Focus(); return; } for (int i = 0; i < dataGridViewX1.Rows.Count; i++) { string chk = dataGridViewX1.Rows[i].Cells["chk"].Value.ToString(); string id = dataGridViewX1.Rows[i].Cells["id"].Value.ToString(); string role = dataGridViewX1.Rows[i].Cells["id"].Value.ToString(); if ("Y".Equals(chk)) { string sql = "update casic_userinfotest set rid=" + id + ",nt='" + nt + "' where username='" + combo_user.Text.Trim() + "' and sysname='GHFX'"; OracleUtils.ExecuteNonQuery(OracleUtils.ConnectionString, CommandType.Text, sql); break; } } MessageBox.Show("用户授权成功!", "结果", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show("用户授权失败:" + ex, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void combo_user_SelectedIndexChanged(object sender, EventArgs e) { if (!String.IsNullOrEmpty(combo_user.Text.Trim())) { string sql = "select rid from casic_userinfotest where username='" + combo_user.Text.Trim() + "' and sysname='GHFX'"; string id = OracleUtils.ExecuteScalar(OracleUtils.ConnectionString, CommandType.Text, sql).ToString(); if (!String.IsNullOrEmpty(id)) { reloadGrid(int.Parse(id)); } } } } }