Log 读取

using MKT;
using MKT.APClient;
using MKT.BaseObject;
using System;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;
using MKT.Document.MS;
using MKT.Document;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using Emacro;
using System.Net.Mail;

 

 

 


namespace mDDFLog
{
 public class fMain : MKTChildForm
 {
  private SocketClient Socket;
        private ParameterCollection p;
  private MKTUser Userdata;
        private MSIE _Exp;

 

  //private ParameterCollection p;

 

        public string greworkno;
        private ColumnHeader columnHeader1;
        private ColumnHeader columnHeader2;
        private ColumnHeader columnHeader3;
        private ColumnHeader columnHeader4;
        private ColumnHeader columnHeader8;
        private ColumnHeader columnHeader7;
        private ColumnHeader columnHeader5;
        private ColumnHeader columnHeader10;
        private ColumnHeader columnHeader11;
        private ColumnHeader columnHeader6;
        private ColumnHeader columnHeader9;
        private ColumnHeader columnHeader13;
        private ColumnHeader columnHeader12;
        private ColumnHeader columnHeader14;
        private SaveFileDialog saveFileDialog1;
        private ColumnHeader columnHeader15;
        private ListView lvLog;
        private ColumnHeader columnHeader25;
        private ColumnHeader columnHeader26;
        private Label labTitle;
        private ToolStripMenuItem exportTextToolStripMenuItem;
        private ToolStripSplitButton toolStripSplitButton1;
        private ToolStripMenuItem excelToolStripMenuItem;
        private ToolStripSeparator toolStripSeparator3;
        private ToolStrip toolStrip1;
        private ToolStripSeparator toolStripSeparator1;
        private ToolStripLabel lbExprtMessage;
        private Panel panel1;
        private Button btnRead;
        private SaveFileDialog saveFileDialog2;
        private ColumnHeader columnHeader27;
        private ColumnHeader columnHeader28;
        private ColumnHeader columnHeader29;
        private ColumnHeader columnHeader30;
        private DateTimePicker dtp;
        private ComboBox cmbServer;
        private ComboBox cmbObject;

 

        private IContainer components = null;

 

  public static void ShowForm(ref Form parentform, ref object socket, ref MKTUser Userdata, string functionid, MKTLanguage Language)
  {
   fMain obj = new fMain();
   obj.Socket = (socket as SocketClient);
   obj.MdiParent = parentform;
   DisplayData.Language = Language;
   DisplayData.FunctionID = functionid;
   DisplayData.Row = Userdata.ModuleFunction.Select("FUNCTIONID = '" + functionid + "'")[0];
   DisplayData.ModuleID = int.Parse(DisplayData.Row["moduleid"].ToString());
   if (parentform.Tag != null)
   {
    string db = parentform.Tag.ToString();
    if (parentform.Tag.ToString().IndexOf(",") >= 0)
    {
     db = parentform.Tag.ToString().Split(new char[]
     {
      ','
     })[0];
    }
    if (db.IndexOf("DatabaseType") >= 0)
    {
     string[] DBstr = db.Split(new char[]
     {
      ':'
     });
     string text = DBstr[1].ToString().ToUpper();
     if (text != null)
     {
      if (!(text == "SQLSERVER"))
      {
       if (!(text == "ACCESS"))
       {
        if (!(text == "ORACLE"))
        {
         if (!(text == "ODBC"))
         {
          if (text == "SQLCompact")
          {
           DisplayData.DBType = TDatabaseType.SQLCompact;
          }
         }
         else
         {
          DisplayData.DBType = TDatabaseType.ODBC;
         }
        }
        else
        {
         DisplayData.DBType = TDatabaseType.Oracle;
        }
       }
       else
       {
        DisplayData.DBType = TDatabaseType.Access;
       }
      }
      else
      {
       DisplayData.DBType = TDatabaseType.SqlServer;
      }
     }
    }
   }
   obj.Text = Language.Transmit(DisplayData.Row["module_name"].ToString(), 0) + ":" + Language.Transmit(DisplayData.Row["function_name"].ToString(), 0);
   obj.Userdata = Userdata;
   Language.Transmit(obj, DisplayData.ModuleID);
   obj.Show();
  }

 

