123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.IO;
- using System.Text;
- using System.Windows.Forms;
- namespace MOTINOVA_Motor_Factory_Set
- {
- public partial class ManageForm : Form
- {
- public string FilePath = "";//文件路径
- public ManageForm()
- {
- InitializeComponent();
- }
- private void ManageForm_Load(object sender, EventArgs e)
- {
- groupBox_File.Visible = true;
- button_Delete.Visible = true;
- button_OpenFile.Visible = true;
- richTextBox1.Visible = false;
-
- if (System.IO.Directory.Exists(FilePath) == false)
- System.IO.Directory.CreateDirectory(FilePath);
- ListDate(FilePath);
- }
- private void ListDate(string path)
- {
- if (System.IO.Directory.Exists(path) == false)
- {
- System.IO.Directory.CreateDirectory(path);
- }
- //装载配置文件日期列表
- string[] DateList = { "" };
- DateList = System.IO.Directory.GetDirectories(path);
- comboBox_Date.Items.Clear();
- foreach (var file in DateList)
- {
- comboBox_Date.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
- }
- }
- private void ListFileRefresh(string path)
- {
- var files = Directory.GetFiles(path, "*.ttcfg");
- listBox_File.Items.Clear();
- foreach (var file in files)
- {
- listBox_File.Items.Add(Path.GetFileName(file));
- }
- if (listBox_File.Items.Count != 0)
- listBox_File.SelectedIndex = 0;
- }
- private void button_Delete_Click(object sender, EventArgs e)
- {
- try
- {
- string SelectFile;
- SelectFile = listBox_File.SelectedItem.ToString();
- //删除选中文件
- if (MessageBox.Show("确认删除?", "确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
- {
- File.Delete(FilePath + "\\" + comboBox_Date.Text + "\\" + SelectFile);
- //删除其它相关文件
- string extFileName = "";
- extFileName = SelectFile.Split('_')[0] + "_" + SelectFile.Split('_')[1] + "_" + SelectFile.Split('_')[6] + "_" + (SelectFile.Split('_')[7].Substring(0, SelectFile.Split('_')[7].LastIndexOf(".")) + ".pdf");
- File.Delete(FilePath + "\\" + comboBox_Date.Text + "\\" + extFileName);
- extFileName = SelectFile.Split('_')[0] + "_" + SelectFile.Split('_')[1] + "_" + SelectFile.Split('_')[6] + "_" + (SelectFile.Split('_')[7].Substring(0, SelectFile.Split('_')[7].LastIndexOf(".")) + ".xls");
- File.Delete(FilePath + "\\" + comboBox_Date.Text + "\\" + extFileName);
- if (System.IO.Directory.Exists(FilePath) == false)
- System.IO.Directory.CreateDirectory(FilePath);
- ListFileRefresh(FilePath + "\\" + comboBox_Date.Text);
- }
- }
- catch
- {
- MessageBox.Show("请选择文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- finally
- {
-
- }
-
- }
- private void button_OpenFile_Click(object sender, EventArgs e)
- {
- if (button_OpenFile.Text == "查看")
- {
- button_OpenFile.Text = "隐藏";
- button_Delete.Visible = false;
- richTextBox1.Visible = true;
- richTextBox1.Text = "";
- //读取选择文件
- try
- {
- string SelectFile;
- if (listBox_File.Items.Count == 0)
- {
- MessageBox.Show("无可用文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- button_OpenFile.Text = "查看";
- button_Delete.Visible = true;
- richTextBox1.Visible = false;
- richTextBox1.Text = "";
- return;
- }
- if (listBox_File.SelectedItems.Count == 0)
- {
- MessageBox.Show("请选择文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- button_OpenFile.Text = "查看";
- button_Delete.Visible = true;
- richTextBox1.Visible = false;
- richTextBox1.Text = "";
- return;
- }
- SelectFile = listBox_File.SelectedItem.ToString();
- richTextBox1.Text += "文件名称:" + SelectFile + "\r\n";
- //打开选中文件
- StreamReader objReader = new StreamReader(FilePath + "\\" + comboBox_Date.Text + "\\" + SelectFile);
- string sLine = "";
- ArrayList arrText = new ArrayList();//创建一个动态数组
- while (sLine != null)
- {
- sLine = objReader.ReadLine();
- arrText.Add(sLine);
- }
- objReader.Close();
- richTextBox1.Text = "";
- foreach (string sOutput in arrText)
- {
- richTextBox1.Text += sOutput + "\r\n";
- }
- }
- catch
- {
- MessageBox.Show("请选择文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- button_OpenFile.Text = "查看";
- button_Delete.Visible = true;
- richTextBox1.Visible = false;
- richTextBox1.Text = "";
- }
- finally
- {
- }
- }
- else if (button_OpenFile.Text == "隐藏")
- {
- button_OpenFile.Text = "查看";
- button_Delete.Visible = true;
- richTextBox1.Visible = false;
- richTextBox1.Text = "";
- }
- }
- private void comboBox_Date_SelectionChangeCommitted(object sender, EventArgs e)
- {
- ListFileRefresh(FilePath + "\\" + comboBox_Date.SelectedItem.ToString());
- }
- private void button_SetPath_Click(object sender, EventArgs e)
- {
- string path = textBox_LocalPath.Text;
- string cfg_file = System.IO.Directory.GetCurrentDirectory() + "\\UserPath";
- StreamReader objReader = new StreamReader(cfg_file);
- ArrayList arrText = new ArrayList();//创建一个动态数组
- objReader.Close();
- arrText.Add("logPath =" + path);
- using (StreamWriter file = new StreamWriter(cfg_file))
- {
- foreach (var entry in arrText)
- {
- file.WriteLine(entry);
- }
- }
- MessageBox.Show("路径已设置,软件重启后生效!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- private void textBox_LocalPath_Click(object sender, EventArgs e)
- {
- textBox_LocalPath.SelectAll();
- }
- }
- }
|