Ejemplo n.º 1
0
        private void btnCreateNewANOTable_Click(object sender, EventArgs e)
        {
            try
            {
                var server = ddExternalDatabaseServer.SelectedItem as ExternalDatabaseServer;

                var a = new ANOTable(Activator.RepositoryLocator.CatalogueRepository, server, tbANOTableName.Text, tbSuffix.Text);

                //if we know the type is e.g. varchar(5)
                var length = ColumnInfo.Discover(DataAccessContext.InternalDataProcessing).DataType.GetLengthIfString();

                if (length > 0)
                {
                    a.NumberOfIntegersToUseInAnonymousRepresentation   = 0;
                    a.NumberOfCharactersToUseInAnonymousRepresentation = length;//give it a sensible maximal that will work
                    a.SaveToDatabase();
                }

                ANOTable = a;//and set the property to it to populate the rest of the form

                gbANOTable.Enabled = true;
                gbSelectExistingANOTable.Enabled = false;
                gbCreateNewANOTable.Enabled      = false;
            }
            catch (Exception exception)
            {
                checksUI1.OnCheckPerformed(new CheckEventArgs("Could not create ANOTable", CheckResult.Fail, exception));
            }
        }
Ejemplo n.º 2
0
        public override void Execute()
        {
            base.Execute();

            var    col        = columnInfo.Discover(DataAccessContext.InternalDataProcessing);
            var    fansiType  = col.DataType;
            string oldSqlType = fansiType.SQLType;


            if (TypeText("New Data Type", "Type", 50, oldSqlType, out string newSqlType, false))
            {
                try
                {
                    fansiType.AlterTypeTo(newSqlType);
                }
                catch (Exception ex)
                {
                    ExceptionViewer.Show("Failed to Alter Type", ex);
                    return;
                }

                columnInfo.Data_type = newSqlType;
                columnInfo.SaveToDatabase();

                var archive = col.Table.Database.ExpectTable(col.Table + "_Archive");

                if (archive.Exists())
                {
                    try
                    {
                        var archiveCol = archive.DiscoverColumn(col.GetRuntimeName());
                        if (archiveCol.DataType.SQLType.Equals(oldSqlType))
                        {
                            if (YesNo($"Alter Type in Archive '{ archive.GetFullyQualifiedName()}'?", "Alter Archive"))
                            {
                                try
                                {
                                    archiveCol.DataType.AlterTypeTo(newSqlType);
                                }
                                catch (Exception ex)
                                {
                                    ExceptionViewer.Show("Failed to Alter Archive Column", ex);
                                    return;
                                }
                            }
                        }
                    }
                    catch (Exception)
                    {
                        //maybe the archive is broken? corrupt or someone just happens to have a Table called that?
                        return;
                    }
                }
            }

            Publish(columnInfo.TableInfo);
        }