123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- using Microsoft.Win32;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Diagnostics;
- using System.IO;
- using System.Net;
- using System.Text;
- using System.Threading;
- using System.Windows.Forms;
- namespace FileWatcher
- {
- public partial class 测试记录解析DCW : Form
- {
- DataHelper dh = new DataHelper();
- ftpOperater ftp = new ftpOperater();
- public 测试记录解析DCW()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- timer1.Interval = 1000 * 10;
- OperateResult.AppendText("连接上服务器\n");
- //timer1.Start();
- }
- public void DoLog(string Message)
- {
- try
- {
- StreamWriter sw = File.AppendText(DateTime.Now.ToString("yyyy-MM-dd") + ".txt");
- sw.WriteLine("\n【时间】" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + Message + "\n");
- sw.Close();
- }
- catch (Exception) { }
- }
- /// <summary>
- /// 私有变量
- /// </summary>
- private List<FileInfo> lst = new List<FileInfo>();
- /// <summary>
- /// 获得目录下所有文件或指定文件类型文件(包含所有子文件夹)
- /// </summary>
- /// <param name="path">文件夹路径</param>
- /// <param name="extName">扩展名可以多个 例如 .mp3.wma.rm</param>
- /// <returns>List<FileInfo></returns>
- public List<FileInfo> getFile(string path, string extName)
- {
- getdir(path, extName);
- return lst;
- }
- /// <summary>
- /// 私有方法,递归获取指定类型文件,包含子文件夹
- /// </summary>
- /// <param name="path"></param>
- /// <param name="extName"></param>
- private void getdir(string path, string extName)
- {
- try
- {
- string[] dir = Directory.GetDirectories(path); //文件夹列表
- DirectoryInfo fdir = new DirectoryInfo(path);
- FileInfo[] file = fdir.GetFiles();
- //FileInfo[] file = Directory.GetFiles(path); //文件列表
- if (file.Length != 0 || dir.Length != 0) //当前目录文件或文件夹不为空
- {
- string SN = "";
- string folderpath = "";
- foreach (FileInfo f in file) //显示当前目录所有文件
- {
- string filename = f.FullName;
- if (filename.Substring(filename.LastIndexOf(".") + 1).ToUpper() == "INI")
- {
- folderpath = f.FullName.Substring(0, f.FullName.LastIndexOf(@"\"));
- SN = f.Name.Split('.')[0].ToUpper().Split('_')[0];
- //if (SN.Length == 12)
- //{
- try
- {
- string ftppath = "/" + DateTime.Now.ToString("yyyy-MM-dd") + "/";
- ftp.UpLoadFile(folderpath, f.Name, ftppath, "");
- int dt = int.Parse(dh.ExecuteSql("insert into STEPTESTDETAIL (std_id,std_sn,std_makecode,std_indate,std_class)values( STEPTESTDETAIL_seq.nextval,'" + SN + "','" + ma_code.Text + "',sysdate,'http://81.71.42.91:8099/ftp" + ftppath + f.Name + "')", "insert").ToString());
- if (dt > 0)
- {
- OperateResult.AppendText("序列号:" + SN + "上传成功\n");
- }
- //else
- //{
- // OperateResult.AppendText("序列号: " + SN + "前工段未扫描\n");
- // MessageBox.Show("序列号: " + SN + "前工段未扫描", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
- //}
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.Message);
- }
- File.Delete(f.FullName);
- //}
- }
- }
- }
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.Message);
- }
- }
- private void timer1_Tick(object sender, EventArgs e)
- {
- try
- {
- getFile(FolderPath.Text, ".txt");
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.Message);
- }
- }
- /// <summary>
- /// 获得目录下所有文件或指定文件类型文件(包含所有子文件夹)
- /// </summary>
- /// <param name="path">文件夹路径</param>
- /// <param name="extName">扩展名可以多个 例如 .mp3.wma.rm</param>
- /// <returns>List<FileInfo></returns>
- public static List<FileInfo> getFile(string path, string extName, List<FileInfo> lst)
- {
- try
- {
- string[] dir = Directory.GetDirectories(path); //文件夹列表
- DirectoryInfo fdir = new DirectoryInfo(path);
- FileInfo[] file = fdir.GetFiles();
- //FileInfo[] file = Directory.GetFiles(path); //文件列表
- if (file.Length != 0 || dir.Length != 0) //当前目录文件或文件夹不为空
- {
- foreach (FileInfo f in file) //显示当前目录所有文件
- {
- if (extName.ToLower().IndexOf(f.Extension.ToLower()) >= 0)
- {
- lst.Add(f);
- }
- }
- foreach (string d in dir)
- {
- getFile(d, extName, lst);//递归
- }
- }
- return lst;
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- 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 ChooseBackUpFolder_Click(object sender, EventArgs e)
- {
- FolderBrowserDialog folder = new FolderBrowserDialog();
- folder.Description = "选择备份文件夹";
- DialogResult result = folder.ShowDialog();
- if (result == DialogResult.OK)
- {
- // BackUpFolderPath.Text = folder.SelectedPath;
- }
- }
- private void Start_Click(object sender, EventArgs e)
- {
- if (!dh.CheckExist("make", "ma_code='" + ma_code.Text + "'"))
- {
- OperateResult.AppendText("工单" + ma_code.Text + "不存在\n");
- return;
- }
- timer1.Start();
- }
- }
- }
|