123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using WordAnalyze;
- using Logger = Log.Log;
- namespace WindowsFormsApp1
- {
- public partial class Form1 : Form
- {
- private WordAnalyze.Analyze Analyzer = null;
- public Form1()
- {
- InitializeComponent();
- // 初始化处理文档对象
- Analyzer = new WordAnalyze.Analyze();
- Logger.Init("log.log");
- init_listView();
- init_textBox();
- }
- // 初始化显示的列表
- private void init_listView()
- {
- listView1.View = View.Details;
- Console.WriteLine(listView1.Columns.Count);
-
- // 第一列,文件名
- if (0 == listView1.Columns.Count)
- {
- listView1.Columns.Add("文件名");
- Console.WriteLine(listView1.Columns.Count);
- }
- Console.WriteLine(listView1.Columns.Count);
- listView1.Columns[0].Text = "文件名";
- listView1.Columns[0].Width = 200;
- listView1.Columns[0].TextAlign = HorizontalAlignment.Left;
- // 第二列,状态
- if (1 == listView1.Columns.Count)
- {
- listView1.Columns.Add("状态");
- }
- listView1.Columns[1].Text = "状态";
- listView1.Columns[1].Width = 50;
- listView1.Columns[1].TextAlign = HorizontalAlignment.Left;
- // 第三列,错误信息,成功则忽略
- if (2 == listView1.Columns.Count)
- {
- listView1.Columns.Add("信息");
- }
- listView1.Columns[2].Text = "信息";
- listView1.Columns[2].Width = 300;
- listView1.Columns[2].TextAlign = HorizontalAlignment.Left;
- }
- // 初始化存储文件夹的显示框
- private void init_textBox()
- {
- textBox1.Enabled = false;
- }
- private bool start_stop = false;
- // 开始处理word文档
- private void button1_Click(object sender, EventArgs e)
- {
- if (fileNames == null || fileNames.Length < 1)
- {
- Logger.D("event start, but no file to analyse");
- return;
- }
- button1.Enabled = false;
- listview_draw(fileNames);
- for (int i = 0; i < fileNames.Length; i ++)
- {
- execStatus(i);
- Logger.D("startanalyze with filename({0})", fileNames[i]);
- if (listView1.Items.Count < i + 1)
- {
- Logger.D("analyze with filename({0}) success but item with index({1}) is unexpected", fileNames[i], i);
- continue;
- }
- if (listView1.Items[i].SubItems.Count != 3)
- {
- Logger.D("analyze with filename({0}) success but item with index({1}) contain unexpected subitem length({2})", fileNames[i], i, listView1.Items[i].SubItems.Count);
- continue;
- }
- var result = Analyzer.AnalyzeFile(fileNames[i]);
- string status = "成功";
- if (result != "")
- {
- status = "失败";
- }
- listView1.Items[i].SubItems[1].Text = status;
- listView1.Items[i].SubItems[2].Text = result;
- Logger.D("analyze with filename({0}) success with result({1})", fileNames[i], result);
- }
- button1.Enabled = true;
- }
- private void folderBrowserDialog1_HelpRequest(object sender, EventArgs e)
- {
- }
- private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
- {
- }
- private void button2_Click(object sender, EventArgs e)
- {
- // 选择文件
- OpenFileDialog openFileDialog = new OpenFileDialog();
- openFileDialog.Filter = "doc files (*.doc)|*.doc| docx files (*.docx)|*.docx";
- openFileDialog.Multiselect = true;
- openFileDialog.Title = "选择doc或者docx文件";
- if (openFileDialog.ShowDialog() == DialogResult.OK)
- {
- fileNames = openFileDialog.FileNames;
- // 先清空列表,再渲染列表
- listview_draw(fileNames);
- }
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- }
- private void listview_draw(string[] fileNames)
- {
- listView1.Items.Clear();
- for (int i = 0; i < fileNames.Length; i++)
- {
- ListViewItem item = new ListViewItem();
- item.Text = fileNames[i];
- item.SubItems.Add("等待中");
- item.SubItems.Add("");
- listView1.Items.Add(item);
- }
- }
- private void execStatus(int index)
- {
- var item = listView1.Items[index];
- item.SubItems[1].Text = "执行中";
- }
- private void listView1_SelectedIndexChanged(object sender, EventArgs e)
- {
-
- }
- private void button3_Click(object sender, EventArgs e)
- {
- FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();
- if(folderBrowserDialog.ShowDialog() == DialogResult.OK)
- {
- AimFolder = folderBrowserDialog.SelectedPath;
- textBox1.Text = AimFolder;
- Analyzer.SetPath(AimFolder);
- }
- }
- private void textBox1_TextChanged(object sender, EventArgs e)
- {
- }
- }
- }
|