You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

205 lines
6.8 KiB

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;
namespace wcfControlMonitorClient
{
public partial class FrmBrowseDarkCasket : Form
{
private static string filePath;
private static FrmBrowseDarkCasket _formInstance;
public static FrmBrowseDarkCasket FormInstance
{
get
{
if (_formInstance == null)
{
_formInstance = new FrmBrowseDarkCasket();
}
return _formInstance;
}
set { _formInstance = value; }
}
public FrmBrowseDarkCasket()
{
InitializeComponent();
_formInstance = this;
}
// 刷新按钮, 窗口登录时调用该函数。
private void button1_Click(object sender, EventArgs e)
{
if (comboBoxFileName.Text=="")
{
MessageBox.Show(" 请选择黑匣子文件!", "误操作提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
string filename = comboBoxFileName.Text;
filename = string.Format("{0}\\{1}", filePath, filename);
if (File.Exists(filename) == false)
{
MessageBox.Show(" 选择的黑匣子文件不存在!", "误操作提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return ;
}
this.Text = comboBoxFileName.Text;
//string[] files = Directory.GetFiles(filePath, "*.log", SearchOption.TopDirectoryOnly);//20101220,只查找LOG文件,避免查找到其它类型的文件
//if (files != null)
//{
// Array.Sort(files);//20100726
// if (files.Length < 1) return;
//}
//else
//{
// return;
//}
//string[] files=Directory.GetFiles(filePath);
//Array.Sort(files);
// 目录为空时候返回
//string opf=files[files.Length - 1];
string opf = filename;
string[] cc=new string[1]{"**"};
string[] sp = null;
//string filename = opf.Substring(opf.LastIndexOf('\\') + 1);
//this.Text = filename;
using( StreamReader sr = new StreamReader(opf))
{
this.listView1.Items.Clear();
sr.ReadLine();
while(!sr.EndOfStream)
{
sp=sr.ReadLine().Split(cc,StringSplitOptions.RemoveEmptyEntries);
// 添加判断条件过滤信息 2011-05-26 zb
if (comboBoxDevice.SelectedIndex > 0 || comboBoxDevice.Text != String.Empty)
{
if (sp.Length < 4) continue;
if (comboBoxDevice.Text != sp[3])
{
continue;
}
}
DateTime dt ;
if (DateTime.TryParse(sp[0].Substring(0,19), out dt) == false) continue;
if ((dt.Hour < this.numericUpDown1.Value) || ((dt.Hour > this.numericUpDown2.Value)))
{
continue;
}
if (sp.GetLength(0) > 0)
{
ListViewItem lvi = new ListViewItem();
lvi.Text = sp[0];
for (int i = 1; i < sp.GetLength(0); i++)
{
lvi.SubItems.Add(sp[i]);
}
listView1.Items.Add(lvi);
lvi = null;
}
}
}
}
private void button2_Click(object sender, EventArgs e)
{
if (MessageBox.Show("您确认要删除当前选中的黑匣子文件吗", "操作提示:", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) != DialogResult.OK)
{
return;
}
string filePath = System.IO.Path.GetFullPath(System.Reflection.Assembly.GetExecutingAssembly().GetName().ToString());
filePath = System.IO.Path.GetDirectoryName(filePath);
filePath = System.IO.Path.Combine(filePath, "DarkCasket");
if (Directory.Exists(filePath) == false)
{
return;
}
if (comboBoxFileName.Items.Count <= 0) return;
string filename = comboBoxFileName.Text;
filename = string.Format("{0}\\{1}", filePath, filename);
string[] files = Directory.GetFiles(filePath);
//if (files.Length < 1) return;
//File.Delete(files[files.Length - 1]);
this.listView1.Items.Clear();
File.Delete(filename);
GetDarkCasketFileNames();
}
private void button3_Click(object sender, EventArgs e)
{
this.Close();
}
private void FrmBrowseDarkCasket_Load(object sender, EventArgs e)
{
filePath = System.IO.Path.GetFullPath(System.Reflection.Assembly.GetExecutingAssembly().GetName().ToString());
filePath = System.IO.Path.GetDirectoryName(filePath);
filePath = System.IO.Path.Combine(filePath, "DarkCasket");
btFresh_Click(sender, e);
}
private void FrmBrowseDarkCasket_FormClosing(object sender, FormClosingEventArgs e)
{
_formInstance = null;
}
private void GetDarkCasketFileNames()
{
try
{
comboBoxFileName.Items.Clear();
string[] files = Directory.GetFiles(filePath, "*.log", SearchOption.TopDirectoryOnly);//20101220,只查找LOG文件,避免查找到其它类型的文件
if (files != null)
{
Array.Reverse(files);
if (files.Length < 1) return;
}
else
{
return;
}
string filename;
for (int i = 0; i < files.Length; i++)
{
filename = files[i].Substring(files[i].LastIndexOf('\\') + 1);
if (comboBoxFileName.Items.IndexOf(filename) >= 0)continue;
comboBoxFileName.Items.Add(filename);
}
comboBoxFileName.SelectedIndex = 0;
}
catch(Exception ex)
{
throw ex;
}
}
private void btFresh_Click(object sender, EventArgs e)
{
GetDarkCasketFileNames();
}
}
}