Пример #1
0
        //Getting the values of the row selected
        private void Button1_Click(object sender, EventArgs e)
        {
            if (checkBusExists == true)
            {
                String[] temp = new string[4];
                for (int i = 0; i < 4; i++)
                {
                    try
                    {
                        var value = tableResult.SelectedRows[0].Cells[i].Value;

                        temp[i] = value.ToString();
                    }catch (ArgumentOutOfRangeException ex)
                    {
                        MessageBox.Show("Highlight and select the whole row before clicking submit");
                        return;
                    }catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
                Booking booking = new Booking(temp[0], temp[1], temp[2], datepicker.Value.ToString("dd/MM/yyyy"), temp[3]);

                this.Hide();
                createBookings3 book3 = new createBookings3(customer, booking);
                book3.ShowDialog();
            }
            else
            {
                MessageBox.Show("No Buses are available for today!");
                return;
            }
        }
Пример #2
0
        private void searchButton_Click(object sender, EventArgs e)
        {
            string date = datepicker.Value.ToString("dd/MM/yyyy");

            //connection to database
            string Conn = "datasource=localhost;port=3306;username=root;password=;database=sbc;sslMode=none";

            //Retrieve records from database
            MySqlConnection MyConn = new MySqlConnection(Conn);

            try
            {
                MyConn.Open();
                MySqlDataReader MyReader;


                string Query = "SELECT NumberPlate, Category, Specification, busowner.name FROM bus" +
                               " JOIN busowner ON bus.OwnerIC = busowner.IC" +
                               " WHERE NumberPlate NOT IN(SELECT BusNumberPlate FROM drivershift WHERE Date = '" + date + "')" +
                               " AND bus.status = 'Available'" +
                               " ORDER BY FIELD(name, 'SBC') DESC;";

                MySqlCommand cmd = new MySqlCommand(Query, MyConn);

                MySqlDataAdapter MyAdapter = new MySqlDataAdapter();
                MyAdapter.SelectCommand = cmd;
                DataTable dTable = new DataTable();
                MyAdapter.Fill(dTable);
                tableResult.DataSource = dTable;
                MyConn.Close();

                //if no records are found, redirect back to mainpage
                if (dTable.Rows.Count < 1)
                {
                    MessageBox.Show("No Buses are available for this day!");
                    checkBusExists = false;
                    return;
                }
                else
                {
                    checkBusExists = true;
                }



                //check if sbc exists
                if (!checkSBC_Exists(dTable))
                {
                    DialogResult dr = MessageBox.Show("Internal SBC bookings are not available, do you want to outsource to external provider?",
                                                      "No SBC Buses Found", MessageBoxButtons.YesNo);
                    switch (dr)
                    {
                    case DialogResult.Yes:
                        Booking emptyBooking = new Booking(datepicker.Value.ToString("dd/MM/yyyy"));
                        this.Hide();
                        createBookings3 book3 = new createBookings3(customer, emptyBooking);
                        book3.ShowDialog();

                        /*MessageBox.Show("Yes");*/
                        break;

                    case DialogResult.No:
                        MessageBox.Show("No");
                        this.Hide();
                        AdminForm adminPage = new AdminForm();
                        adminPage.ShowDialog();
                        break;
                    }
                }
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message);
            }
        }