Example #1
0
        private void CreateDefaultSchema()
        {
            _schema = new DbcSchema();
            for (int i = 0; i < _table.ColumnCount; i++)
            {
                var col = new DbcColumnSchema()
                {
                    Name = "Column" + i,
                    Position = i,
                    Type = ColumnType.Int32,
                    Width = 100,
                };
                _schema.AddColumn(col);
            }

            BindSchema();
        }
Example #2
0
        private void CreateDefaultSchema()
        {
            _schema = new DbcSchema();
            for (int i = 0; i < _table.ColumnCount; i++)
            {
                var col = new DbcColumnSchema()
                {
                    Name     = "Column" + i,
                    Position = i,
                    Type     = ColumnType.Int32,
                    Width    = 100,
                };
                _schema.AddColumn(col);
            }

            BindSchema();
        }
Example #3
0
        public static DbcSchema Load(Stream source, int specifiedColumns)
        {
            XDocument doc    = XDocument.Load(source);
            DbcSchema result = new DbcSchema();

            foreach (var e in doc.Root.Elements("Column"))
            {
                string     name  = e.Attribute("Name").Value;
                int        pos   = int.Parse(e.Attribute("Position").Value);
                ColumnType type  = (ColumnType)Enum.Parse(typeof(ColumnType), e.Attribute("Type").Value, true);
                int        width = int.Parse(e.Attribute("Width").Value);

                var col = new DbcColumnSchema()
                {
                    Position = pos,
                    Name     = name,
                    Type     = type,
                    Width    = width,
                };
                result.AddColumn(col);
            }

            while (result.ColumnCount > specifiedColumns)
            {
                result._columns.RemoveAt(result.ColumnCount - 1);
            }

            while (result._columns.Count < specifiedColumns)
            {
                var col = new DbcColumnSchema()
                {
                    Position = result.ColumnCount,
                    Name     = "Column" + result.ColumnCount,
                    Type     = ColumnType.Int32,
                    Width    = 100,
                };
                result.AddColumn(col);
            }

            return(result);
        }
Example #4
0
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (ofdOpenDbc.ShowDialog() == DialogResult.OK)
            {
                if (_table != null)
                {
                    dgv.Rows.Clear();
                    dgv.Columns.Clear();

                    _table.Dispose();
                    _table = null;
                }

                FileStream fs = File.OpenRead(ofdOpenDbc.FileName);
                _table       = new DbcTable(fs, true);
                _dbcFileName = Path.GetFileName(ofdOpenDbc.FileName);
                _dbcFilePath = Path.GetDirectoryName(ofdOpenDbc.FileName);

                var testSchema = Path.Combine(_dbcFilePath, _dbcFileName + "schema");
                if (File.Exists(testSchema))
                {
                    using (var file = File.OpenRead(testSchema))
                    {
                        _schema         = DbcSchema.Load(file, _table.ColumnCount);
                        _schemaFileName = testSchema;
                    }

                    BindSchema();
                }
                else
                {
                    CreateDefaultSchema();
                    _schemaFileName = null;
                }
                PopulateDbc();
            }
        }
Example #5
0
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (ofdOpenDbc.ShowDialog() == DialogResult.OK)
            {
                if (_table != null)
                {
                    dgv.Rows.Clear();
                    dgv.Columns.Clear();

                    _table.Dispose();
                    _table = null;
                }

                FileStream fs = File.OpenRead(ofdOpenDbc.FileName);
                _table = new DbcTable(fs, true);
                _dbcFileName = Path.GetFileName(ofdOpenDbc.FileName);
                _dbcFilePath = Path.GetDirectoryName(ofdOpenDbc.FileName);

                var testSchema = Path.Combine(_dbcFilePath, _dbcFileName + "schema");
                if (File.Exists(testSchema))
                {
                    using (var file = File.OpenRead(testSchema))
                    {
                        _schema = DbcSchema.Load(file, _table.ColumnCount);
                        _schemaFileName = testSchema;
                    }

                    BindSchema();
                }
                else
                {
                    CreateDefaultSchema();
                    _schemaFileName = null;
                }
                PopulateDbc();
            }
        }
Example #6
0
        public static DbcSchema Load(Stream source, int specifiedColumns)
        {
            XDocument doc = XDocument.Load(source);
            DbcSchema result = new DbcSchema();

            foreach (var e in doc.Root.Elements("Column"))
            {
                string name = e.Attribute("Name").Value;
                int pos = int.Parse(e.Attribute("Position").Value);
                ColumnType type = (ColumnType)Enum.Parse(typeof(ColumnType), e.Attribute("Type").Value, true);
                int width = int.Parse(e.Attribute("Width").Value);

                var col = new DbcColumnSchema()
                {
                    Position = pos,
                    Name = name,
                    Type = type,
                    Width = width,
                };
                result.AddColumn(col);
            }

            while (result.ColumnCount > specifiedColumns)
                result._columns.RemoveAt(result.ColumnCount - 1);

            while (result._columns.Count < specifiedColumns)
            {
                var col = new DbcColumnSchema()
                {
                    Position = result.ColumnCount,
                    Name = "Column" + result.ColumnCount,
                    Type = ColumnType.Int32,
                    Width = 100,
                };
                result.AddColumn(col);
            }

            return result;
        }