Esempio n. 1
0
        private void AddNewUser()
        {
            if (name.Text.Length == 0 || userName.Text.Length == 0 || password.Text.Length == 0 || phone.Text.Length == 0)
            {
                error.Text = "fill all fields";
                return;
            }
            error.Text = "";
            using (var objDataContext = new dbDataContext())
            {
                User user = new User
                {
                    Name        = name.Text,
                    Username    = userName.Text,
                    Password    = password.Text,
                    CountryCode = country.SelectedValue.ToString(),
                    Phone       = phone.Text
                };

                try
                {
                    objDataContext.Users.InsertOnSubmit(user);
                    objDataContext.SubmitChanges();
                    Properties.Settings.Default.userName = userName.Text;
                    this.Hide();
                    var root = new RootWindow();
                    root.Closed += (s, args) => this.Close();
                    root.Show();
                }
                catch (SqlException e)
                {
                    switch (e.Number)
                    {
                    case 2627:
                        error.Text = "username or phone already choosen";
                        break;

                    case 547:
                        error.Text = "username and password length must be between 5 and 30";
                        break;

                    default:
                        error.Text = e.Number.ToString() + " " + e.Message;
                        break;
                    }
                }
            }
        }
Esempio n. 2
0
 private void Login_Click_1(object sender, RoutedEventArgs e)
 {
     using (var db = new dbDataContext())
     {
         var user = (from u in db.Users
                     where u.Username == loginUsername.Text && u.Password == loginPassword.Text
                     select u);
         foreach (User or in user)
         {
             Properties.Settings.Default.userName = loginUsername.Text;
             this.Hide();
             var root = new RootWindow();
             root.Closed += (s, args) => this.Close();
             root.Show();
             break;
         }
         error.Text = "User Not found";
     }
 }