コード例 #1
0
ファイル: File.cs プロジェクト: Topgun122104/SeniorProj
        /// <summary>
        /// Loads a track from an excel file
        /// </summary>
        /// <param name="filename"></param>
        private static void LoadExcelFile(object filename)
        {
            ExcelParser parser = new ExcelParser(filename.ToString());
            parser.processData();
            try
            {
                ProgressBoxForm progress = new ProgressBoxForm();
                progress.CurCircuit.Text = "";
                progress.Show();

                DatabaseConnection conn = new DatabaseConnection(
                    Config.ConfigManager.Database,
                    Config.ConfigManager.Port,
                    Config.ConfigManager.DatabaseName,
                    Config.ConfigManager.UserName,
                    Config.ConfigManager.Password);
                conn.openConnection();

                progress.progressBar1.Maximum = TrackLayout.Track.Count - 1;
                progress.progressBar1.Step = 1;
                int current = 1;
                Cursor.Current = Cursors.WaitCursor;
                foreach (TrackSegment t in TrackLayout.Track)
                {
                    DatabaseOperations.InsertIntoDatabase(conn, t);
                    progress.progressBar1.PerformStep();
                    progress.CurCircuit.Text = "Currently processing Track Circuit " + current + " of " + TrackLayout.Track.Count + "...";
                    current++;
                    progress.CurCircuit.Refresh();
                    Thread.Sleep(500);
                }
                Cursor.Current = Cursors.Default;
                progress.Close();
                conn.closeConnection();
            }
            catch (Exception ex)
            {
                LogManager.Logger.Log(ex);
            }
            parser.cleanUp();
        }
コード例 #2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="worksheet"></param>
        public void FillTrack()
        {
            ProgressBoxForm progressBox = new ProgressBoxForm();
            progressBox.Show();
            try
            {

                ExcelSheet sheet = new ExcelSheet();
                using (StreamReader file = new StreamReader(mFilename))
                {
                    string line = null;
                    string[] row;
                    string tempDir = null;
                    string tempMove = null;
                    // Get to the data
                    while (line == null || line.Split(',')[1] != "Track")
                    {
                        line = file.ReadLine();
                    }

                    // Parse the data
                    while ((line = file.ReadLine()) != null)
                    {
                        row = line.Split(',');
                        // If this cell does not have data then there is no more data.
                        if (row[4] == "")
                        {
                            break;
                        }

                        if (row[2] != "")
                        {
                             tempDir = row[2];
                        }

                         if(row[3] != "")
                         {
                              tempMove = row[3];
                         }

                        /*
                         * Column Name      |   Column Number
                         * Direction        |         1
                         * Move             |         2
                         * Track            |         3
                         * Circuit          |         4
                         * Brake Location   |         5
                         * Target Location  |         6
                         * Worst Grade      |         8
                         * Entry Speed      |         9
                         * Overspeed        |         10
                         * Acceleration     |         12
                         * Reaction Time    |         14
                         * Brake Rate       |         16
                         * Runaway Accel    |         19
                         * Propulsion Remov |         21
                         * Brake Build up   |         23
                         * Overhang Dist    |         25
                         */
                        TrackSegment curRow = new TrackSegment(
                                                    tempDir,
                                                    tempMove,
                                                    row[4],                                             // Circuit
                                                    Convert.ToInt32(row[5]),                            // Brake Location
                                                    Convert.ToInt32(row[6]),                            // Target Location
                                                    Convert.ToDouble(row[7]),                           // Worst Grade
                                                    Convert.ToDouble(row[8]),                           // Entry Speed
                                                    Convert.ToDouble(row[9]),                          // Overspeed
                                                    Convert.ToDouble(row[10]),                          // Acceleration
                                                    Convert.ToDouble(row[11]),                          // Reaction Time
                                                    Convert.ToDouble(row[12]),                          // Brake Rate
                                                    Convert.ToDouble(row[13]),                          // Runaway Accel
                                                    Convert.ToDouble(row[14]),                          // Propulsion Removal
                                                    Convert.ToInt32(row[15]),                           // Brake Build Up
                                                    Convert.ToInt32(row[16]));                          // Overhand Distance

                        TrackLayout.Track.Add(curRow);
                        progressBox.progressBar1.PerformStep();
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("Error Loading File: " + e.ToString());
            }

            progressBox.Close();
        }
コード例 #3
0
ファイル: File.cs プロジェクト: Topgun122104/SeniorProj
        /// <summary>
        /// Load a saved track 
        /// </summary>
        public static void LoadTrack()
        {
            Stream myStream = null;
            OpenFileDialog openFileDialog1 = new OpenFileDialog();
            openFileDialog1.Filter = "xml files (*.xml)|*.xml*";
            openFileDialog1.FilterIndex = 0;
            openFileDialog1.RestoreDirectory = true;

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if ((myStream = openFileDialog1.OpenFile()) != null)
                    {
                        ProgressBoxForm progress = new ProgressBoxForm();

                        progress.Show();
                        using (myStream)
                        {

                            XDocument segment = XDocument.Load(openFileDialog1.FileName);
                            var result = from q in segment.Descendants("TrackSegment")
                                         select new TrackSegment
                                         {
                                             TrackCircuit = q.Element("Circuit").Value,
                                             BrakeLocation = int.Parse(q.Element("BrakeLocation").Value),
                                             TargetLocation = int.Parse(q.Element("TargetLocation").Value),
                                             GradeWorst = double.Parse(q.Element("GradeWorst").Value),
                                             SpeedMax = double.Parse(q.Element("SpeedMax").Value),
                                             OverSpeed = double.Parse(q.Element("OverSpeed").Value),
                                             VehicleAccel = double.Parse(q.Element("VehicleAccel").Value),
                                             ReactionTime = double.Parse(q.Element("ReactionTime").Value),
                                             BrakeRate = double.Parse(q.Element("BrakeRate").Value),
                                             RunwayAccelSec = double.Parse(q.Element("RunwayAccelSec").Value),
                                             PropulsionRemSec = double.Parse(q.Element("PropulsionRemSec").Value),
                                             BrakeBuildUpSec = int.Parse(q.Element("BrakeBuildUpSec").Value),
                                             OverhangDist = int.Parse(q.Element("OverhangDist").Value),
                                         };
                            foreach (var item in result)
                            {
                                TrackLayout.Track.Add(item);

                                progress.progressBar1.Increment(result.Count());
                                Thread.Sleep(100);
                            }

                        }
                        progress.Close();
                    }

                }
                catch (Exception ex)
                {
                    LogManager.Logger.Log(ex);
                }

            }
        }