protected void ProcessBadgeData(string data) { BadgeData badge = null; try { badge = new BadgeData(_groupMap, _locationMap, data); } catch (Exception e) { MessageBox.Show(String.Format("{0}\n\n{1}", e.Message, e.StackTrace), "Error processing Badge", MessageBoxButtons.OK, MessageBoxIcon.Error); } if (badge.IsValidBadge) { _sslRegister.Text = String.Format("Data received at {0}", DateTime.Now); if (RegisterMode) { try { EmitScoreDataSet.GroupDataTable groupTable = new EmitScoreDataSet.GroupDataTable(); EmitScoreDataSet.GroupRow groupRow = groupTable.NewGroupRow(); groupRow.GroupId = badge.BadgeNo; EmitScoreDataSet.CategoryRow defaultCat = (EmitScoreDataSet.CategoryRow)_dataSet.Category.Rows[0]; groupRow.CategoryId = defaultCat.CategoryId; groupTable.AddGroupRow(groupRow); groupTableAdapter.Update(groupTable); } catch (Exception) { } FrmNewGroup newGroup = new FrmNewGroup(badge.BadgeNo); newGroup.ShowDialog(); } else { // Retrieve the Group row EmitScoreDataSet.GroupDataTable groupTable = new EmitScoreDataSet.GroupDataTable(); groupTableAdapter.Fill(groupTable); EmitScoreDataSet.GroupRow groupRow = groupTable.FindByGroupId(badge.BadgeNo); // Reset Group points to zero (they will be accumulated below) badge.SwipeList.TotalPoints = 0; // Delete any existing result rows for this badge EmitScoreDataSet.GroupResultDataTable resultTable = new EmitScoreDataSet.GroupResultDataTable(); groupResultTableAdapter.Fill(resultTable); foreach (DataRow delRow in resultTable.Select(String.Format("GroupId='{0}'", badge.BadgeNo))) { delRow.Delete(); } groupResultTableAdapter.Update(resultTable); resultTable.Clear(); groupResultTableAdapter.Fill(resultTable); // Get the Team Results - to check if any other teams have visited these points EmitScoreDataSet.TeamResultsDataTable teamResTable = new EmitScoreDataSet.TeamResultsDataTable(); teamResultsTableAdapter.Fill(teamResTable); foreach (Swipe swipe in badge.SwipeList) { bool existingLocation = false; if (!groupRow.IsTeamIdNull()) { DataRow[] dr = teamResTable.Select( String.Format("TeamId='{0}' AND LocationId='{1}'", groupRow.TeamId, swipe.Location.CourseLocation.LocationId)); existingLocation = (dr.Length > 0); } EmitScoreDataSet.GroupResultRow resultRow = resultTable.NewGroupResultRow(); resultRow.GroupId = badge.BadgeNo; resultRow.LocationId = swipe.Location.LocationId; if (existingLocation) { // Someone else in the team has collected this Location's points swipe.Points = 0; } resultRow.Points = swipe.Points; badge.SwipeList.TotalPoints += swipe.Points; resultRow.Time = swipe.LocationTime; resultRow.CumTime = swipe.CummulativeTime; resultRow.EndEdit(); resultTable.AddGroupResultRow(resultRow); } groupResultTableAdapter.Update(resultTable); badge.SwipeList.AdjustPoints(); // After points deductions, adjust for time // Now populate the parent record groupRow.BeginEdit(); groupRow.TotalPoints = badge.SwipeList.TotalPoints; groupRow.NettPoints = badge.SwipeList.NettPoints; groupRow.TotalTime = badge.SwipeList.TotalTime; groupRow.TimeDisqualified = badge.SwipeList.TimeDisqualified; groupRow.EndEdit(); if (groupRow.TotalTime > DateTime.MinValue) { groupTableAdapter.Update(groupRow); groupRow.AcceptChanges(); } if (!groupRow.IsTeamIdNull()) { // Check to see if this group, or any others in the team // have been time disqualified, and disqualify them all groupTable = new EmitScoreDataSet.GroupDataTable(); groupTableAdapter.Fill(groupTable); bool anyDisqualified = false; foreach (EmitScoreDataSet.GroupRow gr1 in groupTable) { if (!gr1.IsTeamIdNull() && (gr1.TeamId == groupRow.TeamId)) { if (!gr1.IsTimeDisqualifiedNull() && (gr1.TimeDisqualified == 1)) { anyDisqualified = true; } } } if (anyDisqualified) { foreach (EmitScoreDataSet.GroupRow gr1 in groupTable) { if (!gr1.IsTeamIdNull() && (gr1.TeamId == groupRow.TeamId)) { gr1.BeginEdit(); gr1.NettPoints = 0; gr1.TimeDisqualified = 1; gr1.EndEdit(); groupTableAdapter.Update(gr1); gr1.AcceptChanges(); } } } } MessageBox.Show(String.Format("Group {0} - {1} results received.", groupRow.GroupId, groupRow.GroupName), "Results Received", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
protected void ProcessBadgeData(string data) { BadgeData badge = null; try { badge = new BadgeData(_locationMap, data); } catch (Exception e) { MessageBox.Show(String.Format("{0}\n\n{1}", e.Message, e.StackTrace), "Error processing Badge", MessageBoxButtons.OK, MessageBoxIcon.Error); } if (badge.IsValidBadge) { _sslRegister.Text = String.Format("Data received at {0}", DateTime.Now); if (RegisterMode) { try { EmitScoreDataSet.GroupDataTable groupTable = new EmitScoreDataSet.GroupDataTable(); EmitScoreDataSet.GroupRow groupRow = groupTable.NewGroupRow(); groupRow.GroupId = badge.BadgeNo; EmitScoreDataSet.CategoryRow defaultCat = (EmitScoreDataSet.CategoryRow)_dataSet.Category.Rows[0]; groupRow.CategoryId = defaultCat.CategoryId; groupTable.AddGroupRow(groupRow); groupTableAdapter.Update(groupTable); } catch (Exception) { } FrmNewGroup newGroup = new FrmNewGroup(badge.BadgeNo); newGroup.ShowDialog(); } else { // Retrieve the Group row EmitScoreDataSet.GroupDataTable groupTable = new EmitScoreDataSet.GroupDataTable(); groupTableAdapter.Fill(groupTable); EmitScoreDataSet.GroupRow groupRow = groupTable.FindByGroupId(badge.BadgeNo); // Delete any existing result rows for this badge EmitScoreDataSet.GroupResultDataTable resultTable = new EmitScoreDataSet.GroupResultDataTable(); groupResultTableAdapter.Fill(resultTable); foreach (DataRow delRow in resultTable.Select(String.Format("GroupId='{0}'", badge.BadgeNo))) { delRow.Delete(); } groupResultTableAdapter.Update(resultTable); resultTable.Clear(); groupResultTableAdapter.Fill(resultTable); foreach (Swipe swipe in badge.SwipeList) { EmitScoreDataSet.GroupResultRow resultRow = resultTable.NewGroupResultRow(); resultRow.GroupId = badge.BadgeNo; resultRow.LocationId = swipe.Location.Id; resultRow.Points = swipe.Points; resultRow.Time = swipe.LocationTime; resultRow.CumTime = swipe.CummulativeTime; resultRow.EndEdit(); resultTable.AddGroupResultRow(resultRow); } groupResultTableAdapter.Update(resultTable); badge.SwipeList.AdjustPoints(); // After points deductions, adjust for time // Now populate the parent record groupRow.BeginEdit(); groupRow.TotalPoints = badge.SwipeList.TotalPoints; groupRow.NettPoints = badge.SwipeList.NettPoints; groupRow.TotalTime = badge.SwipeList.TotalTime; groupRow.TimeDisqualified = badge.SwipeList.TimeDisqualified; groupRow.EndEdit(); groupTableAdapter.Update(groupRow); groupRow.AcceptChanges(); LastGroupHome(groupRow.GroupName, groupRow.NettPoints, groupRow.TotalTime); MessageBox.Show(String.Format("Group {0} - {1} results received.", groupRow.GroupId, groupRow.GroupName), "Results Received", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }