Example #1
0
        /// <summary>
        /// This method aims to load and get some services available in ExpenseLoggerAppForm
        /// So the child forms can use the same services with its parents forms.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BaseUserControl_Load(object sender, EventArgs e)
        {
            // Access to parent form and store it to a variable which will be shared cross derived class
            ExpenseLoggerAppForm parentForm = this.Parent?.Parent as ExpenseLoggerAppForm;

            if (parentForm != null)
            {
                appQueries  = parentForm.appQueries;
                appCommands = parentForm.appCommands;
            }
            else
            {
                appQueries  = new ExpenseLoggerQueries();
                appCommands = new ExpenseLoggerCommands();
            }

            this.LoadFormData();
        }
        /// <summary>
        /// Storing user infomation in the shared class and display main form.
        /// </summary>
        /// <param name="loggedInUser"></param>
        private void OpenExpenseLoggerAppForm(User loggedInUser)
        {
            // Storing user information for later use.
            UserIdentity.Instance.UserId    = loggedInUser.Id;
            UserIdentity.Instance.FirstName = loggedInUser.FirstName;
            UserIdentity.Instance.LastName  = loggedInUser.LastName;

            List <Setting> userSettings    = appQueries.GetUserSettings(loggedInUser.Id);
            Setting        currencySetting = userSettings.FirstOrDefault(x => x.Name.Trim().ToLower() == "currency");
            string         currency        = currencySetting == null
                ? AppDefaultValues.Currencies.FirstOrDefault().Text : currencySetting.Value;

            UserIdentity.Instance.Currency = currency;
            UserIdentity.Instance.UserPreferenceCulture = CultureHelper.UserPreferenceCulture(currency);

            // Close the current form and open the main form after logged in
            this.Hide();
            ExpenseLoggerAppForm expenseLoggerAppForm = new ExpenseLoggerAppForm();

            expenseLoggerAppForm.ShowDialog();
            this.Close();
        }