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; namespace Cyberpipe { public partial class FrmAccess : Office2007Form { int id; public FrmAccess(int _id) { InitializeComponent(); id = _id; } /// <summary> /// 窗体初始化事件处理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void FrmAccess_Load(object sender, EventArgs e) { string sql = "select \"name\" from casic_perm"; DataTable dt = OledbHelper.QueryTable(sql); if (dt != null && dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { comboBoxEx1.Items.Add(dt.Rows[i][0].ToString().Trim()); } } if (id != -1) { this.Text = "编辑访问控制信息"; buttonX1.Text = "保存"; sql = "select casic_perm.\"name\",casic_access.\"type\",casic_access.\"value\",casic_access.\"priority\",casic_access.\"desc\" from casic_perm ,casic_access where casic_perm.\"id\" = casic_access.\"pid\" and casic_access.\"id\" = " + id.ToString(); dt = OledbHelper.QueryTable(sql); if (dt != null && dt.Rows.Count > 0) { for (int i = 0; i < comboBoxEx1.Items.Count; i++) { if (comboBoxEx1.Items[i].ToString() == dt.Rows[0][0].ToString().Trim()) { comboBoxEx1.SelectedIndex = i; break; } } txtType.Text = dt.Rows[0][1].ToString().Trim(); txtValue.Text = dt.Rows[0][2].ToString().Trim(); txtPriority.Text = dt.Rows[0][3].ToString().Trim(); txtDesc.Text = dt.Rows[0][4].ToString().Trim(); } } } /// <summary> /// 添加、保存按钮事件处理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonX1_Click(object sender, EventArgs e) { string name = comboBoxEx1.SelectedItem.ToString().Trim(); if (name == "") { MessageBox.Show("请选择一个权限!","提示"); return; } string sql; int pid =-1; try { sql = "select \"id\" from casic_perm where \"name\" ='" + name + "'"; DataTable table = OledbHelper.QueryTable(sql); if (table != null && table.Rows.Count > 0) { pid = Convert.ToInt32(table.Rows[0][0].ToString()); } if (id == -1) { sql = "select * from casic_access where \"type\" ='" + txtType.Text.Trim() + "' and \"value\" ='" + txtValue.Text.Trim() + "' and \"priority\" ='" + txtPriority.Text.Trim() + "' and \"desc\" ='" + txtDesc.Text.Trim() + "' and \"pid\" =" + pid.ToString(); } else { sql = "select * from casic_access where \"type\" ='" + txtType.Text.Trim() + "' and \"value\" ='" + txtValue.Text.Trim() + "' and \"priority\" ='" + txtPriority.Text.Trim() + "' and \"desc\" ='" + txtDesc.Text.Trim() + "' and \"pid\" =" + pid.ToString() + " and \"id\" <> " + id.ToString(); } DataTable dt = OledbHelper.QueryTable(sql); if (dt!=null && dt.Rows.Count>0) { MessageBox.Show("该访问控制信息已录入!"); return; } if (pid != -1) { if (id == -1) { sql = "insert into casic_access(\"type\",\"value\",\"priority\",\"desc\",\"pid\") values('" + txtType.Text.Trim() + "','" + txtValue.Text.Trim() + "','" + txtPriority.Text.Trim() + "','" + txtDesc.Text.Trim() + "'," + pid.ToString() + ")"; } else { sql = "update casic_access set \"type\" ='" + txtType.Text.Trim() + "',\"value\" ='" + txtValue.Text.Trim() + "',\"priority\" ='" + txtPriority.Text.Trim() + "',\"desc\" ='" + txtDesc.Text.Trim() + "',\"pid\" =" + pid.ToString() + " where \"id\" = " + id.ToString(); } } if (OledbHelper.sqlExecuteNonQuery(sql) > 0) { MessageBox.Show("保存成功!"); DialogResult = DialogResult.OK; Close(); } } catch (Exception ex) { LogError.PublishError(ex); } } /// <summary> /// 关闭按钮事件处理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonX2_Click(object sender, EventArgs e) { this.Close(); } } }