private void btnLoadTables_Click(object sender, EventArgs e) { string databaseName = txtDatabaseName.Text; string dataSource = txtDataSource.Text; string initialCatalog = txtInitialCatalog.Text; string userId = txtUserId.Text; string password = txtPassword.Text; bool trustedConnection = chkTrustedConnection.Checked; string schema = txtSchema.Text; try { SprocGenerator sprocGenerator = new SprocGenerator(databaseName, dataSource, initialCatalog, userId, password, trustedConnection, schema); _sprocGenerator = sprocGenerator; MetaInformationSchemaManager metaInformationSchemaManager = new MetaInformationSchemaManager(databaseName, dataSource, initialCatalog, userId, password, trustedConnection, schema); foreach (MetaInformationSchema metaSchema in metaInformationSchemaManager.MetaDataList) { //the reason we do this is because views blow up and are returned //with this set from the query, so we just make sure we are looking //only at base table type objects if (metaSchema.MetaTable.TableType == CommonLibrary.Constants.SqlConstants.BASE_TABLE) { treeAvailableTables.Nodes.Add(metaSchema.MetaTable.TableName); } } foreach (TreeNode node in treeAvailableTables.Nodes) { node.Checked = true; } } catch (System.Data.SqlClient.SqlException sqlEx) { MessageBox.Show(sqlEx.Message); } catch (Microsoft.SqlServer.Management.Smo.SmoException smo) { MessageBox.Show(smo.Message + smo.StackTrace); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnGenerateLists_Click(object sender, EventArgs e) { string databaseName = txtDatabaseName.Text; string dataSource = txtDataSource.Text; string initialCatalog = txtInitialCatalog.Text; string userId = txtUserId.Text; string password = txtPassword.Text; bool trustedConnection = chkTrustedConnection.Checked; string schema = txtSchema.Text; SprocDataLayerGenerator.PredicateFunctions predicateFunctions = new SprocDataLayerGenerator.PredicateFunctions(); MetaInformationSchemaManager metaInformationSchemaManager = //_metaInformationSchemaManager; new MetaInformationSchemaManager(databaseName, dataSource, initialCatalog, userId, password, trustedConnection, schema); DataLayerGenerator dataLayerGenerator = //_sprocDataLayerGenerator; new DataLayerGenerator(metaInformationSchemaManager, this.GetType().Namespace); dataLayerGenerator.AssembliesGeneratedInMemory = _sprocDataLayerGenerator.AssembliesGeneratedInMemory; bool overwriteExisting = chkOverwriteExistingDtos.Checked; if (dataLayerGenerator.AssembliesGeneratedInMemory.Count == 0) { MessageBox.Show("you must create dtos before generating lists based upon dtos, check the app.config file for the settings named CommonLibraryDllLocation and CurrentAppRunningExeLocation and set the path appropriately to your environment"); btnGenerateLists.Enabled = false; } else { List <string> tablesToGen = new List <string>(); List <MetaInformationSchema> schemasToGen = new List <MetaInformationSchema>(); if (this.treeAvailableTables.Nodes.Count > 0) { foreach (TreeNode node in treeAvailableTables.Nodes) { if (node.Checked) { tablesToGen.Add(node.Text); } } } if (tablesToGen.Count > 0) { foreach (string tableName in tablesToGen) { predicateFunctions.TableNameHolder = tableName; schemasToGen.AddRange(metaInformationSchemaManager.MetaDataList.FindAll(predicateFunctions.FindMetaInformationSchemaByTableName)); } } dataLayerGenerator.GenerateListClasses(schemasToGen, overwriteExisting); MessageBox.Show("List Generation Complete"); } btnTestDataAccess.Enabled = true; }
private void btnGenerate_Click(object sender, EventArgs e) { string databaseName = txtDatabaseName.Text; string dataSource = txtDataSource.Text; string initialCatalog = txtInitialCatalog.Text; string userId = txtUserId.Text; string password = txtPassword.Text; bool trustedConnection = chkTrustedConnection.Checked; string schema = txtSchema.Text; try { SprocGenerator sprocGenerator = new SprocGenerator(databaseName, dataSource, initialCatalog, userId, password, trustedConnection, schema); _sprocGenerator = sprocGenerator; MetaInformationSchemaManager metaInformationSchemaManager = new MetaInformationSchemaManager(databaseName, dataSource, initialCatalog, userId, password, trustedConnection, schema); SprocDataLayerGenerator.PredicateFunctions predicateFunctions = new SprocDataLayerGenerator.PredicateFunctions(); List <string> tablesToGen = new List <string>(); List <MetaInformationSchema> schemasToGen = new List <MetaInformationSchema>(); if (this.treeAvailableTables.Nodes.Count > 0) { foreach (TreeNode node in treeAvailableTables.Nodes) { if (node.Checked) { tablesToGen.Add(node.Text); } } } if (tablesToGen.Count > 0) { foreach (string tableName in tablesToGen) { predicateFunctions.TableNameHolder = tableName; schemasToGen.AddRange(metaInformationSchemaManager.MetaDataList.FindAll(predicateFunctions.FindMetaInformationSchemaByTableName)); } } List <StoredProcedure> sprocsGenerated = sprocGenerator.GetStoredProcedures(schemasToGen); //StringBuilder sb = new StringBuilder(); //foreach (StoredProcedure sproc in sprocsGenerated) //{ // sb.Append(sproc.TextHeader); // sb.Append(sproc.TextBody); // sb.Append(Environment.NewLine); // sb.Append(Environment.NewLine); // _sprocsGenerated.Add(sproc); //} //txtSprocsGenerated.Text = sb.ToString(); Dictionary <StoredProcedure, string> sprocsThatCouldNotBeCreated; if (chkOverwriteExisting.Checked) { sprocsThatCouldNotBeCreated = sprocGenerator.CreateNewStoredProceduresAndReplaceExistingOnes(sprocsGenerated); } else { sprocsThatCouldNotBeCreated = sprocGenerator.CreateNewStoredProceduresDoNotReplaceExistingOnes(sprocsGenerated); } if (sprocsThatCouldNotBeCreated.Count > 0) { StringBuilder errorBuilder = new StringBuilder(); errorBuilder.Append("Errors Encountered, could not create the following procedures: "); errorBuilder.Append(Environment.NewLine); foreach (KeyValuePair <StoredProcedure, string> kvp in sprocsThatCouldNotBeCreated) { errorBuilder.Append("SprocName: " + kvp.Key.Name + "ErrorMessage: " + kvp.Value); errorBuilder.Append(Environment.NewLine); _sprocsThatCouldNotBeGenerated.Add(kvp.Key); } MessageBox.Show(errorBuilder.ToString()); } else { MessageBox.Show("Sproc Generation complete without errors"); } } catch (System.Data.SqlClient.SqlException sqlEx) { MessageBox.Show(sqlEx.Message); } catch (Microsoft.SqlServer.Management.Smo.SmoException smo) { MessageBox.Show(smo.Message + smo.StackTrace); } catch (Exception ex) { MessageBox.Show(ex.Message); } btnGetCustomSprocs.Enabled = true; }
private void btnGenerateDtos_Click(object sender, EventArgs e) { SprocDataLayerGenerator.PredicateFunctions predicateFunctions = new SprocDataLayerGenerator.PredicateFunctions(); string databaseName = txtDatabaseName.Text; string dataSource = txtDataSource.Text; string initialCatalog = txtInitialCatalog.Text; string userId = txtUserId.Text; string password = txtPassword.Text; bool trustedConnection = chkTrustedConnection.Checked; string schema = txtSchema.Text; MetaInformationSchemaManager metaInformationSchemaManager = new MetaInformationSchemaManager(databaseName, dataSource, initialCatalog, userId, password, trustedConnection, schema); _metaInformationSchemaManager = metaInformationSchemaManager; DataLayerGenerator dataLayerGenerator = new DataLayerGenerator(metaInformationSchemaManager, this.GetType().Namespace); _sprocDataLayerGenerator = dataLayerGenerator; bool overwriteExisting = chkOverwriteExistingDtos.Checked; List <string> tablesToGen = new List <string>(); List <MetaInformationSchema> schemasToGen = new List <MetaInformationSchema>(); if (this.treeAvailableTables.Nodes.Count > 0) { foreach (TreeNode node in treeAvailableTables.Nodes) { if (node.Checked) { tablesToGen.Add(node.Text); } } } if (tablesToGen.Count > 0) { foreach (string tableName in tablesToGen) { predicateFunctions.TableNameHolder = tableName; schemasToGen.AddRange(metaInformationSchemaManager.MetaDataList.FindAll(predicateFunctions.FindMetaInformationSchemaByTableName)); } } dataLayerGenerator.GenerateDtoClasses(schemasToGen, overwriteExisting); //predicateFunctions.TableNameHolder = "TblGrid"; //MetaInformationSchema metaInformationSchema = // metaInformationSchemaManager.MetaDataList.Find(predicateFunctions.FindMetaInformationSchemaByTableName); //dataLayerGenerator.GenerateOneDtoClass(metaInformationSchema, overwriteExisting); MessageBox.Show("Dto Generation Complete"); btnGenerateLists.Enabled = true; }