Exemplo n.º 1
0
        private void BtnDelete_Click(object sender, EventArgs e)
        {
            if (txtID.Text.Equals(""))
            {
                MessageBox.Show("Please select a user!");
            }
            else
            {
                var result = MessageBox.Show("Are you sure?", "Confirmation Message", MessageBoxButtons.YesNo);

                if (result == DialogResult.Yes)
                {
                    IndexForm fm1    = (IndexForm)MdiParent;
                    var       currID = fm1.getID();

                    var userID = txtID.Text;

                    var checkAdmin = (from Admin x in DB.conn
                                      select x).ToList();

                    if (checkAdmin.Count == 1)
                    {
                        MessageBox.Show("User delete failed! You are the only admin left!");
                    }
                    else
                    {
                        var deleteAdmin = (from Admin x in DB.conn
                                           where x.ID == userID
                                           select x).FirstOrDefault();

                        DB.conn.Delete(deleteAdmin);

                        MessageBox.Show("Admin has been removed!");

                        resetInitial();

                        if (currID.Equals(userID))
                        {
                            MessageBox.Show("Your account has been removed!");
                            fm1.logOut();
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void BtnLogin_Click(object sender, EventArgs e)
        {
            var role     = cbRole.SelectedIndex;
            var email    = txtEmail.Text;
            var password = txtPassword.Text;

            if (email.Equals("") || password.Equals(""))
            {
                MessageBox.Show("Email or Password can't be empty!");
            }
            else if (role == 0)
            {
                MessageBox.Show("Role must be selected!");
            }
            else
            {
                if (role == 1)
                {
                    var userLogin = (from Customer x in DB.conn
                                     where x.email == email && x.password == password
                                     select x).FirstOrDefault();

                    if (userLogin == null)
                    {
                        MessageBox.Show("Incorrect Email or Password!");
                        resetFields();
                    }
                    else
                    {
                        MessageBox.Show("Login Success");

                        IndexForm fm1 = (IndexForm)MdiParent;
                        fm1.customerMenuState();
                        fm1.setID(userLogin.ID);

                        this.Dispose();
                    }
                }
                else if (role == 2)
                {
                    var userLogin = (from Driver x in DB.conn
                                     where x.email == email && x.password == password
                                     select x).FirstOrDefault();

                    if (userLogin == null)
                    {
                        MessageBox.Show("Incorrect Email or Password!");
                        resetFields();
                    }
                    else
                    {
                        MessageBox.Show("Login Success");

                        IndexForm fm1 = (IndexForm)MdiParent;
                        fm1.driverMenuState();
                        fm1.setID(userLogin.ID);

                        this.Dispose();
                    }
                }
                else if (role == 3)
                {
                    var userLogin = (from Admin x in DB.conn
                                     where x.email == email && x.password == password
                                     select x).FirstOrDefault();

                    if (userLogin == null)
                    {
                        MessageBox.Show("Incorrect Email or Password!");
                        resetFields();
                    }
                    else
                    {
                        MessageBox.Show("Login Success");

                        IndexForm fm1 = (IndexForm)MdiParent;
                        fm1.adminMenuState();
                        fm1.setID(userLogin.ID);

                        this.Dispose();
                    }
                }
            }
        }
Exemplo n.º 3
0
        private void BtnOrder_Click(object sender, EventArgs e)
        {
            var pickupLocation      = txtPickupAddress.Text;
            var pickupNotes         = txtPickupNotes.Text;
            var destinationLocation = txtDestinationAddress.Text;
            var destinationNotes    = txtDestinationNotes.Text;
            var serviceType         = cbService.SelectedIndex;
            var vehicleType         = cbVehicleType.Text;
            var passengers          = nudPassengers.Value;
            var pickupDate          = dtpDate.Value;
            var orderDate           = DateTime.Now;;

            var seats = getSeats(serviceType, vehicleType);

            if (pickupLocation.Equals(""))
            {
                MessageBox.Show("Pickup location address can't be empty!");
            }
            else if (destinationLocation.Equals(""))
            {
                MessageBox.Show("Destination address can't be empty!");
            }
            else if (serviceType == 0)
            {
                MessageBox.Show("Service type must be selected!");
            }
            else if (vehicleType.Equals("-- Choose Vehicle Type"))
            {
                MessageBox.Show("Vehicle type must be selected!");
            }
            else if (passengers <= 0)
            {
                MessageBox.Show("Passengers must be more than 0!");
            }
            else if (passengers > seats)
            {
                MessageBox.Show("Number of passengers exceed vehicle capacity!");
            }
            else
            {
                var orderID = generateID();

                IndexForm fm1        = (IndexForm)MdiParent;
                var       customerID = fm1.getID();

                if (serviceType == 1)
                {
                    var getVehicle = (from BlueBird x in DB.conn
                                      where x.type == vehicleType
                                      select x).FirstOrDefault();

                    Order newOrder = new Order
                    {
                        ID                  = orderID,
                        customerID          = customerID,
                        pickupLocation      = pickupLocation,
                        pickupNotes         = pickupNotes,
                        destinationLocation = destinationLocation,
                        destinationNotes    = destinationNotes,
                        pickupDate          = pickupDate,
                        orderDate           = orderDate,
                        passengers          = Int32.Parse(passengers.ToString()),
                        vehicleID           = getVehicle.ID,
                        completed           = false
                    };

                    DB.conn.Store(newOrder);
                }
                else if (serviceType == 2)
                {
                    var getVehicle = (from SilverBird x in DB.conn
                                      where x.type == vehicleType
                                      select x).FirstOrDefault();

                    Order newOrder = new Order
                    {
                        ID                  = orderID,
                        customerID          = customerID,
                        pickupLocation      = pickupLocation,
                        pickupNotes         = pickupNotes,
                        destinationLocation = destinationLocation,
                        destinationNotes    = destinationNotes,
                        pickupDate          = pickupDate,
                        orderDate           = orderDate,
                        passengers          = Int32.Parse(passengers.ToString()),
                        vehicleID           = getVehicle.ID,
                        completed           = false
                    };

                    DB.conn.Store(newOrder);
                }
                else if (serviceType == 3)
                {
                    var getVehicle = (from BigBird x in DB.conn
                                      where x.type == vehicleType
                                      select x).FirstOrDefault();

                    Order newOrder = new Order
                    {
                        ID                  = orderID,
                        customerID          = customerID,
                        pickupLocation      = pickupLocation,
                        pickupNotes         = pickupNotes,
                        destinationLocation = destinationLocation,
                        destinationNotes    = destinationNotes,
                        pickupDate          = pickupDate,
                        orderDate           = orderDate,
                        passengers          = Int32.Parse(passengers.ToString()),
                        vehicleID           = getVehicle.ID,
                        completed           = false
                    };

                    DB.conn.Store(newOrder);
                }

                MessageBox.Show("Success");
                this.Dispose();
            }
        }
        private void BtnChangePw_Click(object sender, EventArgs e)
        {
            var oldPw  = txtOld.Text;
            var newPw  = txtNew.Text;
            var confPw = txtConfirm.Text;

            IndexForm fm1    = (IndexForm)MdiParent;
            var       tempID = fm1.getID();

            if (oldPw.Equals(""))
            {
                MessageBox.Show("Old password can't be empty!");
            }
            else if (newPw.Equals(""))
            {
                MessageBox.Show("New password can't be empty!");
            }
            else if (newPw.Equals(oldPw))
            {
                MessageBox.Show("New password can't be the same as old password!");
            }
            else if (newPw.Length < 6 || newPw.Length > 15)
            {
                MessageBox.Show("Password must be between 6 and 15 characters!");
            }
            else if (!confPw.Equals(newPw))
            {
                MessageBox.Show("Confirm password doesn't match!");
            }
            else
            {
                if (tempID.Contains("CU"))
                {
                    var checkPassword = (from Customer x in DB.conn
                                         where x.password == oldPw
                                         select x.password).FirstOrDefault();

                    if (checkPassword == null)
                    {
                        MessageBox.Show("Incorrect old password!");
                        resetFields();
                    }
                    else
                    {
                        MessageBox.Show("Change Password Success!");

                        var userData = (from Customer x in DB.conn
                                        where x.ID == tempID
                                        select x).FirstOrDefault();

                        userData.password = newPw;

                        DB.conn.Store(userData);

                        MessageBox.Show("Please re-login to update your password!");
                        fm1.logOut();
                        this.Dispose();
                    }
                }
                else if (tempID.Contains("DR"))
                {
                    var checkPassword = (from Driver x in DB.conn
                                         where x.password == oldPw
                                         select x.password).FirstOrDefault();

                    if (checkPassword == null)
                    {
                        MessageBox.Show("Incorrect old password!");
                        resetFields();
                    }
                    else
                    {
                        MessageBox.Show("Change Password Success!");

                        var userData = (from Driver x in DB.conn
                                        where x.ID == tempID
                                        select x).FirstOrDefault();

                        userData.password = newPw;

                        DB.conn.Store(userData);

                        MessageBox.Show("Please re-login to update your password!");
                        fm1.logOut();
                        this.Dispose();
                    }
                }
                else if (tempID.Contains("AD"))
                {
                    var checkPassword = (from Admin x in DB.conn
                                         where x.password == oldPw
                                         select x.password).FirstOrDefault();

                    if (checkPassword == null)
                    {
                        MessageBox.Show("Incorrect old password!");
                        resetFields();
                    }
                    else
                    {
                        MessageBox.Show("Change Password Success!");

                        var userData = (from Admin x in DB.conn
                                        where x.ID == tempID
                                        select x).FirstOrDefault();

                        userData.password = newPw;

                        DB.conn.Store(userData);

                        MessageBox.Show("Please re-login to update your password!");
                        fm1.logOut();
                        this.Dispose();
                    }
                }
            }
        }