开发者

Array to Return Year End Balances For The Past Five Years - (C#)

开发者 https://www.devze.com 2023-03-02 15:32 出处:网络
I am trying to return only the year end information (December 31) for the past five years and display that information in a DataGrid. This does not include the current year.

I am trying to return only the year end information (December 31) for the past five years and display that information in a DataGrid. This does not include the current year.

My program is currently displaying month's end information from the previous year up to the last day of the most recent month in the current year (Example: The current month is May 2011 and the information being displayed in my DataGrid shows the data stored on Jan. 31, 2010; Feb. 28, 2010; Mar. 31, 2010....Dec. 31, 2010; Jan. 31, 2011; Feb. 28, 2011; Mar. 31, 2011; Apr. 30, 2011).

It also adds a totals row after Dec. 31, 2010 and another after Apr. 30, 2011. These two totals rows will not be needed in the new DataGrid.

Below is a snippet of the current code which is returning the months end information.

Please let me know if I left any information out or am not clear on my question.

I apologize in advance for such a rookie question, it has just been driving me crazy the past couple days that I cannot figure this out.

protected DataSet DS;
protected DataRow dr, dNew;

private void GetInfo()
{

}

private double getDbl(string columnName)
{
    if (dr[columnName] != DBNull.Value)
        return Double.Parse(dr[columnName].ToString());
    return 0;
}

private void Calculate()
{
    double cg, na, n, ka, nka, kaa, tca;
    double tmr, to, gpo;
    int year, rowcnt, rowindx, months;

    months = -1;
开发者_如何学Go    rowindx = 0;
    cg = 0;
    na = 0;
    n = 0;
    ka = 0;
    nka = 0;
    kaa = 0;
    tca = 0;
    tmr = 0;
    tor = 0;
    gpo = 0;

    rowcnt = DS.Tables[0].Rows.Count;

    if (rowcnt > 0) year = Int32.Parse(DS.Tables[0].Rows[0]["cy"].ToString());
    else year = 0;

    for (int i = 0; i < rowcnt; i++)
    {
        months++;
        dr = DS.Tables[0].Rows[i]

        if (year != Int32.Parse(dr["cy"].ToString())
        {
            dNew = DS.Tables[0].NewRow();
            dNew["ind"] = rowindx;
            dNew["cg"] = cg;
            dNew["na"] = na;
            dNew["n"] = n;
            dNew["ka"] = ka / months;
            dNew["nka"] = nka / months;
            dNew["kaa"] = kaa / months;
            dNew["tca"] = tca / months;
            dNew["tmr"] = tmr / months;
            dNew["tor"] = tor;
            dNew["gpo"] = gpo / months;

            cg = 0;
            na = 0;
            n = 0;
            ka = 0;
            nka = 0;
            kaa = 0;
            tca = 0;
            tmr = 0;
            tor = 0;
            gpo = 0;
            months = 1;
            year = Int32.Parse(dr["cy"].ToString());
            rowindx++;

            DS.Tables[0].Rows.Add(dNew);

            dNew = DS.Tables[0].NewRow();
            dNew["ind"] = rowindx;
            rowindx++;
            DS.Tables[0].Rows.Add(dNew);
        }

        cg += getDbl("cg");
        na += getDbl("na");
        n += getDbl("n");
        ka += getDbl("ka");
        nka += getDbl("nka");
        kaa += getDbl("kaa");
        tca += getDbl("tca");
        tmr += getDbl("tmr");
        tor += getDbl("tor");
        gpo += getDbl("gpo");
        dr["ind"] = rowindx;
        rowindx++;
    }

    dNew = DS.Tables[0].NewRow();
    dNew["ind"] = rowindx;
    dNew["cg"] = cg;
    dNew["na"] = na;
         dNew["n"] = naum;
         dNew["ka"] = ka / months;
         dNew["nka"] = nka / months;
         dNew["kaa"] = kaa / months;
         dNew["tca"] = tca / months;
         dNew["tmr"] = tmr / months;
         dNew["tor"] = tor;
         dNew["gpo"] = gpo / months;
         DS.Tables[0].Rows.Add(dNew);

      DS.Tables[0].DefaultView.Sort = "ind";
}


Have you tried limiting the dataset query to just the year the you want?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号