Esempio n. 1
0
 public FormVehicleListService(VehicleRentalManagement managerInstance)
 {
     InitializeComponent();
     this.manager = managerInstance;
     VehicleListView.MouseDoubleClick += new MouseEventHandler(VehicleListView_MouseDoubleClick);
     DisplayAllVehicle();
 }
Esempio n. 2
0
        public ContractUpdater(VehicleRentalManagement _manager, RentContract _contract)
        {
            InitializeComponent();
            // Initialize the Form Object for cleaner code:
            this.manager   = _manager;
            this.contract  = _contract;
            this.customer  = contract.CustomerRentCar;
            this.vehicle   = contract.VehicleRented;
            this.insurance = contract.InsuranceUsed;
            // Initialize the Contract into its current state:

            // + Customer Info
            if (customer.Sex == "M")
            {
                this.GenderMaleRadio.Checked = true;
            }
            else
            {
                this.GenderFemaleRadio.Checked = true;
            }
            this.CustomerNameTextBox.Text  = customer.Name;
            this.AddressTextBox.Text       = customer.Address;
            this.PhoneNumberTextBox.Text   = customer.PhoneNumber;
            this.CareerTextBox.Text        = customer.Career;
            this.EmailTextBox.Text         = customer.Email;
            this.DriverLicenseTextBox.Text = customer.Driver_license;

            // + Vehicle Info
            if (vehicle.GetType() == typeof(Car))
            {
                this.TypeCarRadio.Checked = true;
                populateBranchTypeComboBoxWithCarOption();
                Car car = vehicle as Car;
                this.typeTextBox.Text = car.TypeCar.ToString();
            }
            else
            {
                this.TypeTruckRadio.Checked = true;
                populateBranchTypeComboBoxWithTruckOption();
                Truck truck = vehicle as Truck;
                this.typeTextBox.Text = truck.TypeTruck.ToString();
            }
            this.VehicleNameTextBox.Text        = vehicle.Name;
            this.CostPerDayTextBox.Text         = vehicle.CostPerDay.ToString();
            this.KilometerTextBox.Text          = vehicle.NumberKilometers.ToString();
            this.VehicleDescriptionTextBox.Text = vehicle.Description;
            this.branchTextBox.Text             = vehicle.Branch;
            // + Contract Info (Description):
            this.ContractDescriptionTextBox.Text = contract.Description;
            this.StartDate.Value = contract.DateStartRent;
            this.EndDate.Value   = contract.DateEndRent;
            this.TotalCost.Text  = contract.TotalCost.ToString();

            // + Insurance Info:
            this.InsuranceIdTextBox.Text   = insurance.InsuranceId.ToString();
            this.InsuranceTypeSpinBox.Text = insurance.Type.ToString();
            addInsuranceTypeOption();

            this.RegistrationNumberComboBox.Text = vehicle.IdVehicle.ToString();
        }
Esempio n. 3
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (nameVehicleSelected == "")
            {
                MessageBox.Show("Please, Choose Vehicle Your want Rent.");
            }

            else
            {
                Vehicle vehicleSelected = manage.FindVehicle(this.nameVehicleSelected);
                if (vehicleSelected.StateUsed == true)
                {
                    MessageBox.Show("Vehicle not Available, please choose other vehicle.");
                }
                else if (vehicleSelected.Maintain == true)
                {
                    MessageBox.Show("Vehicle having repair, please choose other vehicle.");
                }
                else
                {
                    DateTime         start      = startRent.Value.Date;
                    DateTime         end        = EndRent.Value.Date;
                    double           days       = (end - start).TotalDays;
                    RentContract     contract   = new RentContract(vehicle: vehicleSelected, dateStartRent: startRent.Value.Date, dateEndRent: EndRent.Value.Date, totalCost: (vehicleSelected.CostPerDay * (int)days));
                    FormRentContract formManage = new FormRentContract(contract);
                    var thread = new Thread(() => Program.Start(formManage));
                    thread.Start();
                    thread.Join();
                    manage = Program.LoadData();
                }
            }
        }
Esempio n. 4
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            VehicleRentalManagement manage = LoadData();



            Application.Run(new FormMainMenu(manage));
        }
