Exemple #1
0
        public void WriteContract(DataBaseTable item)
        {
            var path = Path.Combine(Config.CSharp.Repository.Contract.Path, item.Schema);
            var file = $"I{item.Name}Business.cs";

            var nameSpace = new List <string> {
                "System", "XCommon.Patterns.Repository"
            };

            nameSpace.Add($"{Config.CSharp.Entity.NameSpace}.{item.Schema}");
            nameSpace.Add($"{Config.CSharp.Entity.NameSpace}.{item.Schema}.Filter");

            var builder     = new StringBuilderIndented();
            var parentClass = $"IRepositoryEF<{item.Name}Entity, {item.Name}Filter>";
            var appClass    = Config.CSharp.ApplicationClasses.FirstOrDefault(c => c.Name == item.Name && c.Schema == item.Schema);

            if (Config.CSharp.UsingApplicationBase && appClass != null)
            {
                parentClass = $"{appClass.NamespaceContract}.I{item.Name}Business";
                nameSpace   = new List <string>();
            }

            builder
            .InterfaceInit($"I{item.Name}Business", parentClass, $"{Config.CSharp.Repository.Contract.NameSpace}.{item.Schema}", ClassVisibility.Public, nameSpace.ToArray())
            .InterfaceEnd();

            Writer.WriteFile(path, file, builder, false);
        }
Exemple #2
0
        public void WriteConcrete(DataBaseTable item)
        {
            var path = Path.Combine(Config.CSharp.Repository.Concrecte.Path, item.Schema);
            var file = $"{item.Name}Business.cs";

            var parentClass = $"RepositoryEFBase<{item.Name}Entity, {item.Name}Filter, {item.Name}, {Config.CSharp.EntityFramework.ContextName}>";
            var nameSpace   = new List <string> {
                "System", " XCommon.Patterns.Repository"
            };

            nameSpace.Add($"{Config.CSharp.Entity.NameSpace}.{item.Schema}");
            nameSpace.Add($"{Config.CSharp.Entity.NameSpace}.{item.Schema}.Filter");
            nameSpace.Add($"{Config.CSharp.EntityFramework.NameSpace}");
            nameSpace.Add($"{Config.CSharp.EntityFramework.NameSpace}.{item.Schema}");

            if (Config.CSharp.Repository.Contract != null && Config.CSharp.Repository.Contract.Execute)
            {
                nameSpace.Add($"{Config.CSharp.Repository.Contract.NameSpace}.{item.Schema}");
                parentClass = $"RepositoryEFBase<{item.Name}Entity, {item.Name}Filter, {item.Name}, {Config.CSharp.EntityFramework.ContextName}>, I{item.Name}Business";
            }

            var builder = new StringBuilderIndented();

            builder
            .ClassInit($"{item.Name}Business", parentClass, $"{Config.CSharp.Repository.Concrecte.NameSpace}.{item.Schema}", ClassVisility.Public, nameSpace.ToArray())
            .ClassEnd();

            Writer.WriteFile(path, file, builder, false);
        }
Exemple #3
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="dev"></param>
    /// <param name="devtbname"></param>
    /// <param name="tbname"></param>
    /// <returns></returns>
    private DataBaseTable GetAddTable(string dev, string devtbname, ref string tbname)
    {
        DataBaseTable addTB = null;
        DataBase      devDB = DataBase.Factory(BillBase.GetConnByDevKey(dev));

        if (devDB.DataTables.Contains(devtbname))
        {
            addTB = new DataBaseTable(tbname, devDB.DataTables[devtbname]);
        }
        else
        {
            return(null);
        }
        if (DataBase.Factory(conn).DataTables.Contains(tbname))
        {
            DataBaseTable tbOld = DataBase.Factory(conn).DataTables[tbname];
            if (addTB != null && tbOld.CheckChange(addTB))
            {
                return(null);
            }
            else
            {
                tbname += "_1";
                int tbncount = 1;
                while (DataBase.Factory(conn).DataTables.Contains(tbname))
                {
                    tbncount++;
                    tbname = tbname.Remove(tbname.Length - 2) + "_" + tbncount;
                }
                addTB = new DataBaseTable(tbname, devDB.DataTables[devtbname]);
            }
        }
        return(addTB);
    }
Exemple #4
0
        public int DelField(string fieldid, ref string errMsg)
        {
            try
            {
                TF_TB_FIELD field = BLLTable <TF_TB_FIELD> .Factory(conn).GetRowData(TF_TB_FIELD.Attribute.FIELD_ID, fieldid);

                string tbname = BLLTable <TF_TABLE> .Factory(conn).GetOneValue(TF_TABLE.Attribute.TB_ID, field.TB_ID, TF_TABLE.Attribute.TB_NAME);

                string        msg = null;
                DataBaseField f1  = null;
                DataBaseTable t1  = null;
                if (DataBase.Factory(conn).TryGetValue(tbname, field.FIELD_NAME, out t1, out f1))
                {
                    if (!t1.DeleteField(field.FIELD_NAME, false, ref msg))
                    {
                        errMsg += msg; return(0);
                    }
                }
                return(1);
            }
            catch (Exception ex)
            {
                errMsg = ex.ToString();
                return(-1);
            }
        }
Exemple #5
0
        public void WriteValidation(DataBaseTable item)
        {
            var path = Path.Combine(Config.CSharp.Repository.Concrecte.Path, item.Schema, "Validate");
            var file = $"{item.Name}Validate.cs";


            var nameSpace = new List <string> {
                "System", "XCommon.Application.Executes", "XCommon.Patterns.Specification.Validation", "XCommon.Patterns.Specification.Validation.Extensions"
            };

            nameSpace.Add($"{Config.CSharp.Entity.NameSpace}.{item.Schema}");

            var builder = new StringBuilderIndented();

            builder
            .ClassInit($"{item.Name}Validate", $"SpecificationValidation<{item.Name}Entity>", $"{Config.CSharp.Repository.Concrecte.NameSpace}.{item.Schema}.Validate", ClassVisility.Public, nameSpace.ToArray())
            .AppendLine($"public override bool IsSatisfiedBy({item.Name}Entity entity, Execute execute)")
            .AppendLine("{")
            .IncrementIndent()
            .AppendLine("var spefications = NewSpecificationList()")
            .IncrementIndent()
            .AppendLine(".AndIsValid(e => e.Key != Guid.Empty, \"Default key isn't valid\");")
            .DecrementIndent()
            .AppendLine()
            .AppendLine("return CheckSpecifications(spefications, entity, execute);")
            .DecrementIndent()
            .AppendLine("}")
            .InterfaceEnd();

            Writer.WriteFile(path, file, builder, false);
        }
