Exemplo n.º 1
0
        /// <summary>
        /// Refreshes the design.
        /// </summary>
        public void RefreshSchemaModel()
        {
            if (DataSource == null)
            {
                return;
            }

            var macros = TableSchemas.SelectMany(s => s.Fields).
                         Where(w => string.IsNullOrEmpty(w.ValidationMacros) == false);

            var custom = TableSchemas.Where(w => w.TableName != null && w.IsCustom);

            var schema = DataSource.GetSchemaModel();

            schema.AddRange(custom);

            foreach (var macro in macros)
            {
                var item = schema.Where(w => w.TableName == macro.TableName).SingleOrDefault().
                           Fields.Where(w => w.Name == macro.Name).SingleOrDefault();

                if (item != null)
                {
                    item.ValidationMacros = macro.ValidationMacros;
                }
            }
            schema.Add(new TableSchemaModel(ADD_NEW_SCHEMA));
            TableSchemas = schema;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Selecteds the schema.
        /// </summary>
        /// <returns>TableSchemaModel.</returns>
        public TableSchemaModel SelectedSchema()
        {
            var schema = TableSchemas.Where(w => w.TableName == SelectedTable).FirstOrDefault();

            string error = string.Format("The selected Schema {0} was not found in the data source {1}",
                                         this.SelectedTable, this.DataSource.GetConnectionStringBuilder()["Data source"]);

            if (schema == null)
            {
                throw new Exception(error);
            }
            return(schema);
        }
Exemplo n.º 3
0
        public IEnumerable <ColumnSchema> GetColumnSchemas(string tableName)
        {
            if (string.IsNullOrWhiteSpace(tableName))
            {
                return(null);
            }

            List <ColumnSchema> columnSchemas = new List <ColumnSchema>();

            if (tableName.EndsWith("mod"))
            {
                IEnumerable <ColumnSchema> columns = JsonConvert.DeserializeObject <IEnumerable <ColumnSchema> >(CensusHeaderJson);
                columnSchemas.AddRange(columns);
            }

            string command = $"SELECT TOP 1 * FROM [{tableName}] A";

            using (OleDbConnection conn = Connection)
            {
                using (OleDbCommand cmd = new OleDbCommand(command, conn))
                {
                    conn.Open();
                    OleDbDataReader reader = cmd.ExecuteReader();
                    DataTable       schema = reader?.GetSchemaTable();

                    if (schema == null)
                    {
                        conn.Close();
                        return(null);
                    }

                    columnSchemas.AddRange(from DataRow row in schema.Rows select new ColumnSchema(row));

                    if (tableName.EndsWith("PT1") ||
                        tableName.EndsWith("PART1") ||
                        tableName.EndsWith("Part1"))
                    {
                        for (int i = 2; i <= TableSchemas.Count(); i++)
                        {
                            string tblName = tableName.Replace("PT1", $"PT{i}")
                                             .Replace("PART1", $"PART{i}")
                                             .Replace("Part1", $"Part{i}");

                            foreach (TableSchema table in TableSchemas.Where(w => w.Name.EndsWith(tblName)))
                            {
                                IEnumerable <ColumnSchema> columns = GetColumnSchemas(table.Name);
                                columns = columns.Skip(5);
                                columnSchemas.AddRange(columns);
                                SkipList.Add(table.Name);
                            }
                        }
                    }

                    conn.Close();

                    for (int i = 0; i < columnSchemas.Count; i++)
                    {
                        columnSchemas[i].Index = i;

                        switch (columnSchemas[i].Name)
                        {
                        case "P024006":
                            columnSchemas[i].Name = "P0240006";
                            break;

                        case "SDELEM":
                            columnSchemas[i].Name = "SDELM";
                            break;

                        default:
                            columnSchemas[i].Name = columnSchemas[i].Name.Trim();
                            break;
                        }

                        //   string[] skipFields = { "DESC", "DECIMAL", "FIELD", "ID", "ITEM", "ITERATIONS", "LEN", "NOTE", "SEGMENT", "SORT_ID", "STUB", "TABLE" };

                        //   if (columnSchemas[i].Descriptor == null
                        //&& columnSchemas[i].GeoDescriptor == null
                        //&& !columnSchemas[i].Name.Contains(" ")
                        //&& !skipFields.Contains(columnSchemas[i].Name.ToUpperInvariant()))
                        //   {
                        //       Console.WriteLine($"Column missing Descriptors: {columnSchemas[i]}");
                        //   }
                    }

                    return(columnSchemas);
                }
            }
        }