protected void link_Click(object sender, EventArgs e) { var link = (LinkButton)sender; var raceId = Convert.ToInt32(link.CommandArgument); labelError.Text = ""; try { CentralLibrary.RemoveScores(raceId); // Remove Races var ctx = new SailTallyDataContext(); var race = (from r in ctx.SS_Races where r.RaceID == raceId select r).Single(); ctx.SS_Races.DeleteOnSubmit(race); ctx.SubmitChanges(); Server.Transfer("~/OrphanRaces.aspx"); } catch (Exception ex) { labelError.Text = "Unable to remove Orphan Race (Race ID: " + raceId.ToString() + "). Reason:" + ex.Message; } }
protected string GetFleetSeries(int raceId, int?fleetId) { var ctx = new SailTallyDataContext(); var raceSeries = from rs in ctx.SS_RaceSeries join fs in ctx.SS_FleetSeries on rs.FleetSeriesID equals fs.FleetSeriesID join f in ctx.SS_Fleets on fs.FleetID equals f.FleetID join s in ctx.SS_Series on fs.SeriesID equals s.SeriesID where rs.RaceID == raceId orderby f.ListOrder, f.FleetName, s.SeriesName select new { f.FleetName, s.SeriesName, rs.RaceNumber, f.FleetID }; if (fleetId != null) { raceSeries = raceSeries.Where(p => p.FleetID == fleetId); } var fleetSeries = ""; foreach (var raceSery in raceSeries) { if (fleetSeries.Length > 0) { fleetSeries += ", "; } fleetSeries += raceSery.FleetName + " " + raceSery.SeriesName + " " + raceSery.RaceNumber; } return(fleetSeries); }
protected void buttonScoreFleet_Click(object sender, EventArgs e) { var raceId = Convert.ToInt32(hiddenRaceID.Value); var fleetId = Convert.ToInt32(listFleet.SelectedValue); var ctx = new SailTallyDataContext(); // Save the header and hide it SaveRace(raceId); ShowDetail(true); ShowHeader(false); // Get the results (including the boats that have been scored var scoredBoats = from s in ctx.SS_Scores join b in ctx.SS_Boats on s.BoatID equals b.BoatID join p in ctx.SS_Penalties on s.PenaltyID equals p.PenaltyID where s.RaceID == raceId && b.FleetID == fleetId orderby s.FinishPlace select new { s.ScoreID, s.BoatID, b.SailNumber, s.FinishPlace, s.PenaltyID, p.PenaltyName, b.FleetID, p.IsNonPenalty }; // Populate the results (must be done prior to getting the available boats to score) listBoatsScored.Items.Clear(); _boatScores.Clear(); foreach (var scoredBoat in scoredBoats) // list of boats already scored { AddScore(scoredBoat.FleetID, scoredBoat.BoatID, scoredBoat.SailNumber, scoredBoat.FinishPlace, scoredBoat.PenaltyID, scoredBoat.PenaltyName, scoredBoat.IsNonPenalty); } // Get the available boats to score GetUnscoredBoats(fleetId); // Show the results ShowResults(raceId, fleetId); }
protected void listBoatsUnscored_SelectedIndexChanged(object sender, EventArgs e) { // Automatically move boat over to scored column var boatId = Convert.ToInt32(listBoatsUnscored.SelectedItem.Value); var sailNumber = listBoatsUnscored.SelectedItem.Text; var ctx = new SailTallyDataContext(); // Get the boat selected information var boat = (from b in ctx.SS_Boats where b.BoatID == boatId && b.IsActive select b).Single(); // Get the default non-penalty information var penalty = (from p in ctx.SS_Penalties where p.PenaltyName.Trim() == string.Empty && p.IsNonPenalty select p).Single(); AddScore(boat.FleetID, boatId, sailNumber, listBoatsScored.Items.Count + 1, penalty.PenaltyID, penalty.PenaltyName, penalty.IsNonPenalty); // Remove boat from the unscored list listBoatsUnscored.Items.Remove(listBoatsUnscored.SelectedItem); }
public static string GetNextTime(string currentTime) { var ctx = new SailTallyDataContext(); var times = from t in ctx.SS_Times orderby t.NextTimeOrder select t; var timeList = times.Select(time => time.TimeStr).ToList(); // Convert to an array for easier manipulation // Search for the current time var found = false; var timePos = 0; while (!found && timePos < timeList.Count) { if (string.Equals(timeList[timePos], currentTime, StringComparison.CurrentCultureIgnoreCase)) { found = true; } else { timePos++; } } if (found && timePos < timeList.Count - 1) // make sure currentTime was found and there is a next time { return(timeList[timePos + 1]); } return(string.Empty); }
protected void listPenalty_SelectedIndexChanged(object sender, EventArgs e) { if (listPenalty.SelectedItem == null) { return; } var ctx = new SailTallyDataContext(); var penaltyId = Convert.ToInt32(listPenalty.SelectedItem.Value); var penaltyName = listPenalty.SelectedItem.Text; var isNormalPenalty = (from p in ctx.SS_Penalties where p.PenaltyID == penaltyId select p).Single().IsNonPenalty; // Save existing settings var position = listBoatsScored.SelectedIndex; var boatScore = _boatScores[position]; // Remove existing entries listBoatsScored.Items.RemoveAt(position); _boatScores.RemoveAt(position); // Add entry back in to the existing location AddScore(position, boatScore.FleetId, boatScore.BoatId, boatScore.SailNumber, boatScore.FinishPosition, penaltyId, penaltyName, isNormalPenalty); // Re-highlight listBoatsScored.SelectedIndex = position; }
protected void ShowResults(int raceId, int fleetId) { panelResults.Visible = true; listFleet.Enabled = false; buttonScoreFleet.Enabled = false; ResetSelectedBoats(); labelSeriesPerFleet.Text = GetFleetSeries(raceId, fleetId); // Locate the results (if any) var ctx = new SailTallyDataContext(); var raceFleets = from rf in ctx.SS_RaceFleets where rf.RaceID == raceId && rf.FleetID == fleetId select rf; // should be 0 or 1 record selected if (!raceFleets.Any()) { // No results yet checkAbandoned.Checked = false; textCourse.Text = ""; textDistance.Text = ""; textDistanceUnits.Text = "NM"; } else { var raceFleet = raceFleets.Single(); // should only be one record - so get the first // Populate the results checkAbandoned.Checked = (raceFleet.IsAbandoned != null && (bool)raceFleet.IsAbandoned); textCourse.Text = raceFleet.Course; textDistance.Text = raceFleet.Distance.ToString(); textDistanceUnits.Text = raceFleet.DistanceUnits; } }
protected void UpdateRace() { // Note: This is available to allow minor edits to races previously scored var ctx = new SailTallyDataContext(); var raceId = SelectedRace; // ReSharper disable once LoopCanBePartlyConvertedToQuery foreach (var fsr in _fleetSeriesRace) { if (!fsr.Added) { continue; } var raceSeries = new SS_RaceSery { SeasonID = SelectedSeason, RaceID = raceId, FleetSeriesID = fsr.FleetSeriesId, RaceNumber = fsr.RaceNo }; ctx.SS_RaceSeries.InsertOnSubmit(raceSeries); } ctx.SubmitChanges(); }
protected void SaveRace() { // Note: This presumes a new Race ID is created (so if editing, the previous race should have been removed first) var ctx = new SailTallyDataContext(); var race = new SS_Race() { SeasonID = SelectedSeason, FirstWarningDate = SelectedWarning }; ctx.SS_Races.InsertOnSubmit(race); ctx.SubmitChanges(); // ReSharper disable once LoopCanBePartlyConvertedToQuery foreach (var fsr in _fleetSeriesRace) { var raceSeries = new SS_RaceSery { SeasonID = SelectedSeason, RaceID = race.RaceID, FleetSeriesID = fsr.FleetSeriesId, RaceNumber = fsr.RaceNo }; // use the newly created primary key ctx.SS_RaceSeries.InsertOnSubmit(raceSeries); } ctx.SubmitChanges(); }
public AssignRace(int seasonId, int fleetSeriesId, int?raceNumber, int?place, bool findNextAvailable, Races racesAlreadyAssigned) { _seasonId = seasonId; _fleetSeriesId = fleetSeriesId; _raceNumber = raceNumber; _place = place; _findNextAvailable = findNextAvailable; _racesAlreadyAssignedTrophy = racesAlreadyAssigned; // Find the maximum races var ctx = new SailTallyDataContext(); var raceNumbers = from r in ctx.SS_Results where r.SeasonID == _seasonId && r.FleetSeriesID == _fleetSeriesId && r.FinishPlace == _place select r.RaceNumber; _maxRaces = (raceNumbers.Any() ? raceNumbers.Max() : 0); // find the fleet ID and series ID for the given FleetSeriesID (since that is what trophies use) var fleetSery = (from fs in ctx.SS_FleetSeries where fs.FleetSeriesID == _fleetSeriesId && fs.SeasonID == _seasonId select new { fs.FleetID, fs.SeriesID }).Single(); _fleetId = fleetSery.FleetID; _seriesId = fleetSery.SeriesID; }
private void GetBoatResults() { var report = ""; var ctx = new SailTallyDataContext(); var boatResults = from rs in ctx.SS_ResultSummaries join b in ctx.SS_Boats on rs.BoatID equals b.BoatID join f in ctx.SS_Fleets on b.FleetID equals f.FleetID where rs.SeasonID == Convert.ToInt32(listSeason.SelectedValue) orderby f.FleetName, b.BoatID, rs.Position, rs.SeriesName select new { rs.FleetName, rs.BoatName, rs.Skipper, rs.SeriesName, rs.Position, rs.BoatID, rs.SailNumber }; var boatId = -1; report += "<table>"; foreach (var boatResult in boatResults) { if (boatId != boatResult.BoatID) // Have we moved to another boat? If so, new "header" { boatId = boatResult.BoatID; report += "<tr><td colspan='2'><h3>" + boatResult.FleetName + " #" + boatResult.SailNumber + (boatResult.BoatName != null && boatResult.BoatName.Length > 0 ? " " : "") + boatResult.BoatName + ", " + boatResult.Skipper + "</h3></td></tr>"; } report += "<tr><td>" + boatResult.SeriesName + "</td><td>" + CentralLibrary.PositionSuffix(boatResult.Position) + "</td></tr>"; } report += "</table>"; labelBoatResults.Text = report; }
protected void ShowRace(int raceId) { var ctx = new SailTallyDataContext(); var race = (from r in ctx.SS_Races where r.RaceID == raceId select r).Single(); // should only be one record // Populate Header fields hiddenRaceID.Value = raceId.ToString(CultureInfo.InvariantCulture); // save for future use labelWarning.Text = CentralLibrary.FormatDisplayTime(race.FirstWarningDate); labelSeries.Text = GetFleetSeries(raceId, null); textPRO.Text = race.PRO; textAssistPRO.Text = race.AssistPRO; textHelpers.Text = race.Helper; textDocked.Text = race.DockedDate?.ToShortTimeString() ?? CentralLibrary.GetCurrentDateTime().ToShortTimeString(); textWindDirection.Text = race.WindDirection; textWindSpeed.Text = race.WindSpeed; textCourseChange.Text = race.CourseChange; listWindUnits.SelectedValue = (string.IsNullOrEmpty(race.WindUnits) ? "kts" : race.WindUnits); textProtests.Text = race.Protests; textComments.Text = race.Comments; var fleets = GetFleetsForRace(raceId); listFleet.DataSource = fleets; listFleet.DataValueField = "fleetid"; listFleet.DataTextField = "fleetname"; listFleet.DataBind(); buttonScoreFleet.Enabled = (fleets.Any()); buttonRemoveScored.Visible = (!fleets.Any() && CentralLibrary.IsRacesScored(raceId)); // special case to have this function available ButtonAbandonRaces.Enabled = true; }
protected void Page_Load(object sender, EventArgs e) { var row = new TableRow(); AddColumn(row, "Action", CellType.Header); AddColumn(row, "Race ID", CellType.Header); AddColumn(row, "First Warning", CellType.Header); AddColumn(row, "Scored Races", CellType.Header); tableOrphans.Rows.Add(row); var ctx = new SailTallyDataContext(); // Sub Query var raceSeries = (from rs in ctx.SS_RaceSeries orderby rs.RaceID select rs.RaceID).Distinct(); // Main Query var races = from r in ctx.SS_Races where !raceSeries.Contains(r.RaceID) select r; foreach (var race in races) { row = new TableRow(); AddColumn(row, "Delete", CellType.Delete, race.RaceID); AddColumn(row, race.RaceID.ToString(), CellType.Normal); AddColumn(row, CentralLibrary.FormatDisplayTime(race.FirstWarningDate), CellType.Normal); AddColumn(row, (CentralLibrary.IsRacesScored(race.RaceID) ? "Yes" : "No"), CellType.Normal); tableOrphans.Rows.Add(row); } }
protected void GetTrophyResults() { var seasonId = Convert.ToInt32(listSeason.SelectedValue); var report = string.Empty; var ctx = new SailTallyDataContext(); var trophyResults = from t in ctx.SS_Trophies join f in ctx.SS_Fleets on t.FleetID equals f.FleetID join s in ctx.SS_Series on t.SeriesID equals s.SeriesID where t.SeasonID == seasonId orderby f.FleetName, s.SeriesName, t.RaceNumber, t.TrophyName // Order is critical for processing abandoned races select new { f.FleetName, t.FleetID, s.SeriesName, t.SeriesID, t.TrophyName, t.RaceNumber, t.Place, t.ShiftToNext }; report += "<table class='table table-striped TableGeneral'>"; report += "<tr><th>Fleet</th><th>Series</th><th>Scheduled Race #</th><th>Trophy</th><th>Boat</th><th>Race # Assigned</th></tr>"; var racesWithTrophy = new Races(); foreach (var trophyResult in trophyResults) { // On the fly calculation var assignTrophy = new AssignTrophy(trophyResult.FleetID, trophyResult.SeriesID, seasonId, trophyResult.RaceNumber, trophyResult.Place, trophyResult.ShiftToNext); assignTrophy.FindTrophy(racesWithTrophy); report += "<tr><td>" + trophyResult.FleetName + "</td><td>" + trophyResult.SeriesName + "</td><td>" + assignTrophy.RaceNumberStr() + "</td><td>" + trophyResult.TrophyName + "</td><td>" + assignTrophy.BoatWinner() + "</td><td>" + assignTrophy.RaceNumberAssigned() + "</td></tr>"; } report += "</table>"; labelTrophyResults.Text = report; }
protected void ShowRaces() { if (tableRaces.Visible) { var ctx = new SailTallyDataContext(); IQueryable <SS_Race> races; if (radioScheduledAll.Checked) { races = from r in ctx.SS_Races where r.SeasonID == Convert.ToInt32(listSeason.SelectedValue) orderby r.FirstWarningDate select r; } else if (radioScheduledScored.Checked) { races = from r in ctx.SS_Races where r.SeasonID == Convert.ToInt32(listSeason.SelectedValue) && r.DockedDate != null orderby r.FirstWarningDate descending select r; } else // Unscored { races = from r in ctx.SS_Races where r.SeasonID == Convert.ToInt32(listSeason.SelectedValue) && r.DockedDate == null orderby r.FirstWarningDate select r; } tableRaces.Rows.Clear(); var row = new TableRow(); var col = AddColumn("First Warning", -1, true); col.Width = 130; row.Cells.Add(col); //row.Cells.Add(this.AddColumn("Actual Warning", -1, true)); row.Cells.Add(AddColumn("PRO", -1, true)); row.Cells.Add(AddColumn("Series", -1, true)); tableRaces.Rows.Add(row); foreach (var race in races) { row = new TableRow(); row.Cells.Add(AddColumn(CentralLibrary.FormatDisplayTime(race.FirstWarningDate), race.RaceID, false)); //row.Cells.Add(this.AddColumn(race.ActualDate.ToString(), -1, false)); row.Cells.Add(AddColumn(race.PRO, -1, false)); var fleetSeries = GetFleetSeries(race.RaceID, null); row.Cells.Add(AddColumn(fleetSeries, -1, false)); tableRaces.Rows.Add(row); } } }
public static string GetSeason(int seasonId) { var ctx = new SailTallyDataContext(); var season = (from s in ctx.SS_Seasons where s.SeasonID == seasonId select s).First(); return(season != null ? season.SeasonName : "~SEASON NOT FOUND~"); }
public static double ScorePoints(int scoreMethodId, int place) { var ctx = new SailTallyDataContext(); var scoreMethodDetail = (from smd in ctx.SS_ScoreMethodDetails where smd.ScoreMethodID == scoreMethodId && smd.Place == place select smd).Single(); return(scoreMethodDetail.Points); }
public static string FormatDisplayTime(DateTime dt) { var actualTime = FormatTime(dt.ToShortTimeString()); var ctx = new SailTallyDataContext(); var displayTime = (from t in ctx.SS_Times where t.TimeStr == actualTime select t.DisplayTime).FirstOrDefault(); return(dt.ToShortDateString() + " " + displayTime); }
public static int GetNextRaceNumber(int seasonId, int fleetId, int seriesId) { var ctx = new SailTallyDataContext(); var fleetSeriesId = (from fs in ctx.SS_FleetSeries where fs.FleetID == fleetId && fs.SeriesID == seriesId select fs).First().FleetSeriesID; return(GetNextRaceNumber(seasonId, fleetSeriesId)); }
protected string PreflightSaveCheck() { var ctx = new SailTallyDataContext(); // NOTE: The SelectedRace is -1 if a new entry or the actual race ID if an edit. As a result // these following queries should work in both scenarios with the != comparison. // Check to make sure there are no other races scheduled at the same time - currently only // want one race per time slot. var races = (from r in ctx.SS_Races where r.RaceID != SelectedRace && r.SeasonID == SelectedSeason && r.FirstWarningDate == SelectedWarning select r); if (races.Any()) { return("An existing race is already present in this time slot. Please modify that one (Race ID: " + races.First().RaceID + ") to adjust the fleet/series assigned."); } for (var index = 0; index < _fleetSeriesRace.Count; index++) { var fsr = _fleetSeriesRace[index]; // Check to make sure there are no potential duplicate FleetSeries for a given season var raceSerys = from rs in ctx.SS_RaceSeries where rs.RaceID != SelectedRace && rs.SeasonID == SelectedSeason && rs.FleetSeriesID == fsr.FleetSeriesId && rs.RaceNumber == fsr.RaceNo select rs; if (!raceSerys.Any()) { continue; } var raceSery = raceSerys.First(); var race = (from r in ctx.SS_Races where r.RaceID == raceSery.RaceID select r).First(); string raceDate; if (race != null) { raceDate = "Check the schedule date " + race.FirstWarningDate; } else { raceDate = "Unable to find date"; } return("Existing Fleet/Series/Race# '" + listSelectedFleetSeries.Items[index].Text + "' already present. " + raceDate + " (RaceSeries ID #" + raceSery.RaceSeriesID + ")"); } return(string.Empty); }
public static bool HasUserRole(string username, string rolename) { var ctx = new SailTallyDataContext(); var roleFound = (from ur in ctx.SS_UserRoles join u in ctx.SS_Users on ur.UserID equals u.UserID join r in ctx.SS_Roles on ur.RoleID equals r.RoleID where u.Username == username && r.RoleName == rolename select ur).Count() > 1; return(roleFound); }
public static void GetPenalties(DropDownList list) { var ctx = new SailTallyDataContext(); var penalties = from p in ctx.SS_Penalties orderby p.PenaltyName select new { p.PenaltyID, p.PenaltyName }; list.DataSource = penalties; list.DataTextField = "penaltyname"; list.DataValueField = "penaltyid"; list.DataBind(); }
public static void GetTimes(DropDownList list) { var ctx = new SailTallyDataContext(); var times = from t in ctx.SS_Times orderby t.SortOrder select new { t.TimeID, t.TimeStr, t.DisplayTime }; list.DataSource = times; list.DataTextField = "displaytime"; list.DataValueField = "timestr"; list.DataBind(); }
public static bool IsRacesScored(int raceId) { var ctx = new SailTallyDataContext(); var scored = ((from s in ctx.SS_Scores where s.RaceID == raceId select s).Any()); var header = ((from rf in ctx.SS_RaceFleets where rf.RaceID == raceId select rf).Any()); return(scored || header); }
public static bool IsFleetSeriesExist(int seasonId, int fleetId, int seriesId, int fleetSeriesId) { var ctx = new SailTallyDataContext(); var isPresent = (from fs in ctx.SS_FleetSeries where fs.SeasonID == seasonId && fs.FleetID == fleetId && fs.SeriesID == seriesId && fs.FleetSeriesID != fleetSeriesId // don't find self (useful for editing) select fs).Any(); return(isPresent); }
protected void GetFleetsInResults(DropDownList list) { var ctx = new SailTallyDataContext(); var fleetNames = (from rs in ctx.SS_ResultSummaries where rs.SeasonID == SelectedSeason orderby rs.FleetName select new { rs.FleetName }).Distinct(); list.DataSource = fleetNames; list.DataTextField = "fleetname"; list.DataValueField = "fleetname"; list.DataBind(); }
public static void GetFleets(DropDownList list) { var ctx = new SailTallyDataContext(); var fleets = from f in ctx.SS_Fleets where f.IsActive orderby f.ListOrder, f.FleetName select new { f.FleetID, f.FleetName }; list.DataSource = fleets; list.DataTextField = "fleetname"; list.DataValueField = "fleetid"; list.DataBind(); }
protected IQueryable <SS_Fleet> GetFleetsForRace(int raceId) { var ctx = new SailTallyDataContext(); var fleets = (from f in ctx.SS_Fleets join fs in ctx.SS_FleetSeries on f.FleetID equals fs.FleetID join rs in ctx.SS_RaceSeries on fs.FleetSeriesID equals rs.FleetSeriesID join r in ctx.SS_Races on rs.RaceID equals r.RaceID where r.RaceID == raceId orderby f.ListOrder, f.FleetName, f.FleetID select f).Distinct(); return(fleets); }
protected void linkSave_Click(object sender, EventArgs e) { var raceId = Convert.ToInt32(hiddenRaceID.Value); var fleetId = Convert.ToInt32(listFleet.SelectedValue); var ctx = new SailTallyDataContext(); // Delete the existing scores var scoredBoats = from s in ctx.SS_Scores join b in ctx.SS_Boats on s.BoatID equals b.BoatID where s.RaceID == raceId && b.FleetID == fleetId select s; var raceFleets = from rf in ctx.SS_RaceFleets where rf.RaceID == raceId && rf.FleetID == fleetId select rf; ctx.SS_Scores.DeleteAllOnSubmit(scoredBoats); ctx.SS_RaceFleets.DeleteAllOnSubmit(raceFleets); ctx.SubmitChanges(); // Save the scores var raceFleet = new SS_RaceFleet { RaceID = raceId, FleetID = fleetId, IsAbandoned = checkAbandoned.Checked, Course = textCourse.Text, Distance = CentralLibrary.ConvertToDouble(textDistance.Text, 0), DistanceUnits = textDistanceUnits.Text }; ctx.SS_RaceFleets.InsertOnSubmit(raceFleet); // ReSharper disable once LoopCanBePartlyConvertedToQuery foreach (var boatScore in _boatScores) { var score = new SS_Score { RaceID = raceId, BoatID = boatScore.BoatId, PenaltyID = boatScore.PenaltyId, FinishPlace = boatScore.FinishPosition }; ctx.SS_Scores.InsertOnSubmit(score); } ctx.SubmitChanges(); ShowDetail(true); ShowRaces(); }
public static void UpdateResultSummaryPosition(int resultSummaryId, int position) { var ctx = new SailTallyDataContext(); var resultSummary = (from rs in ctx.SS_ResultSummaries where rs.ResultSummaryID == resultSummaryId select rs).First(); // should only have a single record returned if (resultSummary == null) { return; } resultSummary.Position = position; ctx.SubmitChanges(); }