6

私はASPxGridviewこのようなものを持っています:

ここに画像の説明を入力

Grouping なしGroupSummaryでtoの Total を計算する方法はありますか。TotalSummary

GroupSummary's  SummeryType="AVERAGE"

例えば:

MUS_K_ISIM   GroupSummary[RISK_EUR]
2M LOJİSTİK  123.456 
ABA LOJİSTIK 234.567 

次に、必要TotalSummaryRISK_EUR列は 123.456 + 234.567 =358023です。

:通常のGridviewでのみこの計算が必要です。グループ化とは関係ありません。

もう一つの例:

Customer_No Customer_Name Price
123         aaa           50
123         aaa           100
123         aaa           60
124         bbb           60
125         ccc           20
125         ccc           40

私はそのグリッドで欲しい:

What is avarage of 123 number customer = 50 + 100 + 60 = 210/3= 70
What is avarage of 124 number customer = 60/1=60
What is avarage of 125 number customer = 20 + 40 = 60/2= 30

そして、価格の TotalSummary は = 70 + 60 + 30 = 160 です。

どうやってやるの?または、このコードは何ですか?どの機能を使用すればよいですか?

4

2 に答える 2

3

2 つの異なるソリューションが表示されます。

1) データ管理を手動で実装します。a
) 疑似グループ列でデータを並べ替えます。b) 並べ替えられたデータ リストを参照し、集計値を手動で計算し、最終的にこの値を表示します。

2) ページに新しいグリッドを作成し、それをデータにバインドし、必要な列でグループ化し、集計値を取得して、最後に破棄します。

2 番目のアプローチは確認しませんでしたが、このアプローチが機能しない理由がわかりません。

アップデート

カスタム集計を使用している場合のみ、集計値を設定できます。これは、CustomSummaryCalculate イベント ハンドラー内で実行できます。また、集計値を取得するには、次のコードを使用できます。

double total = 0;
                for(int i = 0; i < ASPxGridView1.VisibleRowCount; i ++) {
                    total += Convert.ToDouble(ASPxGridView1.GetGroupSummaryValue(i, someSummaryItem));
                }

このようなものを実装する必要があります。

Update 2 わかりました。この問題に対する最も効果的な解決策を見つけたと思います。説明させてください。まず、カスタム サマリーのトピックで説明されているように、カスタム サマリーを使用する必要があります。CustomSummaryCalculate イベント ハンドラーを使用して、データを Dictionary オブジェクトに収集する必要があります。このオブジェクトのキーには、Customer_No フィールド値、value - この Customer の Price 値のリストが含まれます。最後に、結果の要約を計算する必要があります。以下は、ASPx と C# の両方の完全なコードです。お役に立てば幸いです。

    <dx:ASPxGridView ID="ASPxGridView1" runat="server" OnCustomSummaryCalculate="ASPxGridView1_CustomSummaryCalculate">
        <TotalSummary>
            <dx:ASPxSummaryItem FieldName="Price" SummaryType="Custom" ShowInColumn="Price" />
        </TotalSummary>
        <Settings ShowFooter="True" />
    </dx:ASPxGridView>

...

using System;
using System.Collections.Generic;
using System.Data;
using System.Collections;

    protected void Page_Init(object sender, EventArgs e) {
        ASPxGridView1.DataSource = GetDataSource();
        ASPxGridView1.DataBind();
    }

    private object CreateDataSource() {
        DataTable table = new DataTable();
        table.Columns.Add("Customer_No", typeof(int));
        table.Columns.Add("Price", typeof(int));
        table.Rows.Add(new object[] {123, 50 });
        table.Rows.Add(new object[] {123, 100 });
        table.Rows.Add(new object[] {123, 60 });
        table.Rows.Add(new object[] {124, 60 }); 
        table.Rows.Add(new object[] {125, 20 });
        table.Rows.Add(new object[] {125, 40 });
        return table;
    }
    private object GetDataSource() {
        if(Session["data"] == null)
            Session["data"] = CreateDataSource();
        return Session["data"];
    }

    Dictionary<int, List<int>> dict;
    protected void ASPxGridView1_CustomSummaryCalculate(object sender, DevExpress.Data.CustomSummaryEventArgs e) {
        if(e.SummaryProcess == DevExpress.Data.CustomSummaryProcess.Start)
            dict = new Dictionary<int, List<int>>();
        if(e.SummaryProcess == DevExpress.Data.CustomSummaryProcess.Calculate) {
            int customer_No = Convert.ToInt32(e.GetValue("Customer_No"));
            List<int> list;
            if(!dict.TryGetValue(customer_No, out list)) {
                list = new List<int>();
                dict.Add(customer_No, list);
            }
            list.Add(Convert.ToInt32(e.GetValue("Price")));
        }
        if(e.SummaryProcess == DevExpress.Data.CustomSummaryProcess.Finalize) {
            e.TotalValue = CalculateTotal();
        }
    }
    private object CalculateTotal() {
        IEnumerator en = dict.GetEnumerator();
        en.Reset();
        float result = 0;
        while(en.MoveNext()) {
            KeyValuePair<int, List<int>> current = ((KeyValuePair<int, List<int>>)en.Current);
            int sum = 0;
            for(int i = 0; i < current.Value.Count; i++)
                sum += current.Value[i];
            result += sum / current.Value.Count;
        }
        return result;
    }
于 2011-05-10T21:44:09.827 に答える
0

あなたのSQLに値を返させてください:

select (select SUM(x) from foo f2 where f1.x = f2.x) as sum, f1.x from foo f1
于 2011-05-20T05:21:01.673 に答える