public static double CostForRent = 0.1; //to rent a book, a client have to pay 0.1*Book price public ItemView() { _manager = new InterfaceManager(this); this.InitializeComponent(); //initialise books for exemple (once, at the first connection of any user) if (InterfaceManager.ConnectNum == 0) { ItCollec.InitialiseFirstBooks(); } InterfaceManager.ConnectNum++; //welcome message tBWelcome.Text = string.Format("Welocome {0}, have a great visit...", InterfaceManager.ActualUser.Name); _manager.InitialiseListeView(); //Show the item in list manager _manager.ShowDependingLevel(); //show StackPanel and button dependind of user level NonReturnBooks(); //check if the user didn't returned a book }
bool wantToRegister = false;//allow user to create a client account and check if all data are valid private void Register_Click(object sender, RoutedEventArgs e) { LogIn.Visibility = Visibility.Collapsed; if (!wantToRegister) { ConfirmPassword.Visibility = Visibility.Visible; wantToRegister = true; tBValidation.Text = "Enter your data.."; tBValidation.Foreground = new SolidColorBrush(Colors.LightGreen); } else if (password.Text == tBConfirmPassword.Text) { if (!InterfaceManager.ValidPassword(password.Text)) { tBValidation.Foreground = new SolidColorBrush(Colors.Red); tBValidation.Text = "PassWord have to contain 8 characteres, upper and lower case"; } else if (!uCollect.IsUser(userName.Text)) { User temp = new User(AutorisationLevel.Client, userName.Text, tBConfirmPassword.Text); uCollect.AddUser(temp); tBValidation.Text = "Your account have been created.. you can login.."; tBValidation.Foreground = new SolidColorBrush(Colors.LightGreen); ConfirmPassword.Visibility = Visibility.Collapsed; ClearUI(); LogIn.Visibility = Visibility.Visible; wantToRegister = false; } else { tBValidation.Foreground = new SolidColorBrush(Colors.Red); tBValidation.Text = "An account already Exist with this username"; } } else { tBValidation.Foreground = new SolidColorBrush(Colors.Red); tBValidation.Text = "Your passwords are different"; } }
//Create a user private void createUser_Click(object sender, RoutedEventArgs e) { if (!InterfaceManager.ValidPassword(tBPasswordUser.Text)) { PasswordValidation.Foreground = new SolidColorBrush(Colors.Red); PasswordValidation.Text = "PassWord have to contain 8 characteres, upper and lower case"; return; } string password = tBPasswordUser.Text; if (_uCollect.IsUser(tBNameUser.Text)) { PasswordValidation.Foreground = new SolidColorBrush(Colors.Red); PasswordValidation.Text = "Username already exist. Chose another one..."; return; } string name = tBNameUser.Text; AutorisationLevel autoLevel; if (rBEmployee.IsChecked == true) { autoLevel = AutorisationLevel.Employee; } else if (rBManager.IsChecked == true) { autoLevel = AutorisationLevel.Manager; } else { PasswordValidation.Foreground = new SolidColorBrush(Colors.Red); PasswordValidation.Text = "Choose an autorisation Level"; return; } User tmp = new User(autoLevel, name, password); _uCollect.AddUser(tmp); PasswordValidation.Foreground = new SolidColorBrush(Colors.Green); PasswordValidation.Text = "User Created"; ClearUIData(); }
//show a report of all data system private void showReport_Click(object sender, RoutedEventArgs e) { sPReport.Visibility = Visibility.Visible; sPAddUser.Visibility = Visibility.Collapsed; tbBookNum.Text = string.Format("{0} book{1} ", _itemCollec.BookCount, InterfaceManager.Plurial(_itemCollec.BookCount)); tbBookStock.Text = string.Format("{0} book{1} ", _itemCollec.BookStock, InterfaceManager.Plurial(_itemCollec.BookStock)); tbJournalNum.Text = string.Format("{0} journal{1} ", _itemCollec.JournalCount, InterfaceManager.Plurial(_itemCollec.JournalCount)); tbJournalStock.Text = string.Format("{0} journal{1} ", _itemCollec.JournalStock, InterfaceManager.Plurial(_itemCollec.JournalStock)); tbCliNumber.Text = string.Format("{0} client{1} ", _uCollect.UserPerLevel(AutorisationLevel.Client), InterfaceManager.Plurial(_uCollect.UserPerLevel(AutorisationLevel.Client))); tbEmpNumber.Text = string.Format("{0} employee{1} ", _uCollect.UserPerLevel(AutorisationLevel.Employee), InterfaceManager.Plurial(_uCollect.UserPerLevel(AutorisationLevel.Employee))); tbManNumber.Text = string.Format("{0} manager{1} ", _uCollect.UserPerLevel(AutorisationLevel.Manager), InterfaceManager.Plurial(_uCollect.UserPerLevel(AutorisationLevel.Manager))); tbRentedBook.Text = string.Format("{0} rented book{1} ", _rentCollec.Count, InterfaceManager.Plurial(_rentCollec.Count)); tbTurnover.Text = string.Format("{0:$##########0.##}", _uCollect.TurnOver); tbCliAverage.Text = string.Format("{0:$##########0.##}/ per client", _uCollect.TurnOver / _uCollect.UserPerLevel(AutorisationLevel.Client)); }