i have 4 list boxes that need to have one row from one list box added to the other, then taking from there list boxes and added to another list box together.
for instance
member of staff enters a vehicles details into car list box and truck details into truck list box etc then enters customers details into cust listbox, now they user wants to combine the car to the customer and display in another listbox removing the details from the other listboxs into a new listbox called hired.
I'm using windows Form and have a hire button than displays a combobox where id like the reg number of the cars in the car listbox and another combobox that displays the cust id of cust from the cust listbox..then another button called hire out that wants to send the details from the form to the hired listbox.
I also need to be able to return the customer to the cust box and the car to the car box
Expand|Select|Wrap|Line Numbers
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- namespace SD2coursework
- {
- public partial class FrmHireCo : Form
- /*
- * This is the main form for the car hire system.
- * It allows the adding to new cars to the system, and displaying them in the fleet list
- *
- */
- {
- private Fleet myFleet = new Fleet();
- private scndFleet myScndFleet = new scndFleet();
- private thrdFleet myThrdFleet = new thrdFleet();
- private custBox myCustBox = new custBox();
- //Fleet object used to store cars
- public FrmHireCo()
- {
- //Default constructor
- InitializeComponent();
- }
- private void updateFleetList()
- { //Used to update the fleet displayed on the form
- lstFleet.Items.Clear();
- foreach (Car c in myFleet.fleet)
- {
- string line = "Car: " + c.make +" " + c.model + " " + c.colour + " " + c.registrationNumber;
- lstFleet.Items.Add(line);
- }
- }
- private void updateScndFleetList()
- { //Used to update the fleet displayed on the form
- scndFleet.Items.Clear();
- foreach (MiniBus c in myScndFleet.scndfleet)
- {
- string line = "MiniBus: " + c.make + " " + c.model + " " + c.colour + " " + c.registrationNumber + " " + c.numberOfSeats;
- scndFleet.Items.Add(line);
- }
- }
- private void updateThrdFleetList()
- { // Used to update the thrdFleet displayed on the form
- thrdFleet.Items.Clear();
- foreach (Truck c in myThrdFleet.thrdfleet)
- {
- string line = "Truck: " + c.make + " " + c.model + " " + c.colour + " " + c.registrationNumber + " " + c.grossWeight;
- thrdFleet.Items.Add(line);
- }
- }
- private void updateCustBoxList()
- {// Used to update the custBox displayed on the form
- custBox.Items.Clear();
- foreach (Customer c in myCustBox.CustBox)
- {
- string line = " Customer " + c.foreName + " " + c.surname + " " + c.firstLineOfAddress + " " + c.county + " " + c.postCode + " " + c.custId;
- custBox.Items.Add(line);
- }
- }
- private void btnAddMiniBus_Click(object sender, EventArgs e)
- {
- //Add a new miniBus
- FrmMiniBus mBusGui = new FrmMiniBus(); //Form used to add new MiniBus
- mBusGui.ShowDialog();
- MiniBus myMiniBus = mBusGui.miniBus; //Get new mini bus from MiniBus form
- myScndFleet.addTothescndFleet(myMiniBus); //Add to scndfleet list
- updateScndFleetList(); //Update Scndfleet list
- }
- private void btnAddTruck_Click(object sender, EventArgs e)
- {
- FrmTruck mTruckGui = new FrmTruck();// Form used to add new Truck
- mTruckGui.ShowDialog();
- Truck myTruck = mTruckGui.truck;//Get new truck from Truck form
- myThrdFleet.addTothethrdFleet(myTruck);//add to thrdFleet list
- updateThrdFleetList(); //update thrdTruck list
- }
- private void btnAddCust_Click(object sender, EventArgs e)
- {
- FrmCustomer mCustGui = new FrmCustomer();// Form used to add new customer
- mCustGui.ShowDialog();
- Customer myCust = mCustGui.customer;
- myCustBox.addTothecustBox(myCust);
- updateCustBoxList();
- }
- private void btnAddCar_Click(object sender, EventArgs e)
- {
- //Add a new car
- FrmCar carGui = new FrmCar(); //Form used to add new car
- carGui.ShowDialog();
- Car myCar = carGui.car; //Get new car from form
- myFleet.addToFleet(myCar); //Add to fleet list
- updateFleetList(); //Uodate fleet list
- }
- private void lstFleet_SelectedIndexChanged(object sender, EventArgs e)
- {
- /*
- * This method is used to control the list box
- * It is called when a row is selected by the user, it then displays frmCar
- * with the car details
- */
- if (lstFleet.SelectedIndex > -1)
- {
- int index = lstFleet.SelectedIndex;
- Car myCar = myFleet.fleet.ElementAt(index);
- FrmCar carGui = new FrmCar();
- carGui.car = myCar;
- carGui.ShowDialog();
- updateFleetList();
- }
- }
- private void scndFleet_SelectedIndexChanged(object sender, EventArgs e)
- {
- /*
- * This method is used to control the list box
- * It is called when a row is selected by the user, it then displays FrmMiniBus
- * with the minibus details
- */
- if (scndFleet.SelectedIndex > -1)
- {
- int index = scndFleet.SelectedIndex;
- MiniBus mBus = myScndFleet.scndfleet.ElementAt(index);
- FrmMiniBus mBusGui = new FrmMiniBus();
- mBusGui.miniBus = mBus;
- mBusGui.ShowDialog();
- updateScndFleetList();
- }
- }
- private void thrdFleet_SelectedIndexChanged(object sender, EventArgs e)
- {
- /*
- * This method is used to control the list box
- * It is called when a row is selected by the user, it then displays FrmTruck
- * with the truck details
- */
- if (thrdFleet.SelectedIndex > -1)
- {
- int index = thrdFleet.SelectedIndex;
- Truck mTruck = myThrdFleet.thrdfleet.ElementAt(index);
- FrmTruck mTruckGui = new FrmTruck();
- mTruckGui.truck = mTruck;
- mTruckGui.Show();
- updateThrdFleetList();
- }
- }
- private void custBox_SelectedIndexChanged(object sender, EventArgs e)
- {
- /*
- * This method is used to control the list box
- * It is called when a row is selected by the user, it then displays FrmCustomer
- * with the customer details
- */
- if (custBox.SelectedIndex > -1)
- {
- int index = custBox.SelectedIndex;
- Customer mCust = myCustBox.CustBox.ElementAt(index);
- FrmCustomer mCustGui = new FrmCustomer();
- mCustGui.customer = mCust;
- mCustGui.Show();
- updateCustBoxList();
- }
- }
- private void btnQuit_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- private void FrmHireCo_Load(object sender, EventArgs e)
- {
- // MessageBox.Show( "Please enter vehicle type and details ");
- }
- private void btnHire_Click(object sender, EventArgs e)
- {
- FrmHireToCust HireToGui = new FrmHireToCust();// Form used to add new customer
- HireToGui.ShowDialog();
- //find car details from List of cars
- //assign hirer to that list
- }
- private void btnReturn_Click(object sender, EventArgs e)
- {
- FrmReturn ReturnGui = new FrmReturn();// Form used to add new customer
- ReturnGui.ShowDialog();
- }
- }
- }
- //Form Hire to cust after hitting Hire from above
- }
- public string hirer
- {
- get
- {
- return theHirer;
- }
- set
- {
- theHirer = value;
- }
- }
- public string Car
- {
- get
- {
- return theCar;
- }
- set
- {
- theCar = value;
- }
- }
- //dont know this is me testing but its not
- private void FrmHireToCust_FormClosed(object sender, FormClosedEventArgs e)
- {
- //if (txtCustIdToHire.Text != null)
- //{
- // theHirer = txtCustIdToHire.Text;
- //}
- //if (txtCustREgNoToHire.Text != null)
- //{
- // theCar = txtCustREgNoToHire.Text;
- //}
- }
- private void btnHireToCust_Click(object sender, EventArgs e)
- {
- //Close the form. Causes FrmMiniBusClosed() to be called.
- this.Close();
- }
- //dont know this is me testing but its not workingcomboBox1_SelectedIndexChanged(object sender, EventArgs e)
- //{
- // custBox.Equals(CustId);
- //}
- }
- }