Esempio n. 5
0
 public FormManage(VehicleRentalManagement manage)
 {
     InitializeComponent();
     this.manage                            = manage;
     this.listCarContracts                  = manage.GetCarRelatedConTracts();
     this.listTruckContracts                = manage.GetTruckRelatedConTracts();
     ContractList.MouseDoubleClick         += new MouseEventHandler(contractList_MouseDoubleClick);
     ApprovedContractList.MouseDoubleClick += new MouseEventHandler(approvedContractList_MouseDoubleClick);
     // manage.testGetType();  // This is only for debug: Test if we can infer the type of the Subclass from the parent Class Object.
     SetUpGui();
 }
Esempio n. 6
0
        public static void LoadInsuranceFromDatabase(VehicleRentalManagement manager)
        {
            MySqlConnection  conn               = ConnectDatabase();
            string           query              = "select * from insurance;";
            MySqlDataAdapter adapter            = new MySqlDataAdapter(query, conn);
            DataTable        insuranceDataTable = new DataTable();

            adapter.Fill(insuranceDataTable);
            foreach (DataRow row in insuranceDataTable.Rows)
            {
                Insurance insurance = new Insurance(id: (int)row["IID"], type: (TypeInsurance)Enum.Parse(typeof(TypeInsurance), row["TYPEINSURANCE"].ToString()));
                manager.AddInsurance(insurance);
            }
        }
Esempio n. 7
0
 public FormServiceAVehicle(VehicleRentalManagement mangerInstance, Vehicle vehicleInstance)
 {
     InitializeComponent();
     this.manager = mangerInstance;
     this.vehicleNeedServicing = vehicleInstance;
     this.serviceLog           = vehicleNeedServicing.GetServiceHistory;
     this.serviceLog.RegisterObserver(this);
     this.EngineStateComboBox.Text      = vehicleNeedServicing.EngineState.ToString();
     this.TranmissionStateComboBox.Text = vehicleNeedServicing.TransmissionState.ToString();
     this.TiresStateComboBox.Text       = vehicleNeedServicing.TiresState.ToString();
     PopulateComboboxOption();
     DisplayPossibleServices();
     Display();
     // Load combobox options to manually set the states of the vehicle part:
 }
Esempio n. 8
0
        public static void LoadCarDataFromDatabase(VehicleRentalManagement manager)
        {
            MySqlConnection conn = ConnectDatabase();
            //====================== Fetch the car-related-contract information from datbase================
            string query = "select * from rentcontract RC join insurance I on RC.IDCONTRACT = I.IDCONTRACT, vehicle V, car C where RC.IDVEHICLE = V.ID and V.ID = C.ID;";
            // This adapter connect to the database and execute the query
            MySqlDataAdapter adapter = new MySqlDataAdapter(query, conn);
            // Fill the queried data into a table:
            DataTable carDataTable = new DataTable();

            adapter.Fill(carDataTable);
            foreach (DataRow row in carDataTable.Rows)
            {
                // Create a contract wit the Car: -- Vấn đề về đêm: Nếu bị null dưới database thì khi load lên sẽ lỗi (Khúc oilSIze vói oilNow khi Parse với định dạng Int32) cho nên ở đây t cho giá trị mặc định :(
                Car car = new Car(nameCar: row["Name"].ToString(), branch: row["branch"].ToString(), idCar: Int32.Parse(row["ID"].ToString()), carType: (TypeCar)Enum.Parse(typeof(TypeCar), row["TYPECAR"].ToString()), maintain: Boolean.Parse(row["maintain"].ToString()), costPerDay: Int32.Parse(row["costperday"].ToString()), stateUse: Boolean.Parse(row["stateUsed"].ToString()), oilSize: 2, fluidSize: 3);
                // Create the customer of the Contract:
                Customer customer = new Customer(name: row["NAMECUSTORMER"].ToString(), password: "", Email: row["EMAIL"].ToString(), PhoneNumber: row["PHONENUMBER"].ToString(), Sex: "", Age: 0, Address: row["ADDRESS"].ToString(), Career: row["CAREER"].ToString(), license: row["DRIVERLICENSE"].ToString());
                // Creat a Insurance with the contract:
                Insurance insurance = new Insurance(id: (int)row["IID"], type: (TypeInsurance)Enum.Parse(typeof(TypeInsurance), row["TYPEINSURANCE"].ToString()));
                int       id        = int.Parse(row["IDCONTRACT"].ToString());
                //DateTime dateStartRent = DateTime.ParseExact(row["STARTDATE"].ToString(), CultureInfo.InvariantCulture);
                //DateTime dateEndRent = DateTime.ParseExact(row["ENDDATE"].ToString(), CultureInfo.InvariantCulture);
                string startDateString     = row["STARTDATE"].ToString();
                string startDateTimeFormat = GetDateTimeFormatString(startDateString);

                string endDateString     = row["ENDDATE"].ToString();
                string endDateTimeFormat = GetDateTimeFormatString(endDateString);

                CultureInfo provider = CultureInfo.InvariantCulture;

                DateTime dateStartRent = DateTime.ParseExact(startDateString, startDateTimeFormat, CultureInfo.InvariantCulture);

                DateTime dateEndRent = DateTime.ParseExact(endDateString, endDateTimeFormat, provider);
                int      totalBill   = (int)row["TOTALBILL"];
                string   description = row["DESCRIPTION"].ToString();
                bool     is_approved = (bool)row["APPROVED"];

                RentContract rentContract = new RentContract(id, car, insurance, customer, dateStartRent, dateEndRent, totalBill, description, is_approved);
                manager.AddContract(rentContract);
            }
        }
