0
votes

I have the following on a Winform:

  • Button - to open *.txt file, code already done and works
  • Combo Box - Display the dates found
  • Datagridview - show information for the date selected

Now I want to know how to write the following code to do the following:

  1. Search the txt file for dates (no duplicates)
  2. Show the found dates in a combo box.
  3. Once the person has selected the desired date from the combo box, the information for that date is shown in a datagridview.

I would appreciate any help as i have no working code for this.

What code I have so far is:

private void Historybutton_Click(object sender, EventArgs e)
{
    SSBPgroupBox.Enabled = false;
    DataTable HFdt = new DataTable();
    DialogResult result1 = openFileDialog2.ShowDialog();

    if (result1 == DialogResult.OK) // Test result.
    {

        String Fname = openFileDialog2.FileName;
        string raw_text = System.IO.File.ReadAllText(Fname);


        //add headers to datagrid view
        HFdt.Columns.Add("Sequence");
        HFdt.Columns["Sequence"].DataType = Type.GetType("System.Int32");
        HFdt.Columns.Add("Timing");
        HFdt.Columns["Timing"].DataType = Type.GetType("System.Int32");
    }

    HistorydataGridView.DataSource = HFdt;
}

Sample of text file:

17/05/15-16:40:13:BLAST DRIVER ON

BLASTING PLAN

PU1053 (0005 DETS):

1/7B7C35;11/7B70B2;21/7B7058;31/7B83A1;41/7B70D1;

BLAST SUMMARY

1 PU, 00005 DETS

DELAYS MIN/MAX IN MS : 00001 / 00041

GAP MIN/MAX IN MS : 00010 / 00010

16:40:32:LINE TEST

CALIBRATION

EXTRA DETS :None

INTERMITTENT CONNECTION DETS :None

TEST DETS

MISSING DETS :None

OUT OF ORDER DETS :None

INCOHERENT DETS :None

DELAY ERRORS DETS :None

16:41:52:TEST END

16:44:02:CHARGE

CHECK ENERGIE

ADDITIONAL MISSING DETS :None

LOW ENERGY DETS :None

ADDITIONAL INCOHERENT DETS :None

16:44:29:FIRE

What I want exactly is to show the date as follows in the combo box:

17/05/15 - 0005 Dets

When the user selects this date the datagridview will show:

Sequence    Timing

1           1

2           11

3           21

4           31

5           41

I added the following code to get the text file displayed in the listbox. I am still trying to only display the dates:

String Fname = openFileDialog2.FileName;
            string[] raw_text = System.IO.File.ReadAllLines(Fname);
            var lines = new List<string>();
            foreach (var line in File.ReadLines(Fname))

            {
                listBox1.Items.Add(line);
            }
1
This depends in how the contents if the file are structured. - Chetan
How can I get a copy of the file to you? - Hendrik Sidaway
Please add sample data from your file to your post. - Filburt
Can you share some of sample data from the file here and tell us what should be searched and how it should be searched? And what should be the output based on the sample data? - Chetan
This looks like some standards file format specific to certain industry or business domain. You really don't have any existing parser for such files? - Chetan

1 Answers

0
votes
public class Info
    {
        public string _Info { get; set; }
        public DateTime _Date { get; set; }

    }

        List<Info> infos = new List<Info>();
        //Onload - insert infos from *txt file


        List<DateTime> dates = infos.GroupBy(x => x._Date).Select(y => y.First()).Select(z=>z._Date).ToList();
        //no duplicates dates

        List<string> dateInfos = infos.Where(x => x._Date == selectedDate).Select(z=>z._Info).ToList();
        //show infos for selected date