예제 #1
0
        protected void buttonAddFleetSeries_Click(object sender, EventArgs e)
        {
            SetError();
            if (listFleet.SelectedItem == null)
            {
                SetError("Fleet not Selected.");
            }
            else if (listFleetSeries.SelectedItem == null)
            {
                SetError("Series not Selected.");
            }
            else if (textRaceNo.Text.Length < 1 || Convert.ToInt32(textRaceNo.Text) < 1)
            {
                SetError("Race # not Specified.");
            }
            else if (textPointsFactor.Text.Length < 1 || Convert.ToInt32(textPointsFactor.Text) < 1)
            {
                SetError("Points Factor not specified");
            }
            else if (IsFleetSeriesSelected(SelectedFleet, SelectedFleetSeries))
            {
                SetError("Cannot select a duplicate Series per Fleet for a given Race.");
            }
            else
            {
                //string fleetSeries = this.listFleet.SelectedItem.Text + " / " + this.listFleetSeries.SelectedItem.Text + " / " + this.textRaceNo.Text;
                var fsr = new FleetSeriesRace()
                {
                    FleetId       = Convert.ToInt32(listFleet.SelectedValue),
                    FleetSeriesId = Convert.ToInt32(listFleetSeries.SelectedValue),
                    RaceNo        = Convert.ToInt32(textRaceNo.Text),
                    PointsFactor  = Convert.ToInt32(textPointsFactor.Text),
                    Excludable    = checkExcludable.Checked,
                    FleetName     = listFleet.SelectedItem.Text,
                    SeriesName    = listFleetSeries.SelectedItem.Text,
                    Added         = true
                };
                var fleetSeries = fsr.Display();
                _fleetSeriesRace.Add(fsr);

                var item = new ListItem
                {
                    Text  = fleetSeries,
                    Value = fleetSeries
                };
                listSelectedFleetSeries.Items.Add(item);
                textRaceNo.Text = string.Empty;
            }
        }
예제 #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                _fleetSeriesRace = (List <FleetSeriesRace>)ViewState["_FleetSeriesRace"]; // Load state
            }
            else
            {
                _fleetSeriesRace = new List <FleetSeriesRace>(); // allocate memory

                // Set the values via the IsCrossPagePostBack because the PreviousPage values won't be available after a PostBack here.
                hiddenSeasonID.Value = PreviousPage.SelectedSeason;

                hiddenRaceID.Value = Request[Constant.GetVar.RaceId];

                CentralLibrary.GetTimes(listRace);
                CentralLibrary.GetFleets(listFleet);
                CentralLibrary.GetFleetSeries(listFleetSeries, Convert.ToInt32(listFleet.SelectedValue), SelectedSeason);
                FindNextRaceNumber();

                labelScored.Visible = false;

                if (IsNewRace) // Creating a new race entry
                {
                    linkDeleteRace.Visible = false;

                    if (PreviousPage.SelectedDate.Trim().Length > 0)
                    {
                        UpdateDate(PreviousPage.SelectedDate);
                    }
                    else
                    {
                        UpdateDate(CentralLibrary.GetCurrentDateTime());
                    }
                }
                else // Editing an existing race entry
                {
                    var ctx = new SailTallyDataContext();

                    // Get the data
                    var race = (from r in ctx.SS_Races
                                where r.RaceID == SelectedRace
                                select r).Single();
                    var raceSerys = 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 == SelectedRace
                                    select new { rs.RaceSeriesID, rs.RaceNumber, fs.FleetSeriesID, f.FleetID, f.FleetName, s.SeriesID, s.SeriesName };

                    // Put the data to the controls
                    UpdateDate(race.FirstWarningDate, CentralLibrary.FormatTime(race.FirstWarningDate));

                    foreach (var raceSeries in raceSerys)
                    {
                        var fsr = new FleetSeriesRace()
                        {
                            FleetId       = raceSeries.FleetID,
                            FleetSeriesId = raceSeries.FleetSeriesID,
                            RaceNo        = raceSeries.RaceNumber,
                            RaceSeriesId  = raceSeries.RaceSeriesID,
                            FleetName     = raceSeries.FleetName,
                            SeriesName    = raceSeries.SeriesName
                        };
                        _fleetSeriesRace.Add(fsr);

                        var item        = new ListItem();
                        var fleetSeries = fsr.Display(); //raceSeries.FleetName.Trim() + " / " + raceSeries.SeriesName.Trim() + " / " + raceSeries.RaceNumber.ToString();
                        item.Text  = fleetSeries;
                        item.Value = fleetSeries;
                        listSelectedFleetSeries.Items.Add(item);
                    }

                    // Determine if there are any races scored (if so, disable editing since don't want to create a new RaceID)
                    var scores = from s in ctx.SS_Scores
                                 where s.RaceID == SelectedRace
                                 select s;

                    var raceFleets = from rf in ctx.SS_RaceFleets
                                     where rf.RaceID == SelectedRace
                                     select rf;

                    if (!scores.Any() && !raceFleets.Any())
                    {
                        return;
                    }

                    labelScored.Visible = true;
                    hiddenScored.Value  = "1";

                    calendarRace.Enabled            = false;
                    listRace.Enabled                = false;
                    listSelectedFleetSeries.Enabled = false;
                    buttonRemoveFleetSeries.Enabled = false;
                    linkDeleteRace.Enabled          = false;

                    // Note: Now allow race series insertion (Fleet/Series/RaceNo can be added even if previous scored)
                    //this.listFleet.Enabled = false;
                    //this.listFleetSeries.Enabled = false;
                    //this.textRaceNo.Enabled = false;
                    //this.buttonAddFleetSeries.Enabled = false;
                    //this.linkSave.Enabled = false;
                }
            }
        }