啊啊啊

jingjingzhanghy 2010-09-17 05:23:01
#region 开始分析事件事件
/// <summary>
/// 开始分析事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button3_Click(object sender, EventArgs e)
{
//DataBle模糊过滤字符
//出现输入关键字的日志
if (label4.Text.Length <= 0)
{
MessageBox.Show("请选择日志目录(*.txt)");
}
else
{
if (label5.Text.Length > 0)
{
dv_All = PipingFileReader(fileNames).DefaultView;
dtSameRowCount = dv_All.Table.Rows.Count;
//dataGridView1.DataSource = dv_All;

//Excel中日志信息
DataView dt = ParseExcel(ExcelName, 1).DefaultView;
//dataGridView1.DataSource = dt;

FileStream fs = null;
FileStream fs_Same = null;
StreamWriter sw = null;
StreamWriter sw_Same = null;
fs = new FileStream("D:\\LogFile\\UnSame_Log.txt", FileMode.Create);
sw = new StreamWriter(fs, Encoding.Default);
fs_Same = new FileStream("D:\\LogFile\\Same_Log.txt", FileMode.Create);
sw_Same = new StreamWriter(fs_Same, Encoding.Default);
//1.遍历dt中数据,取出用于比对的数据
//2.循环传入到方法中进行比对
//过滤不相同的日志信息

//10-09-16 修改拼查询字符串
string strCheck = string.Empty;
DataTable dt2 = new DataTable();
for (int j = 1; j < dt.Table.Rows.Count; j++)
{
if (j < dt.Table.Rows.Count - 1)
{
strCheck += "'" + dt.Table.Rows[j]["Id2"].ToString() + "' AND UnNum <> ";
}
else
{
strCheck += "'" + dt.Table.Rows[j]["Id2"].ToString() + "'";
}
}
...全文
34 点赞 收藏 4
写回复
4 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
Love_Air523824 2010-09-17
你想说什么呀
回复
jingjingzhanghy 2010-09-17
public static string[] fileNames; //目录下所有*.txt文件名称
public static int dtSameRowCount = 0, dtUnSameRowCount = 0; //带有数字的日志信息/无数字的日志信息
public static string ExcelName = string.Empty; //打开的Excel文件
DataView dv_All = new DataView();
public Form1()
{
InitializeComponent();
CreateDir();
openFileDialog1.Filter = "Excel文件(*.xls)|*.xls";
openFileDialog1.ReadOnlyChecked = true;
}


#region 比对Excel中出现的日志与过滤Txt日志文件中后的日志信息
/// <summary>
/// 比对Excel中出现的日志与过滤Txt日志文件中后的日志信息
/// </summary>
/// <param name="excelKey">Excel中日志信息</param>
/// <param name="txtKey">过滤Txt文件后的日志信息</param>
/// <returns>DataTable</returns>
private DataView LikeKeyword(string excelKey, string txtKey)
{
//DataBle模糊过滤字符
//出现输入关键字的日志
//DataView dv = PipingFileReader(fileNames).DefaultView;
//dtSameRowCount = dv.Table.Rows.Count;
//string strFilter = "" + excelKey + " <> " + txtKey + " ";
//DataRow[] rows = dv.Table.Select(strFilter);
//DataTable dt = new DataTable();
//dt = dv.Table.Clone();
//foreach (DataRow dr in rows)
//{
// dt.ImportRow(dr);
//}
//dv = dt.DefaultView;
try
{
dv_All.RowFilter = "" + excelKey + " <> " + txtKey + " "; //"" + excelKey + " like '%" + txtKey + "%' ";
}
catch { }
return dv_All;
}
#endregion

#region 比对Excel中出现的日志与过滤Txt日志文件中后的日志信息相同的日志信息
/// <summary>
/// 比对Excel中出现的日志与过滤Txt日志文件中后的日志信息
/// </summary>
/// <param name="excelKey">Excel中日志信息</param>
/// <param name="txtKey">过滤Txt文件后的日志信息</param>
/// <returns>DataTable</returns>
private DataView SameKeyword(string excelKey, string txtKey)
{
//DataBle模糊过滤字符
//出现输入关键字的日志
try
{
dv_All.RowFilter = "" + excelKey + " = '" + txtKey + "' "; //"" + excelKey + " like '%" + txtKey + "%' ";
}
catch { }
return dv_All;
}
#endregion
回复
jingjingzhanghy 2010-09-17
//m_Worksheet = (Excel.Worksheet)m_Workbook.Worksheets.get_Item(sheetIndex);
int sheetCount = m_Workbook.Worksheets.Count;
for (int i = 1; i <= sheetCount; i++)
{
m_Worksheet = (Excel.Worksheet)m_Workbook.Worksheets.get_Item(i);
for (int j = 2; j <= m_Worksheet.UsedRange.Rows.Count; j++)
{
DataRow newRow = dtTemp.NewRow();
//for (int i = 1; i <= m_Worksheet.UsedRange.Columns.Count; i++)
//{
if (((Excel.Range)(m_Worksheet.Cells[j, 2])).Text.ToString() != null && ((Excel.Range)(m_Worksheet.Cells[j, 2])).Text.ToString() != "")
{
//取出Excel指定sheet里面的所有列
newRow[1] = System.Text.RegularExpressions.Regex.Replace(((Excel.Range)(m_Worksheet.Cells[j, 2])).Value2.ToString(), @"[\d]", "");//((Excel.Range)(m_Worksheet.Cells[j, 2])).Value2.ToString();

//}
dtTemp.Rows.Add(newRow);
}
}
//MessageBox.Show(dtTemp.Rows[i]["Id2"].ToString());
}
、、、、、、、、、、、、、、、、、


//每次读一行加1
rowInFil++;
if (strRead.LastIndexOf("BAM Info") < 0)
{
while (strRead != null)
{
if ((strRead.Trim().ToUpper().StartsWith(textBox1.Text.Trim().ToUpper()) || strRead.Trim().ToUpper().IndexOf(textBox1.Text.Trim().ToUpper()) > 0) && (strRead.Trim().Length > 0))
{
rowcount++;
DataRow dr = dt.NewRow();
//dr["Id"] = rowcount.ToString();
dr["FileName"] = FileName;
dr["HasNum"] = strRead;
dr["UnNum"] = System.Text.RegularExpressions.Regex.Replace(strRead, @"[\d]", ""); //去掉字符串中的数字
dr["InFileNum"] = rowInFil.ToString();
dt.Rows.Add(dr);
}
strRead = sr.ReadLine();
rowInFil++;

}
回复
jingjingzhanghy 2010-09-17
//10-09-15 修改
//比较以后Excel与Txt不同的信息
DataView dv = LikeKeyword("UnNum", strCheck);
dt2 = dv.ToTable();
//dataGridView1.DataSource = dt2.DefaultView;
for (int i = 0; i < dt2.Rows.Count; i++)
{
string strIn = "日志: " + dt2.Rows[i]["HasNum"].ToString() + " 大概在【" + dt2.Rows[i]["FileName"].ToString() + "】中,第 [" + dt2.Rows[i]["InFileNum"].ToString() + "] 行\r\n";

sw.WriteLine(strIn);
}
string str_Same = string.Empty;
DataTable dtSame = new DataTable();
for (int j = 0; j < dt.Table.Rows.Count; j++)
{
DataView dvOnSame = SameKeyword("UnNum", dt.Table.Rows[j]["Id2"].ToString());
dtSame = dvOnSame.ToTable();

//计算Excel中的数据与查询出数据出现相同的次数
string Same_Msg = "日志: " + dt.Table.Rows[j]["Id2"].ToString() + " 重复出现:【" + dtSame.Rows.Count.ToString() + "】次\r\n";
sw_Same.WriteLine(Same_Msg);
}
sw.Close();
fs.Close();
sw_Same.Close();
fs_Same.Close();

System.Diagnostics.Process.Start(@"D:\\LogFile\\");
}
else
{
MessageBox.Show("请选择Excel文件!");
}
}
}
#endregion
回复
相关推荐
发帖
非技术区
创建于2007-09-28

7707

社区成员

.NET技术 非技术区
申请成为版主
帖子事件
创建了帖子
2010-09-17 05:23
社区公告
暂无公告