using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.IO;using LumiSoft.Net;using LumiSoft.Net.Log;using LumiSoft.Net.Mime;using LumiSoft.Net.MIME;using LumiSoft.Net.Mail;using LumiSoft.Net.POP3.Client;using System.Text.RegularExpressions;using System.Data.SqlClient;using System.Data.OleDb;using System.Diagnostics;namespace 系统升级器{ public partial class Form1 : Form { public string company, s_server, username, password, s_database; public string conn_str; public Form1() { InitializeComponent(); m_pTabMail_Messages.View = View.Details; m_pTabMail_Messages.HideSelection = false; m_pTabMail_Messages.FullRowSelect = true; m_pTabMail_Messages.Columns.Add("发件人", 50); m_pTabMail_Messages.Columns.Add("标题", 200); m_pTabMail_Messages.Columns.Add("收件时间", 120); m_pTabMail_Messages.Columns.Add("邮件大小", 100); m_pTabMail_Messages.Columns.Add("排序码", 100); m_pTabMail_Messages.Columns.Add("处理时间", 150); m_pTabMail_Attachments.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top; m_pTabMail_Attachments.View = View.SmallIcon; } public void getini() { try { string[] strs = File.ReadAllLines(@"888.ini", Encoding.Default); foreach (string ss in strs) { //me_1.Text = me_1.Text ss.ToString(); if (ss.IndexOf("company=") >= 0) { t_1.Text = ss.Substring(8); } if (ss.IndexOf("server=") >= 0) { t_2.Text = ss.Substring(7); } if (ss.IndexOf("mail=") >= 0) { t_3.Text = ss.Substring(5).Trim(); } if (ss.IndexOf("pop=") >= 0) { t_5.Text = ss.Substring(4).Trim(); } else { t_5.Text ="pop.126.com"; } if (ss.IndexOf("mail_password=") >= 0) { t_4.Text = ss.Substring(5).Trim(); } else { t_4.Text = "test123456"; } } } catch (Exception x) { MessageBox.Show(x.Message); } string ls_company; ls_company = t_1.Text.Trim(); password = t_4.Text.Trim(); switch (ls_company) { case "TEST": username = "ttt123456"; s_database = "ttt"; break;default: if (t_3.Text.Trim() != "") { username = t_3.Text.Trim(); s_database = ls_company; } if (t_4.Text.Trim() != "") { password = t_4.Text.Trim(); } break; } t_3.Text = username; } private void Form1_Load(object sender, EventArgs e) { getini(); } public void GetEmails() { string ls_company; DateTime rev_time; ls_company = t_1.Text.Trim(); password = t_4.Text.Trim(); switch (ls_company) { case "TEST": username = "ttt123456"; s_database = "ttt"; break; default: if (t_3.Text.Trim() != "") { username = t_3.Text.Trim(); s_database = ls_company; } break; } //需要首先设置这些信息 string pop3Server; string ls_time; int pop3Port; bool pop3UseSsl; string ls_from, ls_subject, ls_receive_time, ls_dealtime; List<string> gotEmailIds; List<Mime> result = new List<Mime>(); POP3_Client pop3 = new POP3_Client(); pop3Server = t_5.Text.Trim(); pop3Port = 110; pop3UseSsl = false; s_server = t_2.Text.Trim(); if (s_server == "") { s_server = "."; } //与Pop3服务器建立连接 try { pop3.Connect(pop3Server, pop3Port, pop3UseSsl); } catch (Exception ex) { MessageBox.Show(ex.Message, "邮件服务器连接失败"); return; } //验证身份 try { pop3.Authenticate(username, password, false); } catch (Exception ex) { MessageBox.Show(ex.Message, "用户名/密码错误"); return; } //pop3.Login(username, password); try { //获取邮件信息列表 POP3_ClientMessageCollection infos = pop3.Messages; foreach (POP3_ClientMessage message in infos) { Mail_Message mime = Mail_Message.ParseFromByte(message.HeaderToByte()); ListViewItem item = new ListViewItem(); if (mime.From != null) { item.Text = mime.From.ToString(); ls_from = mime.From.ToString().Trim(); } else { item.Text = "<none>"; ls_from = "<none>"; } if (string.IsNullOrEmpty(mime.Subject)) { item.SubItems.Add("<none>"); ls_subject = "<none>"; } else { item.SubItems.Add(mime.Subject); ls_subject = mime.Subject.Trim(); } item.SubItems.Add(mime.Date.ToString()); rev_time = mime.Date; ls_time = rev_time.ToString("yyyy-MM-dd HH:mm:ss"); item.SubItems.Add(((decimal)(message.Size / (decimal)1000)).ToString("f2") " kb"); item.SubItems.Add(rev_time.Ticks.ToString()); ls_company = t_1.Text.Trim(); switch (ls_company) { case "HNZS": conn_str = string.Format(@"User ID=sa;Data Source={0};Password=780223;Initial Catalog={1};", s_server, s_database); break; default: conn_str = string.Format(@"User ID=sa;Data Source={0};Password=hnzw318OK!;Initial Catalog={1};", s_server, s_database); break; } //是否已经处理过 string sql = string.Format(@" IF NOT EXISTS (SELECT * FROM syscolumns WHERE id = object_id('MsgMailInfo') AND name = 't_addtime') ALTER TABLE [MsgMailInfo] ADD [t_addtime] DATETIME DEFAULT getdate() NULL; "); SqlHelper.ExecuteNonQuery(conn_str, CommandType.Text, sql, new SqlParameter("@prodid", 24)); sql = string.Format(@" IF NOT EXISTS (SELECT * FROM syscolumns WHERE id = object_id('MsgMailInfo') AND name = 't_revtime') ALTER TABLE [MsgMailInfo] ADD [t_revtime] DATETIME NULL; "); SqlHelper.ExecuteNonQuery(conn_str, CommandType.Text, sql, null); sql = string.Format(@" update msgmailinfo set t_revtime= case when charindex('上午',msg_date)>0 then convert(datetime,replace(msg_date,'上午','') ) when charindex('下午',msg_date)>0 then dateadd(hh,12,convert(datetime,replace(msg_date,'下午',''))) else convert(datetime,msg_date) end from msgmailinfo where msg_date is not null "); SqlHelper.ExecuteNonQuery(conn_str, CommandType.Text, sql, null); sql = string.Format(@" select t_addtime from MsgMailInfo where Msg_Subject='{0}' and t_revtime='{1}' ", ls_subject, ls_time); SqlDataReader dr; dr = SqlHelper.ExecuteReader(conn_str, CommandType.Text, sql, null); if (dr.Read()) { item.SubItems.Add(dr[0].ToString()); } else { item.SubItems.Add("未知"); } item.Tag = message; ls_subject = ls_subject.ToLower(); if (!(ls_subject.IndexOf("check_order") < 0 && ls_subject.IndexOf("notice") < 0 && ls_subject.IndexOf("sellprize") < 0 && ls_subject.IndexOf("backprize") < 0 && ls_subject.IndexOf("priceprize") < 0 && ls_subject.IndexOf("lowprize") < 0 && ls_subject.IndexOf("fun") < 0 && ls_subject.IndexOf("prise") < 0 && ls_subject.IndexOf("app") < 0 && ls_subject.IndexOf("营销提奖系统") < 0 && ls_subject.IndexOf("tjxt") < 0 && ls_subject.IndexOf("update") < 0 && ls_subject.IndexOf("comm") < 0)) { m_pTabMail_Messages.Items.Add(item); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "错误"); return; } //m_pTabMail_Messages.Sorting = SortOrder.None; m_pTabMail_Messages.ListViewItemSorter = new ListViewItemComparer(4); m_pTabMail_Messages.Sort(); } private void button1_Click(object sender, EventArgs e) { button1.Enabled=false; button2.Enabled = false; button3.Enabled = false; m_pTabMail_Messages.Clear(); m_pTabMail_Messages.Columns.Add("发件人", 50); m_pTabMail_Messages.Columns.Add("标题", 200); m_pTabMail_Messages.Columns.Add("收件时间", 120); m_pTabMail_Messages.Columns.Add("邮件大小", 100); m_pTabMail_Messages.Columns.Add("排序码", 100); m_pTabMail_Messages.Columns.Add("处理时间", 150); GetEmails(); button1.Enabled = true; button2.Enabled = true; button3.Enabled = true; } private void m_pTabMail_Messages_SelectedIndexChanged(object sender, EventArgs e) { if (m_pTabMail_Messages.SelectedItems.Count > 0) { m_pTabMail_Attachments.Items.Clear(); m_pTabMail_BodyText.Text = ""; POP3_ClientMessage message = (POP3_ClientMessage)m_pTabMail_Messages.SelectedItems[0].Tag; Mail_Message mime = Mail_Message.ParseFromByte(message.MessageToByte()); foreach (MIME_Entity entity in mime.Attachments) { ListViewItem item = new ListViewItem(); if (entity.ContentDisposition != null && entity.ContentDisposition.Param_FileName != null) { item.Text = entity.ContentDisposition.Param_FileName; } else { item.Text = "untitled"; } item.Tag = entity; m_pTabMail_Attachments.Items.Add(item); } if (mime.BodyText != null) { m_pTabMail_BodyText.Text = mime.BodyText; } } } private void button2_Click(object sender, EventArgs e) { Process[] pp = Process.GetProcessesByName("XX系统"); if (pp.Length > 0) { MessageBox.Show("XX系统正在运行,为保证更新成功,请先关闭系统", "提示"); return; } m_pTabMail_Messages.Focus(); Application.DoEvents(); button2.Enabled = false; button1.Enabled = false; button3.Enabled = false; deal_mail(); me_1.Text = "处理完毕!" "\r\n" me_1.Text; button2.Enabled = true; button1.Enabled = true; button3.Enabled = true; } private void run_sql(string ls_body) { //分析并执行邮件正文 string ls_split; string[] ls_sql; string ss = (char)10 "GO"; me_1.Text = "正在分析sql【" ls_body.Substring(0, ls_body.Length > 80 ? 80 : ls_body.Length) "...】" "\r\n" me_1.Text; ; ls_split = "##########"; ls_body = ls_body.Replace(ss, ls_split); ss = (char)10 "go"; ls_body = ls_body.Replace(ss, ls_split); ls_sql = Regex.Split(ls_body, ls_split, RegexOptions.IgnoreCase); foreach (string ls in ls_sql) { if (ls.Trim().Length > 5) { //Return_cls rc1 = mail.ExecuteNonQuery(ls); //ShowMs.Show(ls_body); try { SqlHelper.ExecuteNonQuery(conn_str, CommandType.Text, ls, null); me_1.Text = "执行sql成功【" ls.Substring(0, ls.Length > 80 ? 80 : ls.Length) "...】" "\r\n" me_1.Text; ; } catch (Exception ex) { me_1.Text = "执行sql失败【" ex.Message "...】" "\r\n" me_1.Text; ; } } } } private void deal_mail() { Application.DoEvents(); int ii; DateTime ldt_revtime; ii = 1; string ls_subject, ls_body, ls_filename, ls_sql, ls_from, ls_receive_time; foreach (ListViewItem item in m_pTabMail_Messages.Items) { me_1.Text = "正在处理第(" ii.ToString() ")封邮件【" item.SubItems[1].Text "】" "\r\n" me_1.Text; ls_subject = item.SubItems[1].Text; if (item.SubItems[5].Text == "未知") { ls_from = item.SubItems[0].Text; ls_subject = item.SubItems[1].Text; ls_receive_time = item.SubItems[2].Text; m_pTabMail_Attachments.Items.Clear(); m_pTabMail_BodyText.Text = ""; POP3_ClientMessage message = (POP3_ClientMessage)item.Tag; try { Mail_Message mime = Mail_Message.ParseFromByte(message.MessageToByte()); ldt_revtime = mime.Date; //分析并执行邮件正文 if (mime.BodyText != null && mime.BodyText.Trim().Length > 10 && mime.Subject.Substring(0, 5) == "[sql]") { m_pTabMail_BodyText.Text = mime.BodyText; ls_body = mime.BodyText; run_sql(ls_body); } //下载附件 foreach (MIME_Entity entity in mime.Attachments) { ListViewItem item2 = new ListViewItem(); if (entity.ContentDisposition != null && entity.ContentDisposition.Param_FileName != null) { item2.Text = entity.ContentDisposition.Param_FileName; ls_filename = entity.ContentDisposition.Param_FileName; } else { item2.Text = "untitled"; ls_filename = "untitled"; } item2.Tag = entity; me_1.Text = "正在保存附件【" ls_filename "】" "\r\n" me_1.Text; try { File.WriteAllBytes(@"" ls_filename, ((MIME_b_SinglepartBase)entity.Body).Data); } catch (Exception ex) { MessageBox.Show(ex.Message, "文件保存失败"); } //如果后缀为sql,读取并执行 string ls_hz; string ls_unzip_filename; ls_hz = ls_filename.Substring(ls_filename.Length - 4, 4); //ShowMs.Show(ls_hz); if (ls_hz == ".sql") { me_1.Text = "正在读取sql脚本文件【" ls_filename "】" "\r\n" me_1.Text; string sql; StreamReader sr = new StreamReader(@"" ls_filename, System.Text.Encoding.Default); sql = sr.ReadToEnd(); sr.Close(); run_sql(sql); } if (ls_hz == ".zip") { ls_unzip_filename = ls_filename.Substring(0, ls_filename.Length - 4); me_1.Text = "解压缩文件【" ls_filename "】" "\r\n" me_1.Text; Zip.DeCompressFile(ls_filename, ls_unzip_filename); ls_sql = String.Format("delete from tbl_fileinfo where filename='{0}'", ls_unzip_filename); SqlHelper.ExecuteNonQuery(conn_str, CommandType.Text, ls_sql, null); savefiletodb(ls_unzip_filename); } } ////更新处理标志 item.SubItems[5].Text = System.DateTime.Now.ToString(); ls_receive_time = item.SubItems[2].Text; ls_sql = String.Format("insert msgmailinfo(Msg_FormName,Msg_Subject,t_revtime,Msg_Date) values('{0}','{1}','{2}','{3}')", ls_from, ls_subject, ldt_revtime.ToString("yyyy-MM-dd HH:mm:ss"), ldt_revtime.ToString("yyyy-MM-dd HH:mm:ss")); SqlHelper.ExecuteNonQuery(conn_str, CommandType.Text, ls_sql, null); } catch (Exception ex) { MessageBox.Show(ex.Message, "邮件读取错误"); } } else { me_1.Text = "【该邮件无需再次处理】" "\r\n" me_1.Text; } ii ; } } private void savefiletodb(string fileName) { Application.DoEvents(); //保存客户端文件到数据库 //FileInfo fi = new FileInfo(fileName); //FileStream fs = fi.OpenRead(); //byte[] bytes = new byte[fs.Length]; //fs.Read(bytes, 0, Convert.ToInt32(fs.Length)); string strConnection = string.Format(@"Provider=SQLOLEDB;Data Source={0};Initial Catalog={1};User ID=prise;Password=20110214;", s_server, s_database); OleDbConnection DBConn; OleDbCommand DBCommand; try { DBConn = new OleDbConnection(strConnection); DBConn.Open(); DBCommand = DBConn.CreateCommand(); FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read); Byte[] b = new Byte[fs.Length]; fs.Read(b, 0, b.Length); fs.Close(); DBCommand.CommandText = string.Format(@"insert tbl_fileinfo(version,[filename],filesize,filedata) values('2013','{0}',{1},?)", fileName, b.Length); OleDbParameter prm = new OleDbParameter("@filedata", OleDbType.VarBinary, b.Length, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, b); DBCommand.Parameters.Add(prm); if (DBCommand.ExecuteNonQuery() == 1) { me_1.Text = "【文件(" fileName ")上传数据库成功】" "\r\n" me_1.Text; } else { MessageBox.Show("文件上传数据库失败1", "文件上传数据库失败"); } DBConn.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message, "文件上传数据库失败"); } } private void button3_Click_2(object sender, EventArgs e) { this.Close(); } private void t_1_TextChanged(object sender, EventArgs e) { if (t_1.Text == "ZIP") { button10.Visible = true; } } private void label3_Click(object sender, EventArgs e) { } private void button10_Click(object sender, EventArgs e) { Zip.CompressFile(@"start.pbd", @"start.pbd.zip"); Zip.CompressFile(@"comm.pbd", @"comm.pbd.zip"); Zip.CompressFile(@"jxc.pbd", @"jxc.pbd.zip"); Zip.CompressFile(@"parent.pbd", @"parent.pbd.zip"); Zip.CompressFile(@"sysbase.pbd", @"sysbase.pbd.zip"); Zip.CompressFile(@"run.exe", @"run.exe.zip"); Zip.CompressFile(@"TTF16.ocx", @"TTF16.ocx.zip"); } }}
下载C# 系统升级器用户还喜欢
- 18480 文章数
- 500万+ 热度
作者专栏
编辑推荐
- 淡抹u2引擎,修复内容较多,物有所值
- 界域传说·经典巨作=传世单机(一键安装)
- 丸子版本(175个传世版本大集合)
- GS版本:神话公益服务端+客户端
- 图片放大工具(放大图片不模糊)
- 剪映无限制VIP版
- 传奇世界客户端下载器,史上最全传世客户端
- 传世GS20220920商业引擎注册+登录配置器 解压密码是1
- U2官方排行榜游戏网关 支持元神,支持传家宝
- GS开战传世客户端+服务端
- (淡漠夕阳)u2引擎合区工具
- 传世GS引擎消除“你的游戏客户端版本号过旧,请及时更新”提示
- 传世一机多区双线路配置器--免密码版本
- 传世凤凰登陆器劫持修复软件
- SQLite3 for Navicat
- 传奇世界npc对话框编辑工具
- 传世GS落霞铭文服务器端
- gs_20210409引擎包+注册机(无限制)
- 传奇世界NPC对话封包查看器[支持时长版和极速版]
- 彩虹引擎传世脚本编辑工具1.7版来了,支持函数脚本翻译
评论