⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.cs

📁 email 发送 asp.net 2.0开发
💻 CS
📖 第 1 页 / 共 5 页
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Threading;

using System.Text;
using System.IO;
using System.Net;

using System.Net.Sockets;

namespace HBJ.MailSender
{
	/// <summary>
	/// Form1 的摘要说明。
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.TabControl tabControl1;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.StatusBar statusBar1;
		private System.Windows.Forms.StatusBarPanel status;
		private System.Windows.Forms.Button button2;
		private System.Windows.Forms.Button button3;
		private System.Windows.Forms.TabPage tb_mailContent;
		private System.Windows.Forms.TabPage tb_reseiveMail;
		private System.Windows.Forms.TabPage tb_sendMail;
		private System.Windows.Forms.LinkLabel linkLabel1;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.Label label6;
		private System.Windows.Forms.Label label7;
		private System.Windows.Forms.Label label8;
		private System.Windows.Forms.Label label9;
		private System.Windows.Forms.Label label10;
		private System.Windows.Forms.Button button4;
		private System.Windows.Forms.Button button5;
		private System.Windows.Forms.ListView sendMailList;
		private System.Windows.Forms.ColumnHeader cl_MailName;
		private System.Windows.Forms.ColumnHeader cl_IsTrue;
		private System.Windows.Forms.ColumnHeader cl_SendServer;
		private System.Windows.Forms.ColumnHeader cl_Username;
		private System.Windows.Forms.ColumnHeader cl_Password;
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.GroupBox groupBox2;
		private System.Windows.Forms.Label label11;
		private System.Windows.Forms.Label label12;
		private System.Windows.Forms.Label label13;
		private System.Windows.Forms.Label label14;
		private System.Windows.Forms.Button button6;
		private System.Windows.Forms.Button button7;
		private System.Windows.Forms.Button button8;
		private System.Windows.Forms.CheckBox ischeck;
		private System.Windows.Forms.Label label15;
		private System.Windows.Forms.Label label16;
		private System.Windows.Forms.GroupBox groupBox3;
		private System.Windows.Forms.Button button9;
		private System.Windows.Forms.Button button10;
		private System.Windows.Forms.TextBox mailHtml;
		private System.Windows.Forms.TextBox mailText;
		private System.Windows.Forms.TextBox mailTitle;
		private System.Windows.Forms.TextBox sqlServer;
		private System.Windows.Forms.TextBox sqlPassword;
		private System.Windows.Forms.TextBox databaseName;
		private System.Windows.Forms.TextBox sendedNum;
		private System.Windows.Forms.TextBox startNum;
		private System.Windows.Forms.TextBox sqlUsername;
		private System.Windows.Forms.TextBox txtFile;
		private System.Windows.Forms.CheckBox delRe;
		private System.Windows.Forms.TextBox mailName;
		private System.Windows.Forms.TextBox mailServer;
		private System.Windows.Forms.TextBox mailUsername;
		private System.Windows.Forms.TextBox mailPassword;
		private System.Windows.Forms.TextBox sendSpaceTime;
		private System.Windows.Forms.TabPage tb_Help;
		private System.Windows.Forms.Label label17;
		private System.Windows.Forms.Label label18;
		private System.Windows.Forms.OpenFileDialog openFileDialog1;
		private System.Windows.Forms.TextBox mailCount;
		private System.ComponentModel.IContainer components;

		/// <summary>
		/// 系统配置表
		/// </summary>
		private DataTable systemConfigTable = null;
		private System.Windows.Forms.Button button11;
		private System.Windows.Forms.TabPage tb_SendStatus;
		private System.Windows.Forms.GroupBox groupBox4;
		private System.Windows.Forms.GroupBox groupBox5;
		private System.Windows.Forms.GroupBox groupBox6;
		private System.Windows.Forms.ListView taskList;
		private System.Windows.Forms.ListView succList;
		private System.Windows.Forms.ListView falseList;
		private System.Windows.Forms.Button button12;
		private System.Windows.Forms.Button button13;
		private System.Windows.Forms.Button button14;
		private System.Windows.Forms.ColumnHeader columnHeader1;
		private System.Windows.Forms.ColumnHeader columnHeader2;
		private System.Windows.Forms.ColumnHeader columnHeader3;
		private System.Windows.Forms.Button button15;
		private System.Windows.Forms.Label label19;
		private System.Windows.Forms.Label label20;
		private System.Windows.Forms.Label label21;
		private System.Windows.Forms.Label label22;
		private System.Windows.Forms.Button button16;

		/// <summary>
		/// 系统配置文件路径
		/// </summary>
		private string systemConfigXml = Application.StartupPath + "\\system.config";