Exemple #6
0
        private void WriteDataSource(DataBaseTable item)
        {
            var path = Path.Combine(Config.CSharp.UnitTest.Path, "DataSource", item.Schema);
            var file = $"{item.Name}DataSource.cs";

            var nameSpace = new List <string> {
                "System", "System.Collections.Generic", "XCommon.Extensions.Converters", "XCommon.Util"
            };

            nameSpace.Add($"{Config.CSharp.Entity.NameSpace}.{item.Schema}");
            nameSpace.Add($"{Config.CSharp.Entity.NameSpace}.{item.Schema}.Filter");

            var builder = new StringBuilderIndented();

            builder
            .ClassInit($"{item.Name}DataSource", string.Empty, $"{Config.CSharp.UnitTest.NameSpace}.{item.Schema}", ClassVisibility.PublicStatic, nameSpace.ToArray());

            builder
            .AppendLine($"public static IEnumerable<object[]> {item.Name}EntityDataSource")
            .AppendLine("{")
            .IncrementIndent()
            .AppendLine("get")
            .AppendLine("{")
            .IncrementIndent()
            .AppendLine($"var result = new PairList<Pair<{item.Name}Entity>, bool, string>();");

            builder
            .ClassEnd();

            Writer.WriteFile(path, file, builder, false);
        }
Exemple #7
0
        private List <DataBaseRelationShip> ReadSqlRelationships(SqlConnection cnx, DataBaseTable table)
        {
            var result = new List <DataBaseRelationShip>();

            using (var cmd = new SqlCommand(QuerySqlRelationship(table), cnx))
            {
                using (var reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        var relationShip = new DataBaseRelationShip
                        {
                            SchemaPK = reader["SchemaPK"].ToString(),
                            TablePK  = reader["TablePK"].ToString(),
                            ColumnPK = reader["ColumnPK"].ToString(),

                            SchemaFK = reader["SchemaFK"].ToString(),
                            TableFK  = reader["TableFK"].ToString(),
                            ColumnFK = reader["ColumnFK"].ToString(),

                            Type     = reader["Type"].ToString() == "M" ? DataBaseRelationShipType.Many : DataBaseRelationShipType.Single,
                            Nullable = reader["Nullable"].ToString() == "1"
                        };

                        result.Add(relationShip);
                    }
                }
            }

            return(result);
        }
Exemple #8
0
    protected string GetShowTableInfo(DataBaseTable table)
    {
        if (table == null)
        {
            return("");
        }
        StringBuilder sb      = new StringBuilder();
        string        tabName = table.TableName + (string.IsNullOrEmpty(table.Desc.ZhName) ? "" : ("(" + table.Desc.ZhName + ")"));

        sb.Append("<div class=\"grp dbtable\"><input id=\"" + ("_" + table.TableName) + "\" onclick=\"tabselallfield(this);\" type=\"checkbox\" value=\"" + table.TableName + "\" title=\"" + tabName + "\" /><label for=\"" + ("_" + table.TableName) + "\" title=\"" + tabName + "\">" + stringFormat(tabName, 30) + "</label><a>展开</a></div>");
        sb.Append("<div style=\"display:none;\">");
        foreach (DataBaseField field in table.DataFields)
        {
            sb.Append("<dl class='fieldcheckboxdl" + (field.IsKeyID ? " keyfield" : "") + "'>");
            sb.Append("<dd>");
            sb.Append("<span>");
            string fidName = GetShowFieldName(field);
            sb.Append("<input id=\"" + (table.TableName + "_" + field.FieldName) + "\" onclick=\"selfield(this);\"  type=\"checkbox\" value=\"" + (table.TableName + "." + field.FieldName) + "\" title=\"" + fidName + "\" /><label for=\"" + (table.TableName + "_" + field.FieldName) + "\" title=\"" + fidName + "\">" + stringFormat(fidName, 40) + "</label>");
            sb.Append("</span>");
            sb.Append("</dd>");
            sb.Append("</dl>");
        }
        sb.Append("</div>");
        return(sb.ToString());
    }
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         if (Request["DEV"] != null)
         {
             body1.Visible = false;
             string   conStr = BillBase.GetConnByDevKey(Request["DEV"]);
             DataBase db     = new DataBase(DataBaseConnectStringHelper.GetDataBaseType(conStr, ""), conStr);
             string   tbname = Request["TB"];
             if (db.DataTables.Contains(tbname))
             {
                 DataBaseTable           tb = db.DataTables[tbname];
                 DataBaseFieldCollection fc = tb.DataFields;
                 if (fc != null)
                 {
                     repCus.DataSource = fc;
                     repCus.DataBind();
                 }
             }
         }
         else
         {
         }
     }
 }
Exemple #10
0
    /// <summary>
    /// 获取list页的数据源
    /// 支持主模块的链接
    /// 支持枚举量
    /// 支持时间格式
    /// </summary>
    /// <param name="f1"></param>
    /// <returns></returns>
    public string GetHtmlList(DataBaseField f1, ITableImplement this1)
    {
        if (!f1.Desc.af_Enable)
        {
            return("");                       //是否可用
        }
        if (!f1.Desc.af_Visable)
        {
            return("");                        //是否可见
        }
        string        html      = "";
        string        tableName = f1.TableName;
        AttributeItem attr1     = AttributeItem.Factory(f1);
        object        value1    = (this1.GetValue(attr1));
        DataBaseTable dt1       = f1.DataBaseTable; //DataBaseField f1;

        try
        {
            DataBaseField id1   = dt1.IDField;
            DataBaseField name1 = dt1.NameField;

            if (f1 == dt1.IDField)
            {
                //html = "<a href='index.aspx?id=" + this1.GetValue(dt1.FieldID.FieldName) + "'>" + html + "</a>";
            }
            else if (f1 == dt1.NameField)    // != null && dt1.NameField.FieldName == f1.FieldName)//本模块name详细链接
            {
                string showUrl = "../" + dt1.TableName + "/show.aspx";
                if (!Exist(showUrl))
                {
                    showUrl = "show.aspx";
                }
                html = "<a href='" + showUrl + "?id=" + this1.GetValue(id1) + "&moduleName=" + tableName
                       + "' target='_blank'>" + value1 + "</a>";
            }
            else if (isSelect(f1))    //枚举量
            {
                html = BaseFormHelper.Factory(this1.ConnectKey).GetOptionText(attr1, value1);
            }
            else if (isChaZhao(f1))    //父表
            {
                DataBaseField f2    = f1.DataBaseTable.FatherTable_ChaZhao[0].DataBaseTable.NameField;
                AttributeItem attr2 = AttributeItem.Factory(f2);
                html = Convert.ToString(this1.GetValue(attr2));
            }
            else if (f1.Desc.Switch_CtrlType == BaseCtrlType.FileUpImage)
            {
                html = "<img src ='" + value1 + "' style='height:40px' />";
            }
        }
        catch (Exception ex)
        {
            Cs.Error(ex.ToString());
        }
        if (html == "")
        {
            html = Convert.ToString(value1);
        }
        return(html);
    }
        public void WriteFilter(DataBaseTable item)
        {
            var path = Path.Combine(Config.CSharp.Entity.Path, item.Schema, "Filter");
            var file = $"{item.Name}Filter.cs";

            var nameSpace = new List <string> {
                "System", "XCommon.Patterns.Repository.Entity"
            };
            var builder = new StringBuilderIndented();

            var baseClass = "FilterBase";
            var appClass  = Config.CSharp.ApplicationClasses.FirstOrDefault(c => c.Name == item.Name && c.Schema == item.Schema);

            if (Config.CSharp.UsingApplicationBase && appClass != null)
            {
                nameSpace = new List <string>();
                baseClass = $"{appClass.NamespaceFilter}.{item.Name}Filter";
            }

            builder
            .ClassInit($"{item.Name}Filter", baseClass, $"{Config.CSharp.Entity.NameSpace}.{item.Schema}.Filter", ClassVisibility.Public, nameSpace.ToArray())
            .ClassEnd();

            Writer.WriteFile(path, file, builder, false);
        }
