//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(); }
/// <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); } }
//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); }
//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); }
//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); } }