Winform+Mygeneration【转】

ExpandedBlockStart.gif Interface Code
<% #REFERENCE System.Windows.Forms.dll, System.Drawing.dll  %>  
<% #NAMESPACE System.Windows.Forms, System.Drawing  %>  
       
public   class  GeneratedGui : DotNetScriptGui 
       { 

           
public  GeneratedGui(ZeusContext context) :  base (context) {} 
           
// ----------------------------------------- 
           
//  入口函数
           
// ----------------------------------------- 

           
public   override   void  Setup() 
       { 

           Form1 form 
=   new  Form1(MyMeta, input);  
           
if  (form.ShowDialog()  !=  DialogResult.OK)  
           { 
               ui.IsCanceled 
=   true
           }
       } 
      } 
      
public   class  Form1:Form 
       { 
           
         
private  System.ComponentModel.IContainer components  =   null
         
protected   override   void  Dispose( bool  disposing) 
         { 
         
if  (disposing  &&  (components  !=   null )) 
            { 
              components.Dispose(); 
            } 
            
base .Dispose(disposing); 

          } 
        
private   void  InitializeComponent() 
           { 
               
this .comboBox1  =   new  System.Windows.Forms.ComboBox(); 
               
this .listBox1  =   new  System.Windows.Forms.ListBox(); 
               
this .button1  =   new  System.Windows.Forms.Button(); 
               
this .SuspendLayout(); 
 
               
this .comboBox1.FormattingEnabled  =   true
               
this .comboBox1.Location  =   new  System.Drawing.Point( 22 24 ); 
               
this .comboBox1.Name  =   " comboBox1 "
               
this .comboBox1.Size  =   new  System.Drawing.Size( 233 20 ); 
               
this .comboBox1.TabIndex  =   0
               
this .comboBox1.SelectedIndexChanged  +=   new  System.EventHandler( this .comboBox1_SelectedIndexChanged); 
       
               
this .listBox1.FormattingEnabled  =   true
               
this .listBox1.ItemHeight  =   12
               
this .listBox1.Location  =   new  System.Drawing.Point( 22 50 ); 
               
this .listBox1.Name  =   " listBox1 "
               
this .listBox1.Size  =   new  System.Drawing.Size( 233 196 ); 
               
this .listBox1.TabIndex  =   1
               
this .listBox1.MultiColumn  =   true ;
            
               
this .button1.Location  =   new  System.Drawing.Point( 180 252 ); 
               
this .button1.Name  =   " button1 "
               
this .button1.Size  =   new  System.Drawing.Size( 75 23 ); 
               
this .button1.TabIndex  =   2
               
this .button1.Text  =   " OK "
               
this .button1.UseVisualStyleBackColor  =   true
               
this .button1.Click  +=   new  System.EventHandler( this .button1_Click); 
           

               
this .AutoScaleDimensions  =   new  System.Drawing.SizeF(6F, 12F); 
               
this .AutoScaleMode  =  System.Windows.Forms.AutoScaleMode.Font; 
               
this .ClientSize  =   new  System.Drawing.Size( 284 293 ); 
               
this .Controls.Add( this .button1); 
               
this .Controls.Add( this .listBox1); 
               
this .Controls.Add( this .comboBox1); 
               
this .MaximizeBox  =   false
               
this .MinimizeBox  =   false
               
this .Name  =   " Form1 "
               
this .Text  =   " BLL Class "
               
this .Load  +=   new  System.EventHandler( this .Form1_Load); 

               
this .ResumeLayout( false ); 
           } 
 
           
private  System.Windows.Forms.ComboBox comboBox1; 
           
private  System.Windows.Forms.ListBox listBox1; 
           
private  System.Windows.Forms.Button button1; 
           
private  dbRoot myMeta; 
           
private  IZeusInput zeusInput; 

           
public  Form1(dbRoot myMeta, IZeusInput zeusInput) 
           { 
              
this .myMeta     =  myMeta; 
              
this .zeusInput  =  zeusInput; 
              InitializeComponent(); 
          }    

           
private   void  comboBox1_SelectedIndexChanged( object  sender, EventArgs e) 
          { 
               IDatabase database 
=   this .comboBox1.SelectedValue  as  IDatabase; 
               
if (database  !=   null
               { 
                   
this .listBox1.DataSource  =  database.Tables; 
                   
this .listBox1.DisplayMember  =   " Name "
               }    
          } 

          
private   void  Form1_Load( object  sender, EventArgs e) 
           { 
             
// 获取数据库,传给ComboBox 
             comboBox1.DataSource     =   this .myMeta.Databases; 
             
// ComboBox显示数据库名 
              this .comboBox1.DisplayMember  =   " Name " ;   
            
if ( this .myMeta.DefaultDatabase  !=   null
              { 
                 
// 选中默认的数据库 
                 this .comboBox1.SelectedIndex  =   this .comboBox1.FindStringExact( this .myMeta.DefaultDatabase.Name); 
                
// 通过IDatabase 的Tables属性取得数据库里面所有的数据表 
                
// 作为数据源传给ListBox 
                 this .listBox1.DataSource  =   this .myMeta.DefaultDatabase.Tables; 
                
// ListBox显示数据表的名字 
                 this .listBox1.DisplayMember  =   " Name "
             }    

           } 

            

        
private   void  button1_Click( object  sender, EventArgs e) 
            { 

              IDatabase database 
=   this .comboBox1.SelectedValue  as  IDatabase; 
              ITable    table    
=   this .listBox1.SelectedValue  as  ITable; 
              
this .zeusInput[ " databaseName " =  database.Name; 
              
this .zeusInput[ " tableName " ]     =  table.Name; 
              
this .DialogResult  =  DialogResult.OK; 
              
this .Close(); 
           } 

       }

 

ExpandedBlockStart.gif Template Code
<%  

public   class  GeneratedTemplate : DotNetScriptTemplate 
    { 
        
public  GeneratedTemplate(ZeusContext context) :  base (context) {} 
        
public   override   void  Render() 
        { 

         
// 设置输出语言... 
         MyMeta.Language  =   " C# "
         MyMeta.DbTarget 
=   " SQLClient "
         
// 获得执行完UI后,我们说选中的数据库名,数据表名 
          string  databaseName  =  input[ " databaseName " ].ToString(); 
         
string  tableName     =  input[ " tableName " ].ToString(); 
                
         IDatabase database 
=  MyMeta.Databases[databaseName]; 
         
// 获得数据表的接口 
         ITable table  =  database.Tables[tableName]; 

%>  

namespace  BLL 


    
using  System; 
    
using  System.Data; 
    
using  System.Collections;     
    
using  System.Collections.Generic; 

<%        
           
// 数据表的名称作为BLL类的类名 
           output.writeln( "     public partial class  "   +  tableName ); 
           output.writeln(
"     {    " ); 
           
// 遍历数据表中所有字段     
           foreach  (IColumn column  in  table.Columns) 
           { 
              
// 将字段名第一个字母转为小写 
                string  tmpColumnName  =  DnpUtils.SetCamelCase(column.Name); 
               output.writeln(
"         private  "   +  column.LanguageType  +   "  _ "   +  tmpColumnName  +   " ; " ); 
               output.writeln(
"         public  "   +  column.LanguageType  +   "   "   +  column.Name); 
               output.writeln(
"         { " ); 
               output.writeln(
"             get { return _ "   +  tmpColumnName  +   " ;    } " ); 
               output.writeln(
"             set { _ "   +  tmpColumnName  +   "  = value;   } " ); 
               output.writeln(
"         } " ); 
               output.writeln(
"" );      
          }    
           output.writeln(
"     }    " );      
           output.writeln(
" } " ); 
           output.saveEnc( 
" c:\\tem\\1.cs " , " o " , " unicode "  ); // 输出后 又保存在文件里
         } 
        
   } 
   
 
%>


 说明:由于 Mygeneration 的Interface很有自我特色,为了顺眼改造成了Winform,另一特色就是Template Code没有用默认的vbscript,而是C#。
         只是告诉自己Mygeneration这个东东可以用C#。有时间翻译一个老师的比较完善的模板。

 原:http://www.cppblog.com/woaidongmao/archive/2010/03/03/108776.aspx

转载于:https://www.cnblogs.com/master-zhu/archive/2010/06/10/1755556.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值