internal override void listTables_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 2)
            {
                if (listTables.CurrentRow != null)
                {
                    string tableName = (string)(listTables.CurrentRow.Cells[1].Value);
                    ShowAdvancedForm(tableName, e.RowIndex);
                }
            }
            else
            {
                base.listTables_CellContentClick(sender, e);
            }

            if (e.ColumnIndex != 0)
            {
                return;
            }

            if (!_tables.Single(t => t.Name.Equals((string)listTables.Rows[e.RowIndex].Cells[1].Value)).Selected)
            {
                listTables.Rows[e.RowIndex].Cells[3].Value = String.Empty;
            }
            else
            {
                listTables.Rows[e.RowIndex].Cells[3].Value = "Single column layout";
                AdvancedWizardForm dlg = DicConfig[(string)listTables.Rows[e.RowIndex].Cells[1].Value];
                dlg.GuiTypeForTable = GuiType.IndividualControls;
            }
        }
        private void ShowAdvancedForm(string tableName, int rowIndex)
        {
            AdvancedWizardForm dlg = DicConfig[tableName];

            dlg.TableName        = tableName;
            dlg.ConnectionString = ConnectionString;
            if (dlg.ShowDialog() == DialogResult.Cancel)
            {
                return;
            }

            _tables.Single(t => t.Name.Equals(tableName)).CheckObject(true);
            switch (dlg.GuiTypeForTable)
            {
            case GuiType.IndividualControls:
                listTables.Rows[rowIndex].Cells[3].Value = "Single column layout";
                break;

            case GuiType.Grid:
                listTables.Rows[rowIndex].Cells[3].Value = "Grid layout";
                break;

            case GuiType.MasterDetail:
                listTables.Rows[rowIndex].Cells[3].Value = String.Format("Master-Detail layout, {0}", dlg.DetailTableName);
                break;

            case GuiType.None:
                listTables.Rows[rowIndex].Cells[3].Value = string.Empty;
                break;
            }
        }
 internal override void OnStarting(BaseWizardForm wizard)
 {
     wizardForm = (AdvancedWizardForm)wizard;
     SetDefaults();
     _tableName        = wizardForm.TableName;
     lblTableName.Text = "Select form layout for table " + _tableName;
     _con = new MySqlConnection(wizardForm.ConnectionString);
     _con.Open();
 }
Ejemplo n.º 4
0
    internal void GenerateModel( AdvancedWizardForm wiz )
    {
      if (wiz.ForeignKeys != null)
        wiz.ForeignKeys.Clear();
      _table = wiz.TableName;
      _connectionString = wiz.Connection.ConnectionString;
      _columns = BaseWizard<BaseWizardForm, WindowsFormsCodeGeneratorStrategy>.GetColumnsFromTable(_table, wiz.Connection);

      var wizardForeignKeys = wiz.ForeignKeys;
      wiz.Wizard.RetrieveAllFkInfo(wiz.Connection, _table, out wizardForeignKeys);
      wiz.ForeignKeys = wizardForeignKeys;
      _colValidations = ValidationsGrid.GetColumnValidationList(_table, _columns, wiz.ForeignKeys);
    }
Ejemplo n.º 5
0
        internal override void OnStarting(BaseWizardForm wizard)
        {
            AdvancedWizardForm wiz = (AdvancedWizardForm)wizard;

            // Populate grid
            grdColumnsDetail.DataSource = null;
            GenerateModel(wiz);
            ValidationsGrid.LoadGridColumns(grdColumnsDetail, wiz.Connection, _detailTable, _colValidationsDetail, _detailColumns, wiz.DetailForeignKeys);
            lblTitleDetail.Text = string.Format("Setup the validations for the columns in the table {0}", _detailTable);
            _colValsByName      = new Dictionary <string, ColumnValidation>();
            for (int i = 0; i < _colValidationsDetail.Count; i++)
            {
                _colValsByName.Add(_colValidationsDetail[i].Name, _colValidationsDetail[i]);
            }
        }
Ejemplo n.º 6
0
        internal void GenerateModel(AdvancedWizardForm wiz)
        {
            if (wiz.DetailForeignKeys != null)
            {
                wiz.DetailForeignKeys.Clear();
            }
            _connectionString = wiz.Connection.ConnectionString;
            _detailTable      = wiz.DetailTableName;
            if (string.IsNullOrEmpty(_detailTable))
            {
                return;
            }
            _detailColumns = BaseWizard <BaseWizardForm, WindowsFormsCodeGeneratorStrategy> .GetColumnsFromTable(_detailTable, wiz.Connection);

            var wizardDetailForeignKeys = wiz.DetailForeignKeys;

            wiz.Wizard.RetrieveAllFkInfo(wiz.Connection, _detailTable, out wizardDetailForeignKeys);
            wiz.DetailForeignKeys = wizardDetailForeignKeys;

            _colValidationsDetail = ValidationsGrid.GetColumnValidationList(_detailTable, _detailColumns, wiz.DetailForeignKeys);
        }
