private void btnLogin_Click(object sender, EventArgs e) { try { //Tries to deserialize the data saved in the debug folder. The char 'i' stands for itemmanager and lets the DeserializeData method know that it is supposed // to deserialize the "itemInfo.ser" file to get the item list information that has been saved to the itemManager variable. itemManager = StaticSerialize<ItemManager>.DeserializeData('i'); } catch(Exception) { // If the try block fails to deserialize the data it means that there is no data to be deserialized in the "itemInfo.ser" file and thus creates a new ItemManager object // and assigns it to the itemManager refrence. itemManager = new ItemManager(); } finally { itemManager.SetStartingFilter(); } try { //Tries to create the store form based on the return value of the Login methood. Login method takes the parameters username and password and tries to find a match // then returns the matching user which is sent to the Store form along with the shared resource of userManager and itemManager. storeForm = new StoreForm(userManager.Login(txtUserName.Text, txtPassword.Text), userManager, itemManager); this.Hide(); //When the store form is closed the application serialize the userManager and the itemManager to save all the changes that has been done. storeForm.FormClosed += storeForm_FormClosed; storeForm.Show(); } catch(Exception) { MessageBox.Show("Login Failed"); } }
public StoreForm(User currentUser,UserManager usermanager, ItemManager itemmanager) { _currentUser = currentUser; //Assigns the current user. InitializeComponent(); _itemManager = itemmanager; //Assigns the itemmanager. _userManager = usermanager; // Assings the usermanager. UpdateGUI(_currentUser); //Updates the GUI with user information. }
public AddItemForm(ItemManager itemManager) { InitializeComponent(); _itemManager = itemManager; // Sets the itemManager. }