Exemple #12
0
        public static List <string> ProcessRemapSchema(this DataBaseTable item, GeneratorConfig config, bool isEF)
        {
            var result = new List <string>();

            if (config.CSharp.EntityFramework.Remap == null)
            {
                return(result);
            }

            var remap = config.CSharp.EntityFramework.Remap.Where(
                c => c.Schema == item.Schema &&
                c.Table == item.Name
                );

            if (remap != null)
            {
                result.AddRange(remap.Select(c => c.NameSpace));
            }

            var applicationClass = config.CSharp.ApplicationClasses.Where(c => item.RelationShips.Any(x => x.SchemaPK == c.Schema && x.TablePK == c.Name));

            if (config.CSharp.UsingApplicationBase && applicationClass != null)
            {
                if (isEF)
                {
                    result.AddRange(applicationClass.Select(c => c.NamespaceContext));
                }
                else
                {
                    result.AddRange(applicationClass.Select(c => c.NamespaceEntity));
                }
            }

            return(result);
        }
Exemple #13
0
        private void filteringFormSubmittedAction()
        {
            DataBaseTable dbTable   = new DataBaseTable();
            string        tableName = Request.Form["tableName"];

            dbTable.setTableName(tableName);

            string[]        names      = dbTable.getColumnNames();
            string[]        dataTypes  = new string[names.Length];
            List <string[]> conditions = new List <string[]>(); //list of array of where conditions for filtering

            for (int i = 0; i < names.Length; i++)              //get dataType for each field
            {
                dataTypes[i] = Request.Form[names[i] + "_dataType"];
            }
            //check if the user had manually changed the datatypes of the menu
            bool flag = DatabaseAccessLayer.areDataTypesMatched(tableName, dataTypes);

            if (flag)//ie datatypes are same in database and form submitted
            {
                for (int i = 0; i < names.Length; i++)
                {
                    conditions.Add(createCondition3(names[i], dataTypes[i]));
                }
                Literal1.Text = DatabaseAccessLayer.getFilteringForm(tableName);                 //display filtering form
                Literal2.Text = DatabaseAccessLayer.getFilteredTableData(conditions, tableName); //data
            }
            else
            {
                DatabaseAccessLayer.updateTableDataTypes(tableName, names, dataTypes);
                Literal1.Text = DatabaseAccessLayer.getFilteringForm(tableName);
                Literal2.Text = DatabaseAccessLayer.getTableDataWhole(tableName);
            }
        }
        public void WriteEntity(DataBaseTable item)
        {
            var path = Path.Combine(Config.CSharp.EntityFramework.Path, item.Schema);
            var file = $"{item.Name}.cs";

            var nameSpace = new List <string> {
                "System", "System.Collections.Generic"
            };

            nameSpace.AddRange(item.RelationShips.Where(c => c.TableFK != item.Schema).Select(c => $"{Config.CSharp.EntityFramework.NameSpace}.{c.SchemaFK}").Distinct());
            nameSpace.AddRange(item.RelationShips.Where(c => c.TablePK != item.Schema).Select(c => $"{Config.CSharp.EntityFramework.NameSpace}.{c.SchemaPK}").Distinct());
            nameSpace.AddRange(item.Columns.Where(c => c.Schema != item.Schema).Select(c => c.Schema));
            nameSpace.AddRange(item.ProcessRemapSchema(Config));


            var itemNameSpace = $"{Config.CSharp.EntityFramework.NameSpace}.{item.Schema}";

            nameSpace.RemoveAll(c => c == itemNameSpace);

            var builder = new StringBuilderIndented();

            builder
            .GenerateFileMessage()
            .ClassInit(item.Name, null, itemNameSpace, ClassVisility.Public, nameSpace.ToArray());

            foreach (var property in item.Columns)
            {
                var propertyType = property.ProcessRemapProperty(Config);

                builder
                .AppendLine($"public {propertyType} {property.Name} {{ get; set; }}")
                .AppendLine();
            }

            foreach (var relationShip in item.RelationShips.Where(c => c.Type == DataBaseRelationShipType.Single))
            {
                var relationShipName = ProcessRelationShipName(relationShip, relationShip.TablePK);

                builder
                .AppendLine($"public virtual {relationShip.TablePK} {relationShipName} {{ get; set; }}")
                .AppendLine();
            }

            foreach (var relationShip in item.RelationShips.Where(c => c.Type == DataBaseRelationShipType.Many))
            {
                var relationShipName = ProcessRelationShipName(relationShip, relationShip.TableFK);

                builder
                .AppendLine($"public virtual ICollection<{relationShip.TableFK}> {relationShipName} {{ get; set; }}")
                .AppendLine();
            }

            builder
            .ClassEnd();

            Writer.WriteFile(path, file, builder, true);
        }
Exemple #15
0
        public void WriteQuery(DataBaseTable item)
        {
            var path = Path.Combine(Config.CSharp.Repository.Concrecte.Path, item.Schema, "Query");
            var file = $"{item.Name}Query.cs";

            var nameSpace = new List <string> {
                "System", "System.Linq", "System.Collections.Generic", "XCommon.Patterns.Specification.Query", "XCommon.Patterns.Specification.Query.Extensions", "XCommon.Extensions.String", "XCommon.Extensions.Checks"
            };

            if (Config.CSharp.EntityFramework != null)
            {
                nameSpace.Add($"{Config.CSharp.EntityFramework.NameSpace}.{item.Schema}");
            }

            nameSpace.Add($"{Config.CSharp.Entity.NameSpace}.{item.Schema}.Filter");

            var builder = new StringBuilderIndented();

            var columnOrder = item.Columns.Any(c => c.Name == "Name")
                                ? "Name"
                                : item.PKName;

            var parentClass = $"SpecificationQuery<{item.Name}, {item.Name}Filter>";
            var appClass    = Config.CSharp.ApplicationClasses.FirstOrDefault(c => c.Name == item.Name && c.Schema == item.Schema);

            if (Config.CSharp.UsingApplicationBase && appClass != null)
            {
                parentClass = $"{appClass.NamespaceQuery}.{item.Name}Query";
                nameSpace   = new List <string>();
                builder
                .ClassInit($"{item.Name}Query", parentClass, $"{Config.CSharp.Repository.Concrecte.NameSpace}.{item.Schema}.Query", ClassVisibility.Public, nameSpace.ToArray())
                .ClassEnd();
            }
            else
            {
                builder
                .ClassInit($"{item.Name}Query", parentClass, $"{Config.CSharp.Repository.Concrecte.NameSpace}.{item.Schema}.Query", ClassVisibility.Public, nameSpace.ToArray())
                .AppendLine($"public override IQueryable<{item.Name}> Build(IQueryable<{item.Name}> source, {item.Name}Filter filter)")
                .AppendLine("{")
                .IncrementIndent()
                .AppendLine($"var spefications = NewSpecificationList()")
                .IncrementIndent()
                .AppendLine($".And(e => e.{item.PKName} == filter.Key, f => f.Key.HasValue)")
                .AppendLine($".And(e => filter.Keys.Contains(e.{item.PKName}), f => f.Keys.IsValidList())")
                .AppendLine($".OrderBy(e => e.{columnOrder})")
                .AppendLine(".Take(filter.PageNumber, filter.PageSize);")
                .DecrementIndent()
                .AppendLine()
                .AppendLine("return CheckSpecifications(spefications, source, filter);")
                .DecrementIndent()
                .AppendLine("}")
                .ClassEnd();
            }

            Writer.WriteFile(path, file, builder, false);
        }
        private void lstVwDatabaseTables_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (aDataObject != null && lstVwDatabaseTables.SelectedIndices.Count > 0)
            {
                DataBaseTable testing = new DataBaseTable(aDataObject, lstVwDatabaseTables.SelectedItems[0].Text);

                testing.TransType(true);
                dgTableView.DataSource = testing.Columns;
            }
        }
