예제 #1
0
        public EntityDataTable(Type EntityType, DataPersistance dp,
                               string Condition, string OrderCondition, out DataTable dt)
        {
            this.EntityType = EntityType;
            td = MetaData.GetTableDef(EntityType);

            this.dp = dp ?? BaseFramework.DefaultDataPersistance;

            dt = this.dp.OpenDataTable(null,
                                       EntityType, Condition, OrderCondition);
            foreach (DataColumn dc in dt.Columns)
            {
                dc.ReadOnly = false;
            }

            wrdt     = new WeakReference(dt);
            SqlQuery = BuildSqlQuery(td.BuildSqlFieldSelect(dp,
                                                            true, true), Condition);
        }
예제 #2
0
        private string BuildSqlQuery(string ColumnList, string Condition)
        {
            string SqlQuery;

            if (ColumnList.Length > 0)
            {
                return(string.Concat("SELECT ",
                                     td.BuildSqlFieldSelect(dp, ColumnList),
                                     " FROM ", td._TableName, " WHERE ",
                                     Condition.Length > 0 ? Condition : "1=1"));
            }
            else
            {
                int i = Condition.LastIndexOf("WHERE",
                                              StringComparison.OrdinalIgnoreCase);
                if (i < 0)
                {
                    return(string.Concat(Condition, " WHERE 1=1"));
                }
                else
                {
                    int l    = Condition.Length;
                    int sumx = 0;
                    for (int j = i + 5; j < l; j++)
                    {
                        char x = Condition[j];
                        if (x == '(')
                        {
                            sumx++;
                        }
                        else if (x == ')')
                        {
                            sumx--;
                        }
                    }
                    return(sumx == 0 ? Condition : string.Concat(
                               Condition, " WHERE 1=1"));
                }
            }
        }