Esempio n. 1
0
        public ConnectToServer(ListBox listBoxMails, Label status, string userMail, string password, ProgressBar statusProgressBar)
        {
            // Make the provided label the status label.
            this.status = status;

            // Initialize the provided usermail and password.
            this.userMail = userMail;
            this.password = password;

            // Fetch the provided listbox.
            this.listBoxMails = listBoxMails;

            // Make the provided progressbar the status progressbar.
            this.statusProgressBar = statusProgressBar;

            // Instantiate the database.
            mailDatabase = new MailDatabase();

            try
            {
                // Initialize the connection to the server from this custom constructor.
                InitConnectionToServer();
            }
            catch (Exception e)
            {
                // Output the error to the user.
                ComponentChanges.ReplaceLabelText(status, e.Message);

                // Set the programs status to be having an error.
                MailClientForm.SetProgramStatus(MailClientForm.ProgramStatus.Error);

                // Announce through the status progressbar that we are done with trying to establish the connection.
                ComponentChanges.ReplaceProgressBarValue(statusProgressBar, 100);
            }
        }
Esempio n. 2
0
        private void PopulateListBox()
        {
            // Instantiate the database.
            mailDatabase = new MailDatabase();

            // Instantiate the date for the latest recieved mail so that it is not null.
            newestMailDateTime = new DateTime();

            // Make sure that we do not duplicate mails in the listbox.
            ComponentChanges.ClearItemFromListBox(listBoxMails);

            // Declare and initialize a variable for the amount of mails in the database.
            int dbMailCount = mailDatabase.ReadMailCount(textBoxMail.Text);

            // Count through the amount of mails that are in the database, if any.
            for (int i = 1; i <= dbMailCount; i++)
            {
                // Retrieve the messages headers from the database and put them into the listbox.
                ComponentChanges.AddItemToListBox(listBoxMails, mailDatabase.ReadMail(textBoxMail.Text, i).Headers.From.Address);
            }

            // Check if any mails was found in the database.
            if (dbMailCount > 0)
            {
                // Retrieve the datetime for the latest mail.
                newestMailDateTime = mailDatabase.ReadMail(textBoxMail.Text, dbMailCount).Headers.DateSent;
            }
            else
                // Retrieve all the mails from the server if nothing is in the database.
                connectToServer.RetrieveAllMailsFromServer(listBoxMails);
        }