ASP. NET Office Automation System Development Instance navigation Note 2 System Management Module Design

Source: Internet
Author: User
The first step is to design the [System Management] module, which is also a general system step.
The simple UML activity diagram is as follows:

Databases include:
Loginfo
Operation Log information table sysoptlog
Organization basic info table mrbranch
Department basic information table mrdepartment [the organization level is higher than the Department level. The organization can include multiple departments]
Mrbaseinf [User table]
Module basic information table sysfuncdic
Role basic information table sysrolesdic
User Role Relationship table sysemproles
Module role relationship table sysfuncrights
Table of Contents basic information table paiab

A user can correspond to multiple roles, and a role can contain multiple users. A role can contain multiple modules and a module can also correspond to multiple roles. therefore, they all have many-to-many relationships and can handle complicated permission issues.

1. Manage logon logs

All SQL operations use stored procedures. All pages inherit the base class pagebase. CS.
1. a commonly used function is used in a common class: (delete invisible character functions)

Public static string deleteunvisiblechar (string sourcestring)
{
System. Text. stringbuilder sbuilder = new system. Text. stringbuilder (131 );
For (INT I = 0; I <sourcestring. length; I ++)
{
Int Unicode = sourcestring [I];
If (UNICODE> = 16)
{
Sbuilder. append (sourcestring [I]. tostring ());
}
}
Return sbuilder. tostring ();
}

2. Freely manipulate the DataGrid.
You can use some tips to freely manipulate the DataGrid:
(1) For example, to add a checkbox to the header of each line, you can add a template column and put a checkbox control in the template:

<Asp: templatecolumn>
<Itemtemplate>
<Asp: checkbox id = "checkbox1" runat = "server"> </ASP: checkbox>
</Itemtemplate>
</ASP: templatecolumn>

Do not change other binding columns, so a checkbox will appear, for example, used for multiple selected delete operations. But how to implement delete operations in the program? First, set the datakeyfield keyword field of the DataGrid to the key field (such as the user ID) required for deletion. Then, when the deletion is processed, the first control (I .e. checkbox, but there is no ID, so it must be done in this way) to judge: foreach (datagriditem thisitem in datagridlogininfo. items)
{
If (checkbox) thisitem. cells [0]. controls [1]). Checked) // indicates the first control in the first column of this row
{
String strloginid = datagridlogininfo. datakeys [thisitem. itemindex]. tostring (); // set the datakeyfield of datagridlogininfo to loginid

Delloginlog (strloginid );
}
}

In this way, the checkbox2 code for "All selected" is also simple:

Foreach (maid)
{
(Checkbox) thisitem. cells [0]. controls [1]). Checked = checkbox2.checked;
}

Similarly, we can extend it. For example, how can we add a sequence number before each record?
There are two methods:
First, add a template column and use the number ++ of the global variable of the page;
Second, process the datatable obtained before binding and add a column:

Datatable mytable = myclass. getalllogininfo ();
Datacolumn mycolumn = mytable. Columns. Add ("Number", system. type. GetType ("system. String"); // Add a column to the data source able. Note the following tips:
For (INT I = 0; I <mytable. Rows. Count; I ++)
{
Mytable. Rows [I] ["Number"] = (I + 1). tostring ();
}

This is a very important method. If you want to perform complex operations on the bound data, this principle is often used.

Also, how can we add more complex functions, such as changing the color from the mouse to each record?
This can be handled through the itemdatabound event of the DataGrid. You can add attributes to each item as follows:

// Bind the Javascript script to each line. The color changes when the cursor points to the line.
Private void datagridlogininfo_itemdatabound (Object sender, system. Web. UI. webcontrols. datagriditemeventargs E)
{
Listitemtype itemtype = E. Item. itemtype;
If (itemtype = listitemtype. item)
{

E. Item. attributes ["onmouseout"] = "javascript: This. style. backgroundcolor = '# dedfde ';";
E. Item. attributes ["onmouseover"] = "javascript: This. style. backgroundcolor = '# fff7ce'; cursor = 'hand ';";

}
Else if (itemtype = listitemtype. alternatingitem)
{
E. Item. attributes ["onmouseout"] = "javascript: This. style. backgroundcolor = '# ffff ';";
E. Item. attributes ["onmouseover"] = "javascript: This. style. backgroundcolor = '# fff7ce'; cursor = 'hand ';";
}
}

2. Manage operation logs
There is no difference from the above one. We also need to use the pagebegin method of pagebase to determine the module and check the permission. The benefits of the page base class have already been reflected.

View status viewstate in ASP. net exists by default, and almost all ASP.. Net Control will retain the property value. it is actually a hidden form field, that is, the hidden input.

Add a Javascript script for the server control: button1.attributes. Add ("onclick", "javascript: Alert ('Cool! '");

Iii. Module Management
Module management once again proves that there is nothing unexpected and impossible to do.
The complex handling of permission-bound checkboxlist by datalist is amazing.

Generally, you must use
(Controltype) datalist. items [Index]. findcontrol ("controlname") to obtain the control and then process it.

Commandname must be set for command buttons, and then be processed through judgment in datalist_itemcommand. Therefore, commandname can not only use Edit or delete, but also be varied and flexible.

Because the connections in the class are often local variables and cannot be closed during external calls
Datareader = mycommand. executereader (commandbehavior. closeconnection );
It is more practical to automatically close the connection.

Iv. Directory management
Here is a major knowledge point: if the editing is relatively simple, you can directly use the DataGrid's own editing method:
Here, there are dgcatalog_editcommand, dgcatalog_deletecommand, dgcatalog_cancelcommand, and dgcatalog_updatecommand events. in the same way, the datakey keyword is obtained first and then processed. During update, the (textbox) cells [0] are also obtained. controls [1]. text, and then run the stored procedure and other updates.

Related Article

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.