//wylogowanie, usuniecie niepotrzebnych danych public void Logout() { userAcc = null; db = null; ViewLogic.DisposeDatabase(); InitDbAsync(); }
public UserRecord(konto k) { this.id = k.id; this.login = k.login; this.typ_konta = k.konto_typ.nazwa; this.konto = k; }
//Metoda odpowiada za logowanie, wyszukuje czy istnieje uzytkownik o danym loginie. //Oblicza SHA-512 dla wpisanego hasla i porownuje z danymi w bazie public bool NewLogin(string login, string password) { try { initDbTask.Wait(); Task<konto> tempAcc = db.konto.SingleOrDefaultAsync(o => o.login == login); byte[] passwordAfter = ViewLogic.ObliczSHA(password); tempAcc.Wait(); if (tempAcc.Result == null) { ViewLogic.Blad("Błędny login lub hasło"); return false; } byte[] passwordFromDb = tempAcc.Result.haslo; for (int i = 0; i < 64; i++) { if(passwordAfter[i] != passwordFromDb[i]) { ViewLogic.Blad("Błędny login lub hasło"); userAcc = null; return false; } } userAcc = tempAcc.Result; UpdataWindow(); return true; } catch (Exception) { userAcc = null; return false; } }
private void UserControl_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e) { try { if (System.ComponentModel.DesignerProperties.GetIsInDesignMode(this)) return; db = ViewLogic.dbContext; StocktakingViewModel.Stocktaking.SelectedTab = Tab.Raports; if (db == null || loadUI == false) return; userAcc = StocktakingViewModel.Stocktaking.User; if (!String.IsNullOrWhiteSpace(TypeTextBlock.Text)) { if (Room.IsChecked == true) { Room_Checked(this, null); } else if (Worker.IsChecked == true) { Worker_Checked(this, null); } else if (Device.IsChecked == true) { Device_Checked(this, null); } else if (RoomMan.IsChecked == true) { RoomMan_Checked(this, null); } else if (DeviceMan.IsChecked == true) { DeviceMan_Checked(this, null); } } int Type = userAcc.konto_typ_id; switch (Type) { case 2://Dyrektor zakładu managerUI(); break; case 3:// Kierownik instytutu chiefUI(); break; default: break; } upData(); loadUI = false; } catch (Exception) { ViewLogic.Blad("Wystapił bład w UserControl_IsVisibleChanged!"); } }
private void btZarejestruj_Click(object sender, EventArgs e) { btZarejestruj.Enabled = true; if (imie.Text != "" && nazwisko.Text != "" && miasto.Text != "" && nrLokalu.Text != "" && pesel.Text != "") { uzytkownik user = new uzytkownik(); konto kontoUser = new konto(); Random r = new Random(); int random = r.Next(100, 999); user.login = login.Text; user.imie = imie.Text; user.nazwisko = nazwisko.Text; user.haslo = haslo.Text; user.miasto = miasto.Text; user.ulica = ulica.Text; user.nrLokalu = nrLokalu.Text; user.telefon = telefon.Text; user.pesel = pesel.Text; user.email = email.Text; user.nrRachunku = random.ToString() + pesel.Text; user.status = true; using (var context = new DbBankEntities5()) { context.uzytkowniks.Add(user); context.SaveChanges(); var varKonto = context.uzytkowniks.Where(t => t.login == login.Text).SingleOrDefault(); kontoUser.uzytkownikId = varKonto.uzytkownikId; kontoUser.saldo = 0; context.kontoes.Add(kontoUser); context.SaveChanges(); login.Text = imie.Text = nazwisko.Text = haslo.Text = miasto.Text = ulica.Text = nrLokalu.Text = telefon.Text = pesel.Text = email.Text = ""; infoRejestracjaLb.Text = "Zarejestrowano użytkownika"; btZarejestruj.Enabled = false; } } else { MessageBox.Show("Uzupełnij brakujące pola!", "Niekompletne dane", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public Form(uzytkownik user, konto kontoUzytkownika) { InitializeComponent(); InicjalizacjaUkladuPaneli(); lbNazwisko.Text = user.imie + " " + user.nazwisko; lbUserID.Text = user.uzytkownikId.ToString(); lbEmail.Text = user.email; userTopBarLb.Text = user.imie + " " + user.nazwisko; ostatnieLogowanieLb.Text = DateTime.Now.ToShortDateString(); nrKontaTB.Text = label3.Text = user.nrRachunku; nrRachunkuTb.Text = kwotaPrzelewuTb.Text = ""; lbSaldoKonta.Text = kontoUzytkownika.saldo.ToString() + " zł"; kontoUserOwner = kontoUzytkownika; }
private void wyslijPrzelewBt_Click(object sender, EventArgs e) { konto kontoUpdate = new konto(); transakcja transakcjaDoZapisu = new transakcja(); double kwotaPrzelewuInt; if (kwotaPrzelewuTb.Text != "" && nrRachunkuTb.Text != "" && Double.TryParse(kwotaPrzelewuTb.Text, out kwotaPrzelewuInt)) { using (var context = new DbBankEntities5()) { var userRecive = context.uzytkowniks.Where(t => t.nrRachunku == nrRachunkuTb.Text).SingleOrDefault(); var kontoSend = context.kontoes.Where(t => t.uzytkownikId == kontoUserOwner.uzytkownikId).SingleOrDefault(); if (userRecive != null) { var konto = context.kontoes.Where(t => t.uzytkownikId == userRecive.uzytkownikId).SingleOrDefault(); kontoSend.saldo -= kwotaPrzelewuInt; konto.saldo += kwotaPrzelewuInt; context.SaveChanges(); transakcjaDoZapisu.uzytkownikId = kontoSend.uzytkownikId; transakcjaDoZapisu.nrOdbiorcy = nrKontaTB.Text; transakcjaDoZapisu.dataPrzelewu = DateTime.Now; transakcjaDoZapisu.miasto = miastoTb.Text; transakcjaDoZapisu.ulica = ulicaTb.Text; transakcjaDoZapisu.nrLokalu = nrLokaluTb.Text; transakcjaDoZapisu.kwotaPrzelewu = kwotaPrzelewuInt; transakcjaDoZapisu.tytulPrzelewu = tytulPrzelewu.Text; context.transakcjas.Add(transakcjaDoZapisu); context.SaveChanges(); wymaganePolaLb.Text = "Przelew został wykonany"; miastoTb.Text = ulicaTb.Text = nrLokaluTb.Text = nrRachunkuTb.Text = kwotaPrzelewuTb.Text = tytulPrzelewu.Text = ""; } else { wymaganePolaLb.Text = "Przelew niewykonany. Spróbuj później..."; } } } else { wymaganePolaLb.Text = "Wymagane pola: Rachunek odbiorcy i Kwota przelewu"; } }
private void btZaloguj_Click(object sender, EventArgs e) { errorMessage.Text = ""; log lastLogin = new log(); uzytkownik logedUser = new uzytkownik(); konto kontoUzytkownika = new konto(); bool access = false; using (var context = new DbBankEntities5()) { var user = context.uzytkowniks.Where(t => t.login == login.Text).SingleOrDefault(); if (user != null) { if (user.haslo == haslo.Text && user.status == true) { var saldo = context.kontoes.Where(t => t.uzytkownikId == user.uzytkownikId).SingleOrDefault(); access = true; logedUser = user; kontoUzytkownika = saldo; lastLogin.uzytkownikId = user.uzytkownikId; lastLogin.dataLogowania = DateTime.Now; context.logs.Add(lastLogin); context.SaveChanges(); } } } if (access) { this.WindowState = FormWindowState.Minimized; Form start = new Form(logedUser, kontoUzytkownika); start.Show(); } else { errorMessage.Text = "Nieprawidłowy login lub hasło!"; login.Text = haslo.Text = ""; } }
// w zależności kto się zalogował tak interfejs zostanie zmodyfikowany private void UserControl_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e) { try { if (System.ComponentModel.DesignerProperties.GetIsInDesignMode(this)) return; db = ViewLogic.dbContext; StocktakingViewModel.Stocktaking.SelectedTab = Tab.InstMan; if (db == null || loadUI == false) return; userAcc = StocktakingViewModel.Stocktaking.User; int Type = userAcc.konto_typ_id; switch (Type) { case 2://Dyrektor zakładu managerUI(); upDataManager(); break; case 3:// Kierownik instytutu chiefUI(); upDataChief(); break; case 4:// zakładowy pracownik techniczny technicalWorkerUI(); upDataTechnician(); break; default: break; } loadUI = false; } catch (Exception) { ViewLogic.Blad("Wystapił bład w UserControl_IsVisibleChanged!"); } }
//metoda dodawania nowego uzytkownika private async void dodajButton_Click(object sender, RoutedEventArgs e) { try { if (!ViewLogic.Potwierdz("Czy chcesz dodać użytkownika?")) return; string nowyLogin = nowyLoginTextBox.Text; if (nowyLogin == "") { ViewLogic.Blad("Nie podano loginu!"); hasloPassBox.Clear(); powtorzPassBox.Clear(); return; } bool loginZajety = await db.konto.AnyAsync(k => k.login == nowyLogin); if (loginZajety) { ViewLogic.Blad("Isnieje już użytkownik o podanym loginie!"); hasloPassBox.Clear(); powtorzPassBox.Clear(); return; } string haslo = hasloPassBox.Password; string haslo2 = powtorzPassBox.Password; if (haslo != haslo2) { ViewLogic.Blad("Wprowadzone hasło nie jest jednakowe!"); hasloPassBox.Clear(); powtorzPassBox.Clear(); return; } byte[] sha = ViewLogic.ObliczSHA(haslo); int noweId = 1; await db.konto.LoadAsync(); foreach (konto k in db.konto.Local.OrderBy(k => k.id)) { if (noweId != k.id) break; else ++noweId; } konto_typ nowyTyp = (konto_typ)typComboBox.SelectedItem; pracownik p = (pracownik)pracownikDataGrid.SelectedItem; konto nowy = new konto { id = noweId, haslo = sha, konto_typ = nowyTyp, login = nowyLogin, pracownik = p, pracownik_id = p.id, konto_typ_id = nowyTyp.id }; db.konto.Add(nowy); await db.SaveChangesAsync(); nowyLoginTextBox.Clear(); hasloPassBox.Clear(); powtorzPassBox.Clear(); typComboBox.SelectedItem = null; System.Windows.Data.CollectionViewSource userRecordViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("userRecordViewSource"))); await db.konto.LoadAsync(); List<konto> konta = db.konto.Local.ToList(); List<UserRecord> rekordy = new List<UserRecord>(); foreach (konto k in konta) { rekordy.Add(new UserRecord(k)); } userRecordViewSource.Source = rekordy.OrderBy(r => r.id); System.Windows.Data.CollectionViewSource pracownikViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("pracownikViewSource"))); pracownikViewSource.Source = await db.pracownik.Where(pp => pp.konto.Count == 0).ToListAsync(); } catch (Exception) { ViewLogic.Blad("Wystapił bład w dodajButton_Click!"); } }
public ChangePassword(konto k) { InitializeComponent(); user = k; }