public static ApplyItem getApplyItem(OpenPOP.MIMEParser.Message m)
 {
     if (m.Subject.Contains("在线融资申请") && m.MessageBody.Count > 0)
     {
         String body = m.MessageBody[m.MessageBody.Count - 1].ToString();
         if (m.HTML)
         {
             ApplyItem item = new ApplyItem();
             String    text = Utils.Tools.prepareHTML(body);
             string[]  sub  = text.Split(new String[] { "#" }, StringSplitOptions.RemoveEmptyEntries);
             if (sub.Length % 2 != 0 || sub.Length == 0)
             {
                 return(null);
             }
             for (int i = 0; i < sub.Length; i = i + 2)
             {
                 item.addKeyValue(sub[i], sub[i + 1]);
             }
             item.Time      = m.Date;
             item.From      = m.From;
             item.Title     = m.Subject;
             item.FromEmail = m.FromEmail;
             return(item);
         }
         else
         {
             return(null);
         }
     }
     else
     {
         return(null);
     }
 }
Beispiel #2
0
 private void backgroundWorkerGetAllMails_ProgressChanged(object sender, ProgressChangedEventArgs e)
 {
     if (e.ProgressPercentage == -1)
     {
         int count = (int)(e.UserState);
         WriteLog("返回邮件总数:" + count);
     }
     else
     {
         this.toolStripProgressBar.Visible = true;
         this.toolStripProgressBar.Value   = e.ProgressPercentage;
         this.toolStripStatusLabelMsg.Text = "正在处理," + e.ProgressPercentage + "%";
         ApplyItem item = e.UserState as ApplyItem;
         if (item != null)
         {
             WriteLog(item.ToString());
         }
     }
 }
Beispiel #3
0
        private void backgroundWorkerGetAllMails_DoWork(object sender, DoWorkEventArgs e)
        {
            Utility.Log = true;
            popClient.Disconnect();
            popClient.Connect(config.ServerAddr, int.Parse(config.Port));
            popClient.Authenticate(config.Email, config.PWD);
            int Count   = popClient.GetMessageCount();
            int percent = 0;

            backgroundWorkerGetAllMails.ReportProgress(-1, Count);
            List <ApplyItem> list = new List <ApplyItem>();

            for (int i = Count; i > 0; i--)
            {
                OpenPOP.MIMEParser.Message m = popClient.GetMessage(i, false);
                ApplyItem item = ApplyItemController.getApplyItem(m);
                percent = percent + 1;
                if (item != null)
                {
                    list.Add(item);
                }
                backgroundWorkerGetAllMails.ReportProgress((int)percent * 100 / Count, item);
            }
            for (int k = 0; k < list.Count; k++)
            {
            }
            String       path = Application.StartupPath + "\\Excel\\" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".xls";
            ExcelCreator ec   = new ExcelCreator();

            if (ec.toExcel(list, path))
            {
                e.Result = "path:" + path;
            }
            else
            {
                e.Result = "ER:生成excel失败";
            }
        }
Beispiel #4
0
 public Boolean toExcel(List <ApplyItem> list, String path)
 {
     try
     {
         xlBooks             = xlApp.Workbooks;
         xlBook              = xlBooks.Add(Missing.Value);
         xlsheets            = xlBook.Worksheets;
         xlSheet             = (Excel.Worksheet)xlsheets.get_Item(1);
         xlApp.DisplayAlerts = false;
         string[] keys = new String[] {
             "企业名称",
             "所在省份",
             "所在城市",
             "企业地址",
             "法人代表",
             "企业成立日期",
             "企业联系人",
             "联系人职务",
             "联系电话",
             "手机号码",
             "职工人员",
             "所属行业",
             "主业从业年限",
             "去年销售收入",
             "主导产品、品牌及生产能力",
             "申请融资金额",
             "申请融资产品",
             "申请融资期限",
             "申请融资原因",
             "可提供担保方式"
         };
         xlSheet.Cells[1, 1] = "申请人";
         xlSheet.Cells[1, 2] = "申请邮箱";
         xlSheet.Cells[1, 3] = "标题";
         xlSheet.Cells[1, 4] = "时间";
         int pos = 5;
         for (int i = 0; i < keys.Length; i++)
         {
             xlSheet.Cells[1, i + pos] = keys[i];
         }
         for (int i_item = 0; i_item < list.Count; i_item++)
         {
             ApplyItem item = list[i_item];
             xlSheet.Cells[i_item + 2, 1] = item.From;
             xlSheet.Cells[i_item + 2, 2] = item.FromEmail;
             xlSheet.Cells[i_item + 2, 3] = item.Title;
             xlSheet.Cells[i_item + 2, 4] = item.Time;
             for (int i_key = 0; i_key < keys.Length; i_key++)
             {
                 try
                 {
                     xlSheet.Cells[i_item + 2, i_key + pos] = item.getValue(keys[i_key]);
                 }
                 catch (Exception e)
                 {
                 }
             }
         }
         xlBook.Saved = true;
         xlBook.SaveAs(path, Missing.Value,
                       Missing.Value, Missing.Value, Missing.Value, Missing.Value,
                       Excel.XlSaveAsAccessMode.xlNoChange, Missing.Value, Missing.Value,
                       Missing.Value, Missing.Value, Missing.Value);
         xlBook.Close(false, Missing.Value, Missing.Value);
     }
     catch (Exception e)
     {
     }
     return(true);
 }