		/// <summary>
		/// 当前正在执行的线程名称集合
		/// </summary>
		private ArrayList threadNames = new ArrayList();

		/// <summary>
		/// 线程编号
		/// </summary>
		private int       threadId    = 0;

		/// <summary>
		/// 发送邮件列表的INDEX
		/// </summary>
		private int sendMailIndex = 0;

		/// <summary>
		/// 待发送邮件列表的INDEX
		/// </summary>
		private int taskMailIndex = 0;
		private System.Timers.Timer timer1;
		private System.Timers.Timer timer2;
		private System.Windows.Forms.SaveFileDialog saveFileDialog1;
		private System.Windows.Forms.NotifyIcon notifyIcon1;
		private System.Windows.Forms.Button button18;
		private System.Windows.Forms.Button button19;
		private System.Windows.Forms.Button button20;

		/// <summary>
		/// 逝去的秒数
		/// </summary>
		private int disappearSec = 0;

		#region 系统初始化

		public Form1()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();

			this.timer1.Stop();
			this.timer2.Stop();

			//this.ipaddress.Text = Dns.GetHostByName(Dns.GetHostName()).AddressList[0].ToString();

			Thread thread = new Thread(new ThreadStart(this.LoadSystemConfig));
			thread.IsBackground = true;
			thread.Start();
		}

		/// <summary>
		/// 从XML文档中载入系统配置
		/// </summary>
		private void LoadSystemConfig(){

			this.status.Text = "正在载入上次的数据库等配置.....";
			Thread.Sleep(500);

			if(File.Exists(this.systemConfigXml)){
				
				DataTable table = Public.ReadDataTaBleFromXML(this.systemConfigXml);
				if(table != null && table.Rows.Count == 1){

					this.systemConfigTable = table;

					//将配置内容载入到系统中
					DataRow row = this.systemConfigTable.Rows[0];
					this.sqlServer.Text = row["SqlServer"].ToString();
					this.databaseName.Text = row["SqlDatabaseName"].ToString();
					this.sqlUsername.Text  = row["SqlUsername"].ToString();
					this.sqlPassword.Text  = row["SqlPassword"].ToString();

					//检查邮件服务器是否需要身份验证
					//this.ischeck <> row["MailServerIsCheck"]

					this.sendSpaceTime.Text = row["SendSpaceTime"].ToString();

					//载入数据库配置
					button4_Click(null,null);

					//载入发送邮件和邮件广告内容
					this.LoadSendMail();

					this.LoadMailContent();

				}else{
					MessageBox.Show("载入系统配置时出错,系统已将原配置文件清除!");
					File.Delete(this.systemConfigXml);
					File.Create(this.systemConfigXml);
				}

			}else{
				File.Create(this.systemConfigXml);
			}

			this.status.Text = "等待任务.....";
		}

		/// <summary>
		/// 保存系统配置
		/// </summary>
		private void SaveSystemConfig(){

			this.status.Text = "正在保存配置.....";
			Thread.Sleep(500);
			
			//保存配置到XML文档
			if(this.systemConfigTable == null)
				this.systemConfigTable = Public.BuildSystemConfig();
				
			DataRow row = this.systemConfigTable.NewRow();
			row["SqlServer"] = this.sqlServer.Text;
			row["SqlDatabaseName"] = this.databaseName.Text;
			row["SqlUsername"]     = this.sqlUsername.Text;
			row["SqlPassword"]     = this.sqlPassword.Text;

			if(this.ischeck.Checked)
				row["MailServerIsCheck"] = "1";
			else
				row["MailServerIsCheck"] = "0";

			row["SendSpaceTime"] = this.sendSpaceTime.Text;

			this.systemConfigTable.Rows.Clear();
			this.systemConfigTable.Rows.Add(row);

			//将表保存到XML
			Public.SaveDataTableToXML(this.systemConfigTable,this.systemConfigXml);

			this.status.Text = "等待任务....";
		}

		#endregion

		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows 窗体设计器生成的代码
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.components = new System.ComponentModel.Container();
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
			this.tabControl1 = new System.Windows.Forms.TabControl();
			this.tb_mailContent = new System.Windows.Forms.TabPage();
			this.mailHtml = new System.Windows.Forms.TextBox();
			this.mailText = new System.Windows.Forms.TextBox();
			this.mailTitle = new System.Windows.Forms.TextBox();
			this.label3 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.label1 = new System.Windows.Forms.Label();
			this.tb_reseiveMail = new System.Windows.Forms.TabPage();
			this.button15 = new System.Windows.Forms.Button();
			this.button11 = new System.Windows.Forms.Button();
			this.groupBox3 = new System.Windows.Forms.GroupBox();
			this.delRe = new System.Windows.Forms.CheckBox();
			this.button10 = new System.Windows.Forms.Button();
			this.button9 = new System.Windows.Forms.Button();
			this.txtFile = new System.Windows.Forms.TextBox();
			this.startNum = new System.Windows.Forms.TextBox();
			this.button5 = new System.Windows.Forms.Button();
			this.button4 = new System.Windows.Forms.Button();
			this.sendedNum = new System.Windows.Forms.TextBox();
			this.mailCount = new System.Windows.Forms.TextBox();
			this.databaseName = new System.Windows.Forms.TextBox();
			this.sqlPassword = new System.Windows.Forms.TextBox();
			this.sqlUsername = new System.Windows.Forms.TextBox();
			this.sqlServer = new System.Windows.Forms.TextBox();
			this.label10 = new System.Windows.Forms.Label();
			this.label9 = new System.Windows.Forms.Label();
			this.label8 = new System.Windows.Forms.Label();
			this.label7 = new System.Windows.Forms.Label();
			this.label6 = new System.Windows.Forms.Label();
			this.label5 = new System.Windows.Forms.Label();
			this.label4 = new System.Windows.Forms.Label();
			this.tb_SendStatus = new System.Windows.Forms.TabPage();
			this.button20 = new System.Windows.Forms.Button();
			this.button19 = new System.Windows.Forms.Button();
			this.button18 = new System.Windows.Forms.Button();
			this.button16 = new System.Windows.Forms.Button();
			this.button14 = new System.Windows.Forms.Button();
			this.button13 = new System.Windows.Forms.Button();
			this.button12 = new System.Windows.Forms.Button();
			this.groupBox6 = new System.Windows.Forms.GroupBox();
			this.falseList = new System.Windows.Forms.ListView();
			this.columnHeader3 = new System.Windows.Forms.ColumnHeader();
			this.groupBox5 = new System.Windows.Forms.GroupBox();
			this.succList = new System.Windows.Forms.ListView();
			this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
			this.groupBox4 = new System.Windows.Forms.GroupBox();
			this.taskList = new System.Windows.Forms.ListView();
			this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
			this.tb_Help = new System.Windows.Forms.TabPage();
			this.label21 = new System.Windows.Forms.Label();
			this.label22 = new System.Windows.Forms.Label();
			this.label20 = new System.Windows.Forms.Label();
			this.label19 = new System.Windows.Forms.Label();
			this.label18 = new System.Windows.Forms.Label();
			this.label17 = new System.Windows.Forms.Label();
			this.tb_sendMail = new System.Windows.Forms.TabPage();
			this.groupBox2 = new System.Windows.Forms.GroupBox();
			this.button8 = new System.Windows.Forms.Button();
			this.button7 = new System.Windows.Forms.Button();
			this.mailPassword = new System.Windows.Forms.TextBox();
			this.mailUsername = new System.Windows.Forms.TextBox();
			this.mailServer = new System.Windows.Forms.TextBox();
			this.mailName = new System.Windows.Forms.TextBox();
			this.label14 = new System.Windows.Forms.Label();
			this.label13 = new System.Windows.Forms.Label();
			this.label12 = new System.Windows.Forms.Label();
			this.label11 = new System.Windows.Forms.Label();
			this.button6 = new System.Windows.Forms.Button();
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.label16 = new System.Windows.Forms.Label();
			this.sendSpaceTime = new System.Windows.Forms.TextBox();
			this.label15 = new System.Windows.Forms.Label();
			this.ischeck = new System.Windows.Forms.CheckBox();
			this.sendMailList = new System.Windows.Forms.ListView();
			this.cl_MailName = new System.Windows.Forms.ColumnHeader();
			this.cl_IsTrue = new System.Windows.Forms.ColumnHeader();
			this.cl_SendServer = new System.Windows.Forms.ColumnHeader();
			this.cl_Username = new System.Windows.Forms.ColumnHeader();
			this.cl_Password = new System.Windows.Forms.ColumnHeader();
			this.button1 = new System.Windows.Forms.Button();
			this.statusBar1 = new System.Windows.Forms.StatusBar();
			this.status = new System.Windows.Forms.StatusBarPanel();
			this.button2 = new System.Windows.Forms.Button();
			this.button3 = new System.Windows.Forms.Button();
			this.linkLabel1 = new System.Windows.Forms.LinkLabel();
			this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
			this.timer1 = new System.Timers.Timer();
			this.timer2 = new System.Timers.Timer();
			this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();
			this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);
			this.tabControl1.SuspendLayout();
			this.tb_mailContent.SuspendLayout();
			this.tb_reseiveMail.SuspendLayout();
			this.groupBox3.SuspendLayout();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -