📄 form1.cs
字号:
//
this.cl_MailName.Text = "邮址";
this.cl_MailName.Width = 144;
//
// cl_IsTrue
//
this.cl_IsTrue.Text = "可用?";
this.cl_IsTrue.Width = 50;
//
// cl_SendServer
//
this.cl_SendServer.Text = "邮件服务器";
this.cl_SendServer.Width = 107;
//
// cl_Username
//
this.cl_Username.Text = "用户名";
this.cl_Username.Width = 94;
//
// cl_Password
//
this.cl_Password.Text = "密码";
this.cl_Password.Width = 71;
//
// button1
//
this.button1.Location = new System.Drawing.Point(280, 304);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(80, 23);
this.button1.TabIndex = 1;
this.button1.Text = "开始发送";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// statusBar1
//
this.statusBar1.Location = new System.Drawing.Point(0, 335);
this.statusBar1.Name = "statusBar1";
this.statusBar1.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] {
this.status});
this.statusBar1.ShowPanels = true;
this.statusBar1.Size = new System.Drawing.Size(512, 22);
this.statusBar1.SizingGrip = false;
this.statusBar1.TabIndex = 2;
this.statusBar1.Text = "statusBar1";
//
// status
//
this.status.AutoSize = System.Windows.Forms.StatusBarPanelAutoSize.Spring;
this.status.Text = "等待任务....";
this.status.Width = 512;
//
// button2
//
this.button2.Enabled = false;
this.button2.Location = new System.Drawing.Point(360, 304);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(72, 23);
this.button2.TabIndex = 3;
this.button2.Text = "暂停发送";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button3
//
this.button3.Location = new System.Drawing.Point(432, 304);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(72, 23);
this.button3.TabIndex = 4;
this.button3.Text = "关闭窗口";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// linkLabel1
//
this.linkLabel1.Location = new System.Drawing.Point(8, 312);
this.linkLabel1.Name = "linkLabel1";
this.linkLabel1.Size = new System.Drawing.Size(208, 16);
this.linkLabel1.TabIndex = 5;
this.linkLabel1.TabStop = true;
this.linkLabel1.Tag = "如有问题,请发邮件至:hanbaojun@hotmail.com";
this.linkLabel1.Text = "Created by HBJ.TestSoft@Gmail.com";
this.linkLabel1.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel1_LinkClicked);
//
// openFileDialog1
//
this.openFileDialog1.DefaultExt = "txt";
this.openFileDialog1.Filter = "Txt文档|*.txt";
//
// timer1
//
this.timer1.Enabled = true;
this.timer1.SynchronizingObject = this;
this.timer1.Elapsed += new System.Timers.ElapsedEventHandler(this.timer1_Elapsed);
//
// timer2
//
this.timer2.Enabled = true;
this.timer2.Interval = 1000;
this.timer2.SynchronizingObject = this;
this.timer2.Elapsed += new System.Timers.ElapsedEventHandler(this.timer2_Elapsed);
//
// saveFileDialog1
//
this.saveFileDialog1.DefaultExt = "Txt文本文件|*.txt";
//
// notifyIcon1
//
this.notifyIcon1.Icon = ((System.Drawing.Icon)(resources.GetObject("notifyIcon1.Icon")));
this.notifyIcon1.Text = "邮件广告发送程序(实时 & SQL版)";
this.notifyIcon1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.notifyIcon1_MouseDown);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(512, 357);
this.Controls.Add(this.linkLabel1);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.statusBar1);
this.Controls.Add(this.button1);
this.Controls.Add(this.tabControl1);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "邮件广告发送程序(实时 & SQL版)";
this.Closing += new System.ComponentModel.CancelEventHandler(this.Form1_Closing);
this.SizeChanged += new System.EventHandler(this.Form1_SizeChanged);
this.MinimumSizeChanged += new System.EventHandler(this.Form1_MinimumSizeChanged);
this.tabControl1.ResumeLayout(false);
this.tb_mailContent.ResumeLayout(false);
this.tb_reseiveMail.ResumeLayout(false);
this.groupBox3.ResumeLayout(false);
this.tb_SendStatus.ResumeLayout(false);
this.groupBox6.ResumeLayout(false);
this.groupBox5.ResumeLayout(false);
this.groupBox4.ResumeLayout(false);
this.tb_Help.ResumeLayout(false);
this.tb_sendMail.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
this.groupBox1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.status)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.timer1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.timer2)).EndInit();
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
/// <summary>
/// 打开网页
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void linkLabel1_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e) {
//
}
#region 关闭窗口
/// <summary>
/// 确认是否关闭窗口
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e) {
if(MessageBox.Show("关闭窗口可以会丢失数据,确定关闭吗?","退出确认",MessageBoxButtons.OKCancel,MessageBoxIcon.Question) != DialogResult.OK){
e.Cancel = true;
}
}
/// <summary>
/// 确认关闭窗口
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button3_Click(object sender, System.EventArgs e) {
if(MessageBox.Show("关闭窗口可以会丢失数据,确定关闭吗?","退出确认",MessageBoxButtons.OKCancel,MessageBoxIcon.Question) == DialogResult.OK){
Application.Exit();
}
}
#endregion
#region 发送邮件
/// <summary>
/// 发送
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, System.EventArgs e) {
this.tabControl1.SelectedTab = this.tb_SendStatus;
//检查任务列表
if(this.taskList.Items.Count == 0){
MessageBox.Show("没有待发送的邮件地址!");
this.taskList.Focus();
return;
}
this.taskMailIndex = 0;
this.sendMailIndex = 0;
this.timer1.Interval = (Int32.Parse(this.sendSpaceTime.Text) * 1000);
Thread thread = new Thread(new ThreadStart(this.SendMail));
thread.IsBackground = true;
thread.Start();
this.button1.Enabled = false;
this.button2.Enabled = true;
}
private void SendMail(){
string _subject = this.mailTitle.Text;
string _body = this.mailHtml.Text;
string _SendName = this.mailText.Text;
string _ToMail = this.taskList.Items[this.taskMailIndex].SubItems[0].Text;
string _SendMail = this.sendMailList.Items[sendMailIndex].SubItems[0].Text;
try{
this.SetStatus("正在从 "+ _SendMail +" 发送到 "+ _ToMail +" ....");
Public.SendMailByJmail(_SendMail,_SendName,_ToMail,_ToMail,_subject,_body,this.sendMailList.Items[sendMailIndex].SubItems[2].Text,this.sendMailList.Items[sendMailIndex].SubItems[3].Text,this.sendMailList.Items[sendMailIndex].SubItems[4].Text);
//更新成功列表
this.succList.Items.Add(new ListViewItem(new string[]{_ToMail}));
this.groupBox5.Text = "发送成功("+ this.succList.Items.Count.ToString() +")";
}catch(Exception ex){
//this.status.Text = ex.Message.ToString();
//MessageBox.Show(ex.Message.ToString());
//Thread.Sleep(1000);
//更新失败列表
this.falseList.Items.Add(new ListViewItem(new string[]{_ToMail}));
this.groupBox6.Text = "发送失败("+ this.falseList.Items.Count.ToString() +")";
}
//发送邮件的列表行数递增或置0
if(sendMailIndex >= this.sendMailList.Items.Count -1){
sendMailIndex = 0;
}else{
sendMailIndex ++;
}
//删除已处理过的
this.taskList.Items.Remove(this.taskList.Items[this.taskMailIndex]);
this.groupBox4.Text = "等待发送("+ this.taskList.Items.Count.ToString() +")";
if(this.taskList.Items.Count > 0){
//任务列表行数递增一
//this.taskMailIndex ++;
this.disappearSec = 1;
this.timer2.Start();
//开始下一个等待
this.timer1.Start();
}else{
this.status.Text = "完成....";
Thread.Sleep(50000);
this.status.Text = "等待任务....";
}
//灭掉执行到此的当前线程
Thread.CurrentThread.Abort();
}
/// <summary>
/// 暂停发送
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button2_Click(object sender, System.EventArgs e) {
this.button1.Enabled = true;
this.button2.Enabled = false;
this.timer1.Stop();
this.timer2.Stop();
this.SetStatus("任务已被停止....");
}
/// <summary>
/// 等待时间后触发邮件发送
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e) {
this.timer2.Stop();
this.timer1.Stop();
Thread thread = new Thread(new ThreadStart(this.SendMail));
thread.IsBackground = true;
thread.Start();
}
#endregion
#region 接收邮址
/// <summary>
/// 登录数据库,获取总邮件数和已发送邮件数据
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button4_Click(object sender, System.EventArgs e) {
try{
this.status.Text = "正在连接数据库....";
Thread.Sleep(100);
Database.connStr = "Data Source="+ this.sqlServer.Text +";Initial Catalog="+ this.databaseName.Text +";User Id="+ this.sqlUsername.Text +";Password="+ this.sqlPassword.Text +";";
Database.conn = new System.Data.SqlClient.SqlConnection(Database.connStr);
this.button4.Enabled = false;
this.sqlServer.Enabled = false;
this.databaseName.Enabled = false;
this.sqlUsername.Enabled = false;
this.sqlPassword.Enabled = false;
this.LoadNums();
//保存系统配置
this.SaveSystemConfig();
//可以连接另外的数据库
this.button11.Visible = true;
}catch(Exception ex){
Database.connStr = "";
Database.conn = null;
Public.taskDS = null;
MessageBox.Show(ex.Message.ToString());
this.button4.Enabled = true;
this.sqlServer.Enabled = true;
this.databaseName.Enabled = true;
this.sqlUsername.Enabled = true;
this.sqlPassword.Enabled = true;
this.status.Text = "等待任务....";
}
}
/// <summary>
/// 载入数据
/// </summary>
private void LoadNums(){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -