Rapid development of MIS tables with many fields

Source: Internet
Author: User

Rapid development of MIS tables with many fields

The company wants to develop a MIS system. There may be a large table with more than 100 fields ......
System development with. Net winform ...... The database is MySQL.
It causes a lot of inconvenience. This is my summary of the quick development process.

Here is the added record Function

Step 1. Interface Design
For controls with regular name la S, you can dynamically generate textbox and lable on the front.
You can manually pull the irregular textbox and lable to keep the default ID unchanged.

Step 2: Obtain the Textbox Control ID set.

Foreach (control con in this. Controls)
{

// If (! Con. hascontrols)
If (con is groupbox)
{
Foreach (control con2 in Con. Controls)
{
If (con2 is textbox)
{
Console. writeline (con2.name );
}
//
}

}
Step 3: Replace the text in the Word format and change it to a format similar to textbox43, textbox44, and textbox45. Use the format as the "original format" and save it well ...... To ensure that the order remains unchanged, the subsequent Parameter order will be in the original format order.
Step 4: Convert "original format" to parameter passing format in word, such as textbox29.text, textbox30.text,
Step 5: input data layer parameters
REC c = new rec ();
C. add (gys. text, jhdbh. text, gddh. text, ddbh. text, bjsh. text, SL. text, textbox42.text, textbox43.text, textbox44.text, textbox45.text, plain, textbox27.text, textbox28.text, textbox29.text, textbox31.text, textbox32.text, plain, textbox1_text, plain, textbox13.text, textbox14.text, textbox15.text, textbox16.text, plain, plain, and textbox25.text, textbox18.text, textbox12.text, textbox10.text, textbox11.text, textbox9.text, textbox8.text, textbox7.text, textbox19.text );
Step 6: data layer receiving

Internal void add (string gys, string jhdbh, string gddh, string ddbh, string bjsh, string SL, string textbox42, string textbox43, string textbox44, string textbox45, string textbox46, string textbox47, string textbox49, string textbox50, string textbox34,
String textbox35, string textbox36, string textbox37, string textbox38, string textbox39, string textbox40, string textbox41, string textbox27, string textbox28, string textbox29, string textbox30, string textbox31, string textbox32, string textbox33, string
Textbox48, string textbox20, string textbox57, string textbox21, string textbox56, string textbox55, string textbox22, string textbox23, string textbox24, string textbox13, string textbox14, string textbox15, string textbox16, string textbox17, string textbox26,
String textbox25, string textbox18, string textbox12, string textbox10, string textbox11, string textbox9, string textbox8, string textbox7, string textbox19)
{
// .............. SQL statement ...............
}
  
  
Step 7: Create an SQL statement

String SQL = "insert into mis_rec (gys, keys, gddh, ddbh, bjsh, SL, textbox42, textbox43, textbox44, textbox45, textbox46, textbox47, textbox49, textbox50, textbox34, textbox35, struct, textbox37, textbox38, textbox39, textbox40, textbox41, textbox27, textbox28, textbox29, textbox30, textbox31, struct, textbox57, textbox21, textbox56, textbox55, textbox22, textbox23, textbox24, textbox13, textbox14, textbox15, textbox16, textbox17, textbox26, textbox25, textbox18, textbox12, textbox10, textbox11, textbox9, textbox8, textbox7, textbox19)
Values ('@ gys', '@ jhdbh',' @ gddh', '@ ddbh',' @ bjsh ',' @ SL ',' @ textbox42 ', '@ textbox43', '@ textbox44',' @ textbox45', '@ textbox46', '@ textbox47', '@ textbox49',' @ textbox50 ',' @ textbox34 ', '@ textbox35',' @ textbox36 ',' @ textbox37', '@ textbox38', '@ textbox39', '@ textbox40',' @ textbox41 ',' @ textbox27 ', '@ textbox28',' @ textbox29', '@ textbox30',' @ textbox31 ',' @ textbox32', '@ textbox33',' @ textbox48', '@ textbox20 ', '@ textbox57',' @ textbox21 ',' @ textbox56', '@ textbox55',' @ textbox22 ',' @ textbox23', '@ textbox24', '@ textbox13 ', '@ textbox14',' @ textbox15', '@ textbox16',' @ textbox17', '@ textbox26',' @ textbox25', '@ textbox18', '@ textbox12 ', '@ textbox10',' @ textbox11', '@ textbox9',' @ textbox8', '@ textbox7',' @ textbox19 ')";

The field name on the front is in the original format ...... Field Values in values () must be generated in the original format ...... The Code is as follows:

Internal static string genesqlparam (string S)
{
String r = "";
String [] SA = S. Split (",". tochararray ());
Foreach (string item in SA)
{
If (R. Equals (""))
R = "'@" + item + "'";
Else
R = R + ", '@" + item + "'";
}
Return R;
}

Step 8: Input SQL statement Parameters

SQL = SQL. Replace ("@ gys", gys );
SQL = SQL. Replace ("@ jhdbh", jhdbh );
SQL = SQL. Replace ("@ gddh", gddh );
SQL = SQL. Replace ("@ ddbh", ddbh );
SQL = SQL. Replace ("@ bjsh", bjsh );
SQL = SQL. Replace ("@ sl", SL );
SQL = SQL. Replace ("@ textbox42", textbox42 );
SQL = SQL. Replace ("@ textbox43", textbox43 );
SQL = SQL. Replace ("@ textbox44", textbox44 );
SQL = SQL. Replace ("@ textbox45", textbox45 );
SQL = SQL. Replace ("@ textbox46", textbox46 );
SQL = SQL. Replace ("@ textbox47", textbox47 );
SQL = SQL. Replace ("@ textbox49", textbox49 );
SQL = SQL. Replace ("@ textbox50", textbox50 );
SQL = SQL. Replace ("@ textbox34", textbox34 );
SQL = SQL. Replace ("@ textbox35", textbox35 );
SQL = SQL. Replace ("@ textbox36", textbox36 );
SQL = SQL. Replace ("@ textbox37", textbox37 );
SQL = SQL. Replace ("@ textbox38", textbox38 );
SQL = SQL. Replace ("@ textbox39", textbox39 );
SQL = SQL. Replace ("@ textbox40", textbox40 );
SQL = SQL. Replace ("@ textbox41", textbox41 );
SQL = SQL. Replace ("@ textbox27", textbox27 );
SQL = SQL. Replace ("@ textbox28", textbox28 );
SQL = SQL. Replace ("@ textbox29", textbox29 );
SQL = SQL. Replace ("@ textbox30", textbox30 );
SQL = SQL. Replace ("@ textbox31", textbox31 );
SQL = SQL. Replace ("@ textbox32", textbox32 );
SQL = SQL. Replace ("@ textbox33", textbox33 );
SQL = SQL. Replace ("@ textbox48", textbox48 );
SQL = SQL. Replace ("@ textbox20", textbox20 );
SQL = SQL. Replace ("@ textbox57", textbox57 );
SQL = SQL. Replace ("@ textbox21", textbox21 );
SQL = SQL. Replace ("@ textbox56", textbox56 );
SQL = SQL. Replace ("@ textbox55", textbox55 );
SQL = SQL. Replace ("@ textbox22", textbox22 );
SQL = SQL. Replace ("@ textbox23", textbox23 );
SQL = SQL. Replace ("@ textbox24", textbox24 );
SQL = SQL. Replace ("@ textbox13", textbox13 );
SQL = SQL. Replace ("@ textbox14", textbox14 );
SQL = SQL. Replace ("@ textbox15", textbox15 );
SQL = SQL. Replace ("@ textbox16", textbox16 );
SQL = SQL. Replace ("@ textbox17", textbox17 );
SQL = SQL. Replace ("@ textbox26", textbox26 );
SQL = SQL. Replace ("@ textbox25", textbox25 );
SQL = SQL. Replace ("@ textbox18", textbox18 );
SQL = SQL. Replace ("@ textbox12", textbox12 );
SQL = SQL. Replace ("@ textbox10", textbox10 );
SQL = SQL. Replace ("@ textbox11", textbox11 );
SQL = SQL. Replace ("@ textbox9", textbox9 );
SQL = SQL. Replace ("@ textbox8", textbox8 );
SQL = SQL. Replace ("@ textbox7", textbox7 );
SQL = SQL. Replace ("@ textbox19", textbox19 );

Dbhelpermysql. executesql (SQL );

The above code must be generated in the original format ...... The Code is as follows:

Internal static void genesqlparamreplace (string S)
{
String r = "";
String [] SA = S. Split (",". tochararray ());
Foreach (string item in SA)
{
String S2 = "SQL = SQL. Replace (\" @ "+ item +" \ "," + item + ");";
Console. writeline (S2 );
}



}

