Example #1
0
        private void bt_edit_Click(object sender, EventArgs e)
        {
            if (DataGrid_cars.Rows.Count > 0)
            {
                RentalCar rentalCar = new RentalCar()
                {
                    Available     = (bool)(DataGrid_cars.SelectedRows[0]).Cells[0].Value,
                    AvailableFrom = (DateTime)(DataGrid_cars.SelectedRows[0]).Cells[1].Value,
                    PricePerDay   = (int)(DataGrid_cars.SelectedRows[0]).Cells[2].Value,
                    Brand         = (string)(DataGrid_cars.SelectedRows[0]).Cells[3].Value,
                    Model         = (string)(DataGrid_cars.SelectedRows[0]).Cells[4].Value,
                    LicensePlate  = (string)(DataGrid_cars.SelectedRows[0]).Cells[5].Value,
                    Type          = (string)(DataGrid_cars.SelectedRows[0]).Cells[6].Value,
                };
                if (rentalCar.Available)
                {
                    int index = 0;
                    for (int i = 0; i < cars.Count; i++)
                    {
                        if (cars[i].LicensePlate == rentalCar.LicensePlate)
                        {
                            index = i;
                            break;
                        }
                    }
                    RentalCar editing_car = cars[index];

                    EditCarForm editCarForm = new EditCarForm(editing_car, cars, DataGrid_cars, pnCarsMenu);
                    editCarForm.TopLevel = false;
                    editCarForm.Dock     = DockStyle.Fill;
                    pnChildForm.Controls.Add(editCarForm);
                    editCarForm.BringToFront();
                    pnChildForm.BringToFront();

                    editCarForm.Show();
                }
                else
                {
                    MsgBox msgBox = new MsgBox("Editing error", "The selected car is not available");
                    msgBox.ShowDialog();
                }
            }
            else
            {
                MsgBox msgBox = new MsgBox("Editing error", "You have not chosen the car you want to rent");
                msgBox.ShowDialog();
            }
        }
Example #2
0
 private void bt_remove_Click(object sender, EventArgs e)
 {
     if (DataGrid_cars.Rows.Count > 0)
     {
         RentalCar rentalCar = new RentalCar()
         {
             Available     = (bool)(DataGrid_cars.SelectedRows[0]).Cells[0].Value,
             AvailableFrom = (DateTime)(DataGrid_cars.SelectedRows[0]).Cells[1].Value,
             PricePerDay   = (int)(DataGrid_cars.SelectedRows[0]).Cells[2].Value,
             Brand         = (string)(DataGrid_cars.SelectedRows[0]).Cells[3].Value,
             Model         = (string)(DataGrid_cars.SelectedRows[0]).Cells[4].Value,
             LicensePlate  = (string)(DataGrid_cars.SelectedRows[0]).Cells[5].Value,
             Type          = (string)(DataGrid_cars.SelectedRows[0]).Cells[6].Value,
         };
         if (rentalCar.Available)
         {
             for (int i = 0; i < cars.Count; i++)
             {
                 if (cars[i].LicensePlate == rentalCar.LicensePlate)
                 {
                     cars.RemoveAt(i);
                     break;
                 }
             }
             RentalSerivce.SerializeCars(cars);
             DataGrid_cars.Rows.Clear();
             foreach (var car in cars)
             {
                 AddCarToDataGrid(car);
             }
             MsgBox msgBox = new MsgBox("Removing car", "The car is successfully removed");
             msgBox.ShowDialog();
         }
         else
         {
             MsgBox msgBox = new MsgBox("Removing error", "The selected car is not available");
             msgBox.ShowDialog();
         }
     }
     else
     {
         MsgBox msgBox = new MsgBox("Removing error", "You have not chosen the car you want to remove");
         msgBox.ShowDialog();
     }
 }
