嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 2 元微信扫码支付:2 元
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using System.IO;
using System.Threading;
namespace ReNameFile
{
public partial class MainForm : Form
{
public readonly string SourePath = ConfigurationManager.AppSettings["SourePath"];
public readonly string TargetPath = ConfigurationManager.AppSettings["TargetPath"];
public readonly string Keyword = ConfigurationManager.AppSettings["Keyword"];
DataSet1.DataTable1DataTable dt = new DataSet1.DataTable1DataTable();
public MainForm()
{
InitializeComponent();
}
private void MainForm_Load(object sender, EventArgs e)
{
}
private void btn_add_Click(object sender, EventArgs e)
{
string partNo = txt_partno.Text.Trim();
if (string.IsNullOrEmpty(partNo))
{
MessageBox.Show("请输入料号名称!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
txt_partno.Focus();
return;
}
string FilePath = SourePath.EndsWith(@"\") ? SourePath partNo : SourePath @"\" partNo;
if (!Directory.Exists(FilePath))
{
MessageBox.Show("输入的料号名称不正确,请重新输入!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
txt_partno.Focus();
txt_partno.SelectAll();
return;
}
if (dt.Rows.Count >= 10)
{
MessageBox.Show("每次最多只能操作10个料号!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
if (dt.Select("partno='" partNo "'").Length > 0)
{
MessageBox.Show("已经存在" partNo "料号,请重新输入!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
txt_partno.Focus();
txt_partno.SelectAll();
return;
}
DataSet1.DataTable1Row row = dt.NewDataTable1Row();
row.PartNo = partNo;
row.SourePath = FilePath @"\" Keyword @"\";
row.TargetPath = TargetPath @"\" partNo @"\";
dt.Rows.Add(row);
dataGridView1.DataSource = dt;
txt_partno.Text=string.Empty;
txt_partno.Focus();
// CopyDir(FilePath @"\film", TargetPath @"\" partNo @"\");
}
private static void CopyDir(string sourePath, string trgetPath)
{
if (!Directory.Exists(trgetPath))
{
Directory.CreateDirectory(trgetPath);
}
string[] files = Directory.GetFileSystemEntries(sourePath);
foreach (string file in files)
{
if (Directory.Exists(file))
{
CopyDir(file, trgetPath Path.GetFileName(file) Path.DirectorySeparatorChar);
}
else
{
File.Copy(file, trgetPath Path.GetFileName(file), true);
}
}
}
private void dataGridView1_RowStateChanged(object sender, DataGridViewRowStateChangedEventArgs e)
{
e.Row.HeaderCell.Value = string.Format("{0}", e.Row.Index 1);
}
private void btn_change_Click(object sender, EventArgs e)
{
if (backgroundWorker1.IsBusy != true)
{
progressBar1.Value = 0;
progressBar1.Maximum = dt.Rows.Count;
backgroundWorker1.WorkerReportsProgress = true;
backgroundWorker1.RunWorkerAsync();
}
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
int count=0;
foreach (DataSet1.DataTable1Row row in dt.Rows)
{
count ;
CopyDir(row.SourePath, row.TargetPath);
backgroundWorker1.ReportProgress(count);
}
MessageBox.Show("");
}
private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
progressBar1.Value=e.ProgressPercentage;
}
private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
Thread.Sleep(100);
dt.Rows.Clear();
MessageBox.Show("工程资料传送完成!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}