Windows Form-----Content (10)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.