Esempio n. 9
0
        static public VehicleRentalManagement LoadData()
        {
            MySqlConnection conn   = ConnectDatabase();
            string          sqlcar = "(select c.TYPECAR, V.Name, V.ID,V.branch,V.costperday,V.stateUsed,V.maintain from vehicle V, car c where v.id=c.id); ";
            MySqlCommand    cmd    = new MySqlCommand();

            cmd.Connection  = conn;
            cmd.CommandText = sqlcar;
            VehicleRentalManagement manage = new VehicleRentalManagement();
            //======================== Fetch the two fleet from mySQL: 1 for Car, 1 for Truck =========================
            Fleet fleetcar   = new Fleet();
            Fleet fleettruck = new Fleet();

            using (MySqlDataReader d = cmd.ExecuteReader())
            {
                while (d.Read())
                {
                    fleetcar.AddVehicle(new Car(nameCar: d.GetString(1), branch: d.GetString(3), carType: (TypeCar)Enum.Parse(typeof(TypeCar), d.GetString(0)), stateUse: d.GetBoolean(5), idCar: d.GetInt32(2), costperday: d.GetInt32(4), maintain: d.GetBoolean(6)));
                }
            }
            manage.AddFleet(fleetcar);
            sqlcar = "select T.TYPETRUCK, V.Name, V.ID, V.branch, V.costperday, V.stateUsed, V.maintain, t.TYPETRUCK from vehicle V, TRUCK T where v.id = T.id; ";
            cmd    = new MySqlCommand(sqlcar, conn);
            using (MySqlDataReader d = cmd.ExecuteReader())
            {
                while (d.Read())
                {
                    fleettruck.AddVehicle(new Truck(nameTruck: d.GetString(1), branch: d.GetString(3), typeTruck: (TypeTruck)Enum.Parse(typeof(TypeTruck), d.GetString(0)), stateUse: d.GetBoolean(5), idTruck: d.GetInt32(2), costperday: d.GetInt32(4), maintain: d.GetBoolean(6)));
                }
            }
            manage.AddFleet(fleettruck);
            LoadCarDataFromDatabase(manage);
            LoadTruckDataFromDatabase(manage);
            LoadInsuranceFromDatabase(manage);

            conn.Close();
            return(manage);
        }
Esempio n. 10
0
 public ContractDetailForm(VehicleRentalManagement manage, RentContract contractToShow)
 {
     InitializeComponent();
     this.manage                     = manage;
     this.contract                   = contractToShow;
     this.DateCreated.Text           = DateTime.Now.ToString();
     this.contractNumber.Text        = this.manage.GetContracts().Count().ToString();
     this.CustomerName.Text          = this.contract.CustomerRentCar.Name;
     this.DriverLicense.Text         = this.contract.CustomerRentCar.Driver_license;
     this.Address.Text               = this.contract.CustomerRentCar.Address;
     this.PhoneNum.Text              = this.contract.CustomerRentCar.PhoneNumber;
     this.RegistrationNum.Text       = this.contract.VehicleRented.IdVehicle.ToString();
     this.OilCap.Text                = this.contract.VehicleRented.SizeOil.ToString();
     this.FluidStatus.Text           = this.contract.VehicleRented.SizeFluid.ToString();
     this.KilometerRun.Text          = this.contract.VehicleRented.NumberKilometers.ToString();
     this.CostPerDay.Text            = this.contract.VehicleRented.CostPerDay.ToString();
     this.FromStartToEnd.Text        = this.FromStartToEnd.Text + $"from {this.contract.DateStartRent.ToString()} to {this.contract.DateEndRent.ToString()}";
     this.Model.Text                 = this.contract.VehicleRented.Branch.ToString();
     this.TotalCost.Text             = this.TotalCost.Text + this.contract.TotalCost.ToString();
     this.VehicleDescription.Text    = this.contract.VehicleRented.Description;
     this.AdditionalDescription.Text = this.contract.Description;
     this.InsuranceID.Text           = this.contract.InsuranceUsed.InsuranceId.ToString();
     this.InsuranceType.Text         = this.contract.InsuranceUsed.Type.ToString();
 }
