MyGeneration【ui-原】

------------------------------------------------------------------------

  1)界面就用软件本身封装的

  2)可以选择当前选择的数据库中的几个表

  3) 同MyGeneration【ui-winform】做一下对比而已

 -----------------------------------------------------------------------

ExpandedBlockStart.gif Interface Code
<% #REFERENCE System.Windows.Forms.dll  %>
<% #NAMESPACE System.Windows.Forms, System.Drawing,System, System.Text, System.Collections, Zeus, Zeus.UserInterface, Zeus.DotNetScript, Microsoft.Win32   %>
 
public   class  GeneratedGui : DotNetScriptGui
{
    
public  GeneratedGui( ZeusGuiContext context ) :  base ( context ) {}

    GuiTextBox classNamespace;
    GuiTextBox outputPath;
    GuiTextBox memberPrefix;
    GuiTextBox connectionString;
    
    
public   override   void  Setup()
    {
        
if  (  ! input.Contains(  " chooseTables "  )  ||   ! input.Contains(  " txtPath "  )  ||
                ( 
! input.Contains(  " chkClass "  )  &&   ! input.Contains(  " chkNaming "  ) ) )
        {
            ui.Title 
=   " Zhuer's Generator " ;
            ui.Width 
=   330 ;
            ui.Height 
=   400 ;
                
            
//  选择数据库Label 
            GuiLabel label5  =  ui.AddLabel(  " label5 " " 选择一个数据库: " " 选择一个数据库 "  );
            
            
//  选择数据库下拉列表
            GuiComboBox chooseDatabase  =  ui.AddComboBox(  " chooseDatabase " " 选择一个数据库 "  );
            
            
//  显示当前选择的数据库中所包含的表
            GuiLabel label7  =  ui.AddLabel(  " label7 " " 选择表: " " 选择表 "  );
            GuiListBox chooseTables 
=  ui.AddListBox(  " chooseTables " " 选择表 " );
            chooseTables.Height 
=   200 ;
            
                        
            
//  为选择数据库的下拉列表创建onchange事件
            setupDatabaseDropdown( chooseDatabase );
            
//  绑定处理方法
            chooseDatabase.AttachEvent(  " onchange " " chooseDatabase_onchange " );
            
            ui.ShowGui 
=   true ;
        }
        
else  
        {
            ui.ShowGui 
=   false ;
        }
    }
    
    
// 选择数据库
     public   void  setupDatabaseDropdown( GuiComboBox Databases )
    {
        
try  
        {    
            
if ( MyMeta.IsConnected )
            {
                Databases.BindData( MyMeta.Databases );
                
if ( MyMeta.DefaultDatabase  !=   null  ) 
                {
                    Databases.SelectedValue 
=  MyMeta.DefaultDatabase.Alias;
                    bindTables( Databases.SelectedValue );
                }
            }
        }
        
catch
        {
        }
    }
    
    
// 绑定数据库中的表
     public   void  bindTables(  string  sDatabase )
    {
        
int  count  =   0 ;
    
        GuiListBox lstTables 
=  ui[ " chooseTables " as  GuiListBox;
        
        
try  
        {    
            IDatabase db 
=  MyMeta.Databases[sDatabase];
            lstTables.BindData( db.Tables );
        }
        
catch
        {
        }
    }    
    
    
// 选择数据库引发的事件
     public   void  chooseDatabase_onchange( GuiComboBox control )
    {
        
int  count  =   0 ;

        GuiComboBox cmbDatabases 
=  ui[ " chooseDatabase " as  GuiComboBox;
        bindTables( cmbDatabases.SelectedText );
    } 
    
}
ExpandedBlockStart.gif Template Code
<%
public   class  GeneratedTemplate : DotNetScriptTemplate 
{
    
// 选中的表
     private  IList _selectedTables;
    
// 数据库名
     private   string  _dbName;
    
// 表名
     private   string  _tableName;
    
// 类名
     private   string  _className;
    
// 输出路径
     private   string  _exportPath = " C:\\cs " ;
    
// 文件名
     private   string  _fileName;
    
// 文件名
     private   string  _nameSpace;
    
public  GeneratedTemplate(ZeusContext context) :  base (context) {}

    
// ---------------------------------------------------
    
//  Render()就是Template Code的入口函数,当成Main就好了
    
// ---------------------------------------------------
     public   override   void  Render()
    {
        _dbName 
=  input[ " chooseDatabase " ].ToString();         // 选择的数据库
        _selectedTables  =  input[ " chooseTables " as  ArrayList; // 选择的表
         foreach  ( string  _newTable  in  _selectedTables)
            {
                ITable _workingTable 
=  MyMeta.Databases[_dbName].Tables[_newTable];
                _tableName 
=  _workingTable.Alias.Replace( "   " "" );
                _className 
=  TableToClassName(_workingTable);
                GenerateModelFile(_workingTable.Columns);
                
            }            
        System.Diagnostics.Process.Start(
" explorer.exe " ,_exportPath); // 文件输出完毕,打开输出文件夹
    }
    
    
    
// ---------------------------------------------------
    
//  循环某个表中的所有列  每运行一次 则把一个表实体映射到一个cs文件
    
// ---------------------------------------------------
     private   void  GenerateModelFile( IColumns Columns )
        {
            _nameSpace
= " MyModel " ;
            output.writeln( 
" using System; "  );
            output.writeln( 
""  );
            output.writeln( 
" /// <summary> "  );
            output.writeln(
" ///\tMyGeneration : 实体类  "   +  _className);
            Version();
            output.writeln( 
" /// </summary> "  );
            output.writeln( 
" namespace  "   + _nameSpace + " .Model " );
            output.writeln( 
" { "  );
            output.writeln( 
" \tpublic class  " +  _className);
            output.writeln( 
" \t{ "  );
            
            
// 私有成员变量
            
// BuildPrivateMembers( Columns );
            
// BuildDefaultConstructor( Columns );
            
// BuildPublicProperties( Columns );
            output.writeln(  " \t} "  );
            output.writeln( 
" } "  );
            
            _fileName 
=  _className  +   " .cs " ;
            output.saveEnc( 
" c:\\cs\\ "   +   " MOD_ " + _fileName , " o " , " unicode "  );
            output.clear();
        }
    
    
//  版本信息 【公共小函数】
        private   void  Version()
        {
            output.writeln(
" ///\t作者:You " );
            output.writeln(
" ///\t我的博客:http://you.cnblogs.com/ " );
            output.writeln(
" ///\t版本:1.0 " );
            output.writeln(
" ///\tCreated on  "   +  DateTime.Now);
        }
    
    
    
//  表转换为类名【公共小函数】
     protected   string  TableToClassName(ITable table)
        {
            
string  tableName = table.Alias;
            
return  tableName.Replace( "   " , "" );
        }
}
%>


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

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值