コード例 #1
0
 protected override void ExportColumnProperties(Table table, Column column)
 {
     writer.WriteStartElement("column");
     writer.WriteAttributeString("number", column.ID.ToString());
     writer.WriteAttributeString("name", column.Name);
     writer.WriteAttributeString("datatype", SmoUtil.GetDatatypeString(column));
     writer.WriteAttributeString("size", column.DataType.MaximumLength.ToString());
     writer.WriteAttributeString("nullable", column.Nullable == true ? "Y" : "N");
     writer.WriteAttributeString("inprimarykey", column.InPrimaryKey == true ? "Y" : "N");
     writer.WriteAttributeString("isforeignkey", column.IsForeignKey == true ? "Y" : "N");
     if (column.ExtendedProperties.Contains(SmoUtil.DESCRIPTION_PROPERTY))
     {
         writer.WriteAttributeString("description", column.ExtendedProperties[SmoUtil.DESCRIPTION_PROPERTY].Value.ToString());
     }
     else
     {
         writer.WriteAttributeString("description", string.Empty);
     }
 }
コード例 #2
0
        private void btnImport_Click(object sender, EventArgs e)
        {
            openFileDialogImport.ShowDialog();
            if (!string.IsNullOrEmpty(openFileDialogImport.FileName))
            {
                try
                {
                    FileInfo fileInfo = new FileInfo(openFileDialogImport.FileName);
                    //Allow a little extra space on the progress bar for the XSL transform
                    BeginAction("Importing from " + fileInfo.Name, (int)(db.Tables.Count * 1.1));
                    this.Refresh();

                    switch (fileInfo.Extension)
                    {
                    case ".sql":
                        //Check script contains correct DDC tag
                        string script = fileInfo.OpenText().ReadToEnd();
                        if (script.IndexOf(Exporter.Identifier, StringComparison.InvariantCultureIgnoreCase) == -1)
                        {
                            throw new System.Exception(Resources.ImportErrorCanNotValidateScript);
                        }

                        //Execute SQL script - this command knows how to deal with GO separators
                        server.ConnectionContext.ExecuteNonQuery(script);
                        break;

                    case ".xml":
                        //Check doctype and tags to ensure DDC type
                        XmlDocument xmlDoc = new XmlDocument();
                        xmlDoc.Load(fileInfo.FullName);
                        if (!xmlDoc.DocumentType.Name.Equals(XmlExporter.Identifier, StringComparison.InvariantCultureIgnoreCase))
                        {
                            throw new System.Exception(Resources.ImportErrorUnsupportedVersion);
                        }

                        //Iterate and import
                        foreach (XmlNode tableNode in xmlDoc.SelectNodes("//documentation/tables/table"))
                        {
                            string tbl          = "[" + tableNode.Attributes["schema"].Value + "].[" + tableNode.Attributes["name"].Value + "]";
                            Table  currentTable = SmoUtil.GetTableByName(db, tbl);
                            SetTableDescription(currentTable, tableNode.Attributes["description"].Value);
                            foreach (XmlNode columnNode in tableNode.SelectNodes("column"))
                            {
                                SetPropertyValue(currentTable, SmoUtil.DESCRIPTION_PROPERTY, columnNode.Attributes["description"].Value, columnNode.Attributes["name"].Value, true);
                                foreach (XmlNode columnPropertyNode in columnNode.SelectNodes("property"))
                                {
                                    SetPropertyValue(currentTable, columnPropertyNode.Attributes["name"].Value, columnPropertyNode.Attributes["value"].Value, columnNode.Attributes["name"].Value, true);
                                }
                            }
                        }
                        break;
                    }
                    DocumentationSetup(sqlConnectionString);
                    EndAction(Resources.ImportEndAction);
                }
                catch (Exception ex)
                {
                    EndAction("ERROR: " + ex.Message);
                }
                finally
                {
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Populate the select table fields to be documented
        /// </summary>
        private void FillSelectedTableToDocument()
        {
            BeginAction(Resources.DocumentLoadTableBeginAction, 100);

            if (ddlTables.SelectedIndex >= 0)
            {
                // Select by index rather than name since names aren't consistently populated in SQL2K with a user account
                table = SmoUtil.GetTableByName(db, ddlTables.SelectedItem.ToString());
                if (table.ExtendedProperties.Contains(SmoUtil.DESCRIPTION_PROPERTY))
                {
                    txtTableDescription.Text = table.ExtendedProperties[SmoUtil.DESCRIPTION_PROPERTY].Value.ToString();
                }
                else
                {
                    txtTableDescription.Text = string.Empty;
                }

                chkExcludedTable.Checked = Properties.Settings.Default.ExcludedObjects.Exists(obj => obj == new ExcludedObject(table));

                DataTable columnList = new DataTable();
                columnList.Columns.Add("Number");
                columnList.Columns.Add("Column");
                columnList.Columns.Add("Datatype");
                columnList.Columns.Add("Size");
                columnList.Columns.Add("Nullable");
                columnList.Columns.Add("InPrimaryKey");
                columnList.Columns.Add("IsForeignKey");
                columnList.Columns.Add("Description");

                foreach (string property in additionalPropertiesArray)
                {
                    columnList.Columns.Add(property);
                }

                foreach (Column column in table.Columns)
                {
                    DataRow row = columnList.NewRow();
                    row["Number"]       = column.ID;
                    row["Column"]       = column.Name;
                    row["Datatype"]     = SmoUtil.GetDatatypeString(column);
                    row["Size"]         = column.DataType.MaximumLength;
                    row["Nullable"]     = column.Nullable == true ? "Y" : "N";
                    row["InPrimaryKey"] = column.InPrimaryKey == true ? "Y" : "N";
                    row["IsForeignKey"] = column.IsForeignKey == true ? "Y" : "N";

                    AddColumnToGrid(column, row, "Description", SmoUtil.DESCRIPTION_PROPERTY);

                    foreach (string property in additionalPropertiesArray)
                    {
                        AddColumnToGrid(column, row, property, property);
                    }

                    columnList.Rows.Add(row);
                }

                dgvColumns.DataSource = columnList;
                FormatReadonlyColumn(dgvColumns.Columns["Number"]);
                FormatReadonlyColumn(dgvColumns.Columns["Column"]);
                FormatReadonlyColumn(dgvColumns.Columns["Datatype"]);
                FormatReadonlyColumn(dgvColumns.Columns["Size"]);
                FormatReadonlyColumn(dgvColumns.Columns["Nullable"]);
                FormatReadonlyColumn(dgvColumns.Columns["InPrimaryKey"]);
                FormatReadonlyColumn(dgvColumns.Columns["IsForeignKey"]);
            }

            // This is Ben's silly way of trying to make the document grid look pretty:
            // Set the height of the grid to the same height as the included rows or set to a max height
            int RequiredGridHeight = dgvColumns.Rows.GetRowsHeight(DataGridViewElementStates.None) + dgvColumns.ColumnHeadersHeight;

            if (RequiredGridHeight > Convert.ToInt32(Resources.DocumentMaxGridHeight))
            {
                dgvColumns.Height = Convert.ToInt32(Resources.DocumentMaxGridHeight);
            }
            else
            {
                dgvColumns.Height = RequiredGridHeight;
            }

            EndAction(Resources.DocumentLoadTableEndAction);
        }