Calculating a ASPxGridview Column in DevExpress

2020-05-09 10:02发布

问题:

I have a ASPxGridview (Normally 21 column but i just want process 4 column).

Every column has a decimal value. MV_EDDIE column is empty.

What i want is, calculating programmaticly ,MV_EDDIE columns is RISK_EUR - (IPOTEK + MV_BERND) only in GroupSummary and TotalSummary.

For example; If

RISK_EUR = 100
IPOTEK = 40
MV_BERND = 50

Then MV_EDDIE column should be 100 - (40 + 50) = 10

How can i do that?

NOTE: I have a Sql like this

SELECT A.HESAP_NO, A.TEKLIF_NO1 || '/' || A.TEKLIF_NO2 AS TEKLIF,
            A.MUS_K_ISIM, A.RISK,
            (CASE WHEN A.DOVIZ_KOD = 21 THEN 'EUR' WHEN A.DOVIZ_KOD = 2 THEN 'USD' WHEN A.DOVIZ_KOD = 1 THEN 'TL' END) AS DOVIZ,
            ROUND(KRISK_CV(A.TEKLIF_NO1, A.TEKLIF_NO2,A.DOVIZ_KOD,:TAR),2) AS RISK_EUR,
            NVL(IPOTEK(A.HESAP_NO, :TAR),0) AS IPOTEK, 
            ROUND(SUM(M_V(A.TEKLIF_NO1, A.TEKLIF_NO2,:TAR)),2) AS MV_BERND,
            ROUND(SUM(MV_EX(A.TEKLIF_NO1, A.TEKLIF_NO2,:TAR)),2) AS MV_EDDIE, 
            (CASE WHEN ROUND(SUM(MV_K(A.TEKLIF_NO1, A.TEKLIF_NO2,:TAR)),2) < 0 THEN 
            ROUND(SUM(MV_EX(A.TEKLIF_NO1, A.TEKLIF_NO2,:TAR)),2) ELSE  
            ROUND(SUM(MV_K(A.TEKLIF_NO1, A.TEKLIF_NO2,:TAR)),2) END) AS MV_KASKO,
           B.TARIH, GGUNK(A.TEKLIF_NO1,A.TEKLIF_NO2,:TAR) AS GUN
            FROM S_TEKLIF A, TMP_TAKIP B 
            WHERE A.HESAP_NO = B.HESAP 
            --AND A.HESAP_NO = 316
            AND A.RISK > 0 
            GROUP BY B.TARIH, A.HESAP_NO, A.TEKLIF_NO1 || '/' || A.TEKLIF_NO2 ,
            A.MUS_K_ISIM, GGUNK(A.TEKLIF_NO1,A.TEKLIF_NO2,:TAR),
            A.RISK, A.DOVIZ_KOD,KRISK_CV(A.TEKLIF_NO1, A.TEKLIF_NO2,A.DOVIZ_KOD,:TAR)
            ORDER BY 3

NOTE 2: I can solve this problem changing my sql query, but i don't want it. My query is complicated already. I don't want change it. Because of that, i want to solve it programmaticly ..

EDIT: I want calculate it only GroupSummary and TotalSummary. Not other row.

回答1:

If anyone consider the answer i found it.

protected void ASPxGridView1_Init(object sender, EventArgs e)
  {
      GridViewDataTextColumn colTotal = new GridViewDataTextColumn();
      colTotal.Caption = "Total";
      colTotal.FieldName = "Total";
      colTotal.UnboundType = DevExpress.Data.UnboundColumnType.Decimal;
      colTotal.VisibleIndex = ASPxGridView1.VisibleColumns.Count;
      colTotal.PropertiesTextEdit.DisplayFormatString = "n0";
      ASPxGridView1.Columns.Add(colTotal);

  }

protected void ASPxGridView1_CustomUnboundColumnData(object sender, ASPxGridViewColumnDataEventArgs e)
  {
      if (e.Column.FieldName == "Total")
      {
          decimal risk = Convert.ToDecimal(e.GetListSourceFieldValue("RISK"));
          decimal mv = Convert.ToDecimal(e.GetListSourceFieldValue("MV_BERND"));
          decimal ipotek = Convert.ToDecimal(e.GetListSourceFieldValue("IPOTEK"));


          e.Value = risk - mv - ipotek;
      }

  }