Esempio n. 11
0
 public FormMainMenu(VehicleRentalManagement manage)
 {
     InitializeComponent();
     this.manage = manage;
 }
Esempio n. 12
0
        private void btSave_Click(object sender, EventArgs e)
        {
            try
            {
                Int32.Parse(registration.Text);
                Int32.Parse(Kilometer.Text);
                Int32.Parse(costperdatetext.Text);
                if (CheckedNotNull())
                {
                    if (change)
                    {
                        UpdateVehicle();
                        MessageBox.Show("Update successly!");
                        change = false;
                        manage = Program.LoadData();
                    }
                    else
                    {
                        if (CheckId(Int32.Parse(registration.Text)))
                        {
                            Vehicle vehicle;
                            if ((RadioCarDetail.Checked))
                            {
                                if (descriptiontext.Text == "")
                                {
                                    vehicle = new Car(NameVehicle.Text, BranchVehicle.Text, Int32.Parse(registration.Text), (TypeCar)Enum.Parse(typeof(TypeCar), typeVehicledetail.SelectedItem.ToString()), maintainvehicleview.Checked, statusvehicleview.Checked, Int32.Parse(costperdatetext.Text), Int32.Parse(Kilometer.Text));
                                }
                                else
                                {
                                    vehicle = new Car(NameVehicle.Text, BranchVehicle.Text, Int32.Parse(registration.Text), (TypeCar)Enum.Parse(typeof(TypeCar), typeVehicledetail.SelectedItem.ToString()), maintainvehicleview.Checked, statusvehicleview.Checked, Int32.Parse(costperdatetext.Text), Int32.Parse(Kilometer.Text), descriptiontext.Text);
                                }
                            }

                            else
                            {
                                if (descriptiontext.Text == "")
                                {
                                    vehicle = new Truck(NameVehicle.Text, BranchVehicle.Text, Int32.Parse(registration.Text), (TypeTruck)Enum.Parse(typeof(TypeTruck), typeVehicledetail.SelectedItem.ToString()), maintainvehicleview.Checked, statusvehicleview.Checked, Int32.Parse(costperdatetext.Text), Int32.Parse(Kilometer.Text));
                                }
                                else
                                {
                                    vehicle = new Truck(NameVehicle.Text, BranchVehicle.Text, Int32.Parse(registration.Text), (TypeTruck)Enum.Parse(typeof(TypeTruck), typeVehicledetail.SelectedItem.ToString()), maintainvehicleview.Checked, statusvehicleview.Checked, Int32.Parse(costperdatetext.Text), Int32.Parse(Kilometer.Text), descriptiontext.Text);
                                }
                            }
                            InsertVehicle(vehicle);
                            MessageBox.Show("Add Successly!");
                            addnew = false;
                            manage = Program.LoadData();
                        }
                    }

                    setclear();
                    SetUnChange();
                    if (RadioCarview.Checked)
                    {
                        LoadCar();
                    }
                    else
                    {
                        loadTruck();
                    }
                }
            }
            catch (Exception error)
            {
                MessageBox.Show("Please fill correct!");
            }
        }
Esempio n. 13
0
 public FormBookAndRent(VehicleRentalManagement Mamage)
 {
     InitializeComponent();
     panel2.Enabled = false;
     this.manage    = Mamage;
 }
Esempio n. 14
0
 private void UpdateDataChange()
 {
     this.manage             = Program.LoadData();
     this.listCarContracts   = manage.GetCarRelatedConTracts();
     this.listTruckContracts = manage.GetTruckRelatedConTracts();
 }
Esempio n. 15
0
 private void FormManage_Load(object sender, EventArgs e)
 {
     manage = Program.LoadData();
     SetUpGui();
 }