Example #3
0
        private void bt_addcar_Click(object sender, EventArgs e)
        {
            bool brand_valide = false, model_valide = false, license_plate_valide = false, amount_valide = false;

            if (txtbox_carBrand.Text.Length > 2)
            {
                brand_valide = true;
                for (int i = 0; i < txtbox_carBrand.Text.Length; i++)
                {
                    if (char.IsDigit(txtbox_carBrand.Text[i]))
                    {
                        brand_valide = false;
                        break;
                    }
                }
            }
            if (!brand_valide)
            {
                MsgBox msgBox = new MsgBox("Error adding car", "Entered the wrong car brand. The car brand must be longer than 2 letters and not contain other characters!");
                msgBox.ShowDialog();
            }

            if (txtbox_carBrand.Text.Length > 2)
            {
                model_valide = true;
            }
            else
            {
                MsgBox msgBox = new MsgBox("Error adding car", "Entered the wrong car model. The car model must be longer than 2 characters!");
                msgBox.ShowDialog();
            }

            var num_reg = new Regex(@"^[A-Z]{2}\d{4}[A-Z]{2}$");

            if (num_reg.IsMatch(txtbox_licensePlate.Text))
            {
                license_plate_valide = true;
                for (int i = 0; i < cars.Count; i++)
                {
                    if (cars[i].LicensePlate == txtbox_licensePlate.Text)
                    {
                        license_plate_valide = false;
                        break;
                    }
                }
                if (!license_plate_valide)
                {
                    MsgBox msgBox = new MsgBox("Error adding car", "A car with such a license plate is already there!");
                    msgBox.ShowDialog();
                }
            }
            else
            {
                MsgBox msgBox = new MsgBox("Error adding car", "The license plate of the car is incorrect");
                msgBox.ShowDialog();
            }
            if (brand_valide && model_valide && license_plate_valide)
            {
                cars.Add(new RentalCar()
                {
                    Available = true, AvailableFrom = DateTime.Now, Brand = txtbox_carBrand.Text, LicensePlate = txtbox_licensePlate.Text, Model = txtbox_model.Text,
                    RentedID  = 0, Type = comboBox_carType.SelectedItem.ToString(), PricePerDay = (int)numeric_pricePerDay.Value
                });
                RentalSerivce.SerializeCars(cars);
                MsgBox msgBox = new MsgBox("Adding car", "Car added successfully");
                msgBox.ShowDialog();
                Desktop.BringToFront();
                this.Close();
            }
        }
        private void bt_chngEmail_Click(object sender, EventArgs e)
        {
            bool card_num_valide = false, card_date_valid = false, cvv_cvc_valide = false;
            var  card_reg = new Regex(@"(^\d{16}$)|(^\d{4} \d{4} \d{4} \d{4}$)");

            if (card_reg.IsMatch(txtbox_cardNumber.Text))
            {
                card_num_valide = true;
            }
            else
            {
                MsgBox msgBox = new MsgBox("Payment error", "Invalid card number entered. Enter the number in the format \"1234567898765432\" or \"1234 5678 9876 5432\"");
                msgBox.ShowDialog();
            }

            if (txtbox_cardMM.Text.Length == 2 && txtbox_cardYY.Text.Length == 2)
            {
                bool date_valide = true;
                for (int i = 0; i < txtbox_cardMM.Text.Length; i++)
                {
                    if (!char.IsDigit(txtbox_cardMM.Text[i]))
                    {
                        date_valide = false;
                        break;
                    }
                }
                for (int i = 0; i < txtbox_cardYY.Text.Length; i++)
                {
                    if (!char.IsDigit(txtbox_cardYY.Text[i]))
                    {
                        date_valide = false;
                        break;
                    }
                }
                if (date_valide)
                {
                    int MM = int.Parse(txtbox_cardMM.Text);
                    int YY = int.Parse(txtbox_cardYY.Text);
                    if (MM > 0 && MM <= 12)
                    {
                        if (YY > 20)
                        {
                            card_date_valid = true;
                        }
                        else
                        {
                            MsgBox msgBox = new MsgBox("Payment error", "Invalid card expiration date. The year must be at least 21");
                            msgBox.ShowDialog();
                        }
                    }
                    else
                    {
                        MsgBox msgBox = new MsgBox("Payment error", "Invalid card expiration date. Specify a month from 1 to 12. For example \"05\"");
                        msgBox.ShowDialog();
                    }
                }
                else
                {
                    MsgBox msgBox = new MsgBox("Payment error", "Invalid card expiration date");
                    msgBox.ShowDialog();
                }
            }
            else
            {
                MsgBox msgBox = new MsgBox("Payment error", "Invalid card expiration date");
                msgBox.ShowDialog();
            }

            if (txtbox_cardCVV2_CVC2.Text.Length == 3)
            {
                cvv_cvc_valide = true;
                for (int i = 0; i < txtbox_cardCVV2_CVC2.Text.Length; i++)
                {
                    if (!char.IsDigit(txtbox_cardCVV2_CVC2.Text[i]))
                    {
                        cvv_cvc_valide = false;
                        break;
                    }
                }
            }
            if (!cvv_cvc_valide)
            {
                MsgBox msgBox = new MsgBox("Payment error", "Invalid card CVV2/CVC2");
                msgBox.ShowDialog();
            }

            if (card_num_valide && card_date_valid && cvv_cvc_valide)
            {
                user.ReplishBalance(numeric_ammount.Value);
                lb_balance.Text = user.Balance.ToString();
                user.Serialize();
                MsgBox msgBox = new MsgBox("Replenishment of the balance", "The balance is successfully replenished");
                msgBox.ShowDialog();
                Desktop.BringToFront();
                this.Close();
            }
        }
