Click here to Skip to main content
15,895,256 members
Home / Discussions / C#
   

C#

 
AnswerRe: How do I start programs from a C# program? Pin
Gareth H5-May-08 22:37
Gareth H5-May-08 22:37 
AnswerRe: How do I start programs from a C# program? Pin
Reelix5-May-08 22:41
Reelix5-May-08 22:41 
QuestionHow to ship my test certificate into the clients machine using c# Pin
ananthrahul5-May-08 22:26
ananthrahul5-May-08 22:26 
Questionsolving maze program Pin
sobu5-May-08 22:22
sobu5-May-08 22:22 
AnswerRe: solving maze program Pin
Abhijit Jana5-May-08 22:47
professionalAbhijit Jana5-May-08 22:47 
AnswerRe: solving maze program Pin
Reelix5-May-08 22:52
Reelix5-May-08 22:52 
AnswerRe: solving maze program Pin
PIEBALDconsult6-May-08 5:45
mvePIEBALDconsult6-May-08 5:45 
QuestionKeeping count of total Pin
MumbleB5-May-08 21:36
MumbleB5-May-08 21:36 
Hi Guys. In my app that I am working on I am importing a csv file into a FileHelpers engine. I take the one field from the res and use it to look up a description for it in another function, validate pcode.

I then write the output of the res + prov to a textbox. I then write the textbox data to a .txt file using StreamWriter.

I need to keep count of the totals of each prov I find. There are a total of 9 provinces and I need to list a total of each province. Can sombody advise me on the easiest way of doiing this? Below my code.

This is where I do the validation to find the appropriate province.

My apologies for the lengthy post

private string SearchPcode(string inputStr)
{
    string retval = "";
    int pcode = 0;
    if (!int.TryParse(inputStr, out pcode))
    {
        retval = "Invalid Integer!";
    }
    else if ((pcode >= 4731) && (pcode <= 6499))
    {
        retval = "Eastern Cape";
    }
    else if ((pcode >= 9300) && (pcode <= 9999))
    {
        retval = "Free State";
    }
    else if ((pcode >= 0001) && (pcode <= 0299)
        || (pcode >= 1400) && (pcode <= 2199))
    {
        retval = "Gauteng";
    }
    else if ((pcode >=2900) && (pcode <= 4730))
    {
        retval = "Kwazulu Natal";
    }
    else if ((pcode >= 0500) && (pcode <= 0999))
    {
        retval = "Limpopo";
    }
    else if ((pcode >= 1000) && (pcode <= 1399)
        || (pcode >= 2200) && (pcode <= 2499))
    {
        retval = "Mpumalanga";
    }
    else if ((pcode >= 0300) && (pcode <= 0499)
        || (pcode >= 2500) && (pcode <= 2899))
    {
        retval = "North West Province";
    }
    else if ((pcode >= 8100) && (pcode <= 8999))
    {
        retval = "Northern Cape";
    }
    else if ((pcode >= 6500) && (pcode <= 8099))
    {
        retval = "Western Cape";
    }
    else
    {
        retval = "Invalid PostCode";
    }
    return retval;
}


This is the import for the csv file where I instantiate the search for the province.

private void btnOpenFile_Click(object sender, EventArgs e)
{
    txtboxDisplay.Text = "";
    txtboxPcode.Text = "";
    if (openFileDialog1.ShowDialog() != DialogResult.OK)
    {
        return;
    }
    else
    {
        txtboxSelectFile.Text = openFileDialog1.FileName;
    }
    string filePath;
    filePath = txtboxSelectFile.Text;

    FileHelperEngine<CsvImp> engine = new FileHelperEngine<CsvImp>();

    engine.ErrorManager.ErrorMode = ErrorMode.SaveAndContinue;

    CsvImp[] res = engine.ReadFile(filePath);
    StreamWriter sw = new StreamWriter(@"C:\SOLZ_PROV_" +
        DateTime.Now.ToString("ddMMyyhhmmss") + ".txt");
    if (engine.ErrorManager.ErrorCount > 0)
        engine.ErrorManager.SaveErrors("Errors.txt");
    foreach (CsvImp imp in res)
    {
        string prov = SearchPcode(imp.CallComments); //Search for province
        txtboxDisplay.Text += imp.CompanyCode + "\t"
            + imp.CallType + "\t"
            + imp.CallComments.ToString()
            + "\t" + prov + Environment.NewLine;
    }

        sw.WriteLine(txtboxDisplay.Text);
        sw.Close();
    }


Please advise the easiest way of keeping track and writing the totals for each province.

Excellence is doing ordinary things extraordinarily well.

AnswerRe: Keeping count of total Pin
Christian Graus5-May-08 21:58
protectorChristian Graus5-May-08 21:58 
GeneralRe: Keeping count of total Pin
MumbleB5-May-08 23:39
MumbleB5-May-08 23:39 
GeneralRe: Keeping count of total Pin
Christian Graus6-May-08 1:13
protectorChristian Graus6-May-08 1:13 
GeneralRe: Keeping count of total Pin
MumbleB6-May-08 1:25
MumbleB6-May-08 1:25 
GeneralRe: Keeping count of total Pin
Christian Graus6-May-08 1:29
protectorChristian Graus6-May-08 1:29 
GeneralRe: Keeping count of total Pin
Christian Graus6-May-08 22:15
protectorChristian Graus6-May-08 22:15 
GeneralRe: Keeping count of total Pin
MumbleB7-May-08 1:56
MumbleB7-May-08 1:56 
GeneralRe: Keeping count of total Pin
Christian Graus7-May-08 11:56
protectorChristian Graus7-May-08 11:56 
QuestionDisplaying a form from en existing form Pin
Berlus5-May-08 21:35
Berlus5-May-08 21:35 
AnswerRe: Displaying a form from en existing form Pin
Abhijit Jana5-May-08 21:55
professionalAbhijit Jana5-May-08 21:55 
AnswerRe: Displaying a form from en existing form Pin
Christian Graus5-May-08 22:00
protectorChristian Graus5-May-08 22:00 
QuestionCheckBox in ListView Pin
stancrm5-May-08 21:28
stancrm5-May-08 21:28 
AnswerRe: CheckBox in ListView Pin
Christian Graus5-May-08 22:09
protectorChristian Graus5-May-08 22:09 
QuestionIndexers Pin
Steve Declerck5-May-08 20:44
Steve Declerck5-May-08 20:44 
AnswerRe: Indexers Pin
Vikram A Punathambekar5-May-08 20:59
Vikram A Punathambekar5-May-08 20:59 
GeneralRe: Indexers Pin
Steve Declerck5-May-08 23:15
Steve Declerck5-May-08 23:15 
AnswerRe: Indexers Pin
PIEBALDconsult6-May-08 6:05
mvePIEBALDconsult6-May-08 6:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.