private void ImportFiles(FileInfo f) { IndexList = new List<int>(); GPXList = new List<GPXDatenSpeicher>(); XmlTextReader xr = new XmlTextReader(f.FullName); #region Reader while (xr.Read()) { if (Zustand == GPX_Zustände.START) { if (xr.NodeType == XmlNodeType.Element && xr.Name == "gpx") { Zustand = GPX_Zustände.GPX; }// ende if (xr.NodeType == XmlNodeType.Element && xr.Name == "gpx") }//ende if (Zustand == GPX_Zustände.START) else if (Zustand == GPX_Zustände.GPX) { if (xr.NodeType == XmlNodeType.Element && xr.Name == "trk") { Zustand = GPX_Zustände.GPX_TRK; } if (xr.NodeType == XmlNodeType.Element && xr.Name == "wpt") { if (xr.HasAttributes) { while (xr.MoveToNextAttribute()) { if (xr.Name == "lat") akt_lat = xr.ReadContentAsDouble(); if (xr.Name == "lon") akt_lon = xr.ReadContentAsDouble(); } } Zustand = GPX_Zustände.GPX_WPT; }// ende if (xr.NodeType == XmlNodeType.Element && xr.Name == "wpt") } // ende else if (Zustand == GPX_Zustände.GPX) else if (Zustand == GPX_Zustände.GPX_TRK) { if (xr.NodeType == XmlNodeType.Element && xr.Name == "name") { Zustand = GPX_Zustände.GPX_TRK_NAME; } if (xr.NodeType == XmlNodeType.Element && xr.Name == "trkseg") { Zustand = GPX_Zustände.GPX_TRK_TRKSEG; } if (xr.NodeType == XmlNodeType.EndElement && xr.Name == "trk") { Zustand = GPX_Zustände.GPX; } }// ende else if (Zustand == GPX_Zustände.GPX_TRK) else if (Zustand == GPX_Zustände.GPX_WPT) { if (xr.NodeType == XmlNodeType.Element && xr.Name == "ele") { Zustand = GPX_Zustände.GPX_WPT_ELE; } if (xr.NodeType == XmlNodeType.Element && xr.Name == "name") { Zustand = GPX_Zustände.GPX_WPT_NAME; } if (xr.NodeType == XmlNodeType.Element && xr.Name == "cmt") { Zustand = GPX_Zustände.GPX_WPT_CMT; } if (xr.NodeType == XmlNodeType.Element && xr.Name == "desc") { Zustand = GPX_Zustände.GPX_WPT_DESC; } if (xr.NodeType == XmlNodeType.Element && xr.Name == "sym") { Zustand = GPX_Zustände.GPX_WPT_SYM; } if (xr.NodeType == XmlNodeType.EndElement && xr.Name == "wpt") { SQL = "SELECT count(*) FROM tbl_Wegpunkt WHERE Längengrad like '" + akt_lon + "' AND Breitengrad like '" + akt_lat + "' AND Ele like '" + akt_ele + "' AND Name like '" + name + "' AND CMT like '" + cmt + "' AND DESC_Feld like '" + desc + "' AND sym like '" + sym + "'"; m.cmd = new OleDbCommand(SQL, m.con); m.dr = m.cmd.ExecuteReader(); m.dr.Read(); if ((int)m.dr[0] == 0) { SQL = "INSERT INTO tbl_Wegpunkt (Längengrad,Breitengrad,Ele,Name,CMT,DESC_Feld,sym) VALUES ('" + akt_lon + "','" + akt_lat + "','" + akt_ele + "','" + name + "','" + cmt + "','" + desc + "','" + sym + "')"; } m.cmd = new OleDbCommand(SQL, m.con); m.cmd.ExecuteNonQuery(); Zustand = GPX_Zustände.GPX; } } else if (Zustand == GPX_Zustände.GPX_WPT_ELE) { strBuf = xr.ReadContentAsString().Replace('.', ','); akt_ele = double.Parse(strBuf); if (xr.NodeType == XmlNodeType.EndElement && xr.Name == "ele") { Zustand = GPX_Zustände.GPX_WPT; } } else if (Zustand == GPX_Zustände.GPX_WPT_NAME) { name = xr.ReadContentAsString(); if (xr.NodeType == XmlNodeType.EndElement && xr.Name == "name") { Zustand = GPX_Zustände.GPX_WPT; } } else if (Zustand == GPX_Zustände.GPX_WPT_CMT) { cmt = xr.ReadContentAsString(); if (xr.NodeType == XmlNodeType.EndElement && xr.Name == "cmt") { Zustand = GPX_Zustände.GPX_WPT; } } else if (Zustand == GPX_Zustände.GPX_WPT_DESC) { desc = xr.ReadContentAsString(); if (xr.NodeType == XmlNodeType.EndElement && xr.Name == "desc") { Zustand = GPX_Zustände.GPX_WPT; } } else if (Zustand == GPX_Zustände.GPX_WPT_SYM) { sym = xr.ReadContentAsString(); if (xr.NodeType == XmlNodeType.EndElement && xr.Name == "sym") { Zustand = GPX_Zustände.GPX_WPT; } } else if (Zustand == GPX_Zustände.GPX_TRK_NAME) { Track_Name = xr.ReadContentAsString(); if (xr.NodeType == XmlNodeType.EndElement && xr.Name == "name") { Zustand = GPX_Zustände.GPX_TRK; } } else if (Zustand == GPX_Zustände.GPX_TRK_TRKSEG) { if (xr.NodeType == XmlNodeType.Element && xr.Name == "trkpt") { if (xr.HasAttributes) { // Erst mal ALLE Attribute lesen!! while (xr.MoveToNextAttribute()) { if (xr.Name == "lat") akt_lat = xr.ReadContentAsDouble(); if (xr.Name == "lon") akt_lon = xr.ReadContentAsDouble(); } } Zustand = GPX_Zustände.GPX_TRK_TRKSEG_TRKPT; } if (xr.NodeType == XmlNodeType.EndElement && xr.Name == "trkseg") { Zustand = GPX_Zustände.GPX_TRK; } } else if (Zustand == GPX_Zustände.GPX_TRK_TRKSEG_TRKPT) { if (xr.NodeType == XmlNodeType.Element && xr.Name == "time") { Zustand = GPX_Zustände.GPX_TRK_TRKSEG_TRKPT_TIME; } if (xr.NodeType == XmlNodeType.Element && xr.Name == "ele") { Zustand = GPX_Zustände.GPX_TRK_TRKSEG_TRKPT_ELE; } if (xr.NodeType == XmlNodeType.EndElement && xr.Name == "trkpt") { GPXList.Add(new GPXDatenSpeicher(akt_lat, akt_lon, akt_Zeit, akt_ele, Track_Name)); Zustand = GPX_Zustände.GPX_TRK_TRKSEG; } } else if (Zustand == GPX_Zustände.GPX_TRK_TRKSEG_TRKPT_TIME) { akt_Zeit = xr.ReadContentAsString(); if (xr.NodeType == XmlNodeType.EndElement && xr.Name == "time") { Zustand = GPX_Zustände.GPX_TRK_TRKSEG_TRKPT; } } else if (Zustand == GPX_Zustände.GPX_TRK_TRKSEG_TRKPT_ELE) { strBuf = xr.ReadContentAsString().Replace('.', ','); akt_ele = double.Parse(strBuf); if (xr.NodeType == XmlNodeType.EndElement && xr.Name == "ele") { Zustand = GPX_Zustände.GPX_TRK_TRKSEG_TRKPT; } } }//ende while (xr.Read()) #endregion strBuf = null; //Noch wegpunkt einlesen einbauen... (keine lust) for (int i = 0; i < GPXList.Count; i++) { if (strBuf != GPXList[i].Name) { IndexList.Add(i); } strBuf = GPXList[i].Name; } for (int iLoop = 0; iLoop < IndexList.Count; iLoop++) { EintragGefunden = false; if (!EintragGefunden) { Min_Index = IndexList[iLoop]; EintragGefunden = CheckDataBase(GPXList[IndexList[iLoop]].Name, Min_Index); if (iLoop == (IndexList.Count - 1)) { Max_Index = GPXList.Count; } else { Max_Index = IndexList[iLoop + 1]; } } else { //MessageBox.Show("Gibbet schon"); } if (!EintragGefunden) { SQL = "Insert Into tbl_track (Track_Name, Track_Name_Import) Values ('" + GPXList[IndexList[iLoop]].Name + "','" + GPXList[IndexList[iLoop]].Name + "')"; m.cmd = new OleDbCommand(SQL, m.con); m.cmd.ExecuteNonQuery(); System.Threading.Thread.Sleep(100); SQL = "Select ID_Track From tbl_track Where Track_Name_Import = '" + GPXList[IndexList[iLoop]].Name + "'"; m.cmd = new OleDbCommand(SQL, m.con); m.dr = m.cmd.ExecuteReader(); m.dr.Read(); ID_Track_var = (int)m.dr[0]; //MessageBox.Show(m.dr[0].ToString()); for (int i = Min_Index; i < Max_Index; i++) { SQL = "Insert Into tbl_Trackpoint (Längengrad,Breitengrad,Zeit,Ele,FS_ID_Track) Values ('" + GPXList[i].Longitude + "','" + GPXList[i].Latitude + "','" + GPXList[i].Zeit + "','" + GPXList[i].Ele + "','" + ID_Track_var + "')"; m.cmd = new OleDbCommand(SQL, m.con); m.cmd.ExecuteNonQuery(); } //MessageBox.Show("is drin" + debug.ToString()); } else { //MessageBox.Show("is schon drin" + debug.ToString()); } } }
//Read Program - This method must be refactored into DataSample private void ReadXMLProgram() { CurrentVO2MaxProgram = new VO2MaxProgram(); string RootDiretory = AppDomain.CurrentDomain.BaseDirectory; XmlTextReader reader = null; switch (DataSample.ProgramSelector) { case Enumerators.ProgramSelect.VO2MaxProgram1: reader = new XmlTextReader(RootDiretory + "\\Programs\\VO2MaxProgram1.xml"); lblTitle.Text = "Program: VO2 Max Program 1"; lblDescription.Text = "Program Time: 30 min"; CurrentPowerIndex = GlobalVariables.VO2MaxProgram1PB; break; case Enumerators.ProgramSelect.VO2MaxProgram2: reader = new XmlTextReader(RootDiretory + "\\Programs\\VO2MaxProgram2.xml"); lblTitle.Text = "Program: VO2 Max Program 2"; lblDescription.Text = "Program Time: 30 min"; CurrentPowerIndex = GlobalVariables.VO2MaxProgram2PB; break; case Enumerators.ProgramSelect.VO2MaxProgram3: reader = new XmlTextReader(RootDiretory + "\\Programs\\VO2MaxProgram3.xml"); lblTitle.Text = "Program: VO2 Max Program 3"; lblDescription.Text = "Program Time: 26 min"; CurrentPowerIndex = GlobalVariables.VO2MaxProgram3PB; break; case Enumerators.ProgramSelect.VO2MaxProgram4: reader = new XmlTextReader(RootDiretory + "\\Programs\\VO2MaxProgram4.xml"); lblTitle.Text = "Program: VO2 Max Program 4"; lblDescription.Text = "Program Time: 20 min"; CurrentPowerIndex = GlobalVariables.VO2MaxProgram4PB; break; case Enumerators.ProgramSelect.CPM: reader = new XmlTextReader(RootDiretory + "\\Programs\\CPMProgram.xml"); lblTitle.Text = "Program: Continuous Passive Motion (CPM)"; lblDescription.Text = "Program Time: 20 min"; CurrentPowerIndex = GlobalVariables.CPMProgramPB; break; case Enumerators.ProgramSelect.Proprioception: reader = new XmlTextReader(RootDiretory + "\\Programs\\ProprioceptionProgram.xml"); lblTitle.Text = "Program: Proprioception"; lblDescription.Text = "Program Time: 10 min"; CurrentPowerIndex = GlobalVariables.PropriocenptionProgramPB; break; case Enumerators.ProgramSelect.RehabBilateral: reader = new XmlTextReader(RootDiretory + "\\Programs\\ProgramRehabBilateral.xml"); lblTitle.Text = "Program: Rehabilitation - Bilateral (9 Stages)"; lblDescription.Text = "Program Time: 15 min"; CurrentPowerIndex = GlobalVariables.RehabProgramPB; break; case Enumerators.ProgramSelect.RehabLeftLeg: reader = new XmlTextReader(RootDiretory + "\\Programs\\ProgramRehabLeftLeg.xml"); lblTitle.Text = "Program: Rehabilitation - Left Leg (11 Stages)"; lblDescription.Text = "Program Time: 15 min"; CurrentPowerIndex = GlobalVariables.RehabProgramLeftPB; break; case Enumerators.ProgramSelect.RehabRightLeg: reader = new XmlTextReader(RootDiretory + "\\Programs\\ProgramRehabRightLeg.xml"); lblTitle.Text = "Program: Rehabilitation - Right Leg (11 Stages)"; lblDescription.Text = "Program Time: 15 min"; CurrentPowerIndex = GlobalVariables.RehabProgramRightPB; break; //case Enumerators.ProgramSelect.CustomProgram: // reader = new XmlTextReader(RootDiretory + "\\Programs\\ProgramRehabBilateral.xml"); // lblTitle.Text = "Program: Rehabilitation - Bilateral (9 Stages)"; // lblDescription.Text = "Program Time: 15 min"; // CurrentPowerIndex = GlobalVariables.RehabProgramPB; // break; default: break; } while (reader.Read()) { if (reader.ReadToFollowing("StageIndex")) { VO2MaxStage newVO2MaxStage = new VO2MaxStage(); reader.Read(); newVO2MaxStage.StageIndex = reader.ReadContentAsInt(); reader.ReadToFollowing("StageNumber"); reader.Read(); newVO2MaxStage.StageNumber = reader.ReadContentAsInt(); reader.ReadToFollowing("StageName"); reader.Read(); newVO2MaxStage.StageName = reader.ReadContentAsString(); reader.ReadToFollowing("StageDuration"); reader.Read(); newVO2MaxStage.StageTimeRemaining = new TimeSpan(0, reader.ReadContentAsInt(), 0); reader.ReadToFollowing("Sets"); reader.Read(); while (reader.Read()) { if (reader.Name == "Set") { VO2MaxSet newVO2MaxSet = new VO2MaxSet(); reader.ReadToFollowing("SetIndex"); reader.Read(); newVO2MaxSet.SetIndex = reader.ReadContentAsInt(); reader.ReadToFollowing("Number"); reader.Read(); newVO2MaxSet.SetNumber = reader.ReadContentAsInt(); reader.ReadToFollowing("Duration"); reader.Read(); double SetTime = reader.ReadContentAsDouble(); if (SetTime < 1) { SetTime = SetTime * 60; newVO2MaxSet.TimeRemaining = new TimeSpan(0, 0, Convert.ToInt32(SetTime)); } else { newVO2MaxSet.TimeRemaining = new TimeSpan(0, Convert.ToInt32(SetTime), 0); } reader.ReadToFollowing("Direction"); reader.Read(); newVO2MaxSet.Direction = reader.ReadContentAsString(); reader.ReadToFollowing("DirectionFlag"); reader.Read(); int DirectionVariable = reader.ReadContentAsInt(); if (DirectionVariable == 1) newVO2MaxSet.SelectedDirection = Enumerators.Direction.Forward; else if (DirectionVariable == -1) newVO2MaxSet.SelectedDirection = Enumerators.Direction.Backward; reader.ReadToFollowing("Contraction"); reader.Read(); newVO2MaxSet.Contraction = reader.ReadContentAsString(); reader.ReadToFollowing("Legs"); reader.Read(); newVO2MaxSet.Legs = reader.ReadContentAsString(); reader.ReadToFollowing("Position"); reader.Read(); newVO2MaxSet.Position = reader.ReadContentAsString(); reader.ReadToFollowing("RestDuration"); reader.Read(); newVO2MaxSet.RestTimeRemaining = new TimeSpan(0, reader.ReadContentAsInt(), 0); reader.ReadToFollowing("Instructions"); reader.Read(); newVO2MaxSet.Instructions = reader.ReadContentAsString(); newVO2MaxStage.VO2MaxSetCollection.Add(newVO2MaxSet); reader.Read(); //Read White Space reader.Read(); //Read Set reader.Read(); //Read White Space } else { break; } } CurrentVO2MaxProgram.VO2MaxStageCollection.Add(newVO2MaxStage); } } CurrentVO2MaxProgram.ProgramTime = new TimeSpan(0, 0, 0); foreach (VO2MaxStage stage in CurrentVO2MaxProgram.VO2MaxStageCollection) { CurrentVO2MaxProgram.ProgramTime = CurrentVO2MaxProgram.ProgramTime + stage.StageTimeRemaining; } }