コード例 #1
0
        /// <summary>
        /// Confirm Button Click Event
        /// </summary>
        private async void confirmButton_Click(object sender, System.EventArgs e)
        {
            // Validate user input!
            if (!PassesValidaion())
            {
                return;
            }

            // Add or update the package details
            Package.Name             = packageNameBox.Text;
            Package.Author           = labelAuthor.Text;
            Package.Version          = labelVersion.Text;
            Package.UnitName         = unitNameBox.Text;
            Package.FolderName       = folderNameBox.Text;
            Package.InteriorFileName = intFilenameBox.Text;
            Package.ExteriorFileName = extFilenameBox.Text;

            // Open the database connection and lets go!
            using (AppDatabase db = new AppDatabase())
            {
                // Did we import new data?
                if (!Imported)
                {
                    switch (Package.SoundType)
                    {
                    // Add or update the existing package
                    case SoundType.Engine:
                        db.EngineSoundPackages.AddOrUpdate((EngineSoundPackage)Package);
                        break;

                    case SoundType.Truck:
                        db.TruckSoundPackages.AddOrUpdate((TruckSoundPackage)Package);
                        break;
                    }
                }
                else
                {
                    // Else, we imported. We do this in a seperate task
                    try
                    {
                        // Show task form
                        TaskForm.Show(this,
                                      "Importing Sound Package",
                                      "Importing Sound Package",
                                      "Please wait while the sound package is installed..."
                                      );

                        // Import sound
                        await Task.Run(() => ImportSoundPack(db));

                        // Close task form
                        TaskForm.CloseForm();
                    }
                    catch (Exception ex)
                    {
                        TaskForm.CloseForm();
                        ExceptionHandler.GenerateExceptionLog(ex);
                        MessageBox.Show(ex.Message, "Sound Installation Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
            }

            // Close the form
            this.DialogResult = DialogResult.OK;
            this.Close();
        }