Exemplo n.º 1
0
        private void imperialbutton_Click(object sender, EventArgs e)

        //imperial button
        {
            double sum1          = 0;
            var    time          = Length.ToString(); //initiate variable for length of session
            double seconds       = TimeSpan.Parse(time).TotalSeconds;
            double secondslength = seconds / 3600;    //convert the time of session to seconds



            for (int i = 0; i < dataGridView1.Rows.Count; ++i)
            {
                sum1 += Convert.ToInt32(dataGridView1.Rows[i].Cells["speed"].Value);
            }

            int count_row = dataGridView1.Rows.Count;

            double avespeed;
            double distance;

            GetCalculations calc = new GetCalculations();

            avespeed = calc.CalculateAverage(sum1, count_row);
            distance = calc.CalculateDistance(secondslength, avespeed);

            var MaxID_1 = dataGridView1.Rows.Cast <DataGridViewRow>()
                          .Max(r => Convert.ToInt32(r.Cells["speed"].Value));

            var lines = File.ReadAllLines(openFileDialog1.FileName);

            foreach (var line in lines)
            {
                if (line.StartsWith("SMode="))
                {
                    SMode = int.Parse(line.Replace("SMode=", " "));



                    string     unit_output;
                    string     ret = SMode.ToString();
                    SModeIndex n   = new SModeIndex();
                    unit_output = n.indexing(ret);

                    switch (unit_output)
                    {
                    case "0":     //Convert to miles using ConvertUnits class

                        double mphavg    = ConvertUnits.ConvertKilometersToMiles(avespeed);
                        double maxmph    = ConvertUnits.ConvertKilometersToMiles(MaxID_1);
                        double distmiles = ConvertUnits.ConvertKilometersToMiles(distance);


                        speedcal.Text = "Average Speed:" + mphavg.ToString("N2") + " mph" + System.Environment.NewLine
                                        + System.Environment.NewLine + "Max Speed:"
                                        + maxmph.ToString("N2") + " mph"
                                        + System.Environment.NewLine + System.Environment.NewLine
                                        + "Total Distance covered:" + distmiles.ToString("N2") + " Miles";

                        break;

                    case "1":     //convert to kilometres using ConvertUnits class

                        double kphave    = ConvertUnits.ConvertMilesToKilometers(avespeed);
                        double maxkph    = ConvertUnits.ConvertMilesToKilometers(MaxID_1);
                        double distkilos = ConvertUnits.ConvertMilesToKilometers(distance);


                        speedcal.Text = "Average Speed:" + kphave.ToString("N2") + " mph" + System.Environment.NewLine
                                        + System.Environment.NewLine + "Max Speed:"
                                        + maxkph.ToString("N2") + " mph"
                                        + System.Environment.NewLine + System.Environment.NewLine
                                        + "Total Distance covered:" + distkilos.ToString("N2") + " Miles";

                        break;
                    }

                    ConvertUnits unitsclass = new ConvertUnits("Distance and Speed units have been changed to Miles");
                }
            }
        }
Exemplo n.º 2
0
        private void Metricbutton_click(object sender, EventArgs e)
        {
            //metric button
            {
                double sum1          = 0;
                var    time          = Length.ToString(); //initiate variable for length of session
                double seconds       = TimeSpan.Parse(time).TotalSeconds;
                double secondslength = seconds / 3600;    //convert the time of session to seconds



                for (int i = 0; i < dataGridView1.Rows.Count; ++i)
                {
                    sum1 += Convert.ToInt32(dataGridView1.Rows[i].Cells["speed"].Value);
                }

                int count_row = dataGridView1.Rows.Count;

                double avespeed;
                double distance;

                GetCalculations calc = new GetCalculations();
                avespeed = calc.CalculateAverage(sum1, count_row);
                distance = calc.CalculateDistance(secondslength, avespeed);

                var MaxID_1 = dataGridView1.Rows.Cast <DataGridViewRow>()
                              .Max(r => Convert.ToInt32(r.Cells["speed"].Value));

                var lines = File.ReadAllLines(openFileDialog1.FileName);
                foreach (var line in lines)
                {
                    if (line.StartsWith("SMode="))
                    {
                        SMode = int.Parse(line.Replace("SMode=", " ")); //find out if the eight character in SMode from the input file is a "0"  or a "1"



                        string     unit_output;
                        string     ret = SMode.ToString();
                        SModeIndex n   = new SModeIndex();
                        unit_output = n.indexing(ret);

                        switch (unit_output)
                        {
                        case "0":     //if "0" then units are displayed in kilometres

                            speedcal.Text = "Average Speed:" + avespeed.ToString("N2") + " kph" + System.Environment.NewLine
                                            + System.Environment.NewLine + "Max Speed:"
                                            + MaxID_1.ToString("N2") + " kph"
                                            + System.Environment.NewLine + System.Environment.NewLine
                                            + "Total Distance covered:" + distance.ToString("N2") + " kilometres";



                            break;

                        case "1":     //if "1" units are displayed in miles

                            double mphavg    = ConvertUnits.ConvertKilometersToMiles(avespeed);
                            double maxmph    = ConvertUnits.ConvertKilometersToMiles(MaxID_1);
                            double distmiles = ConvertUnits.ConvertKilometersToMiles(distance);


                            speedcal.Text = "Average Speed:" + mphavg.ToString("N2") + " mph" + System.Environment.NewLine
                                            + System.Environment.NewLine + "Max Speed:"
                                            + maxmph.ToString("N2") + " mph"
                                            + System.Environment.NewLine + System.Environment.NewLine
                                            + "Total Distance covered:" + distmiles.ToString("N2") + " Miles";

                            break;
                        }
                    }
                }
            }
        }