using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using DevComponents.DotNetBar; using System.Data.OracleClient; namespace Cyberpipe { public partial class FrmUserRole : Office2007Form { public static bool IS_OPEN = false; public FrmUserRole() { InitializeComponent(); } private void FrmUserRole_Load(object sender, EventArgs e) { IS_OPEN = true; reloadGrid(-1); initCombox(); if (Utility.userRole.IndexOf("用户角色") == -1) { btn_ok.Visible = false; } } private void initCombox() { string sql = "select username from casic_userinfotest where sysname='EMS'"; 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='EMS'"; 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='EMS'"; OracleUtils.ExecuteNonQuery(OracleUtils.ConnectionString, CommandType.Text, sql); break; } } MessageBox.Show("用户授权成功!", "结果", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show("用户授权失败:" + ex.ToString(), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void combo_user_SelectedIndexChanged(object sender, EventArgs e) { if (!String.IsNullOrEmpty(combo_user.Text.Trim())) { if (combo_user.Text.Trim().Equals("ems")) { btn_ok.Enabled = false; MessageBox.Show("无法对ems用户进行编辑", "提示"); } else { btn_ok.Enabled = true; } string sql = "select rid from casic_userinfotest where sysname='EMS' and username='" + combo_user.Text.Trim() + "'"; string id = OracleUtils.ExecuteScalar(OracleUtils.ConnectionString, CommandType.Text, sql).ToString(); if (!String.IsNullOrEmpty(id)) { reloadGrid(int.Parse(id)); } } } } }