Esempio n. 1
0
        public string BuildGroupSql(string[] groupField, string[] sumField, FilterBuilder fb, string order)
        {
            //ȷ����Ҫ��ӵı�,����ʾ��Ŀ�Ͳ�ѯ�����б���
            List<Table> tablelist = new List<Table>();
            foreach (string s in groupField)
            {
                AddField2Table(s, tablelist);
            }
            foreach (string s in sumField)
            {
                AddField2Table(s, tablelist);
            }
            foreach (Filter filter in fb.FilterList)
            {
                AddTable(filter.FieldFullName, tablelist);
            }
            //׼��select �ֶ�
            StringBuilder fie = new StringBuilder();
            foreach (string s in groupField)
            {
                Field f = GetFieldByFullName(s);
                if (f != null)
                {
                    AddField2Sql(fie, f);//group�ֶβ�����depend on
                }
            }
            foreach (string s in sumField)
            {
                Field f = GetFieldByFullName(s);
                if (f != null)
                {
                    if (f.DependOnField != null)
                    {
                        foreach (string df in f.DependOnField)
                        {
                            Field f2 = GetFieldByFullName(df);
                            if (f2 != null)
                            {
                                AddSumField2Sql(fie, f2);
                            }
                        }
                    }
                    else
                    {
                        AddField2Sql(fie, f);
                    }
                }
            }
            // ׼�� groupby
            StringBuilder groupStr = new StringBuilder();
            foreach (string s in groupField)
            {
                Field f = GetFieldByFullName(s);
                if (f != null)
                {
                    AddGroup2Sql(groupStr, f);
                }
            }

            StringBuilder tab = new StringBuilder(" from ");
            AddTable2Sql(tab, MainTable, true);
            foreach (Table table in tablelist)
            {
                AddTable2Sql(tab, table, false);
            }
            StringBuilder fullsb = new StringBuilder();
            fullsb.Append(fie.ToString());
            fullsb.Append(tab.ToString());
            fullsb.Append(fb.BuildWhere());
            fullsb.Append(groupStr.ToString());
            if (order.Length > 0)
            {
                fullsb.Append(" order by ");
                fullsb.Append(order);
            }
            return fullsb.ToString();
        }
Esempio n. 2
0
        /// <summary>
        /// showField ʹ�� tableAlias.fieldName ����ʽ
        /// </summary>
        /// <param name="showField"></param>
        /// <returns></returns>
        public string BuildSql(string[] showField, FilterBuilder fb, string order)
        {
            //ȷ����Ҫ��ӵı�,����ʾ��Ŀ�Ͳ�ѯ�����б���
            List<Table> tablelist = new List<Table>();
            foreach (Table t in TableList)
            {
                if (t.IsDefault)
                {
                    AddTable(t.Alias, tablelist);//���ﲻֱ�� list.add(t),����Ҫͬʱ���dependOn��
                }
            }
            foreach (string s in showField)
            {
                AddField2Table(s, tablelist);
            }
            foreach (Filter filter in fb.FilterList)
            {
                AddField2Table(filter.FieldFullName, tablelist);
            }
            StringBuilder fie = new StringBuilder();

            foreach (string s in showField)
            {
                Field f = GetFieldByFullName(s);
                if (f != null)
                {
                    if (f.DependOnField != null)
                    {
                        foreach (string df in f.DependOnField)
                        {
                            Field f2 = GetFieldByFullName(df);
                            if (f2 != null)
                            {
                                AddField2Sql(fie, f2);
                            }
                        }
                    }
                    else
                    {
                        AddField2Sql(fie, f);
                    }
                }
            }

            StringBuilder tab = new StringBuilder(" from ");
            AddTable2Sql(tab, MainTable, true);
            foreach (Table table in tablelist)
            {
                AddTable2Sql(tab, table, false);
            }
            StringBuilder fullsb = new StringBuilder();
            fullsb.Append(fie.ToString());
            fullsb.Append(tab.ToString());
            fullsb.Append(fb.BuildWhere());
            if (order.Length > 0)
            {
                fullsb.Append(" order by ");
                fullsb.Append(order);
            }
            return fullsb.ToString();
        }
Esempio n. 3
0
 public static FilterBuilder GetBuilder(Query query, SqlParameterCollection parameterlist)
 {
     FilterBuilder fb = new FilterBuilder();
     fb.query = query;
     fb.parameterList = parameterlist;
     return fb;
 }