Ejemplo n.º 1
0
        public MainWindow()
        {
            InitializeComponent();

            //make a background worker that updates sql database
            // using a background worker here instead of a thread because it supports a "completed" event
            BackgroundWorker SQLWorker = new BackgroundWorker();
            SQLHandler SQLHandlerObject = new SQLHandler();
            SQLWorker.DoWork += SQLHandlerObject.fetchMailsAndAddToDB;
            SQLWorker.RunWorkerCompleted += insertMailstoMailsList;
            SQLWorker.RunWorkerAsync();

            //user settings
            Properties.Settings.Default.userSettingEmail = "*****@*****.**";//set email
            Properties.Settings.Default.userSettingPassword = "******";//set password
            Properties.Settings.Default.Save();//save settings

            //insert mails that allready is in the db to the maillist
            insertMailstoMailsList();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// inserts new mails into the mails List and calls addNewMailsToMailView()
        /// </summary>
        private void insertMailstoMailsList(Object sender = null, RunWorkerCompletedEventArgs e = null)
        {
            //fetch mails from database (SQLThread is not expected to be done yet)
            SQLHandler sqlFetcher = new SQLHandler();
            DataTable newMails = sqlFetcher.fetchMailsFromDB();

            //insert newly received mails to the mails list
            foreach (DataRow mailRow in newMails.Rows)
            {
                bool alreadyExists = mails.Any(mail => mail.MessageId == mailRow["MessageID"].ToString());
                if (!alreadyExists)
                {
                    DateTime d = new DateTime();
                    if ((DateTime.TryParse(mailRow["ReceivedTime"].ToString(), out d)))
                    {
                        Mail mailToAdd = new Mail
                        {
                            Sender = mailRow["Sender"].ToString(),
                            Subject = mailRow["Subject"].ToString(),
                            MessageId = mailRow["MessageID"].ToString(),
                            msgString = mailRow["Message"].ToString(),
                            receivedTime = d,
                            receivingMail = mailRow["ReceivedMail"].ToString(),
                            Importance = mailRow["Importance"].ToString(),
                            hasBeenAdded = false
                        };
                        mails.Add(mailToAdd);
                    }
                }
            }
            //and insert to mailOverview list
            addNewMailsToMailView();
        }