Exemple #17
0
        private IReadOnlyList <DataBaseSchema> BuildResult(SqlConnection cnx, List <DataBaseObject> dataBaseObjects)
        {
            var result = new List <DataBaseSchema>();

            // Read Schema
            foreach (var schema in dataBaseObjects.Select(c => c.Schema).Distinct())
            {
                var dbSchema = new DataBaseSchema(schema);

                // Read Table
                foreach (var table in dataBaseObjects.Where(c => c.Schema == schema).Select(c => c.TableName).Distinct())
                {
                    var dbTable = new DataBaseTable(dbSchema, table);

                    // Read Columns
                    foreach (var column in dataBaseObjects.Where(c => c.Schema == schema && c.TableName == table))
                    {
                        dbTable.Columns.Add(new DataBaseColumn(dbSchema, dbTable, column.ColumnName)
                        {
                            ColumnComputed = column.ColumnComputed,
                            Description    = column.Description,
                            Nullable       = column.Nullable,
                            PK             = column.PK,
                            Size           = column.Size,
                            Type           = column.Type,
                            TypeSql        = column.TypeSql
                        });
                    }

                    // Read Relationships
                    foreach (var relationship in ReadSqlRelationships(cnx, dbTable))
                    {
                        dbTable.RelationShips.Add(new DataBaseRelationShip
                        {
                            ColumnFK = relationship.ColumnFK,
                            ColumnPK = relationship.ColumnPK,
                            Nullable = relationship.Nullable,
                            SchemaFK = relationship.SchemaFK,
                            SchemaPK = relationship.SchemaPK,
                            TableFK  = relationship.TableFK,
                            TablePK  = relationship.TablePK,
                            Type     = relationship.Type
                        });
                    }

                    dbSchema.Tables.Add(dbTable);
                }

                result.Add(dbSchema);
            }

            return(result.AsReadOnly());
        }
Exemple #18
0
        /// <summary>
        /// 从取值对象中获得属性,从条件对象中获得值
        /// </summary>
        /// <param name="valObj"></param>
        /// <param name="condObj"></param>
        /// <returns></returns>
        public List <DataBaseField> Parse(ITableImplement valObj, ITableImplement condObj)
        {
            List <DataBaseField> list2 = new List <DataBaseField>();
            List <AttributeItem> list  = new List <AttributeItem>();

            list.AddRange(valObj.af_GetAvailableAttributeItem());
            if (list.Count == 0)
            {
                list.AddRange(valObj.af_AttributeItemList);
            }

            string tbName = valObj._TableName.ToLower();

            if (tbName == ITableImplement.defaultTableName.ToLower())
            {
                tbName = list[0].TableName;
            }
            #region 表操作
            DataBaseTable dt1 = null;
            dt1 = Runtime_PersistenceLayer.Factory(conn).DataBase.DataTables[tbName];
            if (dt1 == null)
            {
                ConsoleService.Warn(tbName + " 数据表不存在");
                return(new List <DataBaseField>());
            }
            #endregion

            foreach (AttributeItem item in list)
            {
                string fieldName = item.FieldName.ToLower();
                #region 列操作
                DataBaseField f1 = null;
                if (!dt1.DataFields.TryGetValue(fieldName, out f1))
                {
                    ConsoleService.Warn(string.Format("数据表{0},数据字段{1}不存在", tbName, fieldName));
                    continue;
                }
                if (f1.Desc.CtrlType == BaseCtrlType.Text || f1.Desc.CtrlType == BaseCtrlType.HTML ||
                    f1.Desc.CtrlType == BaseCtrlType.SmallText)
                {
                    continue;
                }
                if (condObj != null && condObj.IsNotNull())
                {
                    f1.Value = condObj.GetString(item);
                }
                #endregion
                list2.Add(f1);
            }
            return(list2);
        }
        public void WriteEntity(DataBaseTable item)
        {
            var path = Path.Combine(Config.CSharp.Entity.Path, item.Schema, "Auto");
            var file = $"{item.Name}Entity.cs";

            var nameSpace = new List <string> {
                "System", "XCommon.Patterns.Repository.Entity", "System.Runtime.Serialization"
            };

            nameSpace.AddRange(item.Columns.Where(c => c.Schema != item.Schema).Select(c => c.Schema));
            nameSpace.AddRange(item.ProcessRemapSchema(Config));

            var builder = new StringBuilderIndented();

            builder
            .GenerateFileMessage()
            .ClassInit($"{item.Name}Entity", "EntityBase", $"{Config.CSharp.Entity.NameSpace}.{item.Schema}", ClassVisility.Public, true, nameSpace.ToArray());

            foreach (var column in item.Columns)
            {
                var propertyType = column.ProcessRemapProperty(Config);

                builder
                .AppendLine($"public {propertyType} {column.Name} {{ get; set; }}")
                .AppendLine();
            }

            builder
            .AppendLine()
            .AppendLine("[IgnoreDataMember]")
            .AppendLine("public override Guid Key")
            .AppendLine("{")
            .IncrementIndent()
            .AppendLine("get")
            .AppendLine("{")
            .IncrementIndent()
            .AppendLine($"return {item.PKName};")
            .DecrementIndent()
            .AppendLine("}")
            .AppendLine("set")
            .AppendLine("{")
            .IncrementIndent()
            .AppendLine($"{item.PKName} = value;")
            .DecrementIndent()
            .AppendLine("}")
            .DecrementIndent()
            .AppendLine("}")
            .ClassEnd();

            Writer.WriteFile(path, file, builder, true);
        }
