예제 #1
0
        public double SumAsDouble(string attrDefName)
        {
            double count = 0;
            var    sql   = SqlQueryBuilder.Build(DataContext, Def);

            sql.AddAttribute(attrDefName, SqlQuerySummaryFunction.Sum);

            using (var reader = new SqlQueryReader(DataContext, sql))
            {
                reader.Open();
                if (reader.Read())
                {
                    if (!reader.IsDbNull(0))
                    {
                        if (reader.Reader.GetFieldType(0) == typeof(double))
                        {
                            count = reader.GetDouble(0);
                        }
                        else if (reader.Reader.GetFieldType(0) == typeof(decimal))
                        {
                            count = (double)reader.GetDecimal(0);
                        }
                    }
                }
                reader.Close();
            }
            return(count);
        }
예제 #2
0
        public List <T> All <T>(string attrDefName)
        {
            var list = new List <T>();
            var sql  = SqlQueryBuilder.Build(DataContext, Def);

            sql.AddAttribute(attrDefName);

            using (var reader = new SqlQueryReader(DataContext, sql))
            {
                reader.Open();
                while (reader.Read())
                {
                    if (!reader.IsDbNull(0))
                    {
                        T   item;
                        var v = reader.GetValue(0);
                        list.Add(v.TryParse(out item) ? item : default(T));
                    }
                    else
                    {
                        list.Add(default(T));
                    }
                }
                reader.Close();
            }
            return(list);
        }
예제 #3
0
        public SqlQueryMasterSlaveLink AddMasterLink(SqlQueryReader master, string masterAttrName, string paramName)
        {
            var link = new SqlQueryMasterSlaveLink(Query, masterAttrName, paramName);

            _masterLinks.Add(link, master);
            return(link);
        }
예제 #4
0
        public DataTable All()
        {
            var sql = SqlQueryBuilder.Build(DataContext, Def);

            var table = new DataTable(sql.Source.AliasName);

            using (var reader = new SqlQueryReader(DataContext, sql))
            {
                table.Load(reader.Reader);
            }
            return(table);
        }
예제 #5
0
        public T Sum <T>(string attrDefName)
        {
            var result = default(T);

            using (var reader = new SqlQueryReader(DataContext, Query))
            {
                var v = reader.GetSum(attrDefName);
                if (v != null)
                {
                    v.TryParse(out result);
                }
            }
            return(result);
        }
        public void Update(SqlQueryReader masterSource)
        {
            if (!masterSource.Active)
            {
                return;
            }

            var masterFieldIndex = MasterAttributeId != Guid.Empty
                ? masterSource.TryGetAttributeIndex(MasterAttributeId)
                : masterSource.TryGetAttributeIndex(MasterAttributeName);

            if (masterFieldIndex >= 0)
            {
                Slave.SetParams(SlaveParamName, masterSource.GetValue(masterFieldIndex));
            }
        }
예제 #7
0
        public int Count()
        {
            var count = 0;
            var sql   = SqlQueryBuilder.Build(DataContext, Def);

            sql.AddAttribute("&Id", SqlQuerySummaryFunction.Count);

            using (var reader = new SqlQueryReader(DataContext, sql))
            {
                reader.Open();
                if (reader.Read())
                {
                    if (!reader.IsDbNull(0))
                    {
                        count = reader.GetInt32(0);
                    }
                }
                reader.Close();
            }
            return(count);
        }
예제 #8
0
        public T Sum <T>(string attrDefName)
        {
            T   result = default(T);
            var sql    = SqlQueryBuilder.Build(DataContext, Def);

            sql.AddAttribute(attrDefName, SqlQuerySummaryFunction.Sum);

            using (var reader = new SqlQueryReader(DataContext, sql))
            {
                reader.Open();
                if (reader.Read())
                {
                    if (!reader.IsDbNull(0))
                    {
                        var v = reader.GetValue(0);

                        v.TryParse(out result);
                    }
                }
                reader.Close();
            }
            return(result);
        }
예제 #9
0
 public object Min(string attrDefName)
 {
     using (var reader = new SqlQueryReader(DataContext, Query))
         return(reader.GetMin(attrDefName));
 }
예제 #10
0
 public object Min(Guid attrDefId)
 {
     using (var reader = new SqlQueryReader(DataContext, Query))
         return(reader.GetMin(attrDefId));
 }
예제 #11
0
 public int Count()
 {
     using (var reader = new SqlQueryReader(DataContext, Query))
         return(reader.GetCount());
 }