Пример #1
0
 public MailWindow(Mail mail)
 {
     InitializeComponent();
     //add title & subject
     this.Title = mail.Subject;
     this.SubjectField.Content = mail.Subject;
     this.SenderField.Content = mail.Sender;
     if (mail.receivingMail != null)
     {
         this.locationField.Content = mail.receivingMail;
     }
     else
     {
         this.locationField.Content = "hmm... i dont know yet";
     }
     if (mail.receivedTime != null)
     {
         this.ReceivedTimeField.Content = mail.receivedTime;
     }
     else
     {
         this.ReceivedTimeField.Content = "dont know this either...sorry";
     }
     mailView.NavigateToString(mail.msgString);
 }
Пример #2
0
        //fetch a specific message from sql, "isMessageInDB" should be run before running this
        /// <summary>
        /// fetches specific message from the database, not used anywhere
        /// </summary>
        /// <param name="msgid">message id of the email fetch from the database</param>
        /// <param name="conn">connection to the sqlitedatabase of which to get a message from</param>
        /// <returns>returns a mail object made from the data retrieved from the database</returns>
        public Mail fetchSpecificMessage(string msgid, SQLiteConnection conn)
        {
            //variables used in this function
            DataTable t = new DataTable();
            Mail m = new Mail();

            //sql
            SQLiteCommand cmd = new SQLiteCommand("SELECT * FROM mails WHERE MessageID=@msgid", conn);
            cmd.Parameters.Add(new SQLiteParameter("@msgid", msgid));
            SQLiteDataReader reader = cmd.ExecuteReader();

            //fetch variables from sql statement and put them into a mail object
            reader.Read();
            m.Sender = reader["MessageID"].ToString();
            m.Subject = reader["Subject"].ToString();
            m.MessageId = reader["MessageID"].ToString();
            m.msgString = reader["Message"].ToString();
            m.receivingMail = reader["ReceivedMail"].ToString();
            m.Importance = reader["Importance"].ToString();
            m.receivedTime = ((DateTime)reader["ReceivedTime"]);
            //m.receivedTime = (reader["ReceivedTime"].ToString() as int);
            m.hasBeenAdded = false;
            //return results from sql
            return m;
        }
Пример #3
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();
        }