📄 frmmain.cs
字号:
cbxNET_OutputLanguage.SelectedIndex = (int)m_apApplicationParams.iNETOutputLanguage;
// resume gui logic
this.ResumeLayout();
}
/// <summary>
/// Purpose: serializes the current state of the gui to disk, by writing the gui settings back
/// into the ApplicationParams object and to call the serialize method 'Store'.
/// </summary>
private void SerializeSettingsToDisk()
{
m_apApplicationParams.bNETIncludeAutoComplete = chkNET_IncludeAutoComplete.Checked;
m_apApplicationParams.bNETIncludeComments = chkNET_IncludeCSComments.Checked;
m_apApplicationParams.bNETIncludeCOMPlusSupport = chkNET_IncludeCOMPlusSupport.Checked;
m_apApplicationParams.bNETIncludeJITSupport = chkNET_IncludeJITSupport.Checked;
m_apApplicationParams.bNETIncludeLoadBalancingSupport = chkNET_IncludeLoadBalancingSupport.Checked;
m_apApplicationParams.bNETIncludeNullValueSupport = chkNET_IncludeNullValueSupport.Checked;
m_apApplicationParams.bNETIncludeTransactionSupport = chkNET_IncludeTransactionSupport.Checked;
m_apApplicationParams.bNETIncludeObjectPoolingSupport = chkNET_IncludeObjectPoolingSupport.Checked;
m_apApplicationParams.bNETIncludeConnectionProviderSupport = chkNET_IncludeConnectionProviderSupport.Checked;
m_apApplicationParams.bNETPrefixProperties = chkNET_PrefixProperties.Checked;
m_apApplicationParams.bNETStyleHungarian = rbtNET_StyleHungarian.Checked;
m_apApplicationParams.bSPGenerateDeleteSPs = chkSP_GenerateDeleteSPs.Checked;
m_apApplicationParams.bSPGenerateInsertSPs = chkSP_GenerateInsertSPs.Checked;
m_apApplicationParams.bSPGenerateSelectAllSPs = chkSP_GenerateSelectAllSPs.Checked;
m_apApplicationParams.bSPGenerateSelectSPs = chkSP_GenerateSelectSPs.Checked;
m_apApplicationParams.bSPGenerateUpdateSPs = chkSP_GenerateUpdateSPs.Checked;
m_apApplicationParams.bSPIncludeComments = chkSP_IncludeSPComments.Checked;
m_apApplicationParams.bSPIncludeDrops = chkSP_IncludeDrops.Checked;
m_apApplicationParams.bSPIncludeErrorCodeSupport = chkSP_IncludeErrorCodeSupport.Checked;
m_apApplicationParams.bSPIncludeNoCountStatements = chkSP_IncludeNoCountStatements.Checked;
m_apApplicationParams.bSPPrefixParams = chkSP_PrefixParams.Checked;
m_apApplicationParams.bSPUseFieldListSelectClause = rbtSP_UseFieldListSelectClause.Checked;
m_apApplicationParams.bSQLWindowsAuthentication = rbtC_WindowsAuthentication.Checked;
m_apApplicationParams.sNETClassPrefix = tbxNET_ClassPrefix.Text.Trim();
m_apApplicationParams.sNETNamespace = tbxNET_Namespace.Text.Trim();
m_apApplicationParams.sNETOutputPath = tbxG_NETOutputPath.Text.Trim();
m_apApplicationParams.sSPNamePrefix = tbxSP_SPPrefix.Text.Trim();
m_apApplicationParams.sSPOutputPath = tbxG_SPOutputPath.Text.Trim();
m_apApplicationParams.sSQLCatalog = tbxC_Catalog.Text.Trim();
m_apApplicationParams.sSQLServer = tbxC_Server.Text.Trim();
m_apApplicationParams.sSQLUID = tbxC_LoginID.Text.Trim();
m_apApplicationParams.iNETOutputLanguage = cbxNET_OutputLanguage.SelectedIndex;
if(rbtNET_ConnectionStringRetrieval_AppConfig.Checked)
{
m_apApplicationParams.iNETConnectionStringRetrieval = (int)eConnectionStringRetrieval.AppConfig;
}
if(rbtNET_ConnectionStringRetrieval_COMPlus.Checked)
{
m_apApplicationParams.iNETConnectionStringRetrieval = (int)eConnectionStringRetrieval.ConstructionString;
}
if(rbtNET_ConnectionStringRetrieval_Property.Checked)
{
m_apApplicationParams.iNETConnectionStringRetrieval = (int)eConnectionStringRetrieval.Property;
}
// write to disk
try
{
m_apApplicationParams.Store();
// done
}
catch(Exception ex)
{
// an exception is caught. View it.
frmException wExceptionViewer = new frmException(ex);
wExceptionViewer.ShowDialog();
}
}
/// <summary>
/// Purpose: constructs connection string and connects to the database given. If something fails, an
/// error is reported. If succeeded, the rest of the application is enabled.
/// </summary>
private void DoConnect()
{
try
{
this.Cursor = Cursors.AppStarting;
string sCatalog = tbxC_Catalog.Text.Trim();
string sSQLServer = tbxC_Server.Text.Trim();
if(sSQLServer.Length<=0)
{
throw new Exception("DoConnect::SQL Server name is empty. Cannot connect.");
}
if(sCatalog.Length<=0)
{
throw new Exception("DoConnect::Catalog name is empty. Cannot connect.");
}
// build connection string
StringBuilder sConn = new StringBuilder(
"data source=" + sSQLServer + ";initial catalog=" + sCatalog);
if(rbtC_WindowsAuthentication.Checked)
{
sConn.Append(";integrated security=SSPI;persist security info=False;packet size=4096");
}
else
{
sConn.Append(";UID=" + tbxC_LoginID.Text + ";PWD=" + tbxC_Password.Text);
}
// create connection and test it.
SqlConnection scoTestConnection = new SqlConnection();
scoTestConnection.ConnectionString = sConn.ToString();
// open it
try
{
scoTestConnection.Open();
// ok
}
catch(Exception ex)
{
// error. Leave routine
throw new Exception("DoConnect::Error occured while connecting to database: " + ex.Message + ". Cannot connect.",ex);
}
scoTestConnection.Close();
scoTestConnection.Dispose();
scoTestConnection = null;
// All clear. Enable the rest of the application and store the connection string
m_lgGenerator.sConnectionString = sConn.ToString();
m_lgGenerator.sSQLCatalog = sCatalog;
// enable groups
grpGenerator_Params.Enabled=true;
grpGenerator_Progress.Enabled=true;
grpNETCode.Enabled=true;
grpTablesViews.Enabled=true;
grpTSQLCode.Enabled=true;
btnG_Start.Enabled=true;
sbpServer.Text = sSQLServer;
sbpCatalog.Text = sCatalog;
tbxNET_Namespace.Text = sCatalog + "LLBL";
// disable connect button, enable disconnect button
btnC_Connect.Enabled = false;
btnC_Disconnect.Enabled = true;
// read tables and fill the tables tab.
ReadTablesAndFillTableList();
// make the table tab visible
tclMain.SelectedTab = tbpTables;
}
catch(Exception ex)
{
// an exception is caught. View it.
frmException wExceptionViewer = new frmException(ex);
wExceptionViewer.ShowDialog();
// if tabs were already inserted, remove them
if(tclMain.TabPages.Count > 1)
{
tclMain.TabPages.Clear();
tclMain.TabPages.Add(tbpConnection);
}
}
finally
{
this.Cursor = Cursors.Default;
}
}
/// <summary>
/// Purpose: reads, using the generator object, a list of tables which are found in the catalog
/// the application is connected to, and displays this list in the listview located on the Tables tab.
/// </summary>
private void ReadTablesAndFillTableList()
{
try
{
lvT_Tables.BeginUpdate();
DataTable dtTablesFound = m_lgGenerator.GetAllTablesToProcess();
lvT_Tables.Items.Clear();
foreach(DataRow drTable in dtTablesFound.Rows)
{
ListViewItem lvItem = lvT_Tables.Items.Add(drTable["TABLE_NAME"].ToString());
lvItem.Checked = true;
switch(drTable["TABLE_TYPE"].ToString())
{
case "BASE TABLE":
lvItem.SubItems.Add("Table");
lvItem.Tag = eSQLObjectType.Table;
break;
case "VIEW":
lvItem.SubItems.Add("View");
lvItem.Tag = eSQLObjectType.View;
break;
default:
// remove the item
lvItem.Remove();
break;
}
}
}
catch(Exception ex)
{
// an exception is caught. View it.
frmException wExceptionViewer = new frmException(ex);
wExceptionViewer.ShowDialog();
}
finally
{
lvT_Tables.EndUpdate();
}
}
/// <summary>
/// Purpose: reads for all selected tables the columns and type and stores all unique colums in the
/// ExcludedFields list.
/// </summary>
private void FillExcludedFieldsList()
{
StringBuilder sTableNames = new StringBuilder(4096);
bool bPrefixWithComma = false;
try
{
this.Cursor = Cursors.WaitCursor;
lvSP_ExcludedFields.BeginUpdate();
// for each selected tablename in lvT_Tables, add the name to the string.
foreach(ListViewItem lvItem in lvT_Tables.CheckedItems)
{
string sCommaPrefix = ", ";
if(!bPrefixWithComma)
{
sCommaPrefix = "";
}
sTableNames.Append(sCommaPrefix + "'" + lvItem.Text + "'");
bPrefixWithComma=true;
}
DataTable dtColumns = m_lgGenerator.GetAllColumnNamesInSelectedTables(sTableNames.ToString());
lvSP_ExcludedFields.Items.Clear();
foreach(DataRow drColumn in dtColumns.Rows)
{
ListViewItem lvItem = new ListViewItem(drColumn["COLUMN_NAME"].ToString());
lvItem.SubItems.Add(drColumn["DATA_TYPE"].ToString());
lvSP_ExcludedFields.Items.Add(lvItem);
}
}
catch(Exception ex)
{
// an exception is caught. View it.
frmException wExceptionViewer = new frmException(ex);
wExceptionViewer.ShowDialog();
}
finally
{
lvSP_ExcludedFields.EndUpdate();
this.Cursor = Cursors.Default;
}
}
/// <summary>
/// Purpose: starts the codegeneration
/// </summary>
private void StartCodeGeneration()
{
try
{
tbxG_NETOutputPath.Text.Trim();
tbxG_SPOutputPath.Text.Trim();
if(tbxG_SPOutputPath.Text.Length <= 0)
{
throw new Exception("StartCodeGeneration::T-SQL output path is not specified");
}
if(tbxG_NETOutputPath.Text.Length <= 0)
{
throw new Exception("StartCodeGeneration::Classes output path is not specified");
}
if(tbxG_SPOutputPath.Text[tbxG_SPOutputPath.Text.Length-1].CompareTo('\\')!=0 )
{
tbxG_SPOutputPath.Text += "\\";
}
if(tbxG_NETOutputPath.Text[tbxG_NETOutputPath.Text.Length-1].CompareTo('\\')!=0 )
{
tbxG_NETOutputPath.Text += "\\";
}
// Disable buttons groups, enable groups
btnG_Close.Enabled=false;
btnG_Start.Enabled=false;
// Clear feedback textbox and init the feedback controls.
tbxG_Feedback.Clear();
InitProgressControls();
// Create Code Generator object, pass params and start generation of code per table.
m_lgGenerator.wMainWindow = this;
m_lgGenerator.bNETIncludeAutoComplete = chkNET_IncludeAutoComplete.Checked;
m_lgGenerator.bNETIncludeComments = chkNET_IncludeCSComments.Checked;
m_lgGenerator.bNETIncludeCOMPlusSupport = chkNET_IncludeCOMPlusSupport.Checked;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -