Пример #1
0
    private void GetList(string sql, string a_count)
    {
        sql = sql.Replace("|*|", " " + (PageIndex - 1) * 10 + " ");
        DataTable dt;

        try
        {
            dt     = QueryInfo.GetWeaveInfo(sql);
            RCount = QueryInfo.GetCount(a_count);
            int k = dt.Rows.Count;
        }
        catch (Exception)
        {
            ScriptHelper.SetAlert(Page, GetTran("001039", "提供参数异常,无法进行有效查询"), "AdvanceQuery.aspx");
            return;
        }
        if (RCount % 10 == 0)
        {
            PageCount = RCount / 10;
        }
        else
        {
            PageCount = RCount / 10 + 1;
        }

        //在此处理加和
        table = new Hashtable();

        StringOfNumtable = new Hashtable();

        ArrayList keyList = QueryInfo.getList(Convert.ToDouble(Session["rate"]));

        //如果存在需要统计的列,则加到统计列表中
        foreach (QueryKey key in keyList)
        {
            if (dt.Columns.Contains(key.Name) && key.NeedCount == true)
            {
                table.Add(key.Name, key.CountType);
            }
            if (dt.Columns.Contains(key.Name) && key.DispType.ToLower() == "string")
            {
                StringOfNumtable.Add(key.Name, key.DispType);
            }
        }

        int pageIndex = GridView1.PageIndex;
        int pageSize  = GridView1.PageSize;

        if (dt.Rows.Count > 0)
        {
            int count = 0;
            //循环统计列
            foreach (DataColumn col in dt.Columns)
            {
                if (table.Contains(col.ColumnName))
                {
                    #region "检查看是否存在列,并是否需统计"
                    //如果包含统计列
                    string colName = col.ColumnName;

                    switch (table[colName].ToString())
                    {
                    case "double":
                        double retval = 0;

                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            if (i < dt.Rows.Count)
                            {
                                if (dt.Rows[i][colName] != DBNull.Value)
                                {
                                    retval += Convert.ToDouble(dt.Rows[i][colName]);
                                }
                            }
                            else
                            {
                                break;
                            }
                        }
                        table[count] = retval.ToString("f2");
                        break;

                    case "int":
                        int valInt = 0;

                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            if (i < dt.Rows.Count)
                            {
                                if (dt.Rows[i][colName] != DBNull.Value)
                                {
                                    valInt += Convert.ToInt32(dt.Rows[i][colName]);
                                }
                            }
                            else
                            {
                                break;
                            }
                        }
                        table[count] = valInt;
                        break;
                    }
                    table.Remove(colName);
                    #endregion
                }

                if (StringOfNumtable.Contains(col.ColumnName))
                {
                    #region "检查看是否存在数字字符列"
                    //如果包含统计列
                    string colName = col.ColumnName;

                    switch (StringOfNumtable[colName].ToString())
                    {
                    case "string":
                        StringOfNumtable[count] = "string";
                        break;
                    }
                    StringOfNumtable.Remove(colName);
                    #endregion
                }
                count++;
            }


            GridView1.DataSource = dt;
            GridView1.DataBind();
            if (this.dropPageList.Items.Count == 0)
            {
                for (int i = 0; i < PageCount; i++)
                {
                    dropPageList.Items.Add(new ListItem((i + 1).ToString(), (i).ToString()));
                }
            }
            this.Label1.Text = GetTran("001045", "共") + " " + RCount + " " + GetTran("001049", "条记录 ") + " " + GetTran("000156", "第") + " " + (PageIndex).ToString() + " " + GetTran("001055", "页") + " " + PageCount + GetTran("001055", "页");
        }
        else
        {
            Page.ClientScript.RegisterStartupScript(GetType(), "", "<script language='javascript'>alert('" + GetTran("000760", "对不起,找不到指定条件的记录 ") + "')</script>");
        }
    }