예제 #1
0
        private void btnReset_Click(object sender, EventArgs e)
        {
            try
            {
                var password        = tbPassword.Text;
                var confirmPassword = tbConfirmPassword.Text;

                var user = _db.Users.FirstOrDefault(q => q.id == _user.id);

                if (password != confirmPassword)
                {
                    MessageBox.Show("Password do not match. Please try again!");
                }
                else
                {
                    user.password = Utils.HashPassword(password);
                    _db.SaveChanges();
                    MessageBox.Show("Password was reset successfully");
                    Close();
                }
            }
            catch (Exception)
            {
                MessageBox.Show("An error has occured. Please try again.");
            }
        }
예제 #2
0
        private void btnDeleteCar_Click(object sender, EventArgs e)
        {
            try
            {
                //get ID of selected row
                var id = (int)gvVehicleList.SelectedRows[0].Cells["Id"].Value;

                //query database for recoed
                var car = _db.TypeOfCars.FirstOrDefault(q => q.Id == id);

                DialogResult dr = MessageBox.Show("Are you sure want to delete this record?",
                                                  "Delete", MessageBoxButtons.YesNoCancel,
                                                  MessageBoxIcon.Warning);

                if (dr == DialogResult.Yes)
                {
                    //delete vehicle from table
                    _db.TypeOfCars.Remove(car);
                    _db.SaveChanges();
                }
                PopulateGrid();
            }
            catch (Exception err)
            {
                MessageBox.Show($"DeleteError: {err.Message}");
            }
        }
예제 #3
0
        private void btnResetPassword_Click(object sender, EventArgs e)
        {
            try
            {
                //get ID of selected row
                var id = (int)gvUserList.SelectedRows[0].Cells["id"].Value;

                //query database for recoed
                var user            = _db.Users.FirstOrDefault(q => q.id == id);
                var hashed_password = Utils.DefaultHashPassword();
                user.password = hashed_password;
                _db.SaveChanges();

                MessageBox.Show($"{user.username}'s password has benn reset!");
            }
            catch (Exception ex)
            {
                MessageBox.Show($"ResetPasswordError: {ex.Message}");
            }
        }
예제 #4
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                //Add validation for make and model
                if (string.IsNullOrWhiteSpace(tbMake.Text) ||
                    string.IsNullOrWhiteSpace(tbModel.Text))
                {
                    MessageBox.Show("Please ensure that you provide a make and a model");
                }
                else
                {
                    //if (isEditMode == true)
                    if (isEditMode)
                    {
                        //Edit code here
                        var id  = int.Parse(lblId.Text);
                        var car = _db.TypeOfCars.FirstOrDefault(q => q.Id == id);
                        car.Model = tbModel.Text;
                        car.Make  = tbMake.Text;
                        car.VIN   = tbVIN.Text;
                        car.Year  = int.Parse(tbYear.Text);
                        car.LicensePlateNumber = tbLicenseNum.Text;

                        /* _db.SaveChanges();
                         * Close();*/
                    }
                    else
                    {
                        //Add code here
                        var newCar = new TypeOfCar
                        {
                            LicensePlateNumber = tbLicenseNum.Text,
                            Make  = tbMake.Text,
                            Model = tbModel.Text,
                            VIN   = tbVIN.Text,
                            Year  = int.Parse(tbYear.Text)
                        };

                        _db.TypeOfCars.Add(newCar);
                    }
                    _db.SaveChanges();
                    _manageVehicleListing.PopulateGrid();
                    Close();
                }
            }
            catch (Exception err)
            {
                MessageBox.Show($"SaveError: {err.Message}");
            }
        }
예제 #5
0
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                var username = tbUsername.Text;
                var roleId   = (int)cbRoles.SelectedValue;
                var password = Utils.DefaultHashPassword();
                var user     = new User
                {
                    username = username,
                    password = password,
                    isActive = true
                };
                _db.Users.Add(user);
                _db.SaveChanges();

                var userid = user.id;

                var userRole = new UserRole
                {
                    roleid = roleId,
                    userid = userid
                };

                _db.UserRoles.Add(userRole);
                _db.SaveChanges();

                MessageBox.Show("New user update successfully....");
                _manageUsers.PopulateGrid();
                Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("An error has occured!!!");
            }
        }