Example #5
0
        private void regBt_signUp_Click(object sender, EventArgs e)
        {
            bool log_valide   = false;
            bool email_valide = false;
            bool pass_valide  = false;

            #region check login
            if (regTxtBox_login.Text.Length >= 3 && regTxtBox_login.Text.Length <= 10)
            {
                log_valide = true;
                for (int i = 0; i < regTxtBox_login.Text.Length; i++)
                {
                    if (!char.IsLetterOrDigit(regTxtBox_login.Text[i]))
                    {
                        log_valide = false;
                        break;
                    }
                }
            }
            if (!log_valide)
            {
                MsgBox msgBox = new MsgBox("Bad login", "Login length should be between 3 and 10 characters. No special characters.");
                msgBox.ShowDialog();
            }
            if (log_valide && File.Exists(users_path + regTxtBox_login.Text))
            {
                log_valide = false;
                MsgBox msgBox = new MsgBox("Bad login", "Such a user already exists!");
                msgBox.ShowDialog();
            }
            #endregion

            #region check email
            List <string> emails = new List <string>();
            using (var reader = new StreamReader("emails/emails"))
            {
                while (!reader.EndOfStream)
                {
                    emails.Add(reader.ReadLine());
                }
            }
            var email_reg = new Regex(@"^[a-z,A-Z,0-9](\.?[a-z,A-Z,0-9]){5,}@[a-z]{2,}\.(com|net|ua|ru)$");
            if (email_reg.IsMatch(regTxtBox_email.Text))
            {
                email_valide = true;
            }
            if (!email_valide)
            {
                MsgBox msgBox = new MsgBox("Bad email", "Invalid email specified.");
                msgBox.ShowDialog();
            }
            if (email_valide && emails.Contains(regTxtBox_email.Text))
            {
                email_valide = false;
                MsgBox msgBox = new MsgBox("Bad email", "A user with this email already exists!");
                msgBox.ShowDialog();
            }
            #endregion

            #region check passwd
            if (regTxtBox_passwd.Text.Length >= 5 && regTxtBox_passwd.Text == regTxtBox_confirmPasswd.Text)
            {
                pass_valide = true;
            }
            if (!pass_valide)
            {
                MsgBox msgBox = new MsgBox("Bad passwords", "Password must be at least 5 characters long. The passwords entered must match.");
                msgBox.ShowDialog();
            }
            #endregion

            if (log_valide && email_valide && pass_valide)
            {
                using (var writer = new StreamWriter("emails/emails", true))
                    writer.WriteLine(regTxtBox_email.Text);
                User user = new User(regTxtBox_login.Text, regTxtBox_email.Text, regTxtBox_confirmPasswd.Text);
                user.Serialize();
                RentalSerivce rentalSerivce = new RentalSerivce(user);
                pnLogin.BringToFront();
                this.Hide();
                if (rentalSerivce.ShowDialog() == DialogResult.Retry)
                {
                    this.Show();
                }
                else
                {
                    this.Close();
                }
            }
        }
