//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(); }
//Enable "edit" and "delete" buttons if the Selected Index is valid private void EnableCommands(object sender, SelectionChangedEventArgs e) { if (SelectedIndexIsValid()) { GuiChanges.Enable(btnEdit, btnDelete); } }
/// <summary> /// Manipulation with the GUI Elements depending on selection that user made /// </summary> /// <returns>Selected Item Index if it's in valid range</returns> public int GridSelected() { //Creating the Array of elements for simple handling of GUI, //instead of passing to GuiChanges class Methods each one of the controls, //pass only one array variable. Simple and Effective UIElement[] controlsForDataGrid = { btnEdit, btnDetails, btnDelete, btnBorrow, btnQuantity }; //if user clicks in the DataGrid - check if the click Event //Occurred in the valid range to prevent Exception if (dataLib.SelectedIndex >= 0 && dataLib.SelectedIndex < mainLibrary.Items.Count) { //Enable the buttons GuiChanges.Enable(controlsForDataGrid); //Fine tuning the controls depending on current user Rights ButtonsAvailable(); //Temp variable for Changing the controls text var tmpItem = (AbstractItem)dataLib.SelectedItem; //------------ Changing the controls Caption depending ------------// //------------ on the current Item choosed from the Library ------------// btnDelete.Content = $"Delete this {tmpItem.ItemType}"; btnDetails.Content = $"Details of this {tmpItem.ItemType}"; btnEdit.Content = $"Edit this {tmpItem.ItemType}"; btnQuantity.Content = $"Quantity of this {tmpItem.ItemType}"; //------------ Changing the controls Caption depending ------------// //------------ on the current Item choosed from the Library ------------// //Switch for Borrowing Button - depends on current Item "IsBorrowed" State switch (tmpItem.IsBorrowed) { case true: btnBorrow.Content = $"Return this {tmpItem.ItemType}"; break; case false: btnBorrow.Content = $"Borrow this {tmpItem.ItemType}"; break; } //Return Selected Item index return(dataLib.SelectedIndex); } //If the Selected Index is in invalid range else { //Disable the related controls GuiChanges.Disable(controlsForDataGrid); //Fine tuning the controls depending on current user Rights ButtonsAvailable(); //Return the index (even tough it's invalid) return(dataLib.SelectedIndex); } }
//Showing or Hiding the search controls and fields depending on received Enum private void ShowAndHideSearchFields(eShowOrHide showHide) { //Creating the Array of elements for simple handling of GUI, //instead of passing to GuiChanges class Methods each one of the controls, //pass only one array variable. Simple and Effective UIElement[] searchControls = { lblName, txtName, lblAuthor, txtAuthor, lblIssue, txtIssue, lblBaseCategory, cmbBaseCategory, lblInnerCategory, cmbInnerCategory }; //Switch depending on enum switch (showHide) { //Show the search controls case eShowOrHide.Show: //Show the elements from the created array GuiChanges.Show(searchControls); //Fill the ComboBox of Base category GuiChanges.FillComboWithBaseCategory(cmbBaseCategory); //If no selection of Base Category made if (cmbBaseCategory.SelectedItem == null) { //Hide the inner Category ComboBox GuiChanges.Hide(lblInnerCategory, cmbInnerCategory); } break; //Hide the search controls case eShowOrHide.Hide: //Hide the elements from the created array GuiChanges.Hide(searchControls); //Search for the text fields in elements array foreach (UIElement item in searchControls) { //If the Control is Text Box if (item is TextBox) { //Clear the contents of the Text Box, so //this way there's no interfear with feauture search options //when the fields will be enabled and visible again ((TextBox)item).Text = string.Empty; } } //Clean the Combo Boxes of Base and Inner Categories cmbBaseCategory.ItemsSource = cmbInnerCategory.ItemsSource = null; break; } }
//Fill the Inner Category ComboBox with relative values private void FillInnerCategory() { GuiChanges.FillComboWithInnerCategory(cmbInnerCat, cmbBaseCat.SelectedItem); cmbInnerCat.SelectedItem = CurrentItem.InnerCategory; if (cmbInnerCat.SelectedIndex < 0) { cmbInnerCat.SelectedIndex++; } }
//checks the validity of input from the user and enables //or disables the login button relatively private void CanLogin() { if (!Validity.StringOK(pswPassword.Password) || !Validity.StringOK(txtUserName.Text)) { GuiChanges.Disable(btnLogin); } else { GuiChanges.Enable(btnLogin); } }
//Ctor for add new Item window public AddNewItem() { InitializeComponent(); //Hide the labels and the text boxes ubtil user chooses Item Type GuiChanges.Hide(lblIssue, lblAuthor, txtIssue, txtAuthor); //Obvously understandable by function name GuiChanges.FillComboWithBaseCategory(cmbBaseCat); //Untill user choose the BaseCategory - disable inner GuiChanges.Disable(cmbInnerCat); }
//Multiple Search CheckBox Checked Event private void chkMultiSearch_Checked(object sender, RoutedEventArgs e) { //Show the search options ShowAndHideSearchFields(eShowOrHide.Show); //Cancel regular search option chkSearch.IsChecked = false; //Hide relative controls which not valid for the multiple search GuiChanges.Hide(lblAuthor, txtAuthor, lblIssue, txtIssue); //Raise the flag of multiple search IsMultiSearch = true; }
//Fine tuning the controls depending on current user Rights private void ButtonsAvailable() { //Make desision depending on current User rights - //Show and hide relative Controls switch (mainLibrary.LibraryUsers.CurrentUser.Type) { case User.eUserType.Employee: GuiChanges.Disable(btnUsers); break; case User.eUserType.Client: GuiChanges.Disable(btnDelete, btnUsers, btnEdit, btnAdd, btnBorrow, btnQuantity); break; } }
public EditUsers() { InitializeComponent(); this.WindowStartupLocation = WindowStartupLocation.CenterScreen; //Preventing the DataGrid from inplace editing dataUsers.IsReadOnly = true; //set the source for the DataGrid dataUsers.ItemsSource = MainWindow.mainLibrary.LibraryUsers.Users; //Disable buttons because no User haven't been choosen GuiChanges.Disable(btnDelete, btnEdit); }
//Update the fields from current Item public void UpdateFromItem() { //creating the arrays for easy handling the Journal controls UIElement[] issue = { lblIssue, txtIssue }; //creating the arrays for easy handling the Book controls UIElement[] author = { lblAuthor, txtAuthor }; //-------------- Updating the fields from Current Item -------------// lblISBN.Text = $"ISBN: {CurrentItem.ISBN}"; lblTypeOf.Text = CurrentItem.ItemType; chkBorrowed.IsChecked = CurrentItem.IsBorrowed; GuiChanges.FillComboWithBaseCategory(cmbBaseCat); cmbBaseCat.SelectedItem = CurrentItem.BaseCategory; txtName.Text = CurrentItem.Name; dtPick.SelectedDate = CurrentItem.PrintDate; switch (CurrentItem.ItemType) { case "Book": GuiChanges.Hide(issue); GuiChanges.Show(author); txtAuthor.Text = ((Book)CurrentItem).Author; break; case "Journal": GuiChanges.Hide(author); GuiChanges.Show(issue); txtIssue.Text = ((Journal)CurrentItem).IssueNumber.ToString(); break; } //-------------- Updating the fields from Current Item -------------// }
//init all elements depending on current working state private void InitEditItemWindow() { this.WindowStyle = WindowStyle.SingleBorderWindow; this.ResizeMode = ResizeMode.NoResize; this.WindowStartupLocation = WindowStartupLocation.CenterScreen; lblISBN.TextAlignment = TextAlignment.Center; if (!EditMode) //showing details mode { this.Title = "Item Details"; //Show check button for Telling to the user if the item is borrowed or not GuiChanges.Show(chkBorrowed); //Disable all the controls because we're in "Show Details" mode foreach (UIElement item in this.grdWindowGrid.Children) { GuiChanges.Disable(item); } //Button caption changed to "Exit" btnSaveExit.Content = "Exit"; //After all controls being disabled because of "Show Details" mode, //Enable the Exit button GuiChanges.Enable(btnSaveExit); } else //editing Item Mode { //Button caption changed to "Save Changes" btnSaveExit.Content = "Save Changes"; //Hide "Item is Borrowed" indicator CheckBox GuiChanges.Hide(chkBorrowed); } }
//Fills the Inner Category ComboBox or hides it - //depending on user input private void FillInner() { //Creating an array for easy hiding and showing //the Inner Category controls UIElement[] inner = { lblInnerCategory, cmbInnerCategory }; //If there's any choice from the User on the Base Category ComboBox if (cmbBaseCategory.SelectedItem != null) { //Then fill the Inner Category ComboBox GuiChanges.FillComboWithInnerCategory (cmbInnerCategory, cmbBaseCategory.SelectedItem); //And show the Inner ComboBox to the user GuiChanges.Show(inner); } //If there's no choice from the User on Base Category ComboBox else { //if so - hide the Inner Category ComboBox GuiChanges.Hide(inner); } }
//Hide and show related elements when user chooses the Item type private void rdChecked(object sender, RoutedEventArgs e) { var rdValue = sender as RadioButton; //Creating array of the GUI elements for easy manipulation with the Journal UIElement[] issue = { lblIssue, txtIssue }; //Creating array of the GUI elements for easy manipulation with the Book UIElement[] author = { lblAuthor, txtAuthor }; switch (rdValue.Name) { case "rdBook": CurrentItem = ItemType.Book; GuiChanges.Hide(issue); GuiChanges.Show(author); break; case "rdJournal": CurrentItem = ItemType.Journal; GuiChanges.Hide(author); GuiChanges.Show(issue); break; } }
//Fills inner category relative to base that user chooses //and enables the combo for Inner private void FillInnerCombo(object sender, SelectionChangedEventArgs e) { GuiChanges.Enable(cmbInnerCat); GuiChanges.FillComboWithInnerCategory(cmbInnerCat, cmbBaseCat.SelectedItem); cmbInnerCat.SelectedIndex = 0; }