| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Windows.Forms;
- using System.Xml;
- namespace UAS_XmlAnalysor
- {
- public partial class Form1 : Form
- {
- DataHelper dh = new DataHelper();
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- FolderPath.Text = Properties.Settings.Default.FolderPath;
- BackUpFolderPath.Text = Properties.Settings.Default.BackUpFolderPath;
- }
- private void StartWatch_Click(object sender, EventArgs e)
- {
- if (!dh.CheckExist("source", "sc_code='" + Source.Text + "' and sc_statuscode='AUDITED'"))
- {
- OperateResult.AppendText("岗位资源错误或者未审核\n");
- return;
- }
- XmlWatcher.Path = FolderPath.Text;
- XmlWatcher.Filter = "*.xml";
- XmlWatcher.Created += new FileSystemEventHandler(XmlWatcher_Created);
- XmlWatcher.EnableRaisingEvents = true;
- Properties.Settings.Default.FolderPath = FolderPath.Text;
- Properties.Settings.Default.BackUpFolderPath = BackUpFolderPath.Text;
- Properties.Settings.Default.Save();
- Source.Enabled = false;
- OperateResult.AppendText("开始执行监控\n");
- }
- private void XmlWatcher_Created(object sender, FileSystemEventArgs e)
- {
- while (true)
- {
- try
- {
- using (Stream stream = File.Open(e.FullPath, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
- {
- if (stream != null)
- break;
- }
- System.Threading.Thread.Sleep(500);
- }
- catch (Exception)
- {
- }
- }
- XmlReader myReader = XmlReader.Create(FolderPath.Text + @"\" + e.Name);
- string sncode = e.Name.Split('.')[0];
- OperateResult.AppendText("读取文件" + e.Name + "\n");
- List<string> name = new List<string>();
- List<string> result = new List<string>();
- int name_or_result = 0;
- while (myReader.Read())
- {
- if (myReader.NodeType == XmlNodeType.Text)
- {
- if (name_or_result % 2 == 0)
- {
- name.Add(myReader.Value);
- name_or_result++;
- }
- else
- {
- result.Add(myReader.Value);
- name_or_result++;
- }
- }
- }
- string sql = "insert into STEPTESTDETAIL(std_id,std_sn,std_subclass1,std_testresult,std_date,std_rescode) values (STEPTESTDETAIL_seq.nextval,'" + sncode + "',:std_subclass1,:std_testresult,sysdate,'" + Source.Text + "')";
- dh.BatchInsert(sql, new string[] { "std_subclass1", "std_testresult" }, name.ToArray(), result.ToArray());
- myReader.Close();
- FileInfo file = new FileInfo(FolderPath.Text + @"\" + e.Name);
- if (file.Exists)
- {
- try
- {
- file.MoveTo(BackUpFolderPath.Text + @"\" + e.Name);
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.Message);
- }
- }
- }
- private void StopWatch_Click(object sender, EventArgs e)
- {
- XmlWatcher.EnableRaisingEvents = false;
- Source.Enabled = true;
- OperateResult.AppendText("停止执行监控\n");
- }
- private void Clean_Click(object sender, EventArgs e)
- {
- OperateResult.Clear();
- }
- private void ChooseFolder_Click(object sender, EventArgs e)
- {
- FolderBrowserDialog folder = new FolderBrowserDialog();
- folder.Description = "选择监控文件夹";
- DialogResult result = folder.ShowDialog();
- if (result == DialogResult.OK)
- {
- FolderPath.Text = folder.SelectedPath;
- }
- }
- private void ReadNodeFromXML(string FileName)
- {
- }
- private void ChooseBackUpFolder_Click(object sender, EventArgs e)
- {
- FolderBrowserDialog folder = new FolderBrowserDialog();
- folder.Description = "选择备份文件夹";
- DialogResult result = folder.ShowDialog();
- if (result == DialogResult.OK)
- {
- BackUpFolderPath.Text = folder.SelectedPath;
- }
- }
- }
- }
|