Beispiel #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;
        }
Beispiel #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);
        }
Beispiel #3
0
        private string GenerateEntitySchema(string name)
        {
            var pattern =
                @"// {EntityName}.cs
//
// Generated by Kuicker.Tools.EntityGenerator.
// {Today}

using System;
using System.ComponentModel;
using System.Runtime.Serialization;
using System.Collections.Generic;
using Kuicker;
using Kuicker.Data;

namespace {Namespace}
{
	public partial class {EntityName} : Entity<{EntityName}>
	{
		public override string __TableName
		{
			get
			{
				return ""{TableName}"";
			}
		}
{Properties}
	}
}";
            var now        = DateTime.Now.yyyy_MM_dd_HH_mm_ss_fff();
            var nameSpace  = txtNamespace.Text;
            var tableName  = name;
            var entityName = tableName
                             .TrimStart(txtTableTrimPrefix.Text);

            entityName = NamingFilter(entityName)
                         .AppendSuffix(txtTableAppendSuffix.Text);
            if (entityName.IsNullOrEmpty())
            {
                entityName = tableName;
            }

            var tableSchema = TableSchemas.FirstOrDefault(x =>
                                                          x.TableName == tableName
                                                          );

            var ef           = EnumCache.Get <DataFormat>();
            var sbProperties = new StringBuilder();

            foreach (var column in tableSchema.Columns)
            {
                var propertyName = column.ColumnName
                                   .TrimStart(txtColumnTrimPrefix.Text);
                propertyName = NamingFilter(propertyName)
                               .AppendSuffix(txtColumnAppendSuffix.Text);
                if (propertyName.IsNullOrEmpty())
                {
                    propertyName = column.ColumnName;
                }

                var columnSchema = tableSchema.Columns.FirstOrDefault(x =>
                                                                      x.ColumnName == column.ColumnName
                                                                      );
                if (columnSchema == null)
                {
                    continue;
                }

                if (sbProperties.Length > 0)
                {
                    sbProperties.AppendLine();
                }

                sbProperties.AppendFormat(@"
		/// <summary>
		/// {0}
		/// </summary>
		[Description(""{0}"")]
		[DataMember, Column(""{1}""){2}{3}]
		public {4} {5} {{ get; set; }}"        ,
                                          column.Comments.AirBag(column.ColumnName),
                                          column.ColumnName,
                                          tableSchema
                                          .IsPrimaryKey(column.ColumnName)
                                          .If(", PrimaryKey"),
                                          column
                                          .Nullable
                                          .If(", AllowDBNull"),
                                          columnSchema.ToTypeName(Formater),
                                          propertyName
                                          );
            }

            var sb = new StringBuilder();

            sb.Append(pattern);
            sb
            .Replace(
                "{Comments}",
                tableSchema.Comments.AirBag(tableSchema.TableName)
                )
            .Replace("{Today}", now)
            .Replace("{Namespace}", nameSpace)
            .Replace("{EntityName}", entityName)
            .Replace("{TableName}", tableName)
            .Replace("{Properties}", sbProperties.ToString());

            return(sb.ToString());
        }
Beispiel #4
0
        private string GenerateEntityImplement(string name)
        {
            var pattern =
                @"// {EntityName}.cs
//
// Generated by Kuicker.Tools.EntityGenerator.
// {Today}

using System;
using System.ComponentModel;
using System.Runtime.Serialization;
using System.Collections.Generic;
using Kuicker;
using Kuicker.Data;

namespace {Namespace}
{
	/// <summary>
	/// {Comments}
	/// </summary>
	[Description(""{Comments}"")]
	[DataContract, Table]
	public partial class {EntityName} : Entity<{EntityName}>
	{
		#region constructor
		public {EntityName}()
			: base()
		{
		}
		#endregion

		#region IEntity
		#endregion

		#region static
		#endregion

		#region instance
		#endregion

		#region private
		#endregion

		#region event handler
		#endregion
	}
}";
            var now        = DateTime.Now.yyyy_MM_dd_HH_mm_ss_fff();
            var nameSpace  = txtNamespace.Text;
            var tableName  = name;
            var entityName = tableName
                             .TrimStart(txtTableTrimPrefix.Text);

            entityName = NamingFilter(entityName)
                         .AppendSuffix(txtTableAppendSuffix.Text);
            if (entityName.IsNullOrEmpty())
            {
                entityName = tableName;
            }

            var tableSchema = TableSchemas.FirstOrDefault(x =>
                                                          x.TableName == tableName
                                                          );

            var sb = new StringBuilder();

            sb.Append(pattern);
            sb
            .Replace(
                "{Comments}",
                tableSchema.Comments.AirBag(tableSchema.TableName)
                )
            .Replace("{Today}", now)
            .Replace("{Namespace}", nameSpace)
            .Replace("{EntityName}", entityName)
            .Replace("{TableName}", tableName);

            return(sb.ToString());
        }
Beispiel #5
0
        private void lbxTables_SelectedIndexChanged(
            object sender, EventArgs e)
        {
            ListBox lbx = sender as ListBox;

            if (null == lbx)
            {
                return;
            }

            clbColumns.Items.Clear();
            txtCode.Text = string.Empty;
            string name = lbx.SelectedItem.ToString();

            if (name.IsNullOrEmpty())
            {
                return;
            }

            var obj = TableSchemas.FirstOrDefault(x =>
                                                  x.TableName == name
                                                  );

            if (null == obj)
            {
                return;
            }
            string columnPrefix     = string.Empty;
            bool   columnPrefixDone = false;

            foreach (var column in obj.Columns)
            {
                clbColumns.Items.Add(column.ColumnName, true);

                if (!columnPrefixDone)
                {
                    string[] parts = column.ColumnName.Split('_');
                    if (columnPrefix.IsNullOrEmpty())
                    {
                        if (parts.Length > 1)
                        {
                            columnPrefix = parts[0];
                        }
                        else
                        {
                            columnPrefixDone = true;
                        }
                    }
                    else
                    {
                        if (columnPrefix != parts[0])
                        {
                            columnPrefix = string.Empty;
                        }
                        else
                        {
                            columnPrefix += "_";
                        }
                        columnPrefixDone = true;
                    }
                }
            }

            RefreshTable(name);
        }
        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);
                }
            }
        }