Пример #1
0
        /// <summary>
        /// The event for when the Submit button is clicked.
        /// Converts form submission to a command object.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (titleTextBox.Text == "" || permissionComboBox.SelectedIndex == -1 || cooldownTextBox.Text == "" || outputTextBox.Text == "")
            {
                MessageBox.Show("Please enter some text!");
                return;
            }
            else
            {
                if (!titleTextBox.Text.StartsWith("!"))
                {
                    MessageBox.Show("Make sure the title of your command starts with a '!', like this: !example");
                    return;
                }

                int num;
                if (!int.TryParse(cooldownTextBox.Text, out num))
                {
                    MessageBox.Show("Cooldown has to use numbers");
                    return;
                }

                TimeSpan t = new TimeSpan(0, 0, num);

                comm = new Command(titleTextBox.Text, outputTextBox.Text, permissionComboBox.SelectedItem.ToString(), t);

                grid.AddCommand(comm);

                this.Close();
            }
        }
Пример #2
0
        /// <summary>
        /// Event for when the submit button is clicked.
        /// Converts timer form into a timer(command) object.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (titleTextBox.Text == "" || permissionComboBox.SelectedIndex == -1)
            {
                MessageBox.Show("Please enter some text!");
                return;
            }
            else
            {
                if ((hoursTextBox.Text == "" || minutesTextBox.Text == "" || secondsTextBox.Text == "") && !(countupCheckBox.IsChecked ?? false))
                {
                    MessageBox.Show("Please enter some text!");
                    return;
                }

                if (!titleTextBox.Text.StartsWith("!"))
                {
                    MessageBox.Show("Make sure the title of your command starts with a '!', like this: !example");
                    return;
                }
                titleTextBox.Text.Replace(" ", "");

                if (countupCheckBox.IsChecked ?? false)
                {
                    // this timer is simply counting up, like a stopwatch

                    timercomm = new Command(titleTextBox.Text,                          // title of timer
                                            "Timer is at: {timer}",                     // output of timer
                                            permissionComboBox.SelectedItem.ToString(), // who can use the command
                                            new TimeSpan(0, 0, 0),                      // cooldown is 0
                                            DateTime.Now);                              // the start of the stopwatch timer
                }
                else
                {
                    // parsing for hours, minutes, seconds that timer has to last

                    int hours;
                    if (!int.TryParse(hoursTextBox.Text, out hours))
                    {
                        MessageBox.Show("Hours has to use numbers");
                        return;
                    }

                    int minutes;
                    if (!int.TryParse(minutesTextBox.Text, out minutes))
                    {
                        MessageBox.Show("Minutes has to use numbers");
                        return;
                    }

                    int seconds;
                    if (!int.TryParse(secondsTextBox.Text, out seconds))
                    {
                        MessageBox.Show("Seconds has to use numbers");
                        return;
                    }

                    timercomm = new Command(titleTextBox.Text,                           // title of timer
                                            "Time left: {timer}",                        // output of timer
                                            permissionComboBox.SelectedItem.ToString(),  // who can use the command
                                            new TimeSpan(0, 0, 0),                       // cooldown is 0
                                            new TimeSpan(hours, minutes, seconds),       // how long the timer should last / countdown
                                            DateTime.Now);                               // the start of the timer
                    //MessageBox.Show(new TimeSpan(hours, minutes, seconds).ToString());
                }

                grid.AddCommand(timercomm);

                this.Close();
            }
        }