Esempio n. 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            string email    = txtEmail.Text;
            string password = txtPassword.Text;

            if (!ValidateEmail(txtEmail.Text))
            {
                return;
            }
            else if (!ValidatePassword(txtPassword.Text))
            {
                return;
            }


            var data = from x in db.Users
                       where x.UserEmail.Equals(email) && x.UserPassword.Equals(password)
                       select x;


            if (data.Count() < 1)
            {
                MessageBox.Show("No User Found!");
            }
            else
            {
                User     user = data.First();
                HomeForm home = new HomeForm(user);

                home.Show();

                this.Hide();
            }
        }
        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();
            }
        }