Example #1
0
 private void ReadDataFormMdb(String fileName)
 {
     DataSet ds = DAO.FetchMailContext(fileName);
     if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
     {
         origDataTable = ds.Tables[0];
         this.toolStripStatusLabel.Text = "读取原始邮件成功。";
         this.runToolBtn.Enabled = true;
         this.runToolStripMenuItem.Enabled = true;
         origForm = new OrigForm();
         origForm.MdiParent = this;
         origForm.FormClosed += new FormClosedEventHandler(origForm_FormClosed);
         origForm.setDataGrigViewContext(ds);
         origForm.Show();
     }
     else
     {
         MessageBox.Show("读取数据库出错,请检查数据库是否包含Email表或者表记录不为空。");
     }
 }
Example #2
0
        void fsForm_SelectFinishedEvent(object sender, MyEventArgs e)
        {
            fsForm.SelectFinishedEvent -= new SelectFinishedEventHandler(fsForm_SelectFinishedEvent);
            List<string> entries = (List<string>)e.Value;
            Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.ApplicationClass();
            Microsoft.Office.Interop.Outlook.NameSpace NS = app.GetNamespace("MAPI");
            Microsoft.Office.Interop.Outlook.MAPIFolder objFolder;
            Microsoft.Office.Interop.Outlook.MailItem objMail;

            DataTable table = new DataTable();
            table.Columns.Add("subject", typeof(string));
            table.Columns.Add("body", typeof(string));
            table.Columns.Add("sentOn", typeof(string));
            try
            {
                foreach (string entryID in entries)
                {
                    objFolder = NS.GetFolderFromID(entryID);
                    for (int i = 1; i <= objFolder.Items.Count; i++)
                    {
                        try
                        {
                            objMail = (Microsoft.Office.Interop.Outlook.MailItem)objFolder.Items[i];
                            DataRow dr = table.NewRow();
                            if (!string.IsNullOrEmpty(objMail.Subject) && !string.IsNullOrEmpty(objMail.HTMLBody))
                            {

                                dr["subject"] = objMail.Subject;
                                dr["body"] = objMail.HTMLBody;
                                dr["sentOn"] = objMail.SentOn.ToString("yyyy-MM-dd HH:mm");
                                table.Rows.Add(dr);
                            }
                        }
                        catch (System.InvalidCastException ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                    }
                }
            }
            catch (COMException ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                NS.Logoff();
                objFolder = null;
                objMail = null;
                app = null;
            }

            origDataTable = table;
            this.toolStripStatusLabel.Text = "从Outlook 2007读取原始邮件成功。";
            this.runToolBtn.Enabled = true;
            this.runToolStripMenuItem.Enabled = true;
            this.fsForm.Close();
            this.fsForm.Dispose();
            this.fsForm = null;
            DataSet ds = new DataSet();
            ds.Tables.Add(origDataTable);
            if (origForm == null)
            {
                origForm = new OrigForm();
                origForm.MdiParent = this;
                origForm.WindowState = FormWindowState.Maximized;
                origForm.FormClosed += new FormClosedEventHandler(origForm_FormClosed);
                origForm.setDataGrigViewContext(ds);
                origForm.Show();
            }
            else
            {
                origForm.setDataGrigViewContext(ds);
                origForm.Activate();
                origForm.WindowState = FormWindowState.Maximized;
                origForm.Focus();
            }
        }