예제 #1
0
        private void btnGenerateCustomSprocDtos_Click(object sender, EventArgs e)
        {
            Dictionary <string, string>         mainSprocNameToInputDto   = new Dictionary <string, string>();
            Dictionary <string, List <string> > sprocToDtoListsUsed       = new Dictionary <string, List <string> >();
            Dictionary <string, List <string> > sprocToInputDtosUsed      = new Dictionary <string, List <string> >();
            Dictionary <string, List <string> > sprocToDtosUsed           = new Dictionary <string, List <string> >();
            Dictionary <string, string>         standaloneSprocToInputDto = new Dictionary <string, string>();

            SprocDataLayerGenerator.PredicateFunctions predicateFunctions =
                new SprocDataLayerGenerator.PredicateFunctions();

            List <string>          customSprocsGenerateDtos = new List <string>();
            List <StoredProcedure> customSprocsChosen       = new List <StoredProcedure>();

            if (treeCustomSprocs.Nodes.Count > 0)
            {
                foreach (TreeNode node in treeCustomSprocs.Nodes)
                {
                    if (node.Checked)
                    {
                        customSprocsGenerateDtos.Add(node.Text);
                    }
                }
            }

            if (customSprocsGenerateDtos.Count > 0)
            {
                foreach (string customSprocName in customSprocsGenerateDtos)
                {
                    predicateFunctions.SprocNameHolder = customSprocName;
                    customSprocsChosen.AddRange(_customSprocs.FindAll(predicateFunctions.FindSprocGeneratedBySprocName));
                }
            }

            if (customSprocsChosen.Count > 0)
            {
                _dataLayerGenerator.GenerateCustomSprocsDtosAndLists(customSprocsChosen,
                                                                     out mainSprocNameToInputDto,
                                                                     out sprocToDtoListsUsed,
                                                                     out sprocToInputDtosUsed,
                                                                     out sprocToDtosUsed,
                                                                     out standaloneSprocToInputDto);
            }

            _mainSprocNameToInputDto   = mainSprocNameToInputDto;
            _sprocToDtoListsUsed       = sprocToDtoListsUsed;
            _sprocToInputDtosUsed      = sprocToInputDtosUsed;
            _sprocToDtosUsed           = sprocToDtosUsed;
            _standaloneSprocToInputDto = standaloneSprocToInputDto;


            btnGenerateDataAccessClass.Enabled = true;
            MessageBox.Show("Data Access Methods and Input Dtos and Result List Dtos for Custom Sprocs Generation Complete");
            MessageBox.Show("Now include the classes that the generator created into the solution and compile");
        }
예제 #2
0
        private void btnGetCustomSprocs_Click(object sender, EventArgs e)
        {
            _customSprocs.Clear();
            treeCustomSprocs.Nodes.Clear();

            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;

            _databaseSmoObjectsAndSettings = new CommonLibrary.DatabaseSmoObjectsAndSettings(databaseName,
                                                                                             dataSource,
                                                                                             initialCatalog,
                                                                                             userId,
                                                                                             password,
                                                                                             trustedConnection);

            _dataLayerGenerator = new DataLayerGenerator(_databaseSmoObjectsAndSettings,
                                                         this.GetType().Namespace);

            SprocDataLayerGenerator.PredicateFunctions predicateFunctions = new SprocDataLayerGenerator.PredicateFunctions();
            List <StoredProcedure> customSprocsNotGenerated = new List <StoredProcedure>();


            CommonLibrary.DatabaseSmoObjectsAndSettings databaseSmoObjectsAndSettings =
                new CommonLibrary.DatabaseSmoObjectsAndSettings(databaseName,
                                                                dataSource,
                                                                initialCatalog,
                                                                userId,
                                                                password,
                                                                trustedConnection,
                                                                schema);

            SprocGenerator sprocGenerator = new SprocGenerator(databaseName,
                                                               dataSource,
                                                               initialCatalog,
                                                               userId,
                                                               password,
                                                               trustedConnection,
                                                               schema);

            _sprocGenerator = sprocGenerator;
            List <StoredProcedure> sprocsGenerated = _sprocGenerator.GetStoredProcedures();

            if (sprocsGenerated != null)
            {
                foreach (StoredProcedure sproc in databaseSmoObjectsAndSettings.Database_Property.StoredProcedures)
                {
                    predicateFunctions.SprocNameHolder = sproc.Name;
                    if (!(sprocsGenerated.FindAll(predicateFunctions.FindSprocGeneratedBySprocName).Count > 0))
                    {
                        customSprocsNotGenerated.Add(sproc);
                    }
                }
            }

            if (customSprocsNotGenerated.Count > 0)
            {
                foreach (StoredProcedure customSproc in customSprocsNotGenerated)
                {
                    if (!customSproc.IsSystemObject)
                    {
                        treeCustomSprocs.Nodes.Add(customSproc.Name);
                        _customSprocs.Add(customSproc);
                    }
                }
            }
            btnGenerateCustomSprocDtos.Enabled = true;
            chkSelectAll.Enabled = true;
        }
예제 #3
0
        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;
        }
예제 #4
0
        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;
        }
예제 #5
0
        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;
        }