示例#1
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();
        }
示例#2
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();
                }
            }
        }
示例#3
0
        // The nexxt 2 method open the correspoding Contract Detail Form for user to view the full contract again.
        private void contractList_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            ListViewHitTestInfo listViewHitTestInfo = ContractList.HitTest(e.X, e.Y);
            ListViewItem        clickedItem         = listViewHitTestInfo.Item;

            if (clickedItem != null)
            {
                int          contractID     = int.Parse(clickedItem.SubItems[1].Text);
                RentContract contractToShow = manage.GetContracts()[0];
                foreach (RentContract contract in manage.GetContracts())
                {
                    if (contract.Id == contractID)
                    {
                        contractToShow = contract;
                        break;
                    }
                }
                if (PreviewModeRadio.Checked == true)
                {
                    ContractDetailForm contractDetailForm = new ContractDetailForm(this.manage, contractToShow);
                    var thread = new Thread(() => Program.Start(contractDetailForm));
                    thread.Start();
                    this.Close();
                }
                else
                {
                    ContractUpdater updater = new ContractUpdater(this.manage, contractToShow);
                    var             thread  = new Thread(() => Program.Start(updater));
                    thread.Start();
                    this.Close();
                }
            }
        }
示例#4
0
        /*       private void Listview1_ItemChecked(object sender, ItemCheckedEventArgs e)
         *     {
         *         foreach (ListViewItem Item in ListView1.Items)
         *         {
         *             if (Item != null)
         *             {
         *                 if (Item.Checked == true) N++;
         *             }
         *         }
         *         Textbox1.Text = N.ToString();
         *     }
         *
         *
         *     ListView.CheckedListViewItemCollection checkedItems =
         *         ListView1.CheckedItems;
         *
         *     foreach ( ListViewItem item in checkedItems )
         *     {
         *         value = item.SubItems[1].Text;
         *     }
         */


        private void ApproveButton_Click(object sender, EventArgs e)
        {
            // Get selected row
            ListView.CheckedListViewItemCollection checkedItems = ContractList.CheckedItems;
            foreach (ListViewItem item in checkedItems)
            {
                ListViewItem.ListViewSubItemCollection listSubItem = item.SubItems;
                listSubItem.RemoveAt(0);
                int          contractID = int.Parse(listSubItem[0].Text);
                RentContract contract   = manage.FindContractById(contractID);
                if (checkContractValidity(contract))
                {
                    updateApprovalStatusInDatabase(contractID);
                    ListViewItem approvedItem = new ListViewItem();

                    foreach (ListViewItem.ListViewSubItem subItem in listSubItem)
                    {
                        approvedItem.SubItems.Add(subItem);
                    }

                    // remove it from the left listview
                    ContractList.Items.Remove(item);

                    // Add it to the right listview
                    ApprovedContractList.Items.Add(item);
                }
                //manage = Program.LoadData();
                //setUpGUI();

                // Get the removed item id and change the APPROVED to TRUE in the database:
            }
        }
示例#5
0
        public FormRentContract(RentContract contract)
        {
            InitializeComponent();
            this.contract = contract;
            customerRent  = new Customer();
            Setup();
            contract.CustomerRentCar = customerRent;
            Insurance insurance = new Insurance();

            contract.InsuranceUsed = insurance;
        }
示例#6
0
文件: Program.cs 项目: letuanvu08/OOP
        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);
            }
        }
示例#7
0
        private bool checkContractValidity(RentContract contract)
        {
            bool isValid = true;

            if (contract.VehicleRented.StateUsed)
            {
                isValid = false;
                MessageBox.Show($"Vehicle is being used. Pls check and update the contract with ID: {contract.Id} again before aprroving");
            }
            else if (contract.VehicleRented.Maintain)
            {
                isValid = false;
                MessageBox.Show($"Vehicle is being maintained. Pls check and update the contract with ID: {contract.Id} before approving");
            }
            else if (contract.DateStartRent > contract.DateEndRent)
            {
                isValid = false;
                MessageBox.Show($"Invalid Rent interval. Please check and update the contract with ID: {contract.Id} before approving");
            }

            return(isValid);
        }
示例#8
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();
 }
示例#9
0
 // -===============================Contract Supporting Function=======================
 public void AddContract(RentContract contract)
 {
     this.listContract.Add(contract);
 }
示例#10
0
        // This function find needed information of a contract and return its infomation in a tuple of string:
        private (string empty, string contract_id, string vehicle_id, string customer_name, string customer_license, string insurance_type) getContractInfomation(RentContract contract)
        {
            string empty           = "";
            string contractID      = contract.Id.ToString();
            string vehicleID       = contract.VehicleRented.IdVehicle.ToString();
            string customerName    = contract.CustomerRentCar.Name;
            string customerLicense = contract.CustomerRentCar.Driver_license;
            string insuranceType   = contract.InsuranceUsed.Type.ToString();

            return(empty, contractID, vehicleID, customerName, customerLicense, insuranceType);
        }