示例#1
0
 public AdminForm(Admin admin)
 {
     InitializeComponent();
     this.admin    = admin;
     lb_login.Text = admin.Login;
     HideSubMenu();
     cars = RentalSerivce.DeserializeCars();
 }
示例#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();
     }
 }
示例#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();
            }
        }
示例#4
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();
                }
            }
        }
示例#5
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();
                    }
                }
            }
        }
示例#6
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();
     }
 }