Пример #1
0
        private void b_save_Click(object sender, RoutedEventArgs e)
        {
            if (tb_busride_id.Text == "" || departure_address == "" || departure_city == "" || departure_country == "" || dtp_departuredate.Value == null || arrival_address == "" || arrival_city == "" || arrival_country == "" || dtp_arrivaldate.Value == null || tb_cost.Text == "" || tb_max_seats.Text == "")
            {
                MessageBox.Show("Empty fields are not allowed. (Except for Driver ID)", "Error!", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }


            BusrideObject newObject   = new BusrideObject(Int32.Parse(tb_busride_id.Text), departure_address, departure_city, departure_country, (DateTime)dtp_departuredate.Value, arrival_address, arrival_city, arrival_country, (DateTime)dtp_arrivaldate.Value, Int32.Parse(tb_cost.Text), Int32.Parse(tb_max_seats.Text), tb_driver_id.Text);
            int           rowsChanged = -1;

            if (newbusride)
            {
                rowsChanged = DBConnection.InsertBusride(newObject);
            }
            else
            {
                rowsChanged = DBConnection.UpdateBusride(newObject, oldObject);
            }

            if (rowsChanged > 0)
            {
                parentWindow.UpdateAllChain();
                Close();
            }
        }
Пример #2
0
        public ChangeBusrideWindow(EmployeeWindow _parent, BusrideObject _oldObject)
        {
            InitializeComponent();
            Title                   = "Edit Busride - " + Authenticator.GetUserInfo();
            oldObject               = _oldObject;
            tb_busride_id.Text      = oldObject.busride_id.ToString();
            tb_departure.Text       = oldObject.departure_address + ", " + oldObject.departure_city + ", " + oldObject.departure_country;
            dtp_departuredate.Value = oldObject.departure_date;
            tb_arrival.Text         = oldObject.arrival_address + ", " + oldObject.arrival_city + ", " + oldObject.arrival_country;
            dtp_arrivaldate.Value   = oldObject.arrival_date;
            tb_cost.Text            = oldObject.cost.ToString();
            tb_max_seats.Text       = oldObject.max_seats.ToString();
            tb_driver_id.Text       = (oldObject.driver_id == null) ? "" : oldObject.driver_id.ToString();

            departure_address = oldObject.departure_address;
            departure_city    = oldObject.departure_city;
            departure_country = oldObject.departure_country;

            arrival_address = oldObject.arrival_address;
            arrival_city    = oldObject.arrival_city;
            arrival_country = oldObject.arrival_country;


            parentWindow = _parent;
            newbusride   = false;
        }
Пример #3
0
        public ChangeTravellerBookingWindow(TravellerWindow _parent, BusrideObject _oldObject)
        {
            InitializeComponent();
            Title               = "New Booking - " + Authenticator.GetUserInfo();
            oldObject           = _oldObject;
            l_departure.Content = "Departure: " + Environment.NewLine + oldObject.departure_date.ToString("dd-MMM-yyyy HH:mm:ss") + Environment.NewLine + oldObject.departure_address + Environment.NewLine + oldObject.departure_city + Environment.NewLine + oldObject.departure_country;
            l_arrival.Content   = "Arrival: " + Environment.NewLine + oldObject.arrival_date.ToString("dd-MMM-yyyy HH:mm:ss") + Environment.NewLine + oldObject.arrival_address + Environment.NewLine + oldObject.arrival_city + Environment.NewLine + oldObject.arrival_country;
            tb_seats.Text       = "";


            parentWindow = _parent;
        }
Пример #4
0
        public static int UpdateBusride(BusrideObject newObject, BusrideObject oldObject)
        {
            int affectedRows = -1;

            if (newObject.driver_id == "")
            {
                affectedRows = ExecuteAndGetNonQuery("UPDATE busride SET busride_id = :p0, departure_address = :p1, departure_city = :p2, departure_country = :p3, departure_date = :p4, arrival_address = :p5, arrival_city = :p6, arrival_country = :p7, arrival_date = :p8, cost = :p9, max_seats = :p10, driver_id = NULL WHERE busride_id = :p11;", newObject.busride_id, newObject.departure_address, newObject.departure_city, newObject.departure_country, newObject.departure_date, newObject.arrival_address, newObject.arrival_city, newObject.arrival_country, newObject.arrival_date, newObject.cost, newObject.max_seats, oldObject.busride_id);
            }
            else
            {
                affectedRows = ExecuteAndGetNonQuery("UPDATE busride SET busride_id = :p0, departure_address = :p1, departure_city = :p2, departure_country = :p3, departure_date = :p4, arrival_address = :p5, arrival_city = :p6, arrival_country = :p7, arrival_date = :p8, cost = :p9, max_seats = :p10, driver_id = :p11 WHERE busride_id = :p12;", newObject.busride_id, newObject.departure_address, newObject.departure_city, newObject.departure_country, newObject.departure_date, newObject.arrival_address, newObject.arrival_city, newObject.arrival_country, newObject.arrival_date, newObject.cost, newObject.max_seats, newObject.driver_id, oldObject.busride_id);
            }
            return(affectedRows);
        }
Пример #5
0
        public static int InsertBusride(BusrideObject newObject)
        {
            int affectedRows = -1;

            if (newObject.driver_id == "")
            {
                affectedRows = ExecuteAndGetNonQuery("INSERT INTO busride (busride_id, departure_address, departure_city, departure_country, departure_date, arrival_address, arrival_city, arrival_country, arrival_date, cost, max_seats) values (:p0, :p1, :p2, :p3, :p4, :p5, :p6, :p7, :p8, :p9, :p10);", newObject.busride_id, newObject.departure_address, newObject.departure_city, newObject.departure_country, newObject.departure_date, newObject.arrival_address, newObject.arrival_city, newObject.arrival_country, newObject.arrival_date, newObject.cost, newObject.max_seats);
            }
            else
            {
                affectedRows = ExecuteAndGetNonQuery("INSERT INTO busride (busride_id, departure_address, departure_city, departure_country, departure_date, arrival_address, arrival_city, arrival_country, arrival_date, cost, max_seats, driver_id) values (:p0, :p1, :p2, :p3, :p4, :p5, :p6, :p7, :p8, :p9, :p10, :p11);", newObject.busride_id, newObject.departure_address, newObject.departure_city, newObject.departure_country, newObject.departure_date, newObject.arrival_address, newObject.arrival_city, newObject.arrival_country, newObject.arrival_date, newObject.cost, newObject.max_seats, newObject.driver_id);
            }
            return(affectedRows);
        }
Пример #6
0
        private void b_choose_Click(object sender, RoutedEventArgs e)
        {
            if (lv_lista.SelectedItem != null)
            {
                BusrideObject selected = (BusrideObject)lv_lista.SelectedItem;

                parentWindow.tb_busride_id.Text = selected.busride_id.ToString();

                Close();
            }
            else
            {
                MessageBox.Show("Nothing selected.", "Error!", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
Пример #7
0
        public static int RemoveBusrideChaffor(BusrideObject oldObject, string driver_id)
        {
            if (oldObject.driver_id == null || oldObject.driver_id == driver_id)
            {
                BusrideObject newObject = new BusrideObject(oldObject.busride_id, oldObject.departure_address, oldObject.departure_city, oldObject.departure_country, oldObject.departure_date, oldObject.arrival_address, oldObject.arrival_city, oldObject.arrival_country, oldObject.arrival_date, oldObject.cost, oldObject.max_seats, "");
                return(UpdateBusride(newObject, oldObject));
            }
            else
            {
                MessageBoxResult result = MessageBox.Show("You can only cancel the driver on a busride where you are the driver.", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
            }


            return(-1);
        }
Пример #8
0
        public static int SetBusrideChaffor(BusrideObject oldObject, string driver_id)
        {
            if (oldObject.driver_id == null || oldObject.driver_id == "")
            {
                BusrideObject newObject = new BusrideObject(oldObject.busride_id, oldObject.departure_address, oldObject.departure_city, oldObject.departure_country, oldObject.departure_date, oldObject.arrival_address, oldObject.arrival_city, oldObject.arrival_country, oldObject.arrival_date, oldObject.cost, oldObject.max_seats, driver_id);
                return(UpdateBusride(newObject, oldObject));
            }
            else
            {
                MessageBoxResult result = MessageBox.Show("You can only apply to drive a busride that currently has no driver.", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
            }


            return(-1);
        }
Пример #9
0
        public static int DeleteBusride(BusrideObject oldObject)
        {
            int bookingsCount = 0;

            bookingsCount = ExecuteAndGetScalar("SELECT count(*) FROM booking WHERE booking.busride_id = :p0;", oldObject.busride_id);

            int affectedRows = -1;

            MessageBoxResult result = MessageBox.Show("If you remove this busride a total of " + bookingsCount + " bookings will also be removed! Do you still wish to remove this busride?", "Warning", MessageBoxButton.YesNo, MessageBoxImage.Warning);

            if (result == MessageBoxResult.Yes)
            {
                ExecuteAndGetNonQuery("DELETE FROM booking WHERE busride_id = :p0;", oldObject.busride_id);
                affectedRows = ExecuteAndGetNonQuery("DELETE FROM busride WHERE busride_id = :p0;", oldObject.busride_id);
            }
            return(affectedRows);
        }
Пример #10
0
        public static List <MyBookingObject> SelectBookingsJoinBusride(string _traveller, int limit, int offset)
        {
            List <MyBookingObject> returnObj = new List <MyBookingObject>();

            NpgsqlConnection conn = null;
            NpgsqlDataReader dr   = null;

            try
            {
                conn = OpenConnectionAndGetReader("SELECT * FROM (booking JOIN busride ON booking.busride_id = busride.busride_id) WHERE traveller = :p0 order by booking.busride_id, lower(traveller) limit :p1 offset :p2;", out dr, _traveller, limit, offset);
                while (dr.Read())
                {
                    int      busride_id        = dr.GetFieldValue <int>(dr.GetOrdinal("busride_id"));
                    string   departure_address = dr.GetFieldValue <string>(dr.GetOrdinal("departure_address"));
                    string   departure_city    = dr.GetFieldValue <string>(dr.GetOrdinal("departure_city"));
                    string   departure_country = dr.GetFieldValue <string>(dr.GetOrdinal("departure_country"));
                    DateTime departure_date    = dr.GetFieldValue <DateTime>(dr.GetOrdinal("departure_date"));
                    string   arrival_address   = dr.GetFieldValue <string>(dr.GetOrdinal("arrival_address"));
                    string   arrival_city      = dr.GetFieldValue <string>(dr.GetOrdinal("arrival_city"));
                    string   arrival_country   = dr.GetFieldValue <string>(dr.GetOrdinal("arrival_country"));
                    DateTime arrival_date      = dr.GetFieldValue <DateTime>(dr.GetOrdinal("arrival_date"));
                    int      cost      = dr.GetFieldValue <int>(dr.GetOrdinal("cost"));
                    int      max_seats = dr.GetFieldValue <int>(dr.GetOrdinal("max_seats"));
                    string   driver_id = null;
                    if (!dr.IsDBNull(dr.GetOrdinal("driver_id")))
                    {
                        driver_id = dr.GetFieldValue <string>(dr.GetOrdinal("driver_id"));
                    }
                    BusrideObject buss = new BusrideObject(busride_id, departure_address, departure_city, departure_country, departure_date,
                                                           arrival_address, arrival_city, arrival_country, arrival_date, cost, max_seats, driver_id);

                    string traveller = dr.GetFieldValue <string>(dr.GetOrdinal("traveller"));
                    int    seats     = dr.GetFieldValue <int>(dr.GetOrdinal("seats"));

                    returnObj.Add(new MyBookingObject(buss, traveller, seats));
                }
            }
            finally
            {
                conn.Close();
            }
            return(returnObj);
        }