循环使用转发器以使用foreach方法计算行值

时间:2013-02-17 15:18:15

标签: c# asp.net .nettiers

我创建了一个名为GetCarriersAssest()的方法。我想循环遍历转发器的每一行并获得总值。问题是,当我向转发器添加新项目时,它会计算相同的值,而不是新值。例如,我将输入值为1122的第一个项目,该项目将添加到表格中,但是当我添加第二个项目时,值为700.该表格将添加第一个输入的值,总计1122 +1122,而不是1122 + 700。这是我的代码。

//获取运营商资产

public string GetCarrierAmount(int LoadID)
{
    LkupAccessorialsService lkupaccessorialssvc = new LkupAccessorialsService();
    LkupAccessorialsQuery lkupaccessorialsquery = new LkupAccessorialsQuery();
    AccessorialsService accessorialsvc = new AccessorialsService();
    AccessorialsQuery accessorialsquery = new AccessorialsQuery();
    int carrieraccessorialtotal = 0;

    string getcarrieridfromtblaccessorials = "Select CarrierID From tblLkupAccessorials WHERE LoadId='" + LoadID + "' AND tblLkupAccessorials .AccessorialFlag LIKE '%1%' ";
    lkupaccessorialsquery.AppendInQuery(LkupAccessorialsColumn.CarrierId, getcarrieridfromtblaccessorials);

    TList<LkupAccessorials> tlstcarrieridfromtblaccessorials = DataRepository.LkupAccessorialsProvider.Find(lkupaccessorialsquery.GetParameters());
    if (tlstcarrieridfromtblaccessorials.Count == 0)
    {
        return "0";
    }
    else
    {
        string getcarrieraccessorialamount = "Select AccessorialTypeId From tblLkupAccessorials WHERE CarrierID='" + tlstcarrieridfromtblaccessorials[0].CarrierId + "'AND LoadId='" + LoadID + "' ";
        lkupaccessorialsquery.AppendInQuery(LkupAccessorialsColumn.AccessorialTypeId, getcarrieraccessorialamount);

        TList<LkupAccessorials> tlstcarrieraccessorialamount = DataRepository.LkupAccessorialsProvider.Find(lkupaccessorialsquery.GetParameters());

        string getaccessorialamountbyid = "Select Amount From tblAccessorials WHERE AccessorialTypeID='" + tlstcarrieraccessorialamount[0].AccessorialTypeId + "'";

        if (tlstcarrieraccessorialamount[0].AccessorialFlag == 1)
        {
            accessorialsquery.AppendInQuery(AccessorialsColumn.Amount, getaccessorialamountbyid);
            TList<Accessorials> tlstaccessorialamount = DataRepository.AccessorialsProvider.Find(accessorialsquery.GetParameters());

            foreach (RepeaterItem item in rptaccessorialtype.Items)
            {
                int i;
                Label lblcarriergetaccessorialtotal = item.FindControl("lblcarrieraccessorialtotal") as Label;
                if (tlstaccessorialamount.Count == 0)
                {
                    return "0";
                }
                else
                {
                     for (i = 0; i < rptaccessorialtype.Items.Count; i++)
                     {
                          lblcarriergetaccessorialtotal.Text = tlstaccessorialamount[i].Amount.ToString();
                          int carrieraccessorialrate = Convert.ToInt32(lblcarriergetaccessorialtotal.Text);
                          carrieraccessorialtotal = carrieraccessorialtotal + carrieraccessorialrate;
                      }
                  }
                return carrieraccessorialtotal.ToString();
            }
        }
        return carrieraccessorialtotal.ToString();
    }
}

0 个答案:

没有答案