Ejemplo n.º 7
0
        public override void ProjectFinishedGenerating(Project project)
        {
#if NET_40_OR_GREATER
            var vsProj     = project.Object as VSProject;
            var tables     = new SortedSet <string>();
            var strategies = new Dictionary <string, WindowsFormsCodeGeneratorStrategy>();
            if (vsProj == null)
            {
                return;
            }

            vsProj.References.Add("MySql.Data");
            project.DTE.SuppressUI = true;
            vsProj.Project.Save();

            bool found = false;
            foreach (Reference reference in vsProj.References)
            {
                if (reference.Name.IndexOf("MySql.Data", StringComparison.CurrentCultureIgnoreCase) >= 0 && !String.IsNullOrEmpty(reference.Path))
                {
                    found = true;
                    break;
                }
            }

            if (!found)
            {
                var infoResult = InfoDialog.ShowDialog(
                    InfoDialogProperties.GetOkCancelDialogProperties(
                        InfoDialog.InfoType.Warning,
                        Resources.MySqlDataProviderPackage_ConnectorNetNotFoundError,
                        @"To use it you must download and install the MySQL Connector/Net package from http://dev.mysql.com/downloads/connector/net/",
                        Resources.MySqlDataProviderPackage_ClickOkOrCancel));
                if (infoResult.DialogResult == DialogResult.OK)
                {
                    ProcessStartInfo browserInfo = new ProcessStartInfo("http://dev.mysql.com/downloads/connector/net/");
                    Process.Start(browserInfo);
                }
            }

            try
            {
                foreach (DbTables t in WizardForm.SelectedTables)
                {
                    AdvancedWizardForm crud = WizardForm.CrudConfiguration[t.Name];
                    // Ensure all model exists, even if user didn't went through validation pages.
                    // So metadata for table used in FKs is already loaded.
                    crud.GenerateModels();
                    string detailTableName          = crud.DetailTableName;
                    string canonicalTableName       = GetCanonicalIdentifier(crud.TableName);
                    string canonicalDetailTableName = GetCanonicalIdentifier(detailTableName);
                    // Gather all the tables
                    tables.Add(crud.TableName);
                    if (!string.IsNullOrEmpty(detailTableName))
                    {
                        tables.Add(detailTableName);
                    }
                    foreach (KeyValuePair <string, ForeignKeyColumnInfo> kvp2 in crud.ForeignKeys)
                    {
                        tables.Add(kvp2.Value.ReferencedTableName);
                    }
                    foreach (KeyValuePair <string, ForeignKeyColumnInfo> kvp2 in crud.DetailForeignKeys)
                    {
                        tables.Add(kvp2.Value.ReferencedTableName);
                    }

                    AddColumnMappings(canonicalTableName, crud.ValidationColumns);
                    if (!string.IsNullOrEmpty(detailTableName))
                    {
                        AddColumnMappings(canonicalDetailTableName, crud.ValidationColumnsDetail);
                    }

                    InitializeColumnMappings(crud.ForeignKeys);
                    InitializeColumnMappings(crud.DetailForeignKeys);
                }

                // Generate the model using the proper technology
                if (WizardForm.DataAccessTechnology == DataAccessTechnology.EntityFramework5 ||
                    WizardForm.DataAccessTechnology == DataAccessTechnology.EntityFramework6)
                {
                    if (WizardForm.DataAccessTechnology == DataAccessTechnology.EntityFramework5)
                    {
                        CurrentEntityFrameworkVersion = ENTITY_FRAMEWORK_VERSION_5;
                    }
                    else
                    {
                        CurrentEntityFrameworkVersion = ENTITY_FRAMEWORK_VERSION_6;
                    }

                    AddNugetPackage(vsProj, ENTITY_FRAMEWORK_PCK_NAME, CurrentEntityFrameworkVersion, true);
                    GenerateEntityFrameworkModel(project, vsProj, WizardForm.Connection, "Model1", tables.ToList(), ProjectPath);
                }
                else if (WizardForm.DataAccessTechnology == DataAccessTechnology.TypedDataSet)
                {
                    PopulateColumnMappingsForTypedDataSet();
                    GenerateTypedDataSetModel(vsProj, WizardForm.Connection, tables.ToList());
                }

                try
                {
                    _hasDataGridDateColumn = false;
                    // Start a loop here, to generate screens for all the selected tables.
                    for (int i = 0; i < WizardForm.SelectedTables.Count; i++)
                    {
                        AdvancedWizardForm          crud          = WizardForm.CrudConfiguration[WizardForm.SelectedTables[i].Name];
                        Dictionary <string, Column> columns       = crud.Columns;
                        Dictionary <string, Column> detailColumns = crud.DetailColumns;
                        string canonicalTableName = GetCanonicalIdentifier(crud.TableName);
                        string detailTableName    = crud.DetailTableName;
                        //string canonicalDetailTableName = GetCanonicalIdentifier(detailTableName);

                        if (!TablesIncludedInModel.ContainsKey(crud.TableName))
                        {
                            SendToGeneralOutputWindow(string.Format("Skipping generation of screen for table '{0}' because it does not have primary key.", crud.TableName));
                            continue;
                        }

                        if ((crud.GuiType == GuiType.MasterDetail) && !TablesIncludedInModel.ContainsKey(crud.DetailTableName))
                        {
                            // If Detail table does not have PK, then you cannot edit details, "degrade" layout from Master Detail to Individual Controls.
                            crud.GuiType = GuiType.IndividualControls;
                            SendToGeneralOutputWindow(string.Format(
                                                          "Degrading layout for table '{0}' from master detail to single controls (because detail table '{1}' does not have primary key).",
                                                          crud.TableName, crud.DetailTableName));
                        }

                        // Create the strategy
                        StrategyConfig config = new StrategyConfig(_sw, canonicalTableName, columns, detailColumns,
                                                                   WizardForm.DataAccessTechnology, crud.GuiType, Language,
                                                                   crud.ValidationsEnabled, crud.ValidationColumns, crud.ValidationColumnsDetail,
                                                                   WizardForm.ConnectionStringWithIncludedPassword, WizardForm.ConnectionString, crud.TableName,
                                                                   detailTableName, crud.ConstraintName, crud.ForeignKeys, crud.DetailForeignKeys);
                        WindowsFormsCodeGeneratorStrategy strategy = WindowsFormsCodeGeneratorStrategy.GetInstance(config);
                        strategies.Add(WizardForm.SelectedTables[i].Name, strategy);

                        if (!_hasDataGridDateColumn)
                        {
                            EnsureCodeForDateTimeGridColumn(vsProj, columns, detailColumns);
                        }

                        string frmName = string.Format("frm{0}", canonicalTableName);
                        //string frmDesignerName = string.Format("frm{0}.designer", canonicalTableName);
                        // Add new form to project.
                        AddNewForm(project, frmName, strategy);
                    }
                }
                catch (WizardException e)
                {
                    SendToGeneralOutputWindow(string.Format("An error ocurred: {0}\n\n{1}", e.Message, e.StackTrace));
                }

                // Now generated the bindings & custom code
                List <string> formNames  = new List <string>();
                List <string> tableNames = new List <string>();
                for (int i = 0; i < WizardForm.SelectedTables.Count; i++)
                {
                    AdvancedWizardForm crud = WizardForm.CrudConfiguration[WizardForm.SelectedTables[i].Name];
                    string             canonicalTableName = GetCanonicalIdentifier(crud.TableName);
                    if (!TablesIncludedInModel.ContainsKey(crud.TableName))
                    {
                        continue;
                    }

                    string frmName = string.Format("frm{0}", canonicalTableName);
                    formNames.Add(frmName);
                    tableNames.Add(crud.TableName);
                    string frmDesignerName = string.Format("frm{0}.designer", canonicalTableName);
                    WindowsFormsCodeGeneratorStrategy strategy = strategies[WizardForm.SelectedTables[i].Name];
                    AddBindings(vsProj, strategy, frmName, frmDesignerName);
                }
                // Add menu entries for each form
                AddMenuEntries(vsProj, formNames, tableNames);

                if (WizardForm.DataAccessTechnology == DataAccessTechnology.EntityFramework6)
                {
                    // Change target version to 4.5 (only version currently supported for EF6).
                    project.Properties.Item("TargetFrameworkMoniker").Value = ".NETFramework,Version=v4.5";
                    // This line is a hack to avoid "Project Unavailable" exceptions.
                    project = (Project)((Array)(Dte.ActiveSolutionProjects)).GetValue(0);
                    vsProj  = project.Object as VSProject;
                }

                RemoveTemplateForm(vsProj);

                FixNamespaces();

                SendToGeneralOutputWindow("Building Solution...");
                project.DTE.Solution.SolutionBuild.Build(true);

                Settings.Default.WinFormsWizardConnection = WizardForm.ConnectionName;
                Settings.Default.Save();

                SendToGeneralOutputWindow("Finished project generation.");

                if (project.DTE.Solution.SolutionBuild.LastBuildInfo > 0)
                {
                    InfoDialog.ShowDialog(InfoDialogProperties.GetErrorDialogProperties(Resources.ErrorTitle, Resources.WindowsFormsWizard_SolutionBuildFailed));
                }

                WizardForm.Dispose();
            }
            catch (WizardException e)
            {
                SendToGeneralOutputWindow(string.Format("An error ocurred: {0}\n\n{1}", e.Message, e.StackTrace));
            }
#else
            throw new NotImplementedException();
#endif
        }