public void SetCompetitors(List<CompetitorRace> crs, PassingsInfo pi, List<TagId> tagClashFormList, Race currentRace, DataGridView passingsGrid, Dictionary<TagId, CompetitorRace> disambiuationCRDict) { this.crs = crs; this.tagClashFormList = tagClashFormList; this.tagID = pi.ID; this.currentRace = currentRace; this.passingsGrid = passingsGrid; this.disambiuationCRDict = disambiuationCRDict; DataTable t = new DataTable(); t.Columns.Add("First Name"); t.Columns.Add("Last Name"); t.Columns.Add("Tag ID"); foreach (CompetitorRace cr in crs) { t.Rows.Add(new object[] { cr.firstName, cr.lastName, pi.ID }); this.dataGridView1.DataSource = t; } this.dataGridView1.ClearSelection(); }
public bool ImportEventSchedule(String filename, out BindingList<Race> result) { result = new BindingList<Race>(); try { //DataSet ds = new DataSet(); //string strConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + // "Data Source=" + System.IO.Path.GetDirectoryName(filename) + ";" + "Extended Properties=\"Text;FMT=Delimited\""; //using (System.Data.OleDb.OleDbConnection conText = new System.Data.OleDb.OleDbConnection(strConnectionString)) //{ // System.Data.OleDb.OleDbDataAdapter oleb = new System.Data.OleDb.OleDbDataAdapter("SELECT * FROM [" + System.IO.Path.GetFileName(filename) + "]", conText); // oleb.Fill(ds, "whatever"); // oleb.Dispose(); //} //for (int i = 0; i < ds.Tables[0].Rows.Count; i++) //{ // try // { // //name,type,date,classes // String nameString = ds.Tables[0].Rows[i]["name"].ToString(); // String typeString = ds.Tables[0].Rows[i]["type"].ToString(); // String dateString = ds.Tables[0].Rows[i]["date"].ToString(); // String classesString = ds.Tables[0].Rows[i]["classes"].ToString(); //on the reasons for not using OleDB, please see below method that imports competitors using (CsvReader csv = new CsvReader(new StreamReader(filename), true)) { csv.MissingFieldAction = MissingFieldAction.ReplaceByNull; while (csv.ReadNextRecord()) { try { String nameString = (csv["name"] != null) ? csv["name"].ToString() : ""; String typeString = (csv["type"] != null) ? csv["type"].ToString() : ""; String dateString = (csv["date"] != null) ? csv["date"].ToString() : ""; String classesString = (csv["classes"] != null) ? csv["classes"].ToString() : ""; Race newRace = new Race(nameString, typeString); DateTime d = DateTime.Now; DateTime.TryParse(dateString, out d); newRace.Dates.Add(d); String[] classesArr = classesString.Split(new char[] { ';' }); for (int j = 0; j < classesArr.Length; j += 2) { if (j + 1 >= classesArr.Length || j > classesArr.Length) break; String className = classesArr[j]; String classDescription = classesArr[j + 1]; newRace.validClasses.Add(new Class(className, classDescription)); if (!isActiveClass(className, classDescription)) { this.Classes.Add(new Class(className, classDescription)); } } result.Add(newRace); } catch (Exception exc) { Console.WriteLine(exc.StackTrace); continue; } } } } catch (Exception exc) { Console.WriteLine(exc.StackTrace); return false; } return true; }
/// <summary> /// This method resets the controls once the user changes selection in the /// events or races combo boxes. /// </summary> private void ResetControls() { int selectedRaceIndex = selectedRaceComboBox.SelectedIndex; if (selectedRaceIndex == -1) { passingsDataGrid.DataSource = new BindingList<PassingsInfo>(); passingsDataGrid.Columns["CompetitorRace"].Visible = false; passingsDataGrid.Columns["DateTime"].DefaultCellStyle.Format = "MM/dd/yyyy HH:mm:ss.fff"; raceInformationGridView.DataSource = new BindingList<Race>(); //raceInformationGridView.Columns["competitor"].Visible = false; if (currentRaceList != null) currentRaceList.ListChanged -= currentRaceList_ListChanged; currentRaceList = new SortableBindingList<CompetitorRace>();//new BindingList<CompetitorRace>(); //currentRaceList = new BindingList<CompetitorRace>(); currentRaceList.ListChanged += currentRaceList_ListChanged; currentRace = null; return; } //whenever competitorrace is removed from a race (racelist), make sure corresponding PI's are stored at //the race object - add this functionality to race class //basically add methods CompetitorRaceAdd, CompetitorRaceRemove to the Race class; //they should do standard adding/removal, but also take care of the passings //race keeps passings that were not associated with any competitor currentRace = (selectedRaceComboBox.DataSource as BindingList<Race>)[selectedRaceIndex]; //add non-associated passings to current passings list try { if(currentRaceList != null) currentRaceList.ListChanged -= currentRaceList_ListChanged; } catch (Exception exc) { Console.WriteLine(exc); DataManager.Log("Exception Caught!" + exc.StackTrace); }//exception should never happen currentRaceList = //(selectedRaceComboBox.DataSource as BindingList<Race>)[selectedRaceIndex].competitorRaceList; (selectedRaceComboBox.DataSource as BindingList<Race>)[selectedRaceIndex].competitorRaceList; currentRaceList.ListChanged += currentRaceList_ListChanged; raceInformationGridView.DataSource = currentRaceList; raceInformationGridView.Columns["competitor"].Visible = false; raceInformationGridView.Columns["competitorID"].Visible = false; raceInformationGridView.Columns["raceParent"].Visible = false; raceInformationGridView.Columns["EventEntry"].Visible = false; raceInformationGridView.Columns["BestLap"].Visible = false; raceInformationGridView.Columns["BestLap"].Width = 130; raceInformationGridView.Columns["LastLap"].Visible = false; raceInformationGridView.Columns["LastLap"].Width = 130; raceInformationGridView.Columns["Position"].DisplayIndex = 0; raceInformationGridView.Columns["Position"].Width = 45; raceInformationGridView.Columns["tagID"].Width = 40; raceInformationGridView.Columns["tagID2"].Width = 40; raceInformationGridView.Columns["bikeNumber"].Width = 40; raceInformationGridView.Columns["lapsCompleted"].Width = 40; passingsDataGrid.DataSource = new BindingList<PassingsInfo>(); passingsDataGrid.Columns["CompetitorRace"].Visible = false; passingsDataGrid.Columns["competitorID"].Visible = false; passingsDataGrid.Columns["DateTime"].DefaultCellStyle.Format = "HH:mm:ss.fff"; //"MM/dd/yyyy HH:mm:ss.fff"; //passingsDataGrid.Columns["firstName"].Visible = false; //passingsDataGrid.Columns["lastName"].Visible = false; passingsDataGrid.Columns["Time"].Visible = false; passingsDataGrid.Columns["ID"].Width = 50; passingsDataGrid.Columns["Antenna"].Width = 50; passingsDataGrid.Columns["Hits"].Width = 50; passingsDataGrid.Columns["CompetitionNumber"].Width = 70; //first add passings to a list and sort; //only then add them to binding list //have to do this, otherwise passings will be "sorted" //by competitor List<PassingsInfo> passingsList = new List<PassingsInfo>(); foreach (CompetitorRace cr in currentRaceList) { foreach (PassingsInfo pi in cr.passings) { if(!passingsList.Contains(pi)) passingsList.Add(pi); } } if (currentRace != null) { foreach (PassingsInfo pi in currentRace.passings) { if (!passingsList.Contains(pi)) passingsList.Add(pi); } } //sort passings list by timestamp passingsList.Sort(delegate(PassingsInfo p1, PassingsInfo p2) { if (p1.Time < p2.Time) return -1; else if (p1.Time > p2.Time) return 1; else return 0; }); foreach (PassingsInfo pi in passingsList) { if (!(passingsDataGrid.DataSource as BindingList<PassingsInfo>).Contains(pi)) (passingsDataGrid.DataSource as BindingList<PassingsInfo>).Add(pi); } UpdateRaceStandingsGrid(null); if (currentRace != null) { tagClashFormList = currentRace.tagClashFormList; disambiuationCRDict = currentRace.disambiuationCRDict; } }
private void LoadTestData() { BindingList<DateTime> event1Dates = new BindingList<DateTime>(); event1Dates.Add(new DateTime(2011, 02, 15)); event1Dates.Add(new DateTime(2011, 02, 16)); Event event1 = new Event() { ID = 1, name = "OSU Race February", city = "Columbus", state = "OH", dates = event1Dates }; BindingList<DateTime> event2Dates = new BindingList<DateTime>(); event2Dates.Add(new DateTime(2011, 03, 20)); event2Dates.Add(new DateTime(2011, 03, 21)); Event event2 = new Event() { ID = 2, name = "OSU Race March", city = "Columbus", state = "OH", dates = event2Dates }; events.Add(event1); events.Add(event2); Competitor cmp = new Competitor() { ID = 1, LastName = "Doe", FirstName = "John", Address = new Address("OSU", "Columbus", "OH", 43201), Phone = new PhoneNumber("123-456-7890"), DOB = DateTime.Now, Age = 29, Gender = true, Sponsors = "Honda", BikeBrand = "Honda", BikeNumber = "33", TagNumber = new TagId("0343") }; Competitor cmp2 = new Competitor() { ID = 2, LastName = "Smith", FirstName = "Mike", Address = new Address("OSU", "Columbus", "OH", 43201), Phone = new PhoneNumber("123-456-7890"), DOB = DateTime.Now, Age = 40, Gender = true, Sponsors = "Suzuki", BikeBrand = "Suzuki", BikeNumber = "37", TagNumber = new TagId("0365") }; competitors.Add(cmp); competitors.Add(cmp2); event1.competitors.Add(cmp); event2.competitors.Add(cmp); event1.competitors.Add(cmp2); event2.competitors.Add(cmp2); Class class125cc = new Class(); class125cc.name = "125cc"; class125cc.description = "125cc"; Class class250cc = new Class(); class250cc.name = "250cc"; class250cc.description = "250cc"; classes.Add(class125cc); classes.Add(class250cc); Race event1Race1 = new Race("qualify race 1", "Qualifying"); Race event1Race2 = new Race("qualify race 2", "Qualifying"); Race event1Race3 = new Race("final race", "Race"); Race event2Race1 = new Race("qualify race 1", "Qualifying"); Race event2Race2 = new Race("qualify race 2", "Qualifying"); Race event2Race3 = new Race("final race", "Race"); event1.races = new BindingList<Race>() { event1Race1, event1Race2, event1Race3 }; event2.races = new BindingList<Race>() { event2Race1, event2Race2, event2Race3 }; EventEntry eve1 = new EventEntry(); eve1.competitor = cmp; eve1.eventID = event1.ID; eve1.className = "250cc"; EventEntry eve2 = new EventEntry(); eve2.competitor = cmp2; eve2.eventID = event1.ID; eve2.className = "250cc"; eventEntries.Add(eve1); eventEntries.Add(eve2); LoadTagFile(""); }
private void addRaceButton_Click(object sender, EventArgs e) { //if ((eventDatesGridView.DataSource as BindingList<DateTime>) == null) //{ // MessageBox.Show("Please add event first and then add races to it!"); // return; //} if (this.eventsDataGridView.SelectedRows.Count <= 0) { MessageBox.Show("Please select (create if necessary) event and then add sessions to it!"); return; } if (this.eventsDataGridView.SelectedRows.Count > 0) { Race newRace = new Race(addRaceTextField.Text); int selectedIndex = sessionTypeComboBox.SelectedIndex; newRace.type = sessionTypeComboBox.Items[selectedIndex] as String; (eventRacesGridView.DataSource as BindingList<Race>).Add(newRace); (eventRacesGridView.DataSource as BindingList<Race>).ResetBindings(); } else if(this.eventsDataGridView.Rows.Count == 1)//one row in the grid, selected by default { Race newRace = new Race(addRaceTextField.Text); int selectedIndex = sessionTypeComboBox.SelectedIndex; newRace.type = sessionTypeComboBox.Items[selectedIndex] as String; (eventRacesGridView.DataSource as BindingList<Race>).Add(newRace); (eventRacesGridView.DataSource as BindingList<Race>).ResetBindings(); } else MessageBox.Show("Please select a row in the table first."); }