Пример #1
0
        public FormRentContract(RentContract contract)
        {
            InitializeComponent();
            this.contract = contract;
            customerRent  = new Customer();
            Setup();
            contract.CustomerRentCar = customerRent;
            Insurance insurance = new Insurance();

            contract.InsuranceUsed = insurance;
        }
Пример #2
0
 // This is the fully initialized constructor to insert a complete record into the database
 public RentContract(int id, Vehicle vehicle, Insurance insurance, Customer customer, DateTime dateStartRent, DateTime dateEndRent, int totalCost, string description, bool approval)
 {
     Console.WriteLine(" Constuctor New RentContract with 6 parameter: Customer,Car,...");
     this.Id              = id;
     this.VehicleRented   = vehicle;
     this.DateStartRent   = dateStartRent;
     this.DateEndRent     = dateEndRent;
     this.TotalCost       = totalCost;
     this.Description     = description;
     this.InsuranceUsed   = insurance;
     this.CustomerRentCar = customer;
     this.IsApproved      = approval;
 }
Пример #3
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);
            }
        }
Пример #4
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);
            }
        }
Пример #5
0
 public void AddInsurance(Insurance insurance)
 {
     this.listInsurance.Add(insurance);
 }