Exemple #20
0
        /// <summary>
        /// 创建表
        /// </summary>
        public int AddTableWithDefaultCols(TF_TABLE tbObj, string sourceTable, string sourceConn, ref string errMsg)
        {
            string        tbname = tbObj.TB_NAME;
            DataBaseTable tb1    = null;

            if (!DataBase.Factory(conn).TryGetValue(tbname, out tb1))//如果表不存在,则新建表,带默认字段
            {
                DataBaseTable tb2 = null;
                if (tbObj.M_TB_ID > 0)
                {
                    //if (!DataBase.Factory(conn).Master().TryGetValue("GROUP_WF_MX", out tb2))
                    //    return 0;
                    if (!DataBase.Factory(conn).Master().TryGetValue("af_GROUP_WF_MX_2014", out tb2))
                    {
                        return(0);
                    }
                }
                else
                {
                    //if (!DataBase.Factory(conn).Master().TryGetValue("GROUP_WF", out tb2))
                    //    return 0;
                    if (!DataBase.Factory(conn).Master().TryGetValue("af_GROUP_WF_2014", out tb2))
                    {
                        return(0);
                    }
                }
                DataBaseTable tb3      = new DataBaseTable(tbname, tb2);
                DataBaseTable tbsource = null;
                if (!string.IsNullOrEmpty(sourceTable) && DataBase.Factory(sourceConn).TryGetValue(sourceTable, out tbsource))
                {
                    foreach (DataBaseField f2 in tbsource.DataFields)
                    {
                        tb3.DataFields.Add(f2);
                    }
                }
                if (DataBase.Factory(conn).AddTable(tb3, ref errMsg))
                {
                    return(1);
                }
                else
                {
                    return(0);
                }
            }
            //else
            //{
            //    SaveToTF_TB_FIELD(tbObj, ref errMsg);
            //}
            return(1);
        }
Exemple #21
0
        private string QuerySqlRelationship(DataBaseTable table)
        {
            var sql = "DECLARE \n"
                      + " @Table VARCHAR(100) = '" + table.Schema + "." + table.Name + "' \n"
                      + " \n"
                      + " SELECT \n"
                      + "     SCHEMA_NAME(TBO.SCHEMA_ID) AS SchemaPK, \n"
                      + "     TBO.Name AS TablePK, \n"
                      + "     CLO.Name AS ColumnPK, \n"
                      + "     SCHEMA_NAME(TBD.SCHEMA_ID) AS SchemaFK, \n"
                      + "     TBD.Name AS TableFK, \n"
                      + "     CLD.Name AS ColumnFK, \n"
                      + "     CLD.is_nullable AS Nullable, \n"
                      + "     'M' AS Type \n"
                      + " FROM \n"
                      + "     SYS.TABLES AS TBO \n"
                      + "     JOIN SYS.FOREIGN_KEY_COLUMNS FKC ON FKC.REFERENCED_OBJECT_ID = TBO.[OBJECT_ID] \n"
                      + "     JOIN SYS.TABLES AS TBD ON TBD.OBJECT_ID = FKC.PARENT_OBJECT_ID \n"
                      + "     JOIN SYS.COLUMNS AS CLD ON CLD.COLUMN_ID = FKC.PARENT_COLUMN_ID AND CLD.OBJECT_ID = FKC.PARENT_OBJECT_ID \n"
                      + "     JOIN SYS.COLUMNS AS CLO ON CLO.COLUMN_ID = FKC.REFERENCED_COLUMN_ID AND CLO.OBJECT_ID = FKC.REFERENCED_OBJECT_ID \n"
                      + " WHERE \n"
                      + "     TBO.OBJECT_ID = OBJECT_ID(@Table) \n"
                      + "     AND CLD.COLUMN_ID <> CLO.COLUMN_ID \n"
                      + "     AND TBO.OBJECT_ID <> TBD.OBJECT_ID\n"
                      + "  \n"
                      + " UNION ALL \n"
                      + "  \n"
                      + " SELECT \n"
                      + "     SCHEMA_NAME(TBD.SCHEMA_ID) AS SchemaPK, \n"
                      + "     TBD.Name AS TablePK, \n"
                      + "     CLD.Name AS ColumnPK, \n"
                      + "     SCHEMA_NAME(TBO.SCHEMA_ID) AS SchemaFK, \n"
                      + "     TBO.Name AS TableFK, \n"
                      + "     CLO.Name AS ColumnFK, \n"
                      + "     CLO.is_nullable AS Nullable, \n"
                      + "     'U' AS Type \n"
                      + " FROM \n"
                      + "     SYS.TABLES AS TBO \n"
                      + "     JOIN SYS.FOREIGN_KEY_COLUMNS FKC ON FKC.PARENT_OBJECT_ID = TBO.[OBJECT_ID] \n"
                      + "     JOIN SYS.TABLES AS TBD ON TBD.OBJECT_ID = FKC.REFERENCED_OBJECT_ID \n"
                      + "     JOIN SYS.COLUMNS AS CLD ON CLD.COLUMN_ID = FKC.REFERENCED_COLUMN_ID AND CLD.OBJECT_ID = FKC.REFERENCED_OBJECT_ID \n"
                      + "     JOIN SYS.COLUMNS AS CLO ON CLO.COLUMN_ID = FKC.PARENT_COLUMN_ID AND CLO.OBJECT_ID = FKC.PARENT_OBJECT_ID \n"
                      + " WHERE \n"
                      + "     TBO.OBJECT_ID = OBJECT_ID(@Table) \n"
                      + "     AND TBO.OBJECT_ID <> TBD.OBJECT_ID \n";

            return(sql);
        }
        public Dictionary <DataBaseColumn, object> CreateDatabaseDictionary(DataBaseTable table, ModelBase model, ModelBase parentModel)
        {
            var ret   = new Dictionary <DataBaseColumn, object>();
            var entry = this.OREntries.FirstOrDefault(x => x.RelationName == table.Name);

            foreach (var col in entry.Columns)
            {
                var    column      = table.Columns[col.ColumnName];
                object objectValue = null;
                if (col.AttributeName == "Id")
                {
                    objectValue = model.Id;
                }
                else if (col.AttributeName == "ParentId")
                {
                    objectValue = parentModel.Id;
                }
                else
                {
                    if (column.Type == ColumnType.VARCHAR && model.GetType().GetProperty(col.AttributeName).PropertyType != typeof(string))
                    {
                        if (model.GetType().GetProperty(col.AttributeName).PropertyType.IsEnum)
                        {
                            objectValue = model.GetType().GetProperty(col.AttributeName).GetValue(model);
                        }
                        else
                        {
                            var help = model.GetType().GetProperty(col.AttributeName).GetValue(model) as ModelBase;
                            if (help != null)
                            {
                                objectValue = help.Id;
                            }
                            else
                            {
                                throw new NotSupportedException("Attribut <" + col.AttributeName + "> ist kein gültiger Datentyp!");
                            }
                        }
                    }
                    else
                    {
                        objectValue = model.GetType().GetProperty(col.AttributeName).GetValue(model);
                    }
                }
                ret.Add(column, objectValue);
            }
            return(ret);
        }
