0

我有一个移动功能,可以将文件从一个文件夹移动到另一个文件夹。我想知道如何在对话框中显示移动的文件总数和移动的文件名。或任何想法..!!!!

这里的问题是,一旦我按下移动所有文件移动,如果有一些重复的文件,它会在我的网格视图中显示错误消息.. 其余文件开始不断移动。因此,一旦移动了所有文件,我就需要一种方法..我需要显示一个对话框,其中包含移动的文件总数和在对话框中移动的文件名..这可能..或任何想法..请发布..

我真的很感激..

我的代码:

 private void button3_Click(object sender, EventArgs e)
{
    update = false;
    this.Enabled = false;
    backgroundWorker2.RunWorkerAsync();
    move();
    backgroundWorker2.CancelAsync();
    System.Threading.Thread.Sleep(500);
    this.Enabled = true;
    update = true;
}

public void move()
{
    update = false;
    string archieve_path = ini.ReadValue("Location", "Archive");
    string release_path = ini.ReadValue("Location", "Release");
    string draft_path = ini.ReadValue("Location", "Draft");
    for (int i = 0; i < dataGridView1.Rows.Count; i++)
    {
        if ((!String.IsNullOrEmpty(dataGridView1.Rows[i].Cells["Draft Path"].Value.ToString()) && String.IsNullOrEmpty(dataGridView1.Rows[i].Cells["Release Path"].Value.ToString())) &&
            (dataGridView1.Rows[i].Cells[0].Value != null && (bool)dataGridView1.Rows[i].Cells[0].Value))
        {
            string draftpath = dataGridView1.Rows[i].Cells["Draft Path"].Value.ToString();
            string relasepath = dataGridView1.Rows[i].Cells["Release Path"].Value.ToString();
            string archievepath = dataGridView1.Rows[i].Cells["Archive"].Value.ToString();
            string draftname = System.IO.Path.GetFileName(draftpath);
            if (relasepath != string.Empty && draftname.Equals(Path.GetFileName(relasepath), StringComparison.OrdinalIgnoreCase))
            {
                dataGridView1.Rows[i].Cells["Error"].Value = "Duplicate in Release: " + draftname + "";
                dataGridView1.Rows[i].Cells["Error"].Style = new DataGridViewCellStyle { ForeColor = Color.Red };
                continue;
            }
            if (archievepath != string.Empty && draftname.Equals(Path.GetFileName(archievepath), StringComparison.OrdinalIgnoreCase))
            {
                dataGridView1.Rows[i].Cells["Error"].Value = "Duplicate in Archive: " + draftname + "";
                dataGridView1.Rows[i].Cells["Error"].Style = new DataGridViewCellStyle { ForeColor = Color.Red };
                continue;
            }
            string newpath = System.IO.Path.Combine(release_path, draftname);
            System.IO.File.Move(draftpath, newpath);
            dataGridView1.Rows[i].Cells["Release Path"].Value = newpath;
            dataGridView1.Rows[i].Cells["Draft Path"].Value = string.Empty;
            dataGridView1.Rows[i].Cells[0].Value = false; //Checkbox
        }
        if ((!String.IsNullOrEmpty(dataGridView1.Rows[i].Cells["Draft Path"].Value.ToString())
            && !String.IsNullOrEmpty(dataGridView1.Rows[i].Cells["Release Path"].Value.ToString())) &&
            (dataGridView1.Rows[i].Cells[0].Value != null && (bool)dataGridView1.Rows[i].Cells[0].Value))
        {
            string draftPath = dataGridView1.Rows[i].Cells["Draft Path"].Value.ToString();
            string releasepath = dataGridView1.Rows[i].Cells["Release Path"].Value.ToString();
            string archievepath = dataGridView1.Rows[i].Cells["Archive"].Value.ToString();
            string draftname = System.IO.Path.GetFileName(draftPath);
            string archievename = System.IO.Path.GetFileName(archievepath);
            string releasename = System.IO.Path.GetFileName(releasepath);
            if (archievepath != string.Empty && draftname.Equals(Path.GetFileName(archievepath), StringComparison.OrdinalIgnoreCase))
            {
                dataGridView1.Rows[i].Cells["Error"].Value = "Duplicate in Archive: " + draftname + "";
                dataGridView1.Rows[i].Cells["Error"].Style = new DataGridViewCellStyle { ForeColor = Color.Red };
                continue;
            }
            if (releasepath != string.Empty && draftname.Equals(Path.GetFileName(releasepath), StringComparison.OrdinalIgnoreCase))
            {
                dataGridView1.Rows[i].Cells["Error"].Value = "Duplicate in Release: " + draftname + "";
                dataGridView1.Rows[i].Cells["Error"].Style = new DataGridViewCellStyle { ForeColor = Color.Red };
                continue;
            }
            if (archievepath != string.Empty && releasename.Equals(Path.GetFileName(archievepath), StringComparison.OrdinalIgnoreCase))
            {
                dataGridView1.Rows[i].Cells["Error"].Value = "Duplicate in Archive: " + releasename + "";
                dataGridView1.Rows[i].Cells["Error"].Style = new DataGridViewCellStyle { ForeColor = Color.Red };
                continue;
            }
            string fName1 = System.IO.Path.GetFileNameWithoutExtension(draftPath);
            string fName2 = System.IO.Path.GetFileNameWithoutExtension(releasepath);
            string fName3 = System.IO.Path.GetFileNameWithoutExtension(archievepath);
            var f1 = GetValue(fName1.ToCharArray()[fName1.Length - 2]) * 16 + GetValue(fName1.ToCharArray()[fName1.Length - 1]);
            var f2 = GetValue(fName2.ToCharArray()[fName2.Length - 2]) * 16 + GetValue(fName2.ToCharArray()[fName2.Length - 1]);
            // var f3 = GetValue(fName3.ToCharArray()[fName3.Length - 2]) * 16 + GetValue(fName3.ToCharArray()[fName3.Length - 1]);
            if (f1 > f2)//till here
            {
                //moves from realse to archieve
                string newpath = System.IO.Path.Combine(archieve_path, releasename); //draft name + archieve
                System.IO.File.Move(releasepath, newpath);
                dataGridView1.Rows[i].Cells["Release Path"].Value = string.Empty;
            }
            if (f1 < f2)
            {
                //moves draft to archieve
                string newpath = System.IO.Path.Combine(archieve_path, draftname);
                System.IO.File.Move(draftPath, newpath);
                dataGridView1.Rows[i].Cells["Draft Path"].Value = string.Empty;
                return;
            }
            string newpath1 = System.IO.Path.Combine(release_path, draftname);
            System.IO.File.Move(draftPath, newpath1);
            dataGridView1.Rows[i].Cells["Release Path"].Value = newpath1;
            dataGridView1.Rows[i].Cells["Draft Path"].Value = string.Empty;
            dataGridView1.Rows[i].Cells[0].Value = false; //Checkbox
        }
    }
    update = true;
}

添加代码:

 StringBuilder sbBody = new StringBuilder();
        List<string> lstFiles = new List<string>();

foreach (string file in Directory.GetFiles(newpath, "*.txt"))
                {
                    // msg.Attachments.Add(new System.Net.Mail.Attachment(file));
                    lstFiles.Add(file);
                }
4

1 回答 1

0

我会认为这是一个骗局,但显然不是。无论如何,这是大纲。

向 中添加一个ProgressChanged事件backgroundWorker2,并让它也运行move()(这将需要重写函数以将所有更新 UI 的代码拆分为ProgressChanged委托调用)。在事件处理程序中,使用参数中新修改的计数和文件名数据更新 UI。

于 2014-12-24T06:03:18.263 回答