Step 9: Create a database table

Create an example table first, and add a field like a real one to obtain its SQL statement for table creation.

Create Table 'mis _ rec '(

'Gys 'varchar (50) default null,

'Id' int (11) not null auto_increment,

Primary Key ('id ')
) Engine = InnoDB default charset = utf8;

Because there are many fields, it is difficult to create them manually. You need to generate a field to create an SQL statement in the original format.

Internal static void genecreattablesql (string s) // For MySQL
{
String r = "";
String [] SA = S. Split (",". tochararray ());
Foreach (string item in SA)
{
String S2 = "'" + item + "'varchar (50) default null ,";
Console. Write (S2 );
}
// Return R;
}

The last SQL table creation statement is

Create Table 'mis _ rec '(

'Gys 'varchar (50) default null, 'jhdbh' varchar (50) default null, 'gddh' varchar (50) default null, 'ddbh' varchar (50) default null, 'bjsh' varchar (50) default null, 'Sl 'varchar (50) default null, 'textbox42' varchar (50) default null, 'textbox43' varchar (50)
Default null, 'textbox44' varchar (50) default null, 'textbox45' varchar (50) default null, 'textbox46' varchar (50) default null, 'textbox47' varchar (50) default null, 'textbox49' varchar (50) default null, 'textbox50' varchar (50) default null, 'textbox34' varchar (50)
Default null, 'textbox35' varchar (50) default null, 'textbox36' varchar (50) default null, 'textbox37' varchar (50) default null, 'textbox38' varchar (50) default null, 'textbox39' varchar (50) default null, 'textbox40' varchar (50) default null, 'textbox41' varchar (50)
Default null, 'textbox27' varchar (50) default null, 'textbox28' varchar (50) default null, 'textbox29' varchar (50) default null, 'textbox30' varchar (50) default null, 'textbox31' varchar (50) default null, 'textbox32' varchar (50) default null, 'textbox33' varchar (50)
Default null, 'textbox48' varchar (50) default null, 'textbox20' varchar (50) default null, 'textbox57 'varchar (50) default null, 'textbox21' varchar (50) default null, 'textbox56' varchar (50) default null, 'textbox55' varchar (50) default null, 'textbox22' varchar (50)
Default null, 'textbox23' varchar (50) default null, 'textbox24' varchar (50) default null, 'textbox13 'varchar (50) default null, 'textbox14' varchar (50) default null, 'textbox15' varchar (50) default null, 'textbox16' varchar (50) default null, 'textbox17' varchar (50)
Default null, 'textbox26' varchar (50) default null, 'textbox25' varchar (50) default null, 'textbox18 'varchar (50) default null, 'textbox12' varchar (50) default null, 'textbox10' varchar (50) default null, 'textbox11' varchar (50) default null, 'textbox9' varchar (50)
Default null, 'textbox8' varchar (50) default null, 'textbox7' varchar (50) default null, 'textbox19' varchar (50) default null,

'Id' int (11) not null auto_increment,

Primary Key ('id ')
) Engine = InnoDB default charset = utf8;

Step 10. Pass the test once ...... The advantage is that the automatically generated field names are not manually typed incorrectly.

In my summary, for tables with many such fields, using code generation is a good way to increase the speed ...... The most important thing on the interface is that the default ID of textbox should not be changed ...... It can save a lot of time ...... It also makes the name regular ...... When writing code, you can simply write it as a number. You do not need to return to the interface to view the ID.

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.