Exemplo n.º 1
0
        private void BtnSave_Click_1(object sender, EventArgs e)
        {
            //Get all the variables from the form interface.  Store in variables for ease of use
            var FirstName        = tbFirstName.Text;
            var LastName         = tbLastName.Text;
            var UserName         = tbUserName.Text;
            var Telephone        = tbTelephone.Text;
            var EmailAddress     = tbEmail.Text;
            var experinceInYears = tbExperience.Text;
            var DateOfBirth      = dpDOB.Value;
            var Gender           = cbGender.SelectedValue;
            var HiredDate        = DateTime.Now;//dpHiredDate.Value;
            var Specialization   = cbSpecialization.SelectedValue;
            // var userType = ;
            var DateCreated = DateTime.Now;
            var dateOfHire  = DateTime.Now;

            var rand = new Random();
            //This is my random generation of a password. I am using the first letter of the given first name,
            //the last name and a random number generated between 1 and 100.
            //This password NEEDS TO BE ENCRYPTED!!!!
            var password = $"{FirstName[0]}{LastName}{rand.Next(0, 100)}";


            //Declare an object of the datatype that corresponds with the
            //table that you are about to store data in
            instructor record  = new instructor();
            user       record1 = new user();

            record.firstName = FirstName;
            record.lastName  = LastName;
            // record.Address = Address;
            record1.userName     = UserName;
            record1.phoneNumber  = Telephone;
            record1.emailAddress = EmailAddress;
            //record.dateCreate = DateOfBirth;
            record.instructorGenderId = Convert.ToInt32(Gender);
            // record.DateOfHire = HiredDate;
            record.specializationId = Convert.ToInt32(Specialization);
            //record.DateCreated = DateCreated;


            //Validate minimum data is collected, as well as any other validation that you may want to enforce.
            if (isFormInvalid())
            {
                MessageBox.Show("Please validate all data before submission!");
            }
            //Do further validations to checck for username and email address
            else if (CheckEmail(EmailAddress) || CheckUserName(UserName))
            {
                MessageBox.Show("A user exists with this email/username!");
                this.Show();
            }
            else
            {
                //Add the record (or object) to the the table and save changes
                // cstaffgymn.members.Add(record);
                cinstructors.SaveChanges();
                MessageBox.Show("New Member added Successfully");
                Clear();
            }
        }
Exemplo n.º 2
0
        private void BtnSave_Click(object sender, EventArgs e)
        {
            //Get all the variables from the form interface.  Store in variables for ease of use
            var FirstName    = tbFirstName.Text;
            var LastName     = tbLastName.Text;
            var UserName     = tbUsername.Text;
            var Telephone    = tbTelephone.Text;
            var EmailAddress = tbEmail.Text;
            var DateOfBirth  = dpDOB.Value;
            var Gender       = cbGender.SelectedValue;
            var HiredDate    = DateTime.Now;//dpHiredDate.Value;
            var Salary       = cbSalary.SelectedValue;
            var Address      = tbAddress.Text;
            //var userType = cbUserType;
            var DateCreated = DateTime.Now;

            /*
             *          //For Staff
             *          [First_name
             *          [Last_name
             *          //Gender
             *          //Date Of Birth
             *          [Email
             *          [Phone_number
             *          [Hire_date
             *          [job_id
             *          [salary
             *          [address
             *          [staff_payments_id]
             *          [username]
             *          [password]
             *          Date Created
             */

            var rand = new Random();
            //This is my random generation of a password. I am using the first letter of the given first name,
            //the last name and a random number generated between 1 and 100.
            //This password NEEDS TO BE ENCRYPTED!!!!
            var password = $"{FirstName[0]}{LastName}{rand.Next(0, 100)}";

            /* STart Here
             *
             * //Declare an object of the datatype that corresponds with the
             * //table that you are about to store data in
             * staff record = new staff();
             *
             * record.First_name = FirstName;
             * record.Last_name = LastName;
             * record.address = Address;
             * record.username = UserName;
             * record.password = password;
             * record.Phone_number = Telephone;
             * record.Email = EmailAddress;
             * record. DateOfBirth = DateOfBirth;
             * record.GenderId = Convert.ToInt32(Gender);
             * record.Hire_date = HiredDate;
             * record.salary = Convert.ToInt32(Salary);
             * record.DateCreated = DateCreated;
             * //ar userType = cbUserType;
             *
             * End here */

            //Validate minimum data is collected, as well as any other validation that you may want to enforce.
            if (isFormInvalid())
            {
                MessageBox.Show("Please validate all data before submission!");
            }
            //Do further validations to checck for username and email address
            else if (CheckEmail(EmailAddress) || CheckUserName(UserName))
            {
                MessageBox.Show("A user exists with this email/username!");
                this.Show();
            }
            else
            {
                //Add the record (or object) to the the table and save changes
                // cstaffgymn.members.Add(record);
                cstaffgymn.SaveChanges();
                MessageBox.Show("New Member added Successfully");
                Clear();

                /* Fields not added
                 *
                 * Subscription Status = Subscription_status_id
                 * Organization /branch code = Oraganization_type
                 * Member_progress_id
                 * Payment-info_id
                 * hardcode User_type-id
                 * Fee_payment_option_type
                 */
            }
        }