C # source code generated by Model Code

Source: Internet
Author: User
Private void button2_click (Object sender, eventargs E)
{
Datatable dt = This. gettable ("select * From sysobjects where xtype = 'U '");
For (INT I = 0; I <DT. Rows. Count-1; I ++)
{
String tablebean = convert. tostring (Dt. Rows [I] ["name"]). toupper (). Replace ("WZ _","");
Datatable DTT = This. gettable ("select * from [" + convert. tostring (Dt. Rows [I] ["name"]) + "]");
System. text. stringbuilder sbshu = new stringbuilder ("using system ;"). append (system. environment. newline ). append ("using system. collections. generic ;"). append (system. environment. newline ). append ("using system. text ;"). append (system. environment. newline ). append ("using system. data ;"). append (system. environment. newline ). append ("using mediinfo. pocketpc. sbgl. loaddata ;"). append (system. environment. newline ). append ("using mediinfo. pocketpc. sbgl. dataaccess ;"). append (system. environment. newline ). append ("namespace mediinfo. pocketpc. sbgl. bizcom "). append (system. environment. newline ). append ("{"). append (system. environment. newline ). append ("public class biz" + tablebean + ": base. bizcombase "). append (system. environment. newline ). append ("{"). append (system. environment. newline );

System. Text. stringbuilder sbset = new stringbuilder ("");

System. text. stringbuilder sbbean = new stringbuilder ("Public biz" + tablebean + "selectbyid (string ID) {" + system. environment. newline + "biz" + tablebean + "biz" + tablebean + "= new biz" + tablebean + "();" + system. environment. newline + "");
// The first half of SQL
System. Text. stringbuilder sbsqlbefore = new stringbuilder ("strsql = \" insert into "). append (" WZ _ "). append (tablebean). append ("(");
System. Text. stringbuilder sbsqlafter = new stringbuilder ("values (");
For (Int J = 0; j <DTT. Columns. Count; j ++)
{
Sbshu. append ("Private string _" + DTT. Columns [J]. columnname. tostring () + ";" + system. environment. newline );
Sbset. append ("Public String" + DTT. columns [J]. columnname. tostring () + "{set {This. _ "+ DTT. columns [J]. columnname. tostring () + "= value;} get {return this. _ "+ DTT. columns [J]. columnname. tostring () + ";}}" + system. environment. newline );
Sbbean. append ("biz" + tablebean + ". "+ DTT. columns [J]. columnname. tostring () + "= convert. tostring (DT. rows [0] [\ "" + DTT. columns [J]. columnname. tostring () + "\"]); "). append (system. environment. newline );
If (J! = 0)
{
Sbsqlbefore. append (",");
Sbsqlafter. append (",");
}
Sbsqlbefore. append (DTT. Columns [J]. columnname. tostring ());
Sbsqlafter. append ("'\" + yhxxdt. rows [I] [\ "" + DTT. columns [J]. columnname. tostring () + "\"]. tostring () + \"'");
}
Sbsqlbefore. append (")");
Sbsqlafter. append (")");
Sbshu. append (sbset. tostring ()). append (sbbean. append ("Return biz" + tablebean + ";" + system. environment. newline + "}"). tostring ());
// Load the function;
Sbshu. append (system. environment. newline );
Sbshu. append ("Public serviceresult loaddata (loadmode )");
Sbshu. append (system. environment. newline );
Sbshu. append ("{"); // start
Sbshu. append (system. environment. newline );
Sbshu. append ("try ");
Sbshu. append (system. environment. newline );
Sbshu. append ("{");
Sbshu. append (system. environment. newline );
Sbshu. append ("loadmanager = loadmanager. createinstance ();");
Sbshu. append (system. environment. newline );
Sbshu. append ("// obtain locally inserted data ");
Sbshu. append (system. environment. newline );
Sbshu. append ("datatable yhxxdt = loadmanager. getinitdata (loadmode, \" \ ", \" WZ "+ tablebean +". xml \");");
Sbshu. append (system. environment. newline );
Sbshu. append ("string strsql = \" delete from WZ _ "+ tablebean + "\";");
Sbshu. append (system. environment. newline );
Sbshu. append ("string connstring = localdatabase. createinstance (). getconnectionstring ();");
Sbshu. append (system. environment. newline );
Sbshu. append ("sqlcehelper. executenonquery (connstring, commandtype. Text, strsql, null );");
Sbshu. append (system. environment. newline );
Sbshu. append ("For (INT I = 0; I <yhxxdt. Rows. Count; I ++ )");
Sbshu. append (system. environment. newline );
Sbshu. append ("{");
Sbshu. append (system. environment. newline );
Sbshu. append (""). append (sbsqlbefore. tostring (). append (sbsqlafter. append ("\"; "). tostring ());
Sbshu. append (system. environment. newline );
Sbshu. append ("sqlcehelper. executenonquery (connstring, commandtype. Text, strsql, null );");
Sbshu. append (system. environment. newline );
Sbshu. append ("}");
Sbshu. append (system. environment. newline );
Sbshu. append ("yhxxdt. Dispose ();");
Sbshu. append (system. environment. newline );
Sbshu. append ("serviceresult. retcode = 0 ;");
Sbshu. append (system. environment. newline );
Sbshu. append ("Return serviceresult ;");
Sbshu. append (system. environment. newline );
Sbshu. append ("}");
Sbshu. append (system. environment. newline );
Sbshu. append ("catch (exception ex )");
Sbshu. append (system. environment. newline );
Sbshu. append ("{");
Sbshu. append (system. environment. newline );
Sbshu. append ("exceptionmanager. Publish (Ex );");
Sbshu. append (system. environment. newline );
Sbshu. append ("serviceresult. retcode =-1 ;");
Sbshu. append (system. environment. newline );
Sbshu. append ("serviceresult. retmsg = ex. Message ;");
Sbshu. append (system. environment. newline );
Sbshu. append ("Return serviceresult ;");
Sbshu. append (system. environment. newline );
Sbshu. append ("}");
Sbshu. append (system. environment. newline );

Sbshu. append ("}"); // end
Sbshu. append (system. environment. newline). append ("}"). append (system. environment. newline). append ("}");
This. richtextbox1.text = sbshu. tostring ();
Using (system. io. streamwriter Sw = new system. io. streamwriter (this. filepath + "file: // Biz/" + tablebean + ". CS ", false, system. text. encoding. getencoding ("gb2312 ")))
{
Sw. Write (sbshu. tostring ());
Sw. Flush ();
}

}
// MessageBox. Show (this. filepath );
// Datatable dt = This. gettable (this. combobox1.selectedvalue. tostring (), this. tbname. text. trim (), this. tbpass. text. trim (), "select * From sysobjects where xtype = 'U '");

}
Public datatable gettable (string database, string user, string pass, string SQL)
{
Sqlconnection conn = new sqlconnection ();
Conn. connectionstring = "Initial catalog =" + database + "; Data Source =.; user id =" + User + "; Password =" + pass;
Sqlcommand cmd = new sqlcommand ();
Cmd. Connection = conn;
Cmd. commandtext = SQL;
Sqldataadapter da = new sqldataadapter ();
Da. selectcommand = cmd;
Dataset DS = new dataset ();
Da. Fill (DS );
Return Ds. Tables [0];
}
Public datatable gettable (string SQL)
{
Dataset DS = new dataset ();
Try
{
Sqlconnection conn = new sqlconnection ();
Conn. connectionstring = "Initial catalog = demo; Data Source =.; user id = sa; Password = sa ";
Sqlcommand cmd = new sqlcommand ();
Cmd. Connection = conn;
Cmd. commandtext = SQL;
Sqldataadapter da = new sqldataadapter ();
Da. selectcommand = cmd;

Da. Fill (DS );

}
Catch (exception ex)
{

MessageBox. Show (ex. Message);
}< br> return Ds. Tables [0];
}

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.