Example #6
0
        private void bt_login_Click(object sender, EventArgs e)
        {
            bool is_admin_try = false;

            if (chb_alogin.Checked)
            {
                is_admin_try = true;
                if (File.Exists(admins_path + logTxtBox_login.Text))
                {
                    Admin admin = new Admin();
                    admin.Deserialize(admins_path + logTxtBox_login.Text);
                    if (admin.Passwd == logTxtBox_passwd.Text)
                    {
                        chb_alogin.Checked = false;
                        AdminForm rentalSerivce = new AdminForm(admin);
                        this.Hide();
                        if (rentalSerivce.ShowDialog() == DialogResult.Retry)
                        {
                            this.Show();
                        }
                        else
                        {
                            this.Close();
                        }
                    }
                    else
                    {
                        MsgBox msgBox = new MsgBox("Authorization error", "Wrong password!");
                        msgBox.ShowDialog();
                    }
                }
                else
                {
                    chb_alogin.Checked = false;
                    MsgBox msgBox = new MsgBox("Authorization error", "No user with this login was found!");
                    msgBox.ShowDialog();
                }
            }
            if (!is_admin_try)
            {
                if (!File.Exists(users_path + logTxtBox_login.Text))
                {
                    MsgBox msgBox = new MsgBox("Authorization error", "No user with this login was found!");
                    msgBox.ShowDialog();
                }
                else
                {
                    User user = new User();
                    user.Deserialize(users_path + logTxtBox_login.Text);
                    if (user.Passwd == logTxtBox_passwd.Text)
                    {
                        RentalSerivce rentalSerivce = new RentalSerivce(user);
                        this.Hide();
                        if (rentalSerivce.ShowDialog() == DialogResult.Retry)
                        {
                            this.Show();
                        }
                        else
                        {
                            this.Close();
                        }
                    }
                    else
                    {
                        MsgBox msgBox = new MsgBox("Authorization error", "Wrong password!");
                        msgBox.ShowDialog();
                    }
                }
            }
        }
        private void ButtonLogin_Click(object sender, RoutedEventArgs e)
        {
            bool is_admin_try = false;

            if (chb_alogin.IsChecked == true)
            {
                is_admin_try = true;
                if (File.Exists(admins_path + logTxtBox_login.Text))
                {
                    Admin admin = new Admin();
                    admin.Deserialize(admins_path + logTxtBox_login.Text);
                    if (admin.Passwd == passwdbox.Password)
                    {
                        chb_alogin.IsChecked = false;
                        AdminMenu rentalSerivce = new AdminMenu(admin);
                        this.Hide();
                        if (rentalSerivce.ShowDialog() == true)
                        {
                            this.Show();
                        }
                        else
                        {
                            this.Close();
                        }
                    }
                    else
                    {
                        MsgBox msgBox = new MsgBox("Authorization error", "Wrong password!");
                        msgBox.Owner = this;
                        msgBox.ShowDialog();
                    }
                }
                else
                {
                    chb_alogin.IsChecked = false;
                    MsgBox msgBox = new MsgBox("Authorization error", "No user with this login was found!");
                    msgBox.Owner = this;
                    msgBox.ShowDialog();
                }
            }
            if (!is_admin_try)
            {
                if (!File.Exists(users_path + logTxtBox_login.Text))
                {
                    MsgBox msgBox = new MsgBox("Authorization error", "No user with this login was found!");
                    msgBox.Owner = this;
                    msgBox.ShowDialog();
                }
                else
                {
                    User user = new User();
                    user.Deserialize(users_path + logTxtBox_login.Text);
                    if (user.Passwd == passwdbox.Password)
                    {
                        RentalServiceMenu rentalSerivce = new RentalServiceMenu(user);
                        this.Hide();
                        if (rentalSerivce.ShowDialog() == true)
                        {
                            this.Show();
                        }
                        else
                        {
                            this.Close();
                        }
                    }
                    else
                    {
                        MsgBox msgBox = new MsgBox("Authorization error", "Wrong password!");
                        msgBox.Owner = this;
                        msgBox.ShowDialog();
                    }
                }
            }
        }
Example #8
0
 private void bt_rent_Click(object sender, EventArgs e)
 {
     if (DataGrid_cars.Rows.Count > 0)
     {
         RentalCar rentalCar = new RentalCar()
         {
             Available     = (bool)(DataGrid_cars.SelectedRows[0]).Cells[0].Value,
             AvailableFrom = (DateTime)(DataGrid_cars.SelectedRows[0]).Cells[1].Value,
             PricePerDay   = (int)(DataGrid_cars.SelectedRows[0]).Cells[2].Value,
             Brand         = (string)(DataGrid_cars.SelectedRows[0]).Cells[3].Value,
             Model         = (string)(DataGrid_cars.SelectedRows[0]).Cells[4].Value,
             LicensePlate  = (string)(DataGrid_cars.SelectedRows[0]).Cells[5].Value,
             Type          = (string)(DataGrid_cars.SelectedRows[0]).Cells[6].Value,
         };
         if (rentalCar.Available)
         {
             if (user.Balance >= numeric_daysCount.Value * rentalCar.PricePerDay)
             {
                 int index = 0;
                 for (int i = 0; i < cars.Count; i++)
                 {
                     if (cars[i].LicensePlate == rentalCar.LicensePlate)
                     {
                         index = i;
                         break;
                     }
                 }
                 cars.RemoveAt(index);
                 rentalCar.AvailableFrom = DateTime.Now;
                 rentalCar.AvailableFrom = rentalCar.AvailableFrom.AddDays((int)numeric_daysCount.Value);
                 rentalCar.Available     = false;
                 rentalCar.RentedID      = user.ID;
                 user.Pay(rentalCar.PricePerDay * numeric_daysCount.Value);
                 LB_balance.Text = user.Balance.ToString();
                 cars.Insert(index, rentalCar);
                 RentalSerivce.SerializeCars(cars);
                 user.Serialize();
                 DataGrid_cars.Rows.Clear();
                 foreach (var car in cars)
                 {
                     AddCarToDataGrid(car);
                 }
                 MsgBox msgBox = new MsgBox("Rental success", "The car is successfully rented");
                 msgBox.ShowDialog();
             }
             else
             {
                 MsgBox msgBox = new MsgBox("Rental error", "There are not enough funds on your balance for this rent");
                 msgBox.ShowDialog();
             }
         }
         else
         {
             MsgBox msgBox = new MsgBox("Rental error", "The selected car is not available");
             msgBox.ShowDialog();
         }
     }
     else
     {
         MsgBox msgBox = new MsgBox("Rental error", "You have not chosen the car you want to rent");
         msgBox.ShowDialog();
     }
 }