Exemple #23
0
        /// <summary>
        /// 根据已存在的表,将物理字段,保存入 TF_TB_FIELD 表中
        /// </summary>
        /// <param name="tb1"></param>
        /// <param name="tbObj"></param>
        /// <returns></returns>
        public int SaveToTF_TB_FIELD(string TB_NAME, int TB_ID, ref string errMsg)
        {
            errMsg = "";
            string        tbname = TB_NAME;
            DataBaseTable tb1    = null;
            DataBaseTable tb2    = new DataBaseTable();
            DataBaseTable tb3    = new DataBaseTable();

            if (DataBase.Factory(conn).TryGetValue(tbname, out tb1))//如果表不存在,则新建表,带默认字段
            {
                foreach (DataBaseField f2 in tb1.DataFields)
                {
                    DataBase.Factory(conn).Master().TryGetValue("af_GROUP_WF_2014", out tb2);

                    DataBase.Factory(conn).Master().TryGetValue("af_GROUP_WF_MX_2014", out tb3);

                    if (!tb2.DataFields.Contains(f2.FieldName) && !tb3.DataFields.Contains(f2.FieldName))
                    {
                        TF_TB_FIELD f1 = Parse(f2);
                        f1.TB_ID = TB_ID;

                        int         count1 = 0;
                        TF_TB_FIELD cond1  = new TF_TB_FIELD();
                        cond1.TB_ID      = f1.TB_ID;
                        cond1.FIELD_NAME = f1.FIELD_NAME;
                        //count1 = BLLTable<TF_TB_FIELD>.Factory(conn).SaveOrUpdate(f1, cond1, TF_TB_FIELD.Attribute.FIELD_ID);

                        if (BLLTable <TF_TB_FIELD> .Factory(conn).Exists(cond1))
                        {
                            count1 = BLLTable <TF_TB_FIELD> .Factory(conn).Update(f1, TF_TB_FIELD.Attribute.FIELD_ID);
                        }
                        else
                        {
                            count1 = BLLTable <TF_TB_FIELD> .Factory(conn).Insert(f1, TF_TB_FIELD.Attribute.FIELD_ID);
                        }


                        if (count1 < 1)
                        {
                            Cs.Error("插入 TF_TB_FIELD 失败");
                        }
                    }
                }
                return(1);
            }
            return(-1);
        }
Exemple #24
0
        public void WriteValidation(DataBaseTable item)
        {
            var path = Path.Combine(Config.CSharp.Repository.Concrecte.Path, item.Schema, "Validate");
            var file = $"{item.Name}Validate.cs";


            var nameSpace = new List <string> {
                "System", "System.Threading.Tasks", "XCommon.Application.Executes", "XCommon.Patterns.Specification.Validation", "XCommon.Patterns.Specification.Validation.Extensions"
            };

            nameSpace.Add($"{Config.CSharp.Entity.NameSpace}.{item.Schema}");

            var builder = new StringBuilderIndented();

            var parentClass = $"SpecificationValidation<{item.Name}Entity>";
            var appClass    = Config.CSharp.ApplicationClasses.FirstOrDefault(c => c.Name == item.Name && c.Schema == item.Schema);

            if (Config.CSharp.UsingApplicationBase && appClass != null)
            {
                nameSpace   = new List <string>();
                parentClass = $"{appClass.NamespaceValidate}.{item.Name}Validate";

                builder
                .ClassInit($"{item.Name}Validate", parentClass, $"{Config.CSharp.Repository.Concrecte.NameSpace}.{item.Schema}.Validate", ClassVisibility.Public, nameSpace.ToArray())
                .InterfaceEnd();
            }
            else
            {
                builder
                .ClassInit($"{item.Name}Validate", parentClass, $"{Config.CSharp.Repository.Concrecte.NameSpace}.{item.Schema}.Validate", ClassVisibility.Public, nameSpace.ToArray())
                .AppendLine($"public override async Task<bool> IsSatisfiedByAsync({item.Name}Entity entity, Execute execute)")
                .AppendLine("{")
                .IncrementIndent()
                .AppendLine("var spefications = NewSpecificationList()")
                .IncrementIndent()
                .AppendLine(".AndIsValid(e => e.Key != Guid.Empty, \"Default key isn't valid\");")
                .DecrementIndent()
                .AppendLine()
                .AppendLine("return await CheckSpecificationsAsync(spefications, entity, execute);")
                .DecrementIndent()
                .AppendLine("}")
                .InterfaceEnd();
            }

            Writer.WriteFile(path, file, builder, false);
        }
        private void ProcessMapRelationShips(StringBuilderIndented builder, DataBaseTable item)
        {
            foreach (var relationShip in item.RelationShips.Where(c => c.Type == DataBaseRelationShipType.Single))
            {
                var relationShipNamePK = ProcessRelationShipName(relationShip, relationShip.TablePK);
                var relationShipNameFK = ProcessRelationShipName(relationShip, relationShip.TableFK);

                builder
                .AppendLine("entity")
                .IncrementIndent()
                .AppendLine($".HasOne(d => d.{relationShipNamePK})")
                .AppendLine($".WithMany(p => p.{relationShipNameFK})")
                .AppendLine($".HasForeignKey(d => d.{relationShip.ColumnFK});")
                .DecrementIndent()
                .AppendLine();
            }
        }
        public void WriteFilter(DataBaseTable item)
        {
            var path = Path.Combine(Config.CSharp.Entity.Path, item.Schema, "Filter");
            var file = $"{item.Name}Filter.cs";

            var nameSpace = new List <string> {
                "System", "XCommon.Patterns.Repository.Entity"
            };

            var builder = new StringBuilderIndented();

            builder
            .ClassInit($"{item.Name}Filter", "FilterBase", $"{Config.CSharp.Entity.NameSpace}.{item.Schema}.Filter", ClassVisility.Public, nameSpace.ToArray())
            .ClassEnd();

            Writer.WriteFile(path, file, builder, false);
        }
        public void WriteEntityMap(DataBaseTable item)
        {
            if (Config.CSharp.UsingApplicationBase && Config.CSharp.ApplicationClasses.Any(c => c.Name == item.Name && c.Schema == item.Schema))
            {
                return;
            }

            var path = Path.Combine(Config.CSharp.EntityFramework.Path, item.Schema, "Map");
            var file = $"{item.Name}Map.cs";

            var builder = new StringBuilderIndented();

            builder
            .GenerateFileMessage()
            .ClassInit($"{item.Name}Map", null, $"{Config.CSharp.EntityFramework.NameSpace}.{item.Schema}.Map", ClassVisibility.Internal, "System", "Microsoft.EntityFrameworkCore")
            .AppendLine("internal static void Map(ModelBuilder modelBuilder, bool unitTest)")
            .AppendLine("{")
            .IncrementIndent()
            .AppendLine($"modelBuilder.Entity<{item.Name}>(entity =>")
            .AppendLine("{")
            .IncrementIndent()
            .AppendLine($"entity.HasKey(e => e.{item.PKName});")
            .AppendLine()
            .AppendLine("if (!unitTest)")
            .IncrementIndent()
            .AppendLine($"entity.ToTable(\"{item.Name}\", \"{item.Schema}\");")
            .DecrementIndent()
            .AppendLine("else")
            .IncrementIndent()
            .AppendLine($"entity.ToTable(\"{item.Schema}{item.Name}\");")
            .DecrementIndent()
            .AppendLine();

            ProcessMapColumns(builder, item);
            ProcessMapRelationShips(builder, item);

            builder
            .DecrementIndent()
            .AppendLine("});")
            .DecrementIndent()
            .AppendLine("}")
            .ClassEnd();

            Writer.WriteFile(path, file, builder, true);
        }