예제 #6
0
        private void btnDeleteRecord_Click(object sender, EventArgs e)
        {
            try
            {
                //get ID of selected row
                var id = (int)gvRecordList.SelectedRows[0].Cells["Id"].Value;

                //query database for recoed
                var record = _db.CarRentalRecords.FirstOrDefault(q => q.id == id);

                //delete vehicle from table
                _db.CarRentalRecords.Remove(record);
                _db.SaveChanges();

                PopulateGrid();
            }
            catch (Exception err)
            {
                MessageBox.Show($"DeleteError: {err.Message}");
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                //MessageBox.Show($"Thanks you Renting: {tbCustomerName.Text}");
                string customerName = tbCustomerName.Text;
                var    dateOut      = dtRented.Value;
                var    dateIn       = dtReturned.Value;
                double cost         = Convert.ToDouble(tbCost.Text);

                var carType    = cbTypeOfCar.Text;
                var isValid    = true;
                var errMessage = "";

                if (string.IsNullOrWhiteSpace(customerName) || string.IsNullOrWhiteSpace(carType))
                {
                    isValid     = false;
                    errMessage += "Error: Please enter missing data!!!!\n\r";
                }

                if (dateOut > dateIn)
                {
                    isValid     = false;
                    errMessage += "Error: Illegal date seletion!!!!\n\r";
                }
                //(isValid = true)
                if (isValid)
                {
                    /*if (isEditMode)
                     * {
                     *  var id = int.Parse(lblRecordId.Text);
                     *  var rentalRecord = _db.CarRentalRecords.FirstOrDefault(q => q.id == id);
                     *  rentalRecord.CustomerName = customerName;
                     *  rentalRecord.DateRented = dateOut;
                     *  rentalRecord.DateReturned = dateIn;
                     *  rentalRecord.Cost = (decimal)cost;
                     *  rentalRecord.TypeOfCarid = (int)cbTypeOfCar.SelectedValue;
                     *
                     *  _db.SaveChanges();
                     *
                     *  MessageBox.Show($"Customer Name: {customerName}\n\r" +
                     *             $"Date Rented: {dateOut}\n\r" +
                     *             $"Date Returned: {dateIn}\n\r" +
                     *             $"Cost: {cost}\n\r" +
                     *             $"Car Type: {carType}\n\r" +
                     *             "Thanks you for your business.");
                     * }
                     * else
                     * {
                     *  var rentalRecord = new CarRentalRecord();
                     *  rentalRecord.CustomerName = customerName;
                     *  rentalRecord.DateRented = dateOut;
                     *  rentalRecord.DateReturned = dateIn;
                     *  rentalRecord.Cost = (decimal)cost;
                     *  rentalRecord.TypeOfCarid = (int)cbTypeOfCar.SelectedValue;
                     *
                     *  _db.CarRentalRecords.Add(rentalRecord);
                     *  _db.SaveChanges();
                     *
                     *  MessageBox.Show($"Customer Name: {customerName}\n\r" +
                     *             $"Date Rented: {dateOut}\n\r" +
                     *             $"Date Returned: {dateIn}\n\r" +
                     *             $"Cost: {cost}\n\r" +
                     *             $"Car Type: {carType}\n\r" +
                     *             "Thanks you for your business.");
                     * }*/

                    //Declare an object if the record to be added
                    var rentalRecord = new CarRentalRecord();
                    if (isEditMode)
                    {
                        //If in edit mode, then get the ID and retrive the record from the database and place
                        //the result in the record object
                        var id = int.Parse(lblRecordId.Text);
                        rentalRecord = _db.CarRentalRecords.FirstOrDefault(q => q.id == id);
                    }
                    //Populate record object with values from the form
                    rentalRecord.CustomerName = customerName;
                    rentalRecord.DateRented   = dateOut;
                    rentalRecord.DateReturned = dateIn;
                    rentalRecord.Cost         = (decimal)cost;
                    rentalRecord.TypeOfCarid  = (int)cbTypeOfCar.SelectedValue;

                    //If not in edit mode, then add the record object to the database
                    if (!isEditMode)
                    {
                        _db.CarRentalRecords.Add(rentalRecord);
                    }

                    //save change mode to the entity
                    _db.SaveChanges();

                    MessageBox.Show($"Customer Name: {customerName}\n\r" +
                                    $"Date Rented: {dateOut}\n\r" +
                                    $"Date Returned: {dateIn}\n\r" +
                                    $"Cost: {cost}\n\r" +
                                    $"Car Type: {carType}\n\r" +
                                    "Thanks you for your business.");
                    Close();
                }
                else
                {
                    MessageBox.Show(errMessage);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                //throw;
            }
        }