private void btnLogin_Click(object sender, RoutedEventArgs e) { //Check if the input from the user is correct //if not - show message and clear the input fields if (!MainWindow.mainLibrary.LibraryUsers.CheckUser(txtUserName.Text, pswPassword.Password)) { GuiMsgs.LoginFailed(); //Cleaning the Input fields after for fresh input from the User txtUserName.Text = pswPassword.Password = string.Empty; //Focusing the keyboard into username field txtUserName.Focus(); } //if the input is correct - insert the user data //to the current user variable and show the main window else { MainWindow.mainLibrary.LibraryUsers.CurrentUser = MainWindow.mainLibrary.LibraryUsers.GetCurrentUser(txtUserName.Text, pswPassword.Password); ShowMain = true; this.Close(); } }
private void btnSaveEdit_Click(object sender, RoutedEventArgs e) { ///////////////////////// VALIDATION OF THE USER INPUT ////////////////// if (!Validity.StringOK(txtName.Text)) { GuiMsgs.Warning("Please Enter User Name"); } else if (!Validity.StringOK(txtPassword.Text)) { GuiMsgs.Warning("Please Enter Password"); } else if (cmbType.SelectedIndex < 0) { GuiMsgs.Warning("Please select the User Type"); } ///////////////////////// VALIDATION OF THE USER INPUT ////////////////// else //if all fields are OK { switch (EditMode) { case true: //updating existing user UserToAddOrEdit.Name = txtName.Text; UserToAddOrEdit.Password = txtPassword.Text; UserToAddOrEdit.Type = (User.eUserType)cmbType.SelectedItem; this.Close(); break; case false: //adding new user UserToAddOrEdit = new User(txtName.Text, txtPassword.Text, (User.eUserType)cmbType.SelectedItem); MainWindow.mainLibrary.LibraryUsers.Users.Add(UserToAddOrEdit); this.Close(); break; } } }
//Ctor of Login Dialog public LoginWindow() { InitializeComponent(); //Try open the Data File and read the Info from it. try { //if there's file at all if (File.Exists(DBData.FilePath)) { MainWindow.mainLibrary = MainWindow.mainLibrary.GetBLData(); } //if it's the first initiation of the program - because there's no data file else { GuiMsgs.FirstLogin(); } } //catching the possible Exception and showing to the user with warning sign catch (Exception ex) { GuiMsgs.Warning(ex.Message); } //Disable the login button until the user enters some characters //in both fields GuiChanges.Disable(btnLogin); txtUserName.HorizontalContentAlignment = pswPassword.HorizontalContentAlignment = HorizontalAlignment.Center; pswPassword.PasswordChar = '*'; //Focusing the keyboard into username field txtUserName.Focus(); }
//Search for Copies of the Item by relevant parameters //Excluding the ISBN, which is unique for each Item private void btnQuantity_Click(object sender, RoutedEventArgs e) { //Get the Item to search for from the DataGrid AbstractItem item = (AbstractItem)dataLib.SelectedItem; //Show the result of the Message Box GuiMsgs.Info($"The quantity of this {item.ItemType} is {mainLibrary.ItemQuantity(item)}"); }
private void btnAdd_Click(object sender, RoutedEventArgs e) { ///////////////////////// VALIDATION OF THE USER INPUT ////////////////// if (CurrentItem == ItemType.Default) { GuiMsgs.Warning ("Please Choose the Item Type:" + "\nBook or Journal!"); } //if Base category is choosen else if (cmbBaseCat.SelectedIndex < 0) { GuiMsgs.Warning("Please choose the Base Category!"); } else if (!Validity.StringOK(txtName.Text)) { GuiMsgs.Warning("Please Enter The Name of The Item!"); } else if (dtPick.SelectedDate == null) { GuiMsgs.Warning("Please Select a Publishing Date!"); } else { switch (CurrentItem) { case ItemType.Book: if (!Validity.StringOK(txtAuthor.Text)) { GuiMsgs.Warning("Please Enter The Author Name!"); } else { CreateItem(); this.Close(); } break; case ItemType.Journal: if (!Validity.StringOK(txtIssue.Text)) { GuiMsgs.Warning("Please Enter The Issue Number!"); } else if (!Validity.PositiveInteger(txtIssue.Text)) { GuiMsgs.Warning("Please Enter the valid Issue Number!"); } else //If All the fields are OK - create new Item and add him into the Library { CreateItem(); this.Close(); } break; } } ///////////////////////// VALIDATION OF THE USER INPUT ////////////////// }
//Deleting user private void btnDelete_Click(object sender, RoutedEventArgs e) { if (!IsCurrentUser()) // So current user ca't be deleted { //Warning dialog - last chance to regret and if user approves - //deleting the Item form the Library if (GuiMsgs.AreYouSure($"Are You Sure that\nYou want to delete the\n'{((User)dataUsers.SelectedItem).Name}'\nUser?")) { //Deletion MainWindow.mainLibrary.LibraryUsers.Users.Remove((User)dataUsers.SelectedItem); //Refresh the Grid after the change was made to the Item collection Refresh(); } } }
/// <summary> /// Validation method that checks if all the fields are valid /// before Update the Current Item /// </summary> /// <returns>true if the fields are OK and false if opposite</returns> private bool FieldsValidForUpdate() { if (!Validity.StringOK(txtName.Text)) { GuiMsgs.Warning("Please enter the Item Name!"); return(false); } else if (dtPick.SelectedDate == null) { GuiMsgs.Warning("Please Select the Publishing Date!"); return(false); } else { switch (CurrentItem.ItemType) { case "Book": if (!Validity.StringOK(txtAuthor.Text)) { GuiMsgs.Warning("Please Enter the Author Name!"); return(false); } break; case "Journal": if (!Validity.StringOK(txtIssue.Text)) { GuiMsgs.Warning("Please Enter The Issue Number!"); return(false); } else if (!Validity.PositiveInteger(txtIssue.Text)) { GuiMsgs.Warning("Please Enter the valid Issue Number!"); return(false); } break; } } return(true); }
//Delete Button Clicked Event- //Ask the User for approval and if granted, //delete the current item from the Library private void btnDelete_Click(object sender, RoutedEventArgs e) { //Temporary variable for the Selected Item var currentItem = (AbstractItem)dataLib.SelectedItem; //Last chance to regret before deleting the choosed Item if (GuiMsgs.AreYouSure( $"Are You Positive that You want to delete this {currentItem.ItemType}?" + "\n(There's no way You can undo this action!)")) { //If Uses Approves the deletion - remove the Item from the Library mainLibrary.Items.Remove(currentItem); //Refresh DataGrid because changes was made RefreshDataGrid(); //Cancel the search because changes was made UntickSearchOptions(); } }
/// <summary> /// Check if User from DataGrid is the current User /// </summary> /// <returns>If the User is current - true, opposite - false</returns> private bool IsCurrentUser() { //if the user is current - prevent deletion or editing if (MainWindow.mainLibrary.LibraryUsers.CurrentUser.Name == ((User)dataUsers.SelectedItem).Name) { GuiMsgs.Info("Deletion or Editing of Current user is\nFORBIDDEN!"); return(true); } //if the user is main user - also prevent deletion or editing if (((User)dataUsers.SelectedItem).Name == "BigBoss") { GuiMsgs.Info("Deletion or Editing of the 'Big Boss' is\nFORBIDDEN!\nThis is the Main User,\nSo It's Impossible to Delete him"); return(true); } else { return(false); } }