Exemple #28
0
        /// <summary>
        /// 编辑表 2 为建表成功,无需改名,1为存在旧表,-1为异常。
        /// </summary>
        public int EditTable(string oldname, TF_TABLE tbObj, ref string errMsg)
        {
            int ret = 0;

            try
            {
                string newname = tbObj.TB_NAME;
                if (oldname == newname)
                {
                    return(2);
                }
                //修改正式表字段名称或类型
                DataBaseTable oldt1    = null;
                DataBaseTable newt1    = null;
                bool          oldExist = DataBase.Factory(conn).TryGetValue(oldname, out oldt1);
                errMsg = "被修改的表不存在";
                if (!oldExist)
                {
                    return(0);
                }
                bool newExist = DataBase.Factory(conn).TryGetValue(tbObj.TB_NAME, out newt1);
                errMsg = "新表名已被其他用户使用,请重新命名";
                if (newExist)
                {
                    return(0);
                }
                if (oldt1.ChangeName(newname))
                {
                    return(1);
                }
                else
                {
                    return(0);
                }
            }
            catch (Exception ex)
            {
                errMsg = ex.ToString();
                return(-1);
            }
            return(ret);
        }
Exemple #29
0
        public void WriteContract(DataBaseTable item)
        {
            var path = Path.Combine(Config.CSharp.Repository.Contract.Path, item.Schema);
            var file = $"I{item.Name}Business.cs";

            var nameSpace = new List <string> {
                "System", "XCommon.Patterns.Repository"
            };

            nameSpace.Add($"{Config.CSharp.Entity.NameSpace}.{item.Schema}");
            nameSpace.Add($"{Config.CSharp.Entity.NameSpace}.{item.Schema}.Filter");

            var builder = new StringBuilderIndented();

            builder
            .InterfaceInit($"I{item.Name}Business", $"IRepositoryEF<{item.Name}Entity, {item.Name}Filter>", $"{Config.CSharp.Repository.Contract.NameSpace}.{item.Schema}", ClassVisility.Public, nameSpace.ToArray())
            .InterfaceEnd();

            Writer.WriteFile(path, file, builder, false);
        }
