public Register() { InitializeComponent(); UsersEntities db = new UsersEntities(); OwnerEntities owner = new OwnerEntities(); //db.Database.ExecuteSqlCommand("DBCC CHECKIDENT ('Users.dbo.User', RESEED, 3)"); //owner.Database.ExecuteSqlCommand("DBCC CHECKIDENT ('Owner.dbo.Owners', RESEED, 3)"); //owner.Database.ExecuteSqlCommand("DBCC CHECKIDENT ('Owner.dbo.PhoneBooks', RESEED, 2)"); //db.SaveChanges(); //owner.SaveChanges(); }
private void loginbtn_Click(object sender, RoutedEventArgs e) { using (UsersEntities db = new UsersEntities()) { var q = db.User.Where(x => x.Username == usernametxt.Text).Where(x => x.Password == passwordtxt.Password).Count(); if (q == 1) { MainWindow window = new MainWindow(db.User.Where(x => x.Username == usernametxt.Text).Select(x => x.fName).FirstOrDefault(), db.User.Where(x => x.Username == usernametxt.Text).Select(x => x.lName).FirstOrDefault()); window.Show(); this.Close(); } else { MessageBox.Show("Nieprawidłowy login lub hasło, spróbuj ponownie"); usernametxt.Text = ""; passwordtxt.Password = ""; } } }
private void registerbtn_Click(object sender, RoutedEventArgs e) { using (UsersEntities db = new UsersEntities()) { OwnerEntities owner = new OwnerEntities(); if (db.User.Where(x => x.Username == usernametxt.Text).Count() == 1) { MessageBox.Show("Użytkownik o tej nazwie już istnieje. Spróbuj innej"); usernametxt.Text = ""; passwordtxt.Password = ""; } else if (owner.Owners.Where(x => x.fName == fNametxt.Text).Where(x => x.lName == lnametxt.Text).Count() == 1) { MessageBoxResult result = MessageBox.Show("Chcesz się zalogować?", "Ta osoba posiada już konto", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No); if (result == MessageBoxResult.Yes) { Login log = new Login(); log.Show(); this.Close(); } else { fNametxt.Text = ""; lnametxt.Text = ""; } } else if (usernametxt.Text == "" || fNametxt.Text == "" || lnametxt.Text == "") { MessageBox.Show("Nazwa użytkownika, imię i nazwisko nie mogą być puste"); } else { User user = new User() { Username = usernametxt.Text, Password = passwordtxt.Password, fName = fNametxt.Text, lName = lnametxt.Text }; Owners ow = new Owners() { fName = fNametxt.Text, lName = lnametxt.Text }; db.User.Add(user); owner.Owners.Add(ow); db.SaveChanges(); owner.SaveChanges(); Login log = new Login(); log.Show(); this.Close(); } } }