コード例 #1
0
ファイル: TaskForm.cs プロジェクト: wilson212/ATSEngineTool
        /// <summary>
        /// Closes the Task dialog, and clears the Cancelled event handle subscriptions
        /// </summary>
        public static void CloseForm()
        {
            // No exception here
            if (Instance == null || Instance.IsDisposed)
            {
                return;
            }

            // Remove all cancellation subs
            if (Cancelled != null)
            {
                Cancelled = (CancelEventHandler)Delegate.RemoveAll(Cancelled, Cancelled);
            }

            try
            {
                Instance.Invoke((Action) delegate()
                {
                    Instance.Close();
                    Instance = null;
                });
            }
            catch { }
        }
コード例 #2
0
ファイル: TaskForm.cs プロジェクト: wilson212/ATSEngineTool
 private void TaskForm_FormClosed(object sender, FormClosedEventArgs e)
 {
     Instance = null;
 }
コード例 #3
0
ファイル: TaskForm.cs プロジェクト: wilson212/ATSEngineTool
        /// <summary>
        /// Open and displays the task form.
        /// </summary>
        /// <param name="Parent">The calling form, so the task form can be centered</param>
        /// <param name="WindowTitle">The task dialog window title</param>
        /// <param name="InstructionText">Instruction text displayed after the info icon. Leave null
        /// to hide the instruction text and icon.</param>
        /// <param name="SubMessage">Detail text that is displayed just above the progress bar</param>
        /// <param name="Cancelable">Specifies whether the operation can be canceled</param>
        /// <param name="Style">The progress bar style</param>
        /// <exception cref="Exception">Thrown if the Task form is already open and running. Use the IsOpen property
        /// to determine if the form is already running</exception>
        public static void Show(Form Parent,
                                string WindowTitle,
                                string InstructionText,
                                string SubMessage      = "",
                                bool Cancelable        = false,
                                ProgressBarStyle Style = ProgressBarStyle.Marquee,
                                int ProgressBarSteps   = 0)
        {
            // Make sure we dont have an already active form
            if (Instance != null && !Instance.IsDisposed)
            {
                throw new Exception("Task Form is already being displayed!");
            }

            // Create new instance
            Instance      = new TaskForm();
            Instance.Text = WindowTitle;
            Instance.labelInstructionText.Text = InstructionText;
            Instance.labelContent.Text         = SubMessage;
            Instance.Cancelable        = Cancelable;
            Instance.progressBar.Style = Style;

            // Setup progress bar
            if (ProgressBarSteps > 0)
            {
                Instance.progressBar.Maximum = ProgressBarSteps;
            }

            // Hide Instruction panel if Instruction Text is empty
            if (String.IsNullOrWhiteSpace(InstructionText))
            {
                Instance.panelMain.Hide();
                Instance.labelContent.Location    = new Point(10, 15);
                Instance.labelContent.MaximumSize = new Size(410, 0);
                Instance.labelContent.Size        = new Size(410, 0);
                Instance.progressBar.Location     = new Point(10, 1);
                Instance.progressBar.Size         = new Size(410, 18);
            }

            // Hide Cancel
            if (!Cancelable)
            {
                Instance.panelButton.Hide();
                Instance.Padding   = new Padding(0, 0, 0, 15);
                Instance.BackColor = Color.White;
            }

            // Set window position to center parent
            double H = Parent.Location.Y + (Parent.Height / 2) - (Instance.Height / 2);
            double W = Parent.Location.X + (Parent.Width / 2) - (Instance.Width / 2);

            Instance.Location = new Point((int)Math.Round(W, 0), (int)Math.Round(H, 0));

            // Display the Instanced Form
            Instance.Show(Parent);

            // Wait until the Instance form is displayed
            while (!Instance.IsHandleCreated)
            {
                Thread.Sleep(50);
            }
        }
コード例 #4
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();
        }