private void btnRegister_Click(object sender, EventArgs e) { string confPass = txtPasswordConfirm.Text; if (!ValidatePassword(txtPassword.Text)) { return; } else if (confPass.Equals("")) { MessageBox.Show("Confirm Password Must be Filled"); return; } else if (confPass != txtPassword.Text) { MessageBox.Show("Password and Confirm Password must be the same"); return; } else if (!ValidateEmail(txtEmail.Text)) { return; } else if (!ValidatePhone(txtPhone.Text)) { return; } else if (!ValidateAddress(txtAddress.Text)) { return; } else { User u = new User(); u.UserName = txtUsername.Text; u.UserPassword = txtPassword.Text; u.UserEmail = txtEmail.Text; u.UserPhoneNumber = txtPhone.Text; u.UserAddress = txtAddress.Text; u.RoleName = "Member"; //ID GENERATOR var data = from x in db.Users select x; if (data.Count() != 0) { String generator = string.Format("US{0}", (data.Count() + 2).ToString("000")); u.UserID = generator; } else { u.UserID = "US001"; } db.Users.AddObject(u); db.SaveChanges(); user = u; } { HomeForm home = new HomeForm(user); home.Show(); this.Hide(); } }