Exemple #30
0
        public static List <string> ProcessRemapSchema(this DataBaseTable item, GeneratorConfig config)
        {
            var result = new List <string>();

            if (config.CSharp.EntityFramework.Remap == null)
            {
                return(result);
            }

            var remap = config.CSharp.EntityFramework.Remap.Where(
                c => c.Schema == item.Schema &&
                c.Table == item.Name
                );

            if (remap != null)
            {
                result.AddRange(remap.Select(c => c.NameSpace));
            }

            return(result);
        }
 protected string GetShowTableInfo(DataBaseTable table)
 {
     if (table == null)
         return "";
     StringBuilder sb = new StringBuilder();
     string tabName = table.TableName + (string.IsNullOrEmpty(table.Desc.ZhName) ? "" : ("(" + table.Desc.ZhName + ")"));
     sb.Append("<div class=\"grp dbtable\"><input id=\"" + ("_" + table.TableName) + "\" onclick=\"tabselallfield(this);\" type=\"checkbox\" value=\"" + table.TableName + "\" title=\"" + tabName + "\" /><label for=\"" + ("_" + table.TableName) + "\" title=\"" + tabName + "\">" + stringFormat(tabName, 30) + "</label><a>չ��</a></div>");
     sb.Append("<div style=\"display:none;\">");
     foreach (DataBaseField field in table.DataFields)
     {
         sb.Append("<dl class='fieldcheckboxdl" + (field.IsKeyID ? " keyfield" : "") + "'>");
         sb.Append("<dd>");
         sb.Append("<span>");
         string fidName = GetShowFieldName(field);
         sb.Append("<input id=\"" + (table.TableName + "_" + field.FieldName) + "\" onclick=\"selfield(this);\"  type=\"checkbox\" value=\"" + (table.TableName + "." + field.FieldName) + "\" title=\"" + fidName + "\" /><label for=\"" + (table.TableName + "_" + field.FieldName) + "\" title=\"" + fidName + "\">" + stringFormat(fidName, 40) + "</label>");
         sb.Append("</span>");
         sb.Append("</dd>");
         sb.Append("</dl>");
     }
     sb.Append("</div>");
     return sb.ToString();
 }
        /// <summary>
        /// 创建表
        /// </summary>
        public int AddTableWithDefaultCols(TF_TABLE tbObj,string sourceTable,string sourceConn, ref string errMsg)
        {
            string tbname = tbObj.TB_NAME;
            DataBaseTable tb1 = null;
            if (!DataBase.Factory(conn).TryGetValue(tbname, out tb1))//如果表不存在,则新建表,带默认字段
            {
                DataBaseTable tb2 = null;
                if (tbObj.M_TB_ID > 0)
                {
                    //if (!DataBase.Factory(conn).Master().TryGetValue("GROUP_WF_MX", out tb2))
                    //    return 0;
                    if (!DataBase.Factory(conn).Master().TryGetValue("af_GROUP_WF_MX_2014", out tb2))
                        return 0;
                }
                else
                {
                    //if (!DataBase.Factory(conn).Master().TryGetValue("GROUP_WF", out tb2))
                    //    return 0;
                    if (!DataBase.Factory(conn).Master().TryGetValue("af_GROUP_WF_2014", out tb2))
                        return 0;
                }
                DataBaseTable tb3 = new DataBaseTable(tbname, tb2);
                DataBaseTable tbsource = null;
                if (!string.IsNullOrEmpty(sourceTable) && DataBase.Factory(sourceConn).TryGetValue(sourceTable, out tbsource))
                {
                    foreach (DataBaseField f2 in tbsource.DataFields)
                    {
                        tb3.DataFields.Add(f2);
                    }
                }
                if (DataBase.Factory(conn).AddTable(tb3, ref errMsg))
                    return 1;
                else
                    return 0;

            }
            //else
            //{
            //    SaveToTF_TB_FIELD(tbObj, ref errMsg);
            //}
            return 1;
        }
        /// <summary>
        /// 根据已存在的表,将物理字段,保存入 TF_TB_FIELD 表中
        /// </summary>
        /// <param name="tb1"></param>
        /// <param name="tbObj"></param>
        /// <returns></returns>
        public int SaveToTF_TB_FIELD(string TB_NAME, int TB_ID, ref string errMsg)
        {
            errMsg = "";
            string tbname = TB_NAME;
            DataBaseTable tb1 = null;
            DataBaseTable tb2 = new DataBaseTable();
            DataBaseTable tb3 = new DataBaseTable();
            if (DataBase.Factory(conn).TryGetValue(tbname, out tb1))//如果表不存在,则新建表,带默认字段
            {
                foreach (DataBaseField f2 in tb1.DataFields)
                {
                    DataBase.Factory(conn).Master().TryGetValue("af_GROUP_WF_2014", out tb2);

                    DataBase.Factory(conn).Master().TryGetValue("af_GROUP_WF_MX_2014", out tb3);

                    if (!tb2.DataFields.Contains(f2.FieldName) && !tb3.DataFields.Contains(f2.FieldName))
                    {
                        TF_TB_FIELD f1 = Parse(f2);
                        f1.TB_ID = TB_ID;

                        int count1 = 0;
                        TF_TB_FIELD cond1 = new TF_TB_FIELD();
                        cond1.TB_ID = f1.TB_ID;
                        cond1.FIELD_NAME = f1.FIELD_NAME;
                        //count1 = BLLTable<TF_TB_FIELD>.Factory(conn).SaveOrUpdate(f1, cond1, TF_TB_FIELD.Attribute.FIELD_ID);

                        if (BLLTable<TF_TB_FIELD>.Factory(conn).Exists(cond1))
                        {
                            count1 = BLLTable<TF_TB_FIELD>.Factory(conn).Update(f1, TF_TB_FIELD.Attribute.FIELD_ID);
                        }
                        else
                        {
                            count1 = BLLTable<TF_TB_FIELD>.Factory(conn).Insert(f1, TF_TB_FIELD.Attribute.FIELD_ID);
                        }

                        if (count1 < 1)
                        {
                            Cs.Error("插入 TF_TB_FIELD 失败");
                        }
                    }

                }
                return 1;
            }
            return -1;
        }
        /// <summary>
        /// TF_FORM 从配置中获得表单布局
        /// </summary>
        /// <param name="conn"></param>
        /// <param name="cond"></param>
        /// <returns></returns>
        public bool Parse(TF_TABLE cond,
            out ITableImplement valObj, out ITableImplement condObj, out List<Relation> relationList, out List<ITableImplement> otherValueList,
            out List<ITableImplement> condList, ref string msg)
        {
            valObj = new ITableImplement();
            condObj = new ITableImplement();
            //载入关系
            otherValueList = new List<ITableImplement>();
            condList = new List<ITableImplement>();
            relationList = new List<Relation>();

            msg = "条件不存在";
            if (string.IsNullOrEmpty(cond.TB_NAME))
                return false;

            DataBaseTable tb1;
            List<DataBaseField> listf1 = new List<DataBaseField>();
            List<DataBaseTable> listTb1 = new List<DataBaseTable>();

            bool ret = true; tb1 = null;
            //TF_TABLE val = BLLTable<TF_TABLE>.Factory(conn).GetRowData(new TF_TABLE(), cond);

            TF_TB_FIELD val1 = new TF_TB_FIELD();
            TF_F_COLUMN val2 = new TF_F_COLUMN();
            TF_TABLE val3 = new TF_TABLE();

            TF_TB_FIELD cond1 = new TF_TB_FIELD();
            TF_F_COLUMN cond2 = new TF_F_COLUMN();
            TF_FORM cond3 = new TF_FORM();
            List<ITableImplement> otherValueList1 = new List<ITableImplement>();
            List<ITableImplement> condList1 = new List<ITableImplement>();

            otherValueList1.Add(val2); otherValueList1.Add(val3);

            condList1.Add(cond);
            List<Relation> relationList1 = new List<Relation>();
            relationList1.Add(RelationFactory.TF_TABLE_TF_FORM);
            relationList1.Add(RelationFactory.TF_TABLE_TF_TB_FIELD);
            relationList1.Add(RelationFactory.TF_TB_FIELD_TF_F_COLUMN);

            int pageSize = 100;
            int pageIndex = 1;
            int recount = -1;
            string cachekey = null;
            List<TF_TB_FIELD> list1 = BLLTable<TF_TB_FIELD>.Factory(conn).SelectByPage(val1, relationList1, otherValueList1, condList1,
                pageSize, pageIndex, ref recount, out cachekey);

            if (list1.Count == 0)
            {
                DataBaseTable dt1 = null;
                dt1 = Runtime_PersistenceLayer.Factory(conn).DataBase.DataTables[cond.TB_NAME];
                msg = cond.TB_NAME + " 数据表不存在";
                if (dt1 == null)
                {
                    ret = false;
                    ConsoleService.Warn(msg);
                }
                return ret;
            }
            if (list1.Count > 90)
            {
                msg = "条件错误,所配置的字段记录超过90";
                return false;
            }
            //生成布局模版用
            tb1 = new DataBaseTable();
            foreach (TF_TB_FIELD item in list1)
            {
                string tbName = Convert.ToString(item.GetValue(TF_TABLE.Attribute.TB_NAME)).ToLower();
                #region 表操作
                DataBaseTable dt1 = null;
                dt1 = Runtime_PersistenceLayer.Factory(conn).DataBase.DataTables[tbName];
                msg = tbName + " 数据表不存在"; ret = false;
                if (dt1 == null)
                {
                    ConsoleService.Warn(msg);
                    return ret;
                }
                tb1 = dt1;
                listTb1.Add(dt1);
                //是否显示
                object obj1 = null;
                object obj2 = null;
                object obj3 = null;
                if (item.TryGetValue(TF_FORM.Attribute.FORM_ID, out obj1))
                {
                    dt1.IsVisable = true;
                }

                #endregion
                string fieldName = item.FIELD_NAME.ToLower();
                #region 列操作
                DataBaseField f1 = null;
                msg = string.Format("数据表{0},数据字段{1}不存在", tbName, fieldName);
                if (!dt1.DataFields.TryGetValue(fieldName, out f1))
                {
                    ret = false;
                    ConsoleService.Warn(msg);
                    continue;
                }
                //是否显示
                obj1 = null; obj2 = null; obj3 = null;
                if (item.TryGetValue(TF_F_COLUMN.Attribute.COLUMN_ID, out obj1)
                    && item.TryGetValue(TF_F_COLUMN.Attribute.SHOW_NAME, out obj2)
                    && item.TryGetValue(TF_F_COLUMN.Attribute.CTRL_TYPE, out obj3))
                {
                    //f1.IsVisable = true;
                }
                #endregion
                listf1.Add(f1);
            }
            //取值对象
            valObj = ITableImplement.Factory(tb1);
            //其他取值对象
            foreach (DataBaseTable tb2 in listTb1)
            {
                if (tb2.TableName == tb1.TableName) continue;
                otherValueList.Add(ITableImplement.Factory(tb2));

            }
            //关系呢
            return ret;
        }
Exemple #35
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="dev"></param>
 /// <param name="devtbname"></param>
 /// <param name="tbname"></param>
 /// <returns></returns>
 private DataBaseTable GetAddTable(string dev, string devtbname, ref string tbname)
 {
     DataBaseTable addTB = null;
     DataBase devDB = DataBase.Factory(BillBase.GetConnByDevKey(dev));
     if (devDB.DataTables.Contains(devtbname))
     {
         addTB = new DataBaseTable(tbname, devDB.DataTables[devtbname]);
     }
     else
         return null;
     if (DataBase.Factory(conn).DataTables.Contains(tbname))
     {
         DataBaseTable tbOld = DataBase.Factory(conn).DataTables[tbname];
         if (addTB != null && tbOld.CheckChange(addTB))
         {
             return null;
         }
         else
         {
             tbname += "_1";
             int tbncount = 1;
             while (DataBase.Factory(conn).DataTables.Contains(tbname))
             {
                 tbncount++;
                 tbname = tbname.Remove(tbname.Length - 2) + "_" + tbncount;
             }
             addTB = new DataBaseTable(tbname, devDB.DataTables[devtbname]);
         }
     }
     return addTB;
 }