Nhiberante Interface code 模板文件 -用于Mygeneration
<%#REFERENCE System.Windows.Forms.dll %>
<%#NAMESPACE 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 txtAssembly;
GuiTextBox outputPath;
GuiTextBox memberPrefix;
GuiCheckBox chkUseNull;
//GuiCheckBox chkDontCreateFK;
GuiCheckBox chkEqualsHashCode;
GuiCheckBox chkReadOnly;
GuiCheckBox chkClass;
GuiCheckBox chkMapping;
GuiCheckBox chkLazyClass;
GuiCheckBox chkEnableNullTypes;
public override void Setup()
{
RegistryKey reg ;
reg = Registry.CurrentUser;
reg = reg.CreateSubKey("Software");
reg = reg.CreateSubKey("DDLLY");
reg = reg.CreateSubKey("NHibernateScript");
if ( !input.Contains( "chooseTables" ) || !input.Contains( "txtPath" ) ||
( !input.Contains( "chkClass" ) && !input.Contains( "chkNaming" ) ) )
{
ui.Title = "DDL NHibernate Object Mapping";
ui.Width = 600;
ui.Height = 550;
// Grab default output path
string sOutputPath = "";
if( input.Contains( "defaultOutputPath" ) )
{
sOutputPath = input["defaultOutputPath"].ToString();
}
//Posiciona a pasta no registro
reg = Registry.CurrentUser;
reg = reg.OpenSubKey("Software\\DDLLY\\NHibernateScript");
// Setup Folder selection input control.
GuiLabel label1 = ui.AddLabel( "label1", "输出路径:", "输出路径" );
label1.Width = 200;
outputPath = ui.AddTextBox( "outputPath", sOutputPath, "输出路径" );
outputPath.Width = 450;
outputPath.Text = (string)reg.GetValue("outputPath", sOutputPath);
GuiFilePicker selectPath = ui.AddFilePicker( "selectPath", "选择路径", "选择路径", "outputPath", true );
selectPath.Top = outputPath.Top;
selectPath.Width = 100;
selectPath.Left = outputPath.Left + outputPath.Width + 20;
GuiLabel label2 = ui.AddLabel( "label2", "命名空间: ", "命名空间" );
label2.Top = outputPath.Top + 30;
label2.Width = 265;
classNamespace = ui.AddTextBox( "classNamespace", "NHibernate", "命名空间" );
classNamespace.Top = label2.Top + 20;
classNamespace.Width = label2.Width;
classNamespace.Text = (string)reg.GetValue("classNamespace", "NHibernate");
GuiLabel label3 = ui.AddLabel( "label3", "私有成员前缀: ", "私有成员前缀" );
label3.Width = 80;
label3.Top = classNamespace.Top + 30;
label3.Left = label2.Left; //Width + 20;
memberPrefix = ui.AddTextBox( "memberPrefix", "m_", "" );
memberPrefix.Width = 80;
memberPrefix.Top = label3.Top + 20;
memberPrefix.Left = label2.Left;
memberPrefix.Text = (string)reg.GetValue("memberPrefix", "m_");
GuiLabel label20 = ui.AddLabel ("label20", "程序集:", "程序集");
label20.Width = 160;
label20.Top = classNamespace.Top + 30;
label20.Left = label2.Left + 85;
txtAssembly = ui.AddTextBox("txtAssembly", "Business.Data", "程序集");
txtAssembly.Width = 180;
txtAssembly.Top = label3.Top + 20;
txtAssembly.Left = classNamespace.Left + 85;
txtAssembly.Text = (string)reg.GetValue("Assembly", "NHibernate");
// Setup Database selection combobox.
GuiLabel label4 = ui.AddLabel( "label4", "选择一个数据库:", "选择一个数据库" );
label4.Width = label2.Width;
GuiComboBox chooseDatabase = ui.AddComboBox( "chooseDatabase", "选择一个数据库" );
chooseDatabase.Top = label4.Top + 20;
chooseDatabase.Width = label2.Width;
GuiLabel label5 = ui.AddLabel( "label5", "选项:", "选项" );
label5.Width = 150;
label5.Top = label2.Top;
label5.Left = label2.Width + 20;
chkClass = ui.AddCheckBox( "chkClass", "创建类文件", getBool(reg.GetValue("Class", "true")), "创建类文件(*.cs)" );
chkClass.Width = 150;
chkClass.Top = label5.Top + 20;
chkClass.Left = label5.Left;
chkMapping = ui.AddCheckBox( "chkMapping", "创建XML映射文件", getBool(reg.GetValue("Mapping", "true")), "创建XML映射文件 (*.hbm.xml)" );
chkMapping.Width = 150;
chkMapping.Top = chkClass.Top + 20;
chkMapping.Left = chkClass.Left;
chkReadOnly = ui.AddCheckBox( "chkReadOnly", "只读访问", getBool(reg.GetValue("ReadOnly", "false")), "创建只读访问对象和映射" );
chkReadOnly.Width = 130;
chkReadOnly.Top = chkClass.Top;
chkReadOnly.Left = chkClass.Left + chkClass.Width + 20;
chkLazyClass = ui.AddCheckBox( "chkLazyClass", "启用Lazy类", getBool(reg.GetValue("LazyClass", "false")), "启用Lazy类" );
chkLazyClass.Width = 130;
chkLazyClass.Top = chkReadOnly.Top + 20;
chkLazyClass.Left = chkReadOnly.Left;
chkUseNull = ui.AddCheckBox( "chkUseNull", "在构造函数中使用Null", getBool(reg.GetValue("UseNull", "true")), "在构造函数中使用Null" );
chkUseNull.Width = 200;
chkUseNull.Top = chkMapping.Top + 20;
chkUseNull.Left = chkMapping.Left;
/*
chkDontCreateFK = ui.AddCheckBox( "chkDontCreateFK", "不创建外键类引用", getBool(reg.GetValue("DontCreateFK", "true")), "不创建外键类引用" );
chkDontCreateFK.Width = 300;
chkDontCreateFK.Top = chkUseNull.Top + 20;
chkDontCreateFK.Left = chkMapping.Left;
*/
chkEqualsHashCode = ui.AddCheckBox( "chkEqualsHashCode", "创建Equals和GetHashCode", getBool(reg.GetValue("EqualsHashCode", "true")), "创建Equals和GetHashCode" );
chkEqualsHashCode.Top = chkMapping.Top + 20;
chkEqualsHashCode.Left = chkMapping.Left;
chkEqualsHashCode.Width = chkUseNull.Width;
chkEnableNullTypes = ui.AddCheckBox( "chkEnableNullTypes", "启用nullable类型", getBool(reg.GetValue("EnableNullTypes", "true")), "在.Net2.0中启用nullable类型" );
chkEnableNullTypes.Top = chkEqualsHashCode.Top + 20;
chkEnableNullTypes.Left = chkMapping.Left;
chkEnableNullTypes.Width = chkUseNull.Width;
// Setup Tables selection multi-select listbox.
GuiLabel label7 = ui.AddLabel( "label7", "选择表:", "选择表" );
label7.Top = chooseDatabase.Top + 30;
label7.Width = label2.Width;
GuiListBox chooseTables = ui.AddListBox( "chooseTables", "选择表" );
chooseTables.Width = label7.Width;
chooseTables.Height = 200;
chooseTables.Top = label7.Top + 20;
// Setup Views selection multi-select listbox.
GuiLabel label8 = ui.AddLabel( "label8", "选择视图", "选择视图" );
label8.Top = label7.Top ;
label8.Left = label7.Width + 20;
label8.Width = chooseTables.Width;
GuiListBox chooseViews = ui.AddListBox( "chooseViews", "选择视图" );
chooseViews.Top = label8.Top + 20;
chooseViews.Left = label8.Left;
chooseViews.Width = label8.Width;
chooseViews.Height = chooseTables.Height;
// Attach the onchange event to the cmbDatabases control.
setupDatabaseDropdown( chooseDatabase );
chooseDatabase.AttachEvent( "onchange", "chooseDatabase_onchange" );
GuiButton btnSave = ui.AddButton("btnSave", "Save", "保存改变");
btnSave.AttachEvent("onclick", "btnSave_onclick");
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 );
bindViews( 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 bindViews( string sDatabase )
{
int count = 0;
GuiListBox lstViews = ui["chooseViews"] as GuiListBox;
try
{
IDatabase db = MyMeta.Databases[sDatabase];
lstViews.BindData( db.Views );
}
catch
{
}
}
public void chooseDatabase_onchange( GuiComboBox control )
{
int count = 0;
GuiComboBox cmbDatabases = ui["chooseDatabase"] as GuiComboBox;
bindTables( cmbDatabases.SelectedText );
bindViews( cmbDatabases.SelectedText );
}
private bool getBool(object valor){
return Boolean.Parse((string) valor);
}
public void btnSave_onclick(GuiButton btnSave)
{
RegistryKey reg ;
reg = Registry.CurrentUser;
reg = reg.CreateSubKey("Software");
reg = reg.CreateSubKey("DDLLY");
reg = reg.CreateSubKey("NHibernateScript");
reg.SetValue("classNamespace", classNamespace.Text);
reg.SetValue("Assembly", txtAssembly.Text);
reg.SetValue("EnableNullTypes", chkEnableNullTypes.Value.ToString());
reg.SetValue("outputPath", outputPath.Text);
reg.SetValue("memberPrefix", memberPrefix.Text);
//reg.SetValue("DontCreateFK", chkDontCreateFK.Value.ToString());
reg.SetValue("UseNull", chkUseNull.Value.ToString());
reg.SetValue("EqualsHashCode", chkEqualsHashCode.Value.ToString());
reg.SetValue("ReadOnly", chkReadOnly.Value.ToString());
reg.SetValue("Class", chkClass.Value.ToString());
reg.SetValue("Mapping", chkMapping.Value.ToString());
reg.SetValue("LazyClass", chkLazyClass.Value.ToString());
reg.SetValue("EnableNullTypes", chkEnableNullTypes.Value.ToString());
}
}
还不快抢沙发