Exemplo n.º 1
0
 public void AddRace( Race race )
 {
     lock ( dbLock )
     {
         dbRoot.raceNameIndex.Put( race.Name, race );
         db.Commit();
     }
 }
Exemplo n.º 2
0
        public RaceDetailsDialog( Race race )
        {
            InitializeComponent();
            if ( race == null ) return;

            // Set GUI state
            raceNameTextBox.Text = race.Name;
            raceDescriptionTextBox.Text = race.Description;
            distanceNumericUpDown.Value = (decimal)race.Distance;
            if (race.Date < raceDateTimePicker.MinDate || race.Date > raceDateTimePicker.MaxDate)
            {
                raceDateTimePicker.Value = DateTime.Now;
            }
            else
            {
                raceDateTimePicker.Value = race.Date;
            }
        }
Exemplo n.º 3
0
 public void UpdateCurrentRace(Race newRaceDetails)
 {
     db.UpdateRace(CurrentRace.Oid, newRaceDetails);
 }
Exemplo n.º 4
0
 public void CreateNewRace(Race race, string dbFilename)
 {
     if (db.IsDbOpen)
     {
         db.Close();
     }
     // If we are overwriting, then delete the current file.
     if (File.Exists(dbFilename))
     {
         File.Delete(dbFilename);
     }
     db.Open(dbFilename);
     logController.Open(Path.ChangeExtension(dbFilename, ".log"));
     options.LastFile = dbFilename;
     db.AddRace(race);
 }
Exemplo n.º 5
0
        private void RaceDetailsToolStripMenuItemClick(object sender, EventArgs e)
        {
            if ( !CheckHaveDb()) return;

            var raceDetailsDialog = new RaceDetailsDialog(appController.CurrentRace);
            if (raceDetailsDialog.ShowDialog() != DialogResult.OK)
            {
                // OK - user wants to quit
                return;
            }

            // Create race object
            var race = new Race
            {
                Name = raceDetailsDialog.RaceName,
                Description = raceDetailsDialog.RaceDescritpion,
                Distance = raceDetailsDialog.RaceDistance,
                Date = raceDetailsDialog.RaceDate
            };

            appController.UpdateCurrentRace( race );
            SetTitle();
        }
Exemplo n.º 6
0
        private void NewToolStripMenuItemClick( object sender, EventArgs e )
        {
            // If we have a DB open, check if we want it to be closed first.
            if (! CheckWhatToDoIfHaveDbOpen() ) return;

            // 1. Get race details from user
            var raceDetailsDialog = new RaceDetailsDialog()
            {
                Icon = Icon,
            };
            if ( raceDetailsDialog.ShowDialog() != DialogResult.OK )
            {
                // OK - user wants to quit
                return;
            }

            // Create race object
            var race = new Race
            {
                Name = raceDetailsDialog.RaceName,
                Description = raceDetailsDialog.RaceDescritpion,
                Distance = raceDetailsDialog.RaceDistance,
                Date = raceDetailsDialog.RaceDate
            };

            // 2. Get a filename for data storage from user. This also checks to see if the
            //    file can be overwritten if it exists.
            var saveFileDlg = new SaveFileDialog
            {
                RestoreDirectory = true,
                Filter = "database files (*.dbs)|*.dbs|All files (*.*)|*.*",
                FileName = race.Name + ".dbs",
                Title = "Database file for the race data..."
            };

            if ( saveFileDlg.ShowDialog() != DialogResult.OK )
            {
                // OK - user wants to quit
                return;
            }

            // This will close the current DB and create a new one.
            appController.CreateNewRace( race, saveFileDlg.FileName );
            SetTitle();
        }
Exemplo n.º 7
0
 public void UpdateRace( int oid, Race newDetails )
 {
     lock ( dbLock )
     {
         var race = GetRaces().FirstOrDefault( r => r.Oid == oid );
         if ( race == null )
         {
             throw new Exception( "No race object with oid " + oid );
         }
         race.Name = newDetails.Name;
         race.Description = newDetails.Description;
         race.Distance = newDetails.Distance;
         race.Date = newDetails.Date;
         race.Modify();  // Inform DB that it's been modified
         db.Commit();    // Push changes back to DB
     }
 }