• 大小: 82KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-04-29
  • 语言: 其他
  • 标签: C#  生成Excel  

资源简介

1.定时自动生成excel文件, 2.定时发送邮件

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Threading;
using System.Data;
using System.IO;

namespace AutoSendMail
{
    public class doMain
    {
        private bool isSeneMail = ConfigurationManager.AppSettings[“isSendMail“] == “true“ ? true : false;
        private bool isSendMailWhenStartProgram = ConfigurationManager.AppSettings[“isSendMailWhenStartProgram“] == “true“ ? true : false;
        private string fileSavedPath = ConfigurationManager.AppSettings[“fileSavedPath“];
        private int doDay = Convert.ToInt32(ConfigurationManager.AppSettings[“doDay“]);
        public string threadName;
        int times = 0;

        /// 
        /// 启动
        /// 

        public void Run()
        {
            DateTime _dateTime = System.DateTime.Now.Date;
            double temp = 5;
            try
            {
                temp = Convert.ToDouble(ConfigurationManager.AppSettings[“doTime“]);//执行时间点
                if (temp < 0)
                    temp = Math.Abs(temp);
                temp = temp % 24;
            }
            catch
            {
            }
            _dateTime = _dateTime.AddHours(temp);//将初次执行时间定位到当天中指定的时间
            TimeSpan ts_day = _dateTime - DateTime.Now;//比较执行时间和当前时间
            if (ts_day.TotalSeconds < -2 * 60 * 60)//当前时间大时,第doDay天执行
            {
                _dateTime = _dateTime.AddDays(doDay);
            }
            Console.WriteLine(string.Format(“线程已启动,本次执行时间应在{0}“ _dateTime));

            while (true)
            {
                //记录监控的记录
                string filepath = AppDomain.CurrentDomain.SetupInformation.Applicationbase;

                //比较时间
                TimeSpan ts = DateTime.Now - _dateTime;
                string logStr;
                string errMsg = string.Empty;
                bool result = false;

                if (Math.Abs(ts.TotalMinutes) <= 10 || (times == 0 && isSendMailWhenStartProgram))
                {
                    times++;
                    StringBuilder sb_log = new StringBuilder(““);
                    try
                    {
                        logStr = string.Format(“开始执行:自动发送邮件---{0}“ DateTime.Now);
                        sb_log.AppendLine(logStr);
                        Console.WriteLine(logStr);

                        string filePath = ConfigurationManager.AppSettings[“logPath“];
                        if (filePath.Contains(“~/“))
                            filePath = filePath.Replace(“~/“ filepath);

                        //logStr = string.Format(“   开始保存excel文件---{0}“ DateTime.Now.ToString(“yyyy-MM-dd HH:mm:ss“));
                        //sb_log.AppendLine(logStr);
                        //Console.WriteLine(logStr);

                        //数据处理
                        //1.执行保存excel文件
                        #region
                        /*

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       1097  2013-07-04 17:46  AutoSendMail\AutoSendMail\App.config

     文件       3944  2013-07-01 10:28  AutoSendMail\AutoSendMail\AutoSendMail.csproj

     文件      19456  2013-07-04 18:10  AutoSendMail\AutoSendMail\bin\Debug\AutoSendMail.exe

     文件       1097  2013-07-04 17:46  AutoSendMail\AutoSendMail\bin\Debug\AutoSendMail.exe.config

     文件      34304  2013-07-04 18:10  AutoSendMail\AutoSendMail\bin\Debug\AutoSendMail.pdb

     文件      11608  2013-08-05 09:59  AutoSendMail\AutoSendMail\bin\Debug\AutoSendMail.vshost.exe

     文件       1097  2013-07-04 17:46  AutoSendMail\AutoSendMail\bin\Debug\AutoSendMail.vshost.exe.config

     文件        490  2010-03-17 22:39  AutoSendMail\AutoSendMail\bin\Debug\AutoSendMail.vshost.exe.manifest

     文件       7691  2013-06-29 17:17  AutoSendMail\AutoSendMail\bin\Debug\run.log

     文件      24542  2013-06-29 17:17  AutoSendMail\AutoSendMail\bin\Debug.rar

     文件      12062  2013-07-04 18:10  AutoSendMail\AutoSendMail\doMain.cs

     文件       3402  2013-07-04 18:08  AutoSendMail\AutoSendMail\ExlHandler\ExlClass.cs

     文件       9247  2013-06-29 10:23  AutoSendMail\AutoSendMail\LogHandler\Logger.cs

     文件       3474  2013-06-29 10:24  AutoSendMail\AutoSendMail\MailHandler\SendMail.cs

     文件       1161  2013-08-05 10:00  AutoSendMail\AutoSendMail\obj\x86\Debug\AutoSendMail.csproj.FileListAbsolute.txt

     文件        874  2013-07-04 18:10  AutoSendMail\AutoSendMail\obj\x86\Debug\AutoSendMail.csproj.ResolveComReference.cache

     文件      19456  2013-07-04 18:10  AutoSendMail\AutoSendMail\obj\x86\Debug\AutoSendMail.exe

     文件      34304  2013-07-04 18:10  AutoSendMail\AutoSendMail\obj\x86\Debug\AutoSendMail.pdb

     文件       6177  2013-07-04 18:10  AutoSendMail\AutoSendMail\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件        725  2013-06-29 15:15  AutoSendMail\AutoSendMail\Program.cs

     文件       1356  2013-06-29 10:20  AutoSendMail\AutoSendMail\Properties\AssemblyInfo.cs

     文件       2005  2013-06-29 10:26  AutoSendMail\AutoSendMail\SqlHelper\MssqlDataAccess.cs

     文件        878  2013-06-29 10:20  AutoSendMail\AutoSendMail.sln

    ..A..H.     26112  2013-08-05 11:19  AutoSendMail\AutoSendMail.suo

     目录          0  2013-06-29 10:20  AutoSendMail\AutoSendMail\obj\x86\Debug\TempPE

     目录          0  2014-04-13 21:45  AutoSendMail\AutoSendMail\obj\x86\Debug

     目录          0  2014-04-13 21:45  AutoSendMail\AutoSendMail\bin\Debug

     目录          0  2013-06-29 11:02  AutoSendMail\AutoSendMail\bin\Release

     目录          0  2014-04-13 21:45  AutoSendMail\AutoSendMail\obj\x86

     目录          0  2014-04-13 21:45  AutoSendMail\AutoSendMail\bin

............此处省略11个文件信息

评论

共有 条评论