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 addEntryButton_Click(object sender, EventArgs e) { //save event entry for the given competitor for the given event //don't do if no event or competitor is selected Competitor c = null; Event ev = null; List<Competitor> competitors = GetSelectedCompetitors(); if (competitors.Count > 0) { c = competitors[0]; } else { MessageBox.Show("Please select only one competitor in competitors list!"); return; } if (eventsComboBox.SelectedIndex != -1) ev = DataManager.Instance.Events[eventsComboBox.SelectedIndex]; else { MessageBox.Show("Please select an event!"); return; } try { EventEntry eventEntry = new EventEntry(); eventEntry.competitorID = c.ID; eventEntry.eventID = ev.ID; //FIX WITH COMBO! //eventEntry.className = eventEntryClassTextBox.Text; if (classComboBox.SelectedIndex != -1) { eventEntry.className = classComboBox.Items[classComboBox.SelectedIndex] as String; } else eventEntry.className = ""; eventEntry.bikeBrand = eventEntryBikeBrandTextBox.Text; try { eventEntry.bikeNumber = eventEntryBikeNumTextBox.Text;// int.Parse(eventEntryBikeNumTextBox.Text); } catch { eventEntry.bikeNumber = "0"; } eventEntry.tagNumber = new TagId(eventEntryBikeTagTextBox.Text); eventEntry.tagNumber2 = new TagId(eventEntryBikeTag2TextBox.Text); eventEntry.competitor = c;//will reset info that is ambiguous DataManager.Instance.EventEntries.Add(eventEntry); (competitorEventEntriesGrid.DataSource as BindingList<EventEntry>).Add(eventEntry); (competitorEventEntriesGrid.DataSource as BindingList<EventEntry>).ResetBindings(); DeselectEventEntriesUI(); //have to check whether this is correct behavior if (c == null) return; //fill event entries UI with some default values from competitor, //even if nothing is selected in the event entries grid eventEntryBikeBrandTextBox.Text = c.BikeBrand; eventEntryBikeNumTextBox.Text = "" + c.BikeNumber; eventEntryBikeTagTextBox.Text = "" + c.TagNumber; eventEntryBikeTag2TextBox.Text = "" + c.TagNumber2; } catch (Exception exc) { MessageBox.Show("There was a problem adding your event entry."); } }
private void AddNewCompetitor(Competitor newCompetitor, bool addToCompetitorsList = true) { if(addToCompetitorsList) DataManager.Instance.Competitors.Add(newCompetitor); competitor = newCompetitor; EventEntry newEventEntry = new EventEntry(); newEventEntry.competitor = newCompetitor; Event currentEvent = raceInformationControl.GetSelectedEvent(); if (currentEvent != null) { newEventEntry.eventID = currentEvent.ID; newEventEntry.tagNumber = newCompetitor.TagNumber; newEventEntry.tagNumber2 = newCompetitor.TagNumber2; newEventEntry.bikeNumber = newCompetitor.BikeNumber; if (classComboBox.SelectedIndex != -1) { newEventEntry.className = classComboBox.Items[classComboBox.SelectedIndex] as String; } DataManager.Instance.EventEntries.Add(newEventEntry); } CompetitorRace cr = new CompetitorRace(newEventEntry.competitorID); cr.EventEntry = newEventEntry; cr.lastName = newCompetitor.LastName; cr.firstName = newCompetitor.FirstName; cr.competitorID = newCompetitor.ID; cr.tagID = newCompetitor.TagNumber; cr.tagID2 = newCompetitor.TagNumber2; cr.bikeNumber = newCompetitor.BikeNumber; cr.className = newEventEntry.className; cr.raceParent = raceInformationControl.GetCurrentSession(); raceInformationControl.GetCurrentSession().AddCompetitorRace(cr); UpdatePassings(); }
/// <summary> /// This handler creates event entries for all selected competitors and adds /// them to the selected race (session, run). /// </summary> private void addCompetitorsToRunButton_Click(object sender, EventArgs e) { //if (MessageBox.Show("Are you sure you would like to add all the selected competitors to " + // "the selected run? This will create event entries for each of the competitors!", // "Please confirm", MessageBoxButtons.YesNo) == DialogResult.No) //{ // return; //} if (GetSelectedCompetitors().Count == 0) { MessageBox.Show("Please select at least one competitor in a list!"); return; } //if ((raceCompetitorsGridView.DataSource as BindingList<CompetitorRace>) == null) if ((raceCompetitorsGridView.DataSource as SortableBindingList<CompetitorRace>) == null) { MessageBox.Show("Please add a race to an event first!"); return; } Race selectedRace = null; int index = selectedRaceComboBox.SelectedIndex; if (index != -1) { selectedRace = (selectedRaceComboBox.DataSource as BindingList<Race>)[index]; } if (selectedRace == null) return; //for each competitor, create a new event entry; then add those event entries to the race Event ev = null; if (eventsComboBox.SelectedIndex != -1) ev = DataManager.Instance.Events[eventsComboBox.SelectedIndex]; else { MessageBox.Show("Please select an event!"); return; } try { foreach (Competitor c in GetSelectedCompetitors()) { String eventEntryClass = ""; if (classComboBox.SelectedIndex != -1 && classComboBox.Items != null && classComboBox.Items.Count > 0) { eventEntryClass = classComboBox.Items[classComboBox.SelectedIndex] as String; } EventEntry eventEntry = new EventEntry(); eventEntry.competitor = c; eventEntry.competitorID = c.ID; eventEntry.eventID = ev.ID; eventEntry.tagNumber = c.TagNumber; eventEntry.tagNumber2 = c.TagNumber2; eventEntry.bikeNumber = c.BikeNumber; eventEntry.bikeBrand = c.BikeBrand; eventEntry.className = eventEntryClass; DataManager.Instance.EventEntries.Add(eventEntry); CompetitorRace cr = new CompetitorRace(eventEntry.competitorID); cr.competitor = c; cr.EventEntry = eventEntry; cr.tagID = eventEntry.tagNumber; cr.tagID2 = eventEntry.tagNumber2; cr.bikeNumber = eventEntry.bikeNumber; cr.className = eventEntry.className; cr.raceParent = selectedRace; selectedRace.AddCompetitorRace(cr); raceCompetitorsGridView.Columns["competitor"].Visible = false; } //deselect competitors after adding competitorsDataGridControl.DataGridView.ClearSelection(); competitorDataInput.ClearControls();//sets focus to last name text box as well //DeselectEventEntriesUI(); } catch (Exception exc) { Console.WriteLine(exc.StackTrace); DataManager.Log(exc.StackTrace); MessageBox.Show("Sorry, there was a problem when adding competitors."); } }
private void okButton_Click(object sender, EventArgs e) { // //1. Unknown tag info came, no competitor is originally known for the incoming tag // //possible cases: //a) cancel (nothing done) //b) new competitor added //c) old competitor (existing in the competitor's list, but not racing list) // added to the race // if (competitor == null) { Competitor newCompetitor = new Competitor(); newCompetitor.ID = DataManager.getNextID();//important! otherwise will have id = 0 bool res = competitorDataInput.UpdateCompetitorData(ref newCompetitor); if (!res) { MessageBox.Show("There was a problem with the entered data."); return; } //Competitor existingCompetitor = DataManager.Instance.GetCompetitorByTagID(newCompetitor.TagNumber); //TODO: have to check as well for the name (assume the admin has entered John Doe, //but John Doe already exists somewhere in the competitors list, though with a different //or no tag. How to proceed there? Show the same warning dialog? Competitor existingCompetitor = null; List<Competitor> existingCmps = DataManager.Instance.GetCompetitorByName(newCompetitor.FirstName, newCompetitor.LastName); if (existingCmps.Count > 0) existingCompetitor = existingCmps[0]; if (existingCompetitor != null) { //AddNewCompetitor(existingCompetitor, false); //this.Dispose(); //return; //TEMPORARILY COMMENTED OUT Form userDialog = GetUserDialog("Warning!", "There already exists a competitor with the name " + existingCompetitor.FirstName + " " + existingCompetitor.LastName + ". Do you want to proceed with this user or create a new one?", "Proceed with current user", "Create a new one"); DialogResult dr = userDialog.ShowDialog(); if (dr == System.Windows.Forms.DialogResult.Cancel) { this.Dispose(); return; } else if (dr == System.Windows.Forms.DialogResult.Ignore) { if (newCompetitor.FirstName.Equals("") && newCompetitor.LastName.Equals("")) { if (MessageBox.Show("Are you sure you would like to add competitor with empty name fields?", "Please confirm", MessageBoxButtons.YesNo) == DialogResult.No) { return; } } AddNewCompetitor(newCompetitor); this.Dispose(); return; } else if (dr == System.Windows.Forms.DialogResult.OK)//proceed { if (newCompetitor.FirstName.Equals("") && newCompetitor.LastName.Equals("")) { if (MessageBox.Show("Are you sure you would like to add competitor with empty name fields?", "Please confirm", MessageBoxButtons.YesNo) == DialogResult.No) { return; } } //have to overwrite tags existingCompetitor.TagNumber = newCompetitor.TagNumber; existingCompetitor.TagNumber2 = newCompetitor.TagNumber2; AddNewCompetitor(existingCompetitor, false); this.Dispose(); return; } //AddNewCompetitor(newCompetitor, false); //this.Dispose(); //return; } else //just save new competitor to the competitors list { if (newCompetitor.FirstName.Equals("") && newCompetitor.LastName.Equals("")) { if (MessageBox.Show("Are you sure you would like to add competitor with empty name fields?", "Please confirm", MessageBoxButtons.YesNo) == DialogResult.No) { return; } } AddNewCompetitor(newCompetitor); this.Dispose(); return; } } // //2. some existing competitor was originally selected in the grid // //possible cases: //update or cancel // if (competitor != null && haveToAddEventEntry)// && !competitorDataInput.ChangesMade(competitor)) { if (MessageBox.Show("Are you sure you would like to proceed?", "Confirmation Dialog", MessageBoxButtons.YesNo) == DialogResult.No) { this.Dispose(); } EventEntry newEventEntry = new EventEntry(); newEventEntry.competitor = competitor; Event currentEvent = raceInformationControl.GetSelectedEvent(); if (currentEvent != null) { newEventEntry.eventID = currentEvent.ID; DataManager.Instance.EventEntries.Add(newEventEntry); } CompetitorRace cr = new CompetitorRace(newEventEntry.competitorID); cr.tagID = competitor.TagNumber; cr.tagID2 = competitor.TagNumber2; cr.bikeNumber = competitor.BikeNumber; //cr.className = newCompetitor.//newEventEntry.className; cr.raceParent = raceInformationControl.GetCurrentSession(); raceInformationControl.GetCurrentSession().AddCompetitorRace(cr); UpdatePassings(); this.Dispose(); } else if(competitor != null && !haveToAddEventEntry) { if (MessageBox.Show("Are you sure you would like to save the changes?", "Confirmation Dialog", MessageBoxButtons.YesNo) == DialogResult.No) { this.Dispose(); } else { bool updateResult = competitorDataInput.UpdateCompetitorData(ref competitor); if (!updateResult) { MessageBox.Show("There was a problem with the entered data."); return; } UpdatePassings(); this.Dispose(); } } }