  public fMain()
  {
   this.InitializeComponent();
  }

 

  public override void RefreshChild(string[] param)
  {
   this.Text = DisplayData.Language.Transmit(DisplayData.Row["module_name"].ToString(), 0) + ":" + DisplayData.Language.Transmit(DisplayData.Row["function_name"].ToString(), 0);
   DisplayData.Language.Transmit(this, DisplayData.ModuleID);
  }

 

  protected override void Dispose(bool disposing)
  {
   if (disposing && this.components != null)
   {
    this.components.Dispose();
   }
   base.Dispose(disposing);
  }

 

  private void InitializeComponent()
  {
            System.Windows.Forms.ListViewItem listViewItem1 = new System.Windows.Forms.ListViewItem(new string[] {
            ""}, -1, System.Drawing.Color.Empty, System.Drawing.Color.WhiteSmoke, null);
            this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
            this.columnHeader2 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
            this.columnHeader3 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
            this.columnHeader4 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
            this.columnHeader8 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
            this.columnHeader7 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
            this.columnHeader5 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
            this.columnHeader10 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
            this.columnHeader11 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
            this.columnHeader6 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
            this.columnHeader9 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
            this.columnHeader13 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
            this.columnHeader12 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
            this.columnHeader14 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
            this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();
            this.columnHeader15 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
            this.lvLog = new System.Windows.Forms.ListView();
            this.columnHeader27 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
            this.columnHeader28 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
            this.columnHeader29 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
            this.columnHeader30 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
            this.columnHeader25 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
            this.columnHeader26 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
            this.labTitle = new System.Windows.Forms.Label();
            this.exportTextToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.toolStripSplitButton1 = new System.Windows.Forms.ToolStripSplitButton();
            this.excelToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.toolStripSeparator3 = new System.Windows.Forms.ToolStripSeparator();
            this.toolStrip1 = new System.Windows.Forms.ToolStrip();
            this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
            this.lbExprtMessage = new System.Windows.Forms.ToolStripLabel();
            this.panel1 = new System.Windows.Forms.Panel();
            this.cmbServer = new System.Windows.Forms.ComboBox();
            this.cmbObject = new System.Windows.Forms.ComboBox();
            this.dtp = new System.Windows.Forms.DateTimePicker();
            this.btnRead = new System.Windows.Forms.Button();
            this.saveFileDialog2 = new System.Windows.Forms.SaveFileDialog();
            this.toolStrip1.SuspendLayout();
            this.panel1.SuspendLayout();
            this.SuspendLayout();
            //
            // columnHeader1
            //
            this.columnHeader1.Text = "時間";
            this.columnHeader1.Width = 160;
            //
            // columnHeader2
            //
            this.columnHeader2.Text = "Object";
            this.columnHeader2.Width = 132;
            //
            // columnHeader3
            //
            this.columnHeader3.Text = "Action";
            this.columnHeader3.Width = 200;
            //
            // columnHeader4
            //
            this.columnHeader4.Text = "狀況";
            this.columnHeader4.Width = 218;
            //
            // columnHeader8
            //
            this.columnHeader8.Text = "型號";
            this.columnHeader8.Width = 90;
            //
            // columnHeader7
            //
            this.columnHeader7.Text = "線別";
            this.columnHeader7.Width = 120;
            //
            // columnHeader5
            //
            this.columnHeader5.Text = "線別";
            this.columnHeader5.Width = 120;
            //
            // columnHeader10
            //
            this.columnHeader10.Text = "工單";
            this.columnHeader10.Width = 96;
            //
            // columnHeader11
            //
            this.columnHeader11.Text = "批號";
            this.columnHeader11.Width = 108;
            //
            // columnHeader6
            //
            this.columnHeader6.Text = "投入時間";
            this.columnHeader6.Width = 160;
            //
            // columnHeader9
            //
            this.columnHeader9.Text = "中文站組";
            this.columnHeader9.Width = 80;
            //
            // columnHeader13
            //
            this.columnHeader13.Text = "英文站組";
            this.columnHeader13.Width = 80;
            //
            // columnHeader12
            //
            this.columnHeader12.Text = "數量";
            this.columnHeader12.Width = 120;
            //
            // columnHeader14
            //
            this.columnHeader14.Text = "型號";
            this.columnHeader14.Width = 90;
            //
            // columnHeader15
            //
            this.columnHeader15.Text = "停留時間";
            this.columnHeader15.Width = 84;
            //
            // lvLog
            //
            this.lvLog.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
            this.columnHeader27,
            this.columnHeader28,
            this.columnHeader29,
            this.columnHeader30});
            this.lvLog.Dock = System.Windows.Forms.DockStyle.Fill;
            this.lvLog.FullRowSelect = true;
            this.lvLog.GridLines = true;
            this.lvLog.Items.AddRange(new System.Windows.Forms.ListViewItem[] {
            listViewItem1});
            this.lvLog.Location = new System.Drawing.Point(0, 94);
            this.lvLog.Name = "lvLog";
            this.lvLog.Size = new System.Drawing.Size(948, 381);
            this.lvLog.TabIndex = 24;
            this.lvLog.UseCompatibleStateImageBehavior = false;
            this.lvLog.View = System.Windows.Forms.View.Details;
            //
            // columnHeader27
            //
            this.columnHeader27.Text = "時間";
            this.columnHeader27.Width = 120;
            //
            // columnHeader28
            //
            this.columnHeader28.Text = "Object";
            this.columnHeader28.Width = 100;
            //
            // columnHeader29
            //
            this.columnHeader29.Text = "Action";
            this.columnHeader29.Width = 120;
            //
            // columnHeader30
            //
            this.columnHeader30.Text = "狀況";
            this.columnHeader30.Width = 200;
            //
            // columnHeader25
            //
            this.columnHeader25.Text = "線別";
            this.columnHeader25.Width = 120;
            //
            // columnHeader26
            //
            this.columnHeader26.Text = "型號";
            this.columnHeader26.Width = 90;
            //
            // labTitle
            //
            this.labTitle.AutoSize = true;
            this.labTitle.BackColor = System.Drawing.Color.Transparent;
            this.labTitle.Font = new System.Drawing.Font("Microsoft JhengHei", 9.75F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic))), System.Drawing.GraphicsUnit.Point, ((byte)(136)));
            this.labTitle.ForeColor = System.Drawing.Color.White;
            this.labTitle.Location = new System.Drawing.Point(5, 4);
            this.labTitle.Name = "labTitle";
            this.labTitle.Size = new System.Drawing.Size(41, 17);
            this.labTitle.TabIndex = 12;
            this.labTitle.Text = "Label";
            //
            // exportTextToolStripMenuItem
            //
            this.exportTextToolStripMenuItem.Name = "exportTextToolStripMenuItem";
            this.exportTextToolStripMenuItem.Size = new System.Drawing.Size(105, 22);
            this.exportTextToolStripMenuItem.Text = "Text";
            this.exportTextToolStripMenuItem.Click += new System.EventHandler(this.exportTextToolStripMenuItem_Click);
            //
            // toolStripSplitButton1
            //
            this.toolStripSplitButton1.BackColor = System.Drawing.Color.Transparent;
            this.toolStripSplitButton1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
            this.toolStripSplitButton1.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.exportTextToolStripMenuItem,
            this.excelToolStripMenuItem});
            this.toolStripSplitButton1.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.toolStripSplitButton1.Name = "toolStripSplitButton1";
            this.toolStripSplitButton1.Size = new System.Drawing.Size(62, 19);
            this.toolStripSplitButton1.Text = "Export";
            //
            // excelToolStripMenuItem
            //
            this.excelToolStripMenuItem.Name = "excelToolStripMenuItem";
            this.excelToolStripMenuItem.Size = new System.Drawing.Size(105, 22);
            this.excelToolStripMenuItem.Text = "Excel";
            this.excelToolStripMenuItem.Click += new System.EventHandler(this.excelToolStripMenuItem_Click);
            //
            // toolStripSeparator3
            //
            this.toolStripSeparator3.Name = "toolStripSeparator3";
            this.toolStripSeparator3.Size = new System.Drawing.Size(6, 22);
            //
            // toolStrip1
            //
            this.toolStrip1.AutoSize = false;
            this.toolStrip1.BackColor = System.Drawing.Color.Transparent;
            this.toolStrip1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
            this.toolStrip1.GripStyle = System.Windows.Forms.ToolStripGripStyle.Hidden;
            this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.toolStripSeparator3,
            this.toolStripSplitButton1,
            this.toolStripSeparator1,
            this.lbExprtMessage});
            this.toolStrip1.Location = new System.Drawing.Point(0, 72);
            this.toolStrip1.Name = "toolStrip1";
            this.toolStrip1.Size = new System.Drawing.Size(948, 22);
            this.toolStrip1.TabIndex = 23;
            this.toolStrip1.Text = "toolStrip1";
            //
            // toolStripSeparator1
            //
            this.toolStripSeparator1.Name = "toolStripSeparator1";
            this.toolStripSeparator1.Size = new System.Drawing.Size(6, 22);
            //
            // lbExprtMessage
            //
            this.lbExprtMessage.AutoSize = false;
            this.lbExprtMessage.Name = "lbExprtMessage";
            this.lbExprtMessage.Size = new System.Drawing.Size(200, 25);
            this.lbExprtMessage.Text = "  ";
            this.lbExprtMessage.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            //
            // panel1
            //
            this.panel1.BackColor = System.Drawing.Color.White;
            this.panel1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
            this.panel1.Controls.Add(this.cmbServer);
            this.panel1.Controls.Add(this.cmbObject);
            this.panel1.Controls.Add(this.dtp);
            this.panel1.Controls.Add(this.btnRead);
            this.panel1.Controls.Add(this.labTitle);
            this.panel1.Dock = System.Windows.Forms.DockStyle.Top;
            this.panel1.Font = new System.Drawing.Font("Microsoft JhengHei", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(136)));
            this.panel1.Location = new System.Drawing.Point(0, 0);
            this.panel1.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
            this.panel1.Name = "panel1";
            this.panel1.Size = new System.Drawing.Size(948, 72);
            this.panel1.TabIndex = 22;
            //
            // cmbServer
            //
            this.cmbServer.AutoCompleteCustomSource.AddRange(new string[] {
            "服務器1",
            "服務器2"});
            this.cmbServer.FormattingEnabled = true;
            this.cmbServer.Items.AddRange(new object[] {
            "服務器223",
            "服務器225",
            "本地"});
            this.cmbServer.Location = new System.Drawing.Point(52, 24);
            this.cmbServer.Name = "cmbServer";
            this.cmbServer.Size = new System.Drawing.Size(121, 24);
            this.cmbServer.TabIndex = 16;
            this.cmbServer.Text = "服務器223";
            //
            // cmbObject
            //
            this.cmbObject.FormattingEnabled = true;
            this.cmbObject.Items.AddRange(new object[] {
            "Application Server",
            "Object Host",
            "Data Terminal Service",
            "Alarm Server"});
            this.cmbObject.Location = new System.Drawing.Point(201, 25);
            this.cmbObject.Name = "cmbObject";
            this.cmbObject.Size = new System.Drawing.Size(163, 24);
            this.cmbObject.TabIndex = 15;
            this.cmbObject.Text = "Application Server";
            //
            // dtp
            //
            this.dtp.Location = new System.Drawing.Point(414, 29);
            this.dtp.Name = "dtp";
            this.dtp.Size = new System.Drawing.Size(200, 23);
            this.dtp.TabIndex = 14;
            //
            // btnRead
            //
            this.btnRead.Location = new System.Drawing.Point(678, 25);
            this.btnRead.Name = "btnRead";
            this.btnRead.Size = new System.Drawing.Size(75, 23);
            this.btnRead.TabIndex = 13;
            this.btnRead.Text = "讀取";
            this.btnRead.UseVisualStyleBackColor = true;
            this.btnRead.Click += new System.EventHandler(this.btnRead_Click);
            //
            // fMain
            //
            this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 16F);
            this.ClientSize = new System.Drawing.Size(948, 475);
            this.Controls.Add(this.lvLog);
            this.Controls.Add(this.toolStrip1);
            this.Controls.Add(this.panel1);
            this.Margin = new System.Windows.Forms.Padding(3, 5, 3, 5);
            this.Name = "fMain";
            this.Text = "UserForm";
            this.toolStrip1.ResumeLayout(false);
            this.toolStrip1.PerformLayout();
            this.panel1.ResumeLayout(false);
            this.panel1.PerformLayout();
            this.ResumeLayout(false);

 

  }
        /// <summary>
        /// 連接服務器
        /// </summary>
        /// <param name="remoteHost">IP</param>
        /// <param name="userName">用戶名</param>
        /// <param name="passWord">密碼</param>
        /// <returns></returns>
        public bool Connect(string remoteHost, string userName, string passWord)
        {
            bool Flag = true;
            Process proc = new Process();
            proc.StartInfo.FileName = "cmd.exe";
            proc.StartInfo.UseShellExecute = false;
            proc.StartInfo.RedirectStandardInput = true;
            proc.StartInfo.RedirectStandardOutput = true;
            proc.StartInfo.RedirectStandardError = true;
            proc.StartInfo.CreateNoWindow = true;
            try
            {
                proc.Start();
               // string cmddel = @"net use */delete";
               // proc.StandardInput.WriteLine(cmddel);
                //cmddel = "exit";
                //proc.StandardInput.WriteLine(cmddel);
                string cmddel = @"net use \\" + remoteHost + "  " + passWord + "  " + "  /user:" + userName;
                proc.StandardInput.WriteLine(cmddel);
                cmddel = "exit";
                proc.StandardInput.WriteLine(cmddel);
                ///string cmdcon = @"net  use  \\" + remoteHost + "  " + passWord + "  " + "  /user:" + userName + ">NUL";
                //string cmdcon = @"net use D:\\" + remoteHost + "/C$" + " "+passWord + "  " + "  /user:" + userName;
                //proc.StandardInput.WriteLine(cmdcon);
                //cmdcon= "exit";
                //proc.StandardInput.WriteLine(cmdcon);
                while (proc.HasExited == false)
                {
                    proc.WaitForExit(1000);
                }
                string errormsg = proc.StandardError.ReadToEnd();
                if (errormsg != "")
                {
                    Flag = false;
                    MessageBox.Show(errormsg);
                }
                   
                proc.StandardError.Close();
               
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());               
                Flag = false;
            }
            finally
            {
                proc.Close();
                proc.Dispose();
            }
            return Flag;
        }
        /// <summary>
        ///  獲取日誌
        /// </summary>
        /// <returns></returns>
        private bool GetTxt(string url)
        {
            for (int i = this.lvLog.Columns.Count; i > 9; i--)
            {
                this.lvLog.Columns.RemoveAt(i - 1);
            }
            this.lvLog.Items.Clear();
            //string currentDate = DateTime.Now.ToString("yyyyMMdd");
            string currentDate = dtp.Value.ToString("yyyyMMdd");
            //string fPath = @"C:\Users\KGO05632\Desktop\AP Log(8天)\log\" + currentDate + ".log";
            // if (this.Connect("172.16.75.76","KGO04883@giantplus.com","myy_841110ok..."))
            //if (this.Connect("172.16.75.76", "administrator@giantplus0", "admp@ssw0rd"))
            try
            {
                if (this.Connect("172.16.75.55", "KGO05632@giantplus.com.cn", "qwer!123"))
                {

 

                    if (url == "DTlog")
                    {
                        string fPath = @"\\172.16.75.55\C$\Users\KGO05632\Desktop\Log\" + url + "/" + currentDate + "-CMC503.log";
                        //MessageBox.Show(fPath);
                        if (File.Exists(fPath))
                        {
                            char sp = ' ';
                            FileStream fs = new FileStream(fPath, FileMode.Open);
                            //MessageBox.Show(fPath);
                            StreamReader sr = new StreamReader(fs);
                            //StreamReader sr = File.OpenText(fPath);
                            //string str = sr.ReadLine();
                            // MessageBox.Show(str);
                            string str = " ";
                            while ((str = sr.ReadLine()) != null)
                            {

 

                                string[] oLog = str.Split(sp);
                                string  time = oLog[0] + " " + oLog[1].Substring(0,8);
                                string oBject = oLog[1].Substring(9) +" "+ oLog[2];
                                string reason = oLog[3].Trim();
                                string iPort = oLog[4].Trim();
                                Array.Clear(oLog,0,5);
                                string[] log = new string[] {time,oBject,reason,iPort};
                              
                             
                                      

 

                              for (int i = 0; i < log.Length; i++)
                                {
                                //    MessageBox.Show(log[i]);
                                    //return false;
                                   //log[3] = log[3].Substring(13);
                                    ListViewItem listViewItem = new ListViewItem();
                                    listViewItem.Text = log[0];
                                    listViewItem.SubItems.Add(log[1]);
                                    listViewItem.SubItems.Add(log[2]);
                                    listViewItem.SubItems.Add(log[3]);
                                    this.lvLog.Items.Add(listViewItem); 
                                  //  string reSult = log[3];
                                    // MessageBox.Show(reSult);
                                   /* if (reSult.IndexOf("sessionid") != -1 && reSult.IndexOf("-1310159944") != -1)
                                    {
                                        MessageBox.Show(reSult);
                                        string[] to = new string[] { "kgo05632@giantplus.com.cn" };
                                        string[] cc = new string[] { "kgo04883@giantplus.com.cn" };
                                        string sub = "服務器session異常";
                                        string sDesc = "";
                                        sDesc = "<b>===================== 事件明細  =====================</b><br>";
                                        sDesc = sDesc + "<b>時間 : </b>" + log[0] + "<br>" + System.Environment.NewLine;
                                        sDesc = sDesc + "<b>對象 : </b>" + log[1] + "<br>" + System.Environment.NewLine;
                                        sDesc = sDesc + "<b>動作 : </b>" + log[2] + "<br>" + System.Environment.NewLine;
                                        sDesc = sDesc + "<b>異常 : </b>" + log[3] + "<br>" + System.Environment.NewLine;
                                        sDesc = sDesc + "<b>請相關人員協助解決!!!<br>" + System.Environment.NewLine;
                                        this.SendMail(to, cc, sub, sDesc);
                                    }
                                     */

 

                                   
                                }
                                          

 

                            }

 

                            sr.Close();

 

                        }
                        else
                        {
                            MessageBox.Show("文件不存在");
                            return false;

 

                        }

 


                    }
                    else
                    {
                        string fPath = @"\\172.16.75.55\C$\Users\KGO05632\Desktop\Log\" + url + "/" + currentDate + ".log";
                       // MessageBox.Show(fPath);
                        if (File.Exists(fPath))
                        {
                            char sp = ',';
                            FileStream fs = new FileStream(fPath, FileMode.Open);
                            //MessageBox.Show(fPath);
                            StreamReader sr = new StreamReader(fs);
                            //StreamReader sr = File.OpenText(fPath);
                            //string str = sr.ReadLine();
                            // MessageBox.Show(str);
                            string str = " ";
                            while ((str = sr.ReadLine()) != null)
                            {
                                string[] log = str.Split(sp);
                                //List<string> log=
                                // string []inlog=log[3].Split(' ');

 

                                for (int i = 0; i < log.Length; i++)
                                {
                                    //log[3] = log[3].Substring(13);
                                    ListViewItem listViewItem = new ListViewItem();
                                    listViewItem.Text = log[0];
                                    listViewItem.SubItems.Add(log[1]);
                                    listViewItem.SubItems.Add(log[2]);
                                    listViewItem.SubItems.Add(log[3]);
                                    this.lvLog.Items.Add(listViewItem);
                                    // string reSult = log[3];
                                    // MessageBox.Show(reSult);
                                    /* if (reSult.IndexOf("sessionid") != -1 && reSult.IndexOf("-1310159944") != -1)
                                     {
                                         MessageBox.Show(reSult);
                                         string[] to = new string[] { "kgo05632@giantplus.com.cn" };
                                         string[] cc = new string[] { "kgo04883@giantplus.com.cn" };
                                         string sub = "服務器session異常";
                                         string sDesc = "";
                                         sDesc = "<b>===================== 事件明細  =====================</b><br>";
                                         sDesc = sDesc + "<b>時間 : </b>" + log[0] + "<br>" + System.Environment.NewLine;
                                         sDesc = sDesc + "<b>對象 : </b>" + log[1] + "<br>" + System.Environment.NewLine;
                                         sDesc = sDesc + "<b>動作 : </b>" + log[2] + "<br>" + System.Environment.NewLine;
                                         sDesc = sDesc + "<b>異常 : </b>" + log[3] + "<br>" + System.Environment.NewLine;
                                         sDesc = sDesc + "<b>請相關人員協助解決!!!<br>" + System.Environment.NewLine;
                                         //sDesc = sDesc + "<b>警示代碼 : </b>" + AlarmCode + "<br>" + System.Environment.NewLine;
                                         //  sDesc = sDesc + "<b>事件編號 : </b>" + sID + "<br>" + System.Environment.NewLine;
                                         //sDesc = sDesc + "<b>說明 : LOT良率低於 </b>" + sPara + "<br>" + System.Environment.NewLine;
                                         // sDesc = sDesc + "<b>機種 : </b>" + (Data[0].Value as DataTable).Rows[idx]["model_name"].ToString() + "<br>" + System.Environment.NewLine;
                                         // sDesc = sDesc + "<b>料號 : </b>" + (Data[0].Value as DataTable).Rows[idx]["part_number"].ToString() + "<br>" + System.Environment.NewLine;
                                         // sDesc = sDesc + "<b>品名 : </b>" + (Data[0].Value as DataTable).Rows[idx]["part_desc1"].ToString() + "<br>" + System.Environment.NewLine;
                                         // sDesc = sDesc + "<b>LOT NO : </b>" + (Data[0].Value as DataTable).Rows[idx]["runcard"].ToString() + "<br>" + System.Environment.NewLine;
                                         this.SendMail(to, cc, sub, sDesc);
                                     }
                                       */
                                }

 

                            }

 

                            sr.Close();
                        }
                        else
                        {
                            MessageBox.Show("文件不存在");
                            return false;
                        }

 

                    }

 

                }
                else
                {
                    MessageBox.Show("沒有訪問權限!!!");
                }

 

               // return true;
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }

 

            return true;

 

        }
       
       /// <summary>
       /// 讀取事件
       /// </summary>
       /// <param name="sender"></param>
       /// <param name="e"></param>
        private void btnRead_Click(object sender, EventArgs e)
        {
            string rObject = this.cmbObject.SelectedItem.ToString();
            //Application;
            //Server Object Host; \\Data Terminal \\Service Alarm Server
            if(rObject=="Application Server")
            {
                rObject = "APlog" ;
            }
            else if(rObject=="Object Host")
            {
               rObject = "Objectlog" ;
            }
            else if(rObject=="Data Terminal Service")
            {
               rObject = "DTlog" ;
            }
            else{
               
               rObject = "ALMlog" ;
            }
            this.GetTxt(rObject);
            //this.SendMail();
            /*
            string[] to = new string[] { "kgo05632@giantplus.com.cn" };
            string[] cc = new string[] { "kgo05632@giantplus.com.cn" };
            string sub = "服務器session異常";
            string sDesc = "";
            sDesc = "<b>===================== 事件明細  =====================</b><br>";
            sDesc = sDesc + "<b>時間 : </b>" + this.lvLog.Items[1].SubItems[0].Text + "<br>" ;
            sDesc = sDesc + "<b>對象 : </b>" + this.lvLog.Items[1].SubItems[1].Text + "<br>" ;
            sDesc = sDesc + "<b>動作 : </b>" + this.lvLog.Items[1].SubItems[2].Text + "<br>" ;
            this.SendMail(to, cc, sub, sDesc);
              */
            //this.SendMail();
        }

 

        /// <summary>
        /// 導出TXT
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void exportTextToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.saveFileDialog1.DefaultExt = "txt";
            if (this.saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                string text = "";
                string fileName = this.saveFileDialog1.FileName;
                StreamWriter streamWriter = new StreamWriter(fileName, false, Encoding.Default);
                for (int i = 0; i < this.lvLog.Columns.Count; i++)
                {
                    text = text + this.lvLog.Columns[i].Text + "\t";
                }
                streamWriter.WriteLine(text);
                for (int j = 0; j < this.lvLog.Items.Count; j++)
                {
                    text = "";
                    for (int i = 0; i < this.lvLog.Columns.Count; i++)
                    {
                        text = text + this.lvLog.Items[j].SubItems[i].Text + "\t";
                    }
                    streamWriter.WriteLine(text);
                }
                streamWriter.Close();
                MessageBox.Show(DisplayData.Language.Transmit("File Export Complete !!", DisplayData.ModuleID));
            }
        }

 

        /// <summary>
        /// 導出EXCEL
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void excelToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.saveFileDialog1.DefaultExt = "xls";
            this.saveFileDialog1.Filter = "Excel|*.xls";
            if (this.saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                string fileName = this.saveFileDialog1.FileName;
                this._Exp = new MSIE();
                this._Exp.ExportState += new EventHandler<ExportProgressEventArgs>(this._Exp_ExportState);
                this._Exp.ExportClose += new EventHandler<ExportEventArgs>(this._Exp_ExportClose);
                DataTable dataTable = new DataTable("Transfer");
                for (int i = 0; i < this.lvLog.Columns.Count; i++)
                {
                    dataTable.Columns.Add(this.lvLog.Columns[i].Text);
                }
                for (int j = 0; j < this.lvLog.Items.Count; j++)
                {
                    DataRow dataRow = dataTable.NewRow();
                    int num = 0;
                    for (int i = 0; i < this.lvLog.Columns.Count; i++)
                    {
                        dataRow[num] = this.lvLog.Items[j].SubItems[i].Text;
                        num++;
                    }
                    dataTable.Rows.Add(dataRow);
                }
                if (!this._Exp.Export(this.saveFileDialog1.FileName, dataTable, true))
                {
                    MessageBox.Show("Export Table Fail");
                }
                this._Exp.ExportState -= new EventHandler<ExportProgressEventArgs>(this._Exp_ExportState);
                // this._Exp.ExportStart(new EventHandler<ExportProgressEventArgs>(this._Exp_ExportState));
                this._Exp.ExportClose -= new EventHandler<ExportEventArgs>(this._Exp_ExportClose);
                this._Exp = null;
            }

 

        }

 

        private void _Exp_ExportState(object sender, ExportProgressEventArgs e)
        {
            this.lbExprtMessage.Text = e.ProgressText + " " + e.Value.ToString();
        }

        private void _Exp_ExportClose(object sender, ExportEventArgs e)
        {
            this.lbExprtMessage.Text = "";
            MessageBox.Show(DisplayData.Language.Transmit("File Export Complete !!", DisplayData.ModuleID));
        }
        /// <summary>
        /// 發送郵件
        /// </summary>
        /// <param name="toUser">收件人</param>
        /// <param name="ccUser">抄送人</param>
        /// <param name="sub">主體</param>
        /// <param name="messAge">郵件內容</param>
        public void SendMail(string[] toUser, string [] ccUser, string subJect, string messAge)
           {
                System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
                //添加收件人
                for (int i = 0; i < toUser.Length; i++)
                {
                   // MessageBox.Show(toUser[i]);
                    msg.To.Add(toUser[i]);
                }
            //添加抄送人
                for (int j = 0; j < ccUser.Length; j++)
               {
                   // MessageBox.Show(ccUser[j]);
                    msg.CC.Add(ccUser[j]);
               }
                 msg.From = new MailAddress("messystem@giantplus.com.cn", "messystem@giantplus.com.cn", System.Text.Encoding.UTF8);
                 msg.Subject = subJect;//邮件标题
                 msg.SubjectEncoding = System.Text.Encoding.UTF8;//邮件标题编码
                 //msg.Body = messAge;//邮件内容
                 msg.Body = messAge;//邮件内容
                 msg.BodyEncoding = System.Text.Encoding.UTF8;//邮件内容编码
                 msg.IsBodyHtml = true;//是否是HTML邮件
                 msg.Priority = MailPriority.High;//邮件优先级
                SmtpClient client = new SmtpClient();
                client.Credentials = new System.Net.NetworkCredential("kgo05632@giantplus.com.cn", "qwer!123");
                client.Host = "172.16.100.201";
                object userState = msg;
                try
                {
                    client.SendAsync(msg, userState);
                    //简单一点儿可以client.Send(msg);
                    MessageBox.Show("发送成功");
                 }
                catch (System.Net.Mail.SmtpException ex)
                {
                   MessageBox.Show(ex.Message, "发送邮件出错");
                 }
         }
 }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值