Rights Management:
First, set permissions:
(a) Design interface:
(b) Code:
1. When the form is loaded: Load the person and load the function. **
2. View its corresponding functions according to the person. **
3. Set the function of the person.
Load the interface according to permissions:
namespace windowsformsapplication17{public partial class Form1:form {public Form1 () {I Nitializecomponent (); private void Filluser () {list<userpermisstiondata> List = new Userpermisstionda (). Select (); Cmb. DataSource = list; Cmb. DisplayMember = "Name"; Cmb. ValueMember = "UserName"; } private void Form1_Load (object sender, EventArgs e) {filluser (); Load permissions//Fillmodule (); } private void Btn_click (object sender, EventArgs e) {//Take the person code out of string username = (c Mb. SelectedItem as Userpermisstiondata). UserName; Remove Uptomoduleda.deletebyusname (username) from the existing functions of the person; Traversal function to see if the foreach (Control item in Flowpane.controls) {if (item is CheckBox) was selected {checkbox cb = Item as CheckBox; if (CB. Checked = = True) {string modulecode = cb. Tag.tostring (); Insert the Personnel Code and function code into the database uptomoduledata data = new Uptomoduledata (); Data. Usname = Username; Data. Modulecode = Modulecode; New Uptomoduleda (). Insert (data); }}} MessageBox.Show ("Add success"); }//load Permissions private void Fillmodule () {//Take the person code out of String name = (CMB. SelectedItem as Userpermisstiondata). UserName; According to the Personnel Code check function List<uptomoduledata> List = new Uptomoduleda (). Selectbyusname (name); Display the function to the interface flowPane.Controls.Clear (); list<moduledata> Listall = new Moduleda (). Select ();//All functions foreach (Moduledata data in Listall)//Traversal all functions {CheckBox cb = new Ch Eckbox (); Cb. Text = data. Zhiwei; Cb. Tag = data. Code; foreach (Uptomoduledata item in list)//This person has the function {if (data. Code = = Item. Modulecode) {cb. Checked = true; Break }} FLOWPANE.CONTROLS.ADD (CB); }} private void Cmb_selectedindexchanged (object sender, EventArgs e) {//Load permissions Fillmodule (); } }}
With the other several tables, do not repeat, the main code as above
Note: the list<uptomoduledata> list = null;
Change to:list<uptomoduledata> List = new list<uptomoduledata> ();
Otherwise, it is easy to report a null error.
Windows Form-----Content (10)