コード例 #1
0
 private void CancelBtn_Click(object sender, EventArgs e)
 {
     RouteTextBox.Clear();
     ToTextBox.Clear();
     FromTextBox.Clear();
     TypeComboBox.SelectedIndex = -1;
 }
コード例 #2
0
        private void addSchedule()
        {
            if (RouteTextBox.Text == "" || ToTextBox.Text == "" || FromTextBox.Text == "" || TimePicker.Text == "" || TypeComboBox.Text == "")
            {
                MessageBox.Show("Please enter all the details.", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (TimePicker.Text == DateTime.Now.ToString("HH:mm:ss"))
            {
                MessageBox.Show("Please enter a valid time.", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                try
                {
                    con.Open();

                    // adding new schedule
                    string sql = "INSERT INTO schedules (route, start_from, ends_at, departure_time, type) VALUES('" + RouteTextBox.Text + "', '" + FromTextBox.Text + "', '" + ToTextBox.Text + "', '" + TimePicker.Text + "', '" + TypeComboBox.Text + "')";

                    SqlCommand cmd = new SqlCommand(sql, con);
                    cmd.ExecuteNonQuery();

                    MessageBox.Show("Schedule created successfully!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    con.Close();

                    refreshData();

                    RouteTextBox.Clear();
                    ToTextBox.Clear();
                    FromTextBox.Clear();
                    TypeComboBox.SelectedIndex = -1;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    con.Close();
                }
            }
        }