using System; using System.Data; using System.Windows.Forms; using DevComponents.DotNetBar; namespace Cyberpipe { public partial class FrmOper : Office2007Form { int id; public FrmOper(int _id) { InitializeComponent(); id = _id; } DataTable table; /// <summary> /// 窗体初始化事件处理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void FrmRESC_Load(object sender, EventArgs e) { string sql = "select \"id\",\"name\" from casic_app"; table = OledbHelper.QueryTable(sql); if (table != null) { if (table.Rows.Count > 0) { for (int i = 0; i < table.Rows.Count; i++) { comboBoxEx1.Items.Add(table.Rows[i]["name"].ToString()); } if (id != -1) { Text = "修改操作信息"; buttonX1.Text = "保存"; sql = "select casic_app.\"name\",casic_oper.\"name\",casic_oper.\"mask\",casic_oper.\"code\",casic_oper.\"desc\" from casic_app inner join casic_oper on casic_app.\"id\" = casic_oper.\"aid\" where casic_oper.\"id\" = " + id; table = OledbHelper.QueryTable(sql); if (table != null && table.Rows.Count > 0) { for (int j = 0; j < comboBoxEx1.Items.Count; j++) { if (comboBoxEx1.Items[j].ToString() == table.Rows[0][0].ToString()) { comboBoxEx1.SelectedIndex = j; break; } } txtCode.Text = table.Rows[0][3].ToString(); txtDesc.Text = table.Rows[0][4].ToString(); txtMask.Text = table.Rows[0][2].ToString(); txtName.Text = table.Rows[0][1].ToString(); } } } } } /// <summary> /// 添加、保存按钮事件处理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonX1_Click(object sender, EventArgs e) { if (comboBoxEx1.SelectedIndex == -1) { MessageBox.Show("请选择分系统名称!"); return; } if (txtName.Text.Trim() == "") { MessageBox.Show("请输入操作名称!"); return; } if (txtMask.Text.Trim() == "") { MessageBox.Show("请输入操作掩码!"); return; } if (txtCode.Text.Trim() == "") { MessageBox.Show("请输入操作代码!"); return; } string sql; try { sql = "select \"id\" from casic_app where \"name\" = '" + comboBoxEx1.SelectedItem + "'"; DataTable dt = OledbHelper.QueryTable(sql); if (dt != null) { if (dt.Rows.Count > 0) { int aid = Convert.ToInt32(dt.Rows[0][0].ToString()); if (id == -1) { sql = "select * from casic_oper where \"name\" ='" + txtName.Text.Trim() + "' and \"aid\" =" + aid; if (OledbHelper.QueryTable(sql).Rows.Count > 0) { MessageBox.Show("该分系统下已录入该操作信息!"); return; } sql = "insert into casic_oper(\"name\",\"mask\",\"code\",\"desc\",\"aid\") values('" + txtName.Text.Trim() + "'," + txtMask.Text.Trim() + ",'" + txtCode.Text.Trim() + "','" + txtDesc.Text.Trim() + "'," + aid + ")"; } else { if (txtCode.Text == table.Rows[0][3].ToString() && txtDesc.Text == table.Rows[0][4].ToString() && txtMask.Text == table.Rows[0][2].ToString() && txtName.Text == table.Rows[0][1].ToString() && comboBoxEx1.SelectedItem.ToString() == table.Rows[0][0].ToString()) { DialogResult = DialogResult.OK; Close(); return; } sql = "select * from casic_oper where \"name\" ='" + txtName.Text.Trim() + "' and \"aid\" =" + aid + " and \"id\" <> " + id; if (OledbHelper.QueryTable(sql).Rows.Count > 0) { MessageBox.Show("该分系统下已录入该操作信息!"); return; } sql = "update casic_oper set \"name\"='" + txtName.Text.Trim() + "',\"mask\" = '" + txtMask.Text.Trim() + "',\"code\" =" + txtCode.Text.Trim() + ",\"desc\" = '" + txtDesc.Text.Trim() + "',\"aid\" = " + aid + " where \"id\" = " + id; } 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) { Close(); } } }