Ejemplo n.º 1
0
 private void BtnLogin_Click(object sender, RoutedEventArgs e)
 {
     if (textEmail.Text.Length == 0)
     {
         MessageBox.Show("Error: Enter Your Email");
         textEmail.Focus();
     }
     else if (!Regex.IsMatch(textEmail.Text, @"^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$"))
     {
         MessageBox.Show("Error: Enter Valid Email");
         textEmail.Select(0, textEmail.Text.Length);
         textEmail.Focus();
     }
     else
     {
         string        email    = textEmail.Text;
         string        password = passwordbox.Password;
         SqlConnection con      = new SqlConnection("Data Source=.;Initial Catalog=PatientDB;Integrated Security=True");
         con.Open();
         SqlCommand cmd = new SqlCommand("Select * from Registration where Email='" + email + "'  and password='******'", con);
         cmd.CommandType = CommandType.Text;
         SqlDataAdapter adapter = new SqlDataAdapter();
         adapter.SelectCommand = cmd;
         DataSet dataSet = new DataSet();
         adapter.Fill(dataSet);
         if (dataSet.Tables[0].Rows.Count > 0)
         {
             var    DBtable      = dataSet.Tables[0].Rows[0];
             string username     = DBtable["FirstName"].ToString() + " " + DBtable["LastName"].ToString();
             string fulluserinfo = DBtable["FirstName"].ToString() + " " + DBtable["LastName"].ToString() + "\r\n" + DBtable["Email"].ToString() + "\r\n" + DBtable["Gender"].ToString() + "\r\n" + DBtable["Birthday"].ToString() + "\r\n" + DBtable["PhoneNo"].ToString() + "\r\n" + DBtable["Address1"].ToString() + "\r\n" + DBtable["Address2"].ToString() + "\r\n" + DBtable["Postcode"].ToString() + "\r\n" + DBtable["State"].ToString();
             MessageBox.Show("Welcome " + username);
             PagePortal pagepor = new PagePortal();
             pagepor.getGooglePlusUser(username);
             pagepor.getuserinfo(fulluserinfo);
             this.NavigationService.Navigate(pagepor);
         }
         else
         {
             MessageBox.Show("Error: Email or Password incorrect");
         }
         con.Close();
     }
 }
        private void Btnregister_Click(object sender, RoutedEventArgs e)
        {
            if (emailR.Text.Length == 0)
            {
                MessageBox.Show("Error: Enter Your Email");
                emailR.Text = "";
                emailR.Focus();
            }
            else if (!Regex.IsMatch(emailR.Text, @"^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$"))
            {
                MessageBox.Show("Error: Enter a valid email");
                emailR.Text = "";
                emailR.Select(0, emailR.Text.Length);
                emailR.Focus();
            }
            else
            {
                string firstname = Fname.Text;
                string lastname  = Lname.Text;
                string email     = emailR.Text;
                string Genders   = gender.Text;
                string phoneNum  = phoneNo.Text;
                string birthdayU = birthday.Text;
                string password  = password1.Password;
                if (password1.Password.Length == 0)
                {
                    MessageBox.Show("Error: Enter password");
                    password1.Focus();
                }
                else if (confirmPassword.Password.Length == 0)
                {
                    MessageBox.Show("Error: Enter Confirm password");
                    confirmPassword.Focus();
                }
                else if (password1.Password != confirmPassword.Password)
                {
                    MessageBox.Show("Error: Confirm password must be same as password.");
                    confirmPassword.Focus();
                }
                else
                {
                    string        addressL  = address1.Text;
                    string        addressLL = address2.Text;
                    string        location  = state.Text;
                    string        locID     = postcode.Text;
                    SqlConnection con       = new SqlConnection("Data Source=.;Initial Catalog=PatientDB;Integrated Security=True");
                    con.Open();
                    SqlCommand cmd = new SqlCommand("Insert into Registration (FirstName,LastName,Email,Password,Gender,Birthday,PhoneNo,Address1,Address2,Postcode,State) values('" + firstname + "','" + lastname + "','" + email + "','" + password + "','" + Genders + "','" + birthdayU + "','" + phoneNum + "','" + addressL + "','" + addressLL + "','" + locID + "','" + location + "')", con);
                    cmd.CommandType = CommandType.Text;
                    cmd.ExecuteNonQuery();
                    con.Close();
                    MessageBox.Show("You have Registered successfully");
                    PagePortal pagepor = new PagePortal();

                    pagepor.getuserinfo(firstname + " " + lastname + "\r\n" + email + "\r\n" + Genders + "\r\n" + birthdayU + "\r\n" + phoneNum + "\r\n" + addressL + "\r\n" + addressLL + "\r\n" + locID + "\r\n" + location);
                    pagepor.getGooglePlusUser(firstname + " " + lastname);
                    this.NavigationService.Navigate(pagepor);
                    Reset();
                }
            }
        }