using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using PMSystem.classes;
namespace PMSystem
{
public partial class frmLimit : Form
{
OleDbConnection MyConn;
int lid;
string strLimit;
public frmLimit(int id,string aa)
{
InitializeComponent();
lid = id;
strLimit = aa;
}
private void frmLimit_Load(object sender, EventArgs e)
{
MyConn = new OleDbConnection(conn.connString);
MyConn.Open();
string strSel = "select *from 权限表";
DataSet ds = new DataSet();
OleDbDataAdapter objCommand = new OleDbDataAdapter(strSel, MyConn);
objCommand.Fill(ds, "权限表");
//MessageBox.Show(strLimit);
this.checkedListBox1.DataSource = ds.Tables["权限表"];
this.checkedListBox1.ValueMember = "lid";
this.checkedListBox1.DisplayMember = "cname";
//string bb = "2";
for (int i = 0; i < checkedListBox1.Items.Count; i++)
{
DataRowView dv = ((DataRowView)checkedListBox1.Items[i]);
string dd =dv["lid"].ToString();
if (strLimit.LastIndexOf(","+ dd +",")!=-1)
{
checkedListBox1.SetItemChecked(i,true);
}
}
MyConn.Close();
}
private void button1_Click(object sender, EventArgs e)
{
string aa = ",";
for (int i = 0;i<checkedListBox1.CheckedItems.Count;i++)
{
DataRowView dv = ((DataRowView)checkedListBox1.CheckedItems[i]);
aa += dv["lid"].ToString() + ",";
}
//MessageBox.Show(aa);
string sql = "Update 系统用户表 set czyqx='" + aa + "' where id=" + lid;
// string sql = "update 权限表 set lid=" + Convert.ToInt32(strLid) + ",cname='" + strName + "' where id=" + intID;
OleDbCommand myComm = new OleDbCommand(sql, MyConn);
try
{
if (MyConn.State == 0)
{
MyConn.Open();
}
myComm.ExecuteNonQuery();
MessageBox.Show("权限设置成功!", "信息窗口", MessageBoxButtons.OK, MessageBoxIcon.Information);
// string aaa = "select id,lid as 序号,cname as 名称 from 权限表";
// DataBind(aaa, dataGridView1, "权限表");
}
catch (Exception err)
{
MessageBox.Show(err.Message, "错误窗口", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
}
}