Windows From

Discussion in 'Software' started by jcast, Apr 25, 2012.

  1. jcast

    jcast Private E-2

    Hi I am new to programminh and I am trying to display the whole list of my array into a textbox in windows form:

    private void btnLoadCDR_Click(object sender, EventArgs e)
    {
    string inputString = txtInput.Text;
    var inputList = inputString.Split('\n');
    var accountSvc = new Shared.Core.Account.AccountSvc();

    foreach (string phoneNumber in inputList)
    {
    var history = accountSvc.GetCallDurationRecords(phoneNumber, DateTime.Parse("01/01/12"), DateTime.Parse("04/14/2012"));
    var calledType = history[0].CallType;


    txtOut.Text += string.Format("{0}:{1},{2},{3}", phoneNumber, history[31].CalledNumber, history[31].CallType, history[31].Cost) + Environment.NewLine;

    }
    }

    I can get the record of the array 31 for example but how do I get all the records all in one.?
     
  2. Wyatt_Earp

    Wyatt_Earp MajorGeek

    Since it's hard to tell the structure of your data from the post, I'll give it a shot.

    It sounds like you need another loop, e.g.

    Code:
    // Also don't forget to initialize txtOut.Text
    txtOut.Text = string.Empty;
    
    foreach (string phonNumber in inputList)
    {
    [INDENT]string inputString = txtInput.Text;
    var inputList = inputString.Split('\n');
    var accountSvc = new Shared.Core.Account.AccountSvc();
    
    txtOut.Text += string.Format("{0}:\r\n", phoneNumber);
    
    foreach (var histItem in history)
    {
    [INDENT]txtOut.Text += string.Format("- {0},{1},{2}\r\n", histItem.CalledNumber, histItem.CallType, histItem.Cost);[/INDENT]
    }
    [/INDENT]
    }
    
     
  3. jcast

    jcast Private E-2

    Thanks Wyatt; The other loop solves the problem, Another question if I want to get the total of my histItem.Cost; how can I add the value of the cost for each record and display a total cost.

    you think you can help me with that?
     
  4. jcast

    jcast Private E-2

    Here is the code: all the values are displaying fine but I need to get the sum of the cdrRecord.cost in the same txtOut.text.

    Please help me.

    privatevoid btnLoadCDR_Click(object sender,EventArgs e)

    {

    string inputString = txtInput.Text;

    var inputList = inputString.Split('\n');

    var accountSvc = new Shared.Core.Account.AccountSvc();



    foreach (string phoneNumberin inputList)

    {

    var history = accountSvc.GetCallDurationRecords(phoneNumber,DateTime.Parse("01/01/12"),DateTime.Parse("04/14/2012"));



    foreach (var cdrRecordin history)

    {

    if (cdrRecord.CalledNumber == "19402383244" && cdrRecord.Cost > 0)

    {

    txtOut.Text +=string.Format("- {0},{1},{2}\r\n", cdrRecord.CalledNumber, cdrRecord.CallType, cdrRecord.Cost);



    }

    else

    {



    }



    }

    }

    }

    Thanks
     
  5. PC-XT

    PC-XT Master Sergeant

    It will be best to make another variable, something like this: (untested, but edits commented)
    Code:
    privatevoid btnLoadCDR_Click(object sender,EventArgs e)
    
            {
    
               string inputString = txtInput.Text;
    
               var inputList = inputString.Split('\n');
    
               var accountSvc = new Shared.Core.Account.AccountSvc();
    
               float total;//new variable, which I'll initialize in the loop, use an appropriate name: "total" is really just a placeholder...
    
               foreach (string phoneNumberin inputList)
    
                {
    
                   var history = accountSvc.GetCallDurationRecords(phoneNumber,DateTime.Parse("01/01/12"),DateTime.Parse("04/14/2012"));
    
                    total=0.0;//init and reset to 0 for each history
    
                    foreach (var cdrRecordin history)
    
                    {
    
                       if (cdrRecord.CalledNumber == "19402383244" && cdrRecord.Cost > 0)
    
                        {
    
                            txtOut.Text +=string.Format("- {0},{1},{2}\r\n", cdrRecord.CalledNumber, cdrRecord.CallType, cdrRecord.Cost);
    
                          total+=cdrRecord.Cost;//accumulate the total, assuming cdrRecord.Cost is a number
    
                        }
    
                        txtOut.Text+=string.Format("- Total {0}\r\n",total);//put the total at the end
    
                       else
    
                        {
    
     
    
                        }
    
     
    
                    }
    
                }
    
            }
     
  6. jcast

    jcast Private E-2

    Hi; I need to make a new post (New question) and I cannot find where to click to create a new thread. Please let me know cause I need to ask a new question.

    Thanks
     
  7. jcast

    jcast Private E-2

    I figured it out how to make a new post.

    Thanks anyways
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds