DTS

原创 2007年09月15日 10:48:00
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using Topdeep.DataImportExport.Config;
using System.Data.SqlClient;
namespace DbSchemaBuilder
{
    public partial class MainForm : Form
    {
        private DataBaseSchemaConfigSection schemaConfig = null;
        private DataBaseSchemaSection currentSchemaSection = null;
        private Configuration config;
        private string currentConfigFile = string.Empty;
        private DataBaseTableSection currentTableSection = null;
        public MainForm()
        {
            InitializeComponent();
        }
        private void toolStripMenuItemExit_Click(object sender, EventArgs e)
        {
            Close();
        }
        private void toolStripMenuItemOpen_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                currentConfigFile = openFileDialog1.FileName;
                OpenConfigFile();
            }
        }
        private void OpenConfigFile()
        {
            ExeConfigurationFileMap filemap = new ExeConfigurationFileMap();
            filemap.ExeConfigFilename = this.currentConfigFile;
            config = ConfigurationManager.OpenMappedExeConfiguration(filemap, ConfigurationUserLevel.None);
            if (config != null)
            {
                schemaConfig = (DataBaseSchemaConfigSection)config.Sections["DataBaseSchemaConfig"];
                if (schemaConfig == null)
                {
                    schemaConfig = new DataBaseSchemaConfigSection();
                    config.Sections.Add("DataBaseSchemaConfig", schemaConfig);
                }
            }
            else
            {
                schemaConfig = null;
            }
            LoadSchemaConfig();
        }
        private void LoadSchemaConfig()
        {
            listBoxSchema.Items.Clear();
            if (schemaConfig == null) return;
            foreach (DataBaseSchemaSection schemaSection in schemaConfig.SchemaCollection)
            {
                listBoxSchema.Items.Add(schemaSection);
            }
        }
        private void listBoxSchema_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listBoxSchema.SelectedIndex < 0) return;
            DataBaseSchemaSection schemaSection = listBoxSchema.SelectedItem as DataBaseSchemaSection;
            currentSchemaSection = schemaSection;
            LoadSchemaSection(schemaSection);
        }
        private void LoadSchemaSection(DataBaseSchemaSection schemaSection)
        {
            ShowSchemaInfo(schemaSection);
            treeViewSchema.ExpandAll();
        }
        private void ShowSchemaInfo(DataBaseSchemaSection schemaSection)
        {
            treeViewSchema.Nodes.Clear();
            if (schemaSection == null) return;
            TreeNode tablesRoot = treeViewSchema.Nodes.Add("表");
            for (int i = 0; i < schemaSection.TableCollection.Count; i++)
            {
                DataBaseTableSection tableSection = schemaSection.TableCollection[i];
                ShowTableInfo(tablesRoot, tableSection);
            }
        }
        private void ShowTableInfo(TreeNode tablesRoot, DataBaseTableSection tableSection)
        {
            TreeNode tableNode = tablesRoot.Nodes.Add(tableSection.TableDesc + " [" + tableSection.TableName + "]");
            tableNode.Tag = tableSection;
            for (int i = 0; i < tableSection.ColumnCollection.Count; i++)
            {
                DataBaseColumnSection columnSection = tableSection.ColumnCollection[i];
                ShowColumnInfo(tableNode, columnSection);
            }
        }
        private void ShowColumnInfo(TreeNode tableNode, DataBaseColumnSection columnSection)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(columnSection.ColumnDesc);
            sb.Append(" [");
            sb.Append(columnSection.ColumnName);
            sb.Append("] ");
            if (columnSection.IsIdentity)
            {
                sb.Append(" (Identity) ");
            }
            sb.Append(columnSection.ColumnType.ToString());
            tableNode.Nodes.Add(sb.ToString()).Tag = columnSection;
        }
        private void toolStripMenuItemAddTable_Click(object sender, EventArgs e)
        {
            if (currentSchemaSection == null) return;
            SchemaTableEditForm dlg = new SchemaTableEditForm();
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                DataBaseTableSection tableSection = new DataBaseTableSection();
                tableSection.TableName = dlg.TableName;
                tableSection.TableDesc = dlg.TableDesc;
                try
                {
                    currentSchemaSection.TableCollection.Add(tableSection);
                    LoadSchemaSection(currentSchemaSection);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
        private void treeViewSchema_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                if (treeViewSchema.SelectedNode == null) return;
                //if (treeViewSchema.SelectedNode.Level != 0) return;
                if (treeViewSchema.SelectedNode.Level == 0)
                {
                    contextMenuStrip1.Show(treeViewSchema, e.X, e.Y);
                }
                if (treeViewSchema.SelectedNode.Level == 1)
                {
                    contextMenuStrip2.Show(treeViewSchema, e.X, e.Y);
                }
                if (treeViewSchema.SelectedNode.Level == 2)
                {
                    contextMenuStrip3.Show(treeViewSchema, e.X, e.Y);
                }
                else
                {
                    return;
                }
            }
        }
        private void ToolStripMenuItemAlterTable_Click(object sender, EventArgs e)
        {
            if (currentSchemaSection == null) return;
            SchemaTableEditForm dlg = new SchemaTableEditForm();
            DataBaseTableSection tableSection = treeViewSchema.SelectedNode.Tag as DataBaseTableSection;
            dlg.TableName = tableSection.TableName;
            dlg.TableDesc = tableSection.TableDesc;
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    tableSection.TableName = dlg.TableName;
                    tableSection.TableDesc = dlg.TableDesc;
                    LoadSchemaSection(currentSchemaSection);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
        private void ToolStripMenuItemDeleteTable_Click(object sender, EventArgs e)
        {

            if (currentSchemaSection == null) return;
            DataBaseTableSection tableSection = treeViewSchema.SelectedNode.Tag as DataBaseTableSection;
            DialogResult result;
            result = MessageBox.Show("确定要删除表吗?", "提示信息", MessageBoxButtons.YesNo);
            if (result == DialogResult.Yes)
            {
                //currentSchemaSection.TableCollection
                //treeViewSchema.SelectedNode.Remove();
                currentSchemaSection.TableCollection.Remove(tableSection);
                LoadSchemaSection(currentSchemaSection);
            }
            else
            {
                return;
            }
        }
       
        private void toolStripMenuItemAddColumn_Click(object sender, EventArgs e)
        {
            SchemaColumnEditForm dlg = new SchemaColumnEditForm();
            currentTableSection = treeViewSchema.SelectedNode.Tag as DataBaseTableSection;
            DataBaseColumnSection columnSection = new DataBaseColumnSection();
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                columnSection.ColumnName = dlg.ColumnName;
                columnSection.ColumnDesc = dlg.ColumnDesc;
                columnSection.ColumnType = dlg.ColumnType;
                columnSection.IsIdentity = dlg.ColumnIdentify;
            }
            try
            {
                currentTableSection.ColumnCollection.Add(columnSection);
                LoadSchemaSection(currentSchemaSection);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void toolStripMenuItemAlterColumn_Click(object sender, EventArgs e)
        {
            if (currentSchemaSection == null) return;
            SchemaColumnEditForm dlg = new SchemaColumnEditForm();
            DataBaseColumnSection columnSection = treeViewSchema.SelectedNode.Tag as DataBaseColumnSection;
            dlg.ColumnName = columnSection.ColumnName;
            dlg.ColumnDesc = columnSection.ColumnDesc;
            dlg.ColumnType = columnSection.ColumnType;
            dlg.ColumnIdentify = columnSection.IsIdentity;
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    columnSection.ColumnName = dlg.ColumnName;
                    columnSection.ColumnDesc = dlg.ColumnDesc;
                    columnSection.ColumnType = dlg.ColumnType;
                    columnSection.IsIdentity = dlg.ColumnIdentify;
                    LoadSchemaSection(currentSchemaSection);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
        private void toolStripMenuItemDeleteColumn_Click(object sender, EventArgs e)
        {
            if (currentSchemaSection == null) return;
            DataBaseColumnSection columnSection = treeViewSchema.SelectedNode.Tag as DataBaseColumnSection;
            currentTableSection = treeViewSchema.SelectedNode.Parent.Tag as DataBaseTableSection;
            DialogResult result;
            result = MessageBox.Show("确定要删除字段吗?", "提示信息", MessageBoxButtons.YesNo);
            if (result == DialogResult.Yes)
            {
                currentTableSection.ColumnCollection.Remove(columnSection);
                LoadSchemaSection(currentSchemaSection);
            }
            else
            {
                return;
            }
        }
        private void toolStripMenuItemAddSchema_Click(object sender, EventArgs e)
        {
            SchemaEditForm dlg = new SchemaEditForm();
            // schemaConfig = listBoxSchema .SelectedValue  as DataBaseSchemaConfigSection  ;
            DataBaseSchemaSection schemaSection = new DataBaseSchemaSection();
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                schemaSection.SchemaName = dlg.SchemaName;
                schemaSection.SchemaVersion = dlg.SchemaVersion;
                schemaSection.SchemaFlag = dlg.SchemaFlag;
            }
            try
            {
                schemaConfig.SchemaCollection.Add(schemaSection);
                LoadSchemaConfig();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void toolStripMenuItemAlterSchema_Click(object sender, EventArgs e)
        {
            SchemaEditForm dlg = new SchemaEditForm();
            DataBaseSchemaSection schemaSection;
            schemaSection = listBoxSchema.SelectedItem as DataBaseSchemaSection;
            dlg.SchemaName = schemaSection.SchemaName;
            dlg.SchemaVersion = schemaSection.SchemaVersion;
            dlg.SchemaFlag = schemaSection.SchemaFlag;
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    schemaSection.SchemaName = dlg.SchemaName;
                    schemaSection.SchemaVersion = dlg.SchemaVersion;
                    schemaSection.SchemaFlag = dlg.SchemaFlag;
                    LoadSchemaConfig();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
        private void toolStripMenuItemDeleteSchema_Click(object sender, EventArgs e)
        {
            if (currentSchemaSection == null) return;
            DataBaseSchemaSection schemaSection;
            schemaSection = listBoxSchema.SelectedItem as DataBaseSchemaSection;
            DialogResult result;
            result = MessageBox.Show("确定要删除架构吗?", "提示信息", MessageBoxButtons.YesNo);
            if (result == DialogResult.Yes)
            {
                schemaConfig.SchemaCollection.Remove(schemaSection);
                LoadSchemaConfig();
                LoadSchemaSection(null);
            }
            else
            {
                return;
            }
        }
        private void toolStripMenuItemSave_Click(object sender, EventArgs e)
        {
            if (config == null) return;
            config.Save();
        }
       
        private void toolStripMenuItemNew_Click(object sender, EventArgs e)
        {
            if (config != null)
            {
                //if 配置文件修改过了,提示保存
                DialogResult ret = MessageBox.Show("是否保存当前的修改", "警告信息", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
                if (ret == DialogResult.Cancel) return;
                if (ret == DialogResult.Yes)
                {
                    config.Save();
                }
            }
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                currentConfigFile = saveFileDialog1.FileName;
                OpenConfigFile();
            }
        }
        private void toolStripMenuItemDBConnect_Click(object sender, EventArgs e)
        {
        }
        private void toolStripMenuItemImportDbSchema_Click(object sender, EventArgs e)
        {
            if (currentSchemaSection == null) return;
            DataBaseSchemaSection schemaSection = listBoxSchema.SelectedItem as DataBaseSchemaSection;
            if (schemaSection == null) return;
            #region 获取数据库连接
            string connectionString;
            DbInfoForm dlg = new DbInfoForm();
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                connectionString = dlg.ConnectionString;
            }
            else
            {
                return;
            }
            #endregion
            #region 连接数据库并获取数据架构填充或修改当前的数据架构
            SqlConnection connection = new SqlConnection(connectionString);
            try
            {
                connection.Open();
                #region 获得所有的表
                string[] restrictions = new string[4];
                restrictions[3] = "BASE TABLE";
                DataTable table = connection.GetSchema("Tables", restrictions);
                // Display the contents of the table.
                //DisplayData(table,treeViewSchema  );
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    DataRow dr = table.Rows[i];
                    string tblName = dr["table_name"].ToString().Trim().ToUpper();
                    DataBaseTableSection tblSection = null;
                    bool find = false;
                    foreach (DataBaseTableSection tableSection in schemaSection.TableCollection)
                    {
                        if (tableSection.TableName.Equals(tblName, StringComparison.CurrentCultureIgnoreCase))
                        {
                            find = true;
                            tableSection.TableName = tblName;
                            tblSection = tableSection;
                            break;
                        }
                    }
                    if (!find)
                    {
                        tblSection = new DataBaseTableSection();
                        tblSection.TableName = tblName;
                        tblSection.TableDesc = "";
                        schemaSection.TableCollection.Add(tblSection);
                    }
                    #region 获取字段信息
                    SqlCommand cmd = connection.CreateCommand();
                    cmd.CommandText = "select * from " + tblSection.TableName + " where 0 = 1";
                    SqlDataAdapter da = new SqlDataAdapter(cmd);
                    DataTable tblTable = new DataTable();
                    da.FillSchema(tblTable, SchemaType.Source);
                    foreach (DataColumn column in tblTable.Columns)
                    {
                        bool findColumn = false;
                        string columnName = column.ColumnName.Trim().ToUpper();
                        DataBaseColumnSection colSection = null;
                        foreach (DataBaseColumnSection columnSection in tblSection.ColumnCollection)
                        {
                            if (columnSection.ColumnName.Equals(columnName, StringComparison.CurrentCultureIgnoreCase))
                            {
                                find = true;
                                colSection = columnSection;
                                colSection.ColumnName = columnName;
                                break;
                            }
                        }
                        if (!findColumn)
                        {
                            colSection = new DataBaseColumnSection();
                            colSection.ColumnName = columnName;
                            colSection.ColumnDesc = "";
                            tblSection.ColumnCollection.Add(colSection);
                        }
                        colSection.ColumnType = column.DataType;
                        colSection.IsIdentity = column.AutoIncrement;
                    }
                    #endregion
                }
                #endregion
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                connection.Close();
                LoadSchemaSection(schemaSection);
            }
            #endregion
        }
    }
}
 

Linux-DTS基础

设备树资料 QQ交流:EMMC-UFS Community 581375017,欢迎加入!
  • zxj_forever
  • zxj_forever
  • 2016年07月29日 17:25
  • 1524

linux DTS 分析

1、现在实用的内核3.10已经开始实用DTS方法。 2、bootloader启动时将加载dtb给内核,内核分析dtb即可知道machine,所以bootloader 不再需要传递设备ID号。 例如:/...
  • xmzzy2012
  • xmzzy2012
  • 2015年10月30日 18:28
  • 1805

linux DTS gpio example

http://developer.t-firefly.com/thread-648-1-1.html http://v.youku.com/v_show/id_XODY4NTA3OTcy.html?...
  • gaoguoxin2
  • gaoguoxin2
  • 2016年11月20日 10:13
  • 2289

DTS入门知识(转载)

一、dts产生原因..............................................................................................
  • u014717231
  • u014717231
  • 2016年11月12日 13:16
  • 1196

Linux 设备驱动之 DTS 描述的资源

在linux使用platform_driver_register() 注册 platform_driver 时, 需要在 platform_driver 的probe() 里面知道设备的中断号, 内...
  • xy010902100449
  • xy010902100449
  • 2015年07月16日 22:27
  • 3309

mt7620 openwrt编译,修改dts文件

对于 MT7620a 。必须修改dts文件,否则编译出来的固件将无法启动:vi target/linux/ramips/dts/MT7620a.dts把 ethernet@10100000 和 gsw...
  • aa120515692
  • aa120515692
  • 2015年08月18日 11:35
  • 4249

MT通过DTS添加设备

以MT7620a为例阐述dts如何匹配driver openwrtmt7620的SDK默认配置常用的外设都没有被使能,默认编译出来的固件在/dev目录下无法查到如I2C-0\SPI0等节点,还以为ke...
  • sevenjoin
  • sevenjoin
  • 2015年12月05日 11:17
  • 2536

从零开始写设备树DTS

7、从零开始写设备树 设备树就是有一些属性和节点组成的一种数据结构,属性一般会赋予一些属性值,而节点则可能是是由属性跟其下的子节点构成。下面是一个简单的例子: /dts-v1/;  ...
  • woshidahuaidan2011
  • woshidahuaidan2011
  • 2016年10月27日 19:12
  • 4962

AM335X中的DTS简单介绍

Linux内核在2011年后开始转换到DTS配置的方式。详细的device tree source (设备树)相关的文档请参考Documentation/devicetree/bindings相关文档...
  • lichangc
  • lichangc
  • 2016年05月27日 17:02
  • 828

linux dts i2c

1. dts configuration kernel_imx/arch/arm/boot/dts/imx6sl-evk.dts &i2c2{ ... /*luke add for li...
  • gaoguoxin2
  • gaoguoxin2
  • 2016年12月01日 23:07
  • 781
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:DTS
举报原因:
原因补充:

(最多只允许输入30个字)