private Boolean Checked;        //radio button state store
 public AddJourneyWindow(int vehicleID, Boolean payable)
 {
     InitializeComponent();
     this.J       = new Journey(0, DateTime.Now, DateTime.Now, DateTime.Now, vehicleID, false); //Random journey
     saveState    = false;                                                                      //when window constructed has not been saved yet
     validJourney = true;
     Checked      = false;
     //Disable specifiable as payable (admin only)
     if (!payable)
     {
         PaidRadioBtn.IsHitTestVisible = false; PaidRadioBtn.Opacity = 0.5;
     }
 }
        //JOURNEYS ADD EDIT DELETE
        private void AddJourniesBtn_Click(object sender, RoutedEventArgs e)
        {
            beforeEffects();
            AddJourneyWindow addJourneyWin = new AddJourneyWindow(vehicleID, true);

            addJourneyWin.ShowDialog();
            if (addJourneyWin.getSaveState() && addJourneyWin.getValidity())
            {
                Journey J = addJourneyWin.getJourney(); // Get the new journey
                journies.Add(J);                        //  Add to the list
                allJournies.Add(J);                     //Add to the list of all journeys
                Console.WriteLine(" Journey Added");
            }
            afterEffects();
        }
示例#3
0
        //Add new journey
        private void NewJourneyBtn_Click(object sender, RoutedEventArgs e)
        {
            AddJourneyWindow addJourneyWin = new AddJourneyWindow(R.getVehicle().getVehicleID(), false);

            addJourneyWin.ShowDialog();
            if (addJourneyWin.getSaveState() && addJourneyWin.getValidity())
            {
                Journey   J        = addJourneyWin.getJourney(); // Get the new journey
                Boolean[] rentable = R.isJourneyRentable(J);     //use rental of vehicle to check if vehicle can be rented for this journey

                //Add to the list of unpaid journies
                if (rentable[0] && rentable[1] && rentable[2] && rentable[3]) //Rentable as met all conditions
                {
                    R.addTemporaryRental(J);                                  //set rental awaiting payment
                    performRefresh();                                         //Refresh display
                    //Disable button, one sucessful rent for window
                    NewJourneyBtn.IsHitTestVisible = false;
                    NewJourneyBtn.Opacity          = 0.5;
                }
                else
                { //not rentable
                    String errorMsg = "Not Rentable:";
                    if (!rentable[0])
                    {
                        errorMsg = errorMsg + " Date Taken!";
                    }                                                           //Check if journey of same date exists in database!
                    if (!rentable[1])
                    {
                        errorMsg = errorMsg + " Service Required!";
                    }                                                                 //Needs service
                    if (!rentable[2])
                    {
                        errorMsg = errorMsg + " Journey date older than car!";
                    }                                                                            //Car doesn't exist yet!
                    if (!rentable[3])
                    {
                        errorMsg = errorMsg + " Journey too long!";
                    }                          //Journey too long!
                    MessageBox.Show(errorMsg); //WHy not rentable
                }
            }
            else if (!addJourneyWin.getValidity())
            {
                MessageBox.Show("Invalid Data Inputs");
            }
        }
        private void computeJourneyHistoryDetails(Vehicle v, List <Journey> allJournies)
        {
            //Get data
            List <Journey> vJournies = Journey.FindJournies(allJournies, v.getVehicleID()); //Get the journies for this vehicle!

            //Compute revenue info
            double revenue = 0; double unpaid = 0; //initialise costings

            foreach (Journey j in vJournies)
            {                                        //loop through journies for vehicle
                revenue = revenue + j.JourneyCost(); //Sum journey costs
                if (!j.isPaid())
                {
                    unpaid = unpaid + j.JourneyCost();
                }                                                       //Sum unpaid costs for this vehicle
            }
            this.revenueInfo = revenue + " (with " + unpaid + " unpaid)";
        }
        public HistoryWindow(int vehicleID, List <Service> allServices, List <Journey> allJournies, List <FuelPurchase> allFuelPurchases)
        {
            InitializeComponent();
            this.vehicleID = vehicleID;
            this.Title     = "History of Vehicle ID: " + vehicleID;

            // the journeys of the car
            this.allJournies = allJournies;
            this.journies    = Journey.FindJournies(allJournies, vehicleID);
            // services of the car
            this.allServices = allServices;
            this.services    = Service.FindServices(allServices, vehicleID);
            //Fuel Purchase of the car
            this.allFuelPurchases = allFuelPurchases;
            this.FPurchases       = FuelPurchase.FindFuelPurchases(allFuelPurchases, vehicleID);

            this.DataContext = this; formatDates("{0:dd/MM/yyyy}");  performRefresh(); //Binding
        }
        private void EditJourniesBtn_Click(object sender, RoutedEventArgs e)
        {
            IList iL = JourniesDisplayLvw.SelectedItems;  //select items (journies)

            if (iL.Count == 1)
            {
                beforeEffects();
                EditJourneyWindow editJourneyWin = new EditJourneyWindow((Journey)iL[0]);
                editJourneyWin.ShowDialog();
                // Check if saved or not
                if (editJourneyWin.getSaveState() && editJourneyWin.getValidity()) //if a journey was saved
                {
                    Journey J = editJourneyWin.getJourney();                       // Get the saved journey
                    journies[journies.IndexOf((Journey)iL[0])]       = J;          // Overide the service at the editted location
                    allJournies[allJournies.IndexOf((Journey)iL[0])] = J;          //Overide the service in all journies!
                    Console.WriteLine(" Journey Edited");
                }
                afterEffects();
            }
            else
            {
                MessageBox.Show(" Select a single journey to  edit");
            }
        }
 /// <summary>
 /// Add how far the car has driven to Journey and OdoneterReading
 /// </summary>
 /// <param name="km"></param>
 public void AddJourney(double km)
 {
     Journey.AddKilometers(km);
     OdometerReading += km;
 }
        //Load All() Gets everything in the Sql
        public static Object[] LoadAll(String conStr)
        {
            String           p1, p2, p3, p4, p5, p6, p7;
            DataTable        table;
            MySqlDataAdapter adapter;
            MySqlCommand     cmd;

            try
            {
                //Create the connection
                using (MySqlConnection con = new MySqlConnection(conStr))
                {
                    con.Open(); //Open

                    //Vehicle data
                    List <Vehicle> vehicleData = new List <Vehicle>();                                                                                //fresco
                    table   = new DataTable();                                                                                                        //new table
                    cmd     = new MySqlCommand("SELECT * FROM `vehicles`", con);                                                                      //get table command
                    adapter = new MySqlDataAdapter(cmd);
                    adapter.Fill(table);                                                                                                              //fill table
                    Vehicle v;
                    foreach (DataRow row in table.Rows)                                                                                               //go through table rows
                    {
                        Object[] arr = row.ItemArray;                                                                                                 //get row as objects
                        v = new Vehicle((int)arr[1], arr[3].ToString(), arr[2].ToString(), (int)arr[4], (int)arr[5], arr[6].ToString(), (int)arr[7]); //new vehicle
                        vehicleData.Add(v);
                    }

                    //Service Data
                    List <Service> serviceData = new List <Service>();           //new list
                    table   = new DataTable();                                   // new table
                    cmd     = new MySqlCommand("SELECT * FROM `services`", con); // get tabl;e command
                    adapter = new MySqlDataAdapter(cmd);
                    adapter.Fill(table);                                         //fill the table
                    Service s;
                    foreach (DataRow row in table.Rows)                          //going through table rows
                    {
                        Object[] arr = row.ItemArray;                            // get row as obects
                        s = new Service((int)arr[1], (int)arr[2], (int)arr[3], (DateTime)arr[4], (DateTime)arr[5], (DateTime)arr[6]);
                        serviceData.Add(s);
                    }

                    //Journey Data
                    List <Journey> journeyData = new List <Journey>();
                    table   = new DataTable();
                    cmd     = new MySqlCommand("SELECT * FROM `journies`", con);
                    adapter = new MySqlDataAdapter(cmd);
                    adapter.Fill(table);  //fill the table
                    Journey j;
                    foreach (DataRow row in table.Rows)
                    {
                        Object[] arr  = row.ItemArray;
                        Boolean  paid = (((int)arr[6]) == 1); //convert to boolean
                        j = new Journey((int)arr[2], (DateTime)arr[3], (DateTime)arr[4], (DateTime)arr[5], (int)arr[1], paid);
                        journeyData.Add(j);
                    }

                    //Fuel Data
                    List <FuelPurchase> fuelData = new List <FuelPurchase>();
                    table   = new DataTable();
                    cmd     = new MySqlCommand("SELECT * FROM `fuelpurchases`", con);
                    adapter = new MySqlDataAdapter(cmd);
                    adapter.Fill(table);  //fill the table
                    FuelPurchase fp;
                    foreach (DataRow row in table.Rows)
                    {
                        Object[] arr = row.ItemArray;
                        fp = new FuelPurchase((int)arr[2], (double)arr[3], (DateTime)arr[4], (DateTime)arr[5], (int)arr[1]);
                        fuelData.Add(fp);
                    }

                    con.Close(); //Close
                    return(new Object[] { vehicleData, serviceData, journeyData, fuelData });
                }
            } catch (Exception mse) { Console.WriteLine(mse.ToString()); Console.WriteLine("Error SQL"); return(null); }
        }
示例#9
0
 //Add temporary rental and if not paid (after checking isJourneyRentable) for remove later
 public void addTemporaryRental(Journey J)
 {
     temporaryJourney = J;                 //add to list as not paid waiting payment (or remove from list)
     unpaidJournies.Add(temporaryJourney); //  Add to the list
     allJournies.Add(temporaryJourney);    // Add to all journies
 }