private DataTable GetFileTable(string path) { List <string> fileList = new List <string>(); fileList.Clear(); fileList = Mca.GetMcaList(path); DataTable dataTable = new DataTable(); dataTable.Columns.Add("状态", Type.GetType("System.String")); dataTable.Columns.Add("数量", Type.GetType("System.String")); dataTable.Columns.Add("文件名", Type.GetType("System.String")); foreach (string file in fileList) { //int index = this.dataGridView1.Rows.Add(); //this.dataGridView1.Rows[index].Cells[0].Value = "未合并"; //this.dataGridView1.Rows[index].Cells[0].Style.BackColor = Color.Yellow; //this.dataGridView1.Rows[index].Cells[1].Value = mca.GetFileLinesCount(file) - 2; //this.dataGridView1.Rows[index].Cells[2].Value = mca.GetFileName(file); DataRow row = dataTable.NewRow(); row[0] = "未合并"; row[1] = Mca.GetFileLineCount(file) - 2; row[2] = Mca.GetFileName(file); dataTable.Rows.Add(row); } return(dataTable); }
string combineMcaPath = "";//全局变量保存临时合并mca的路径,所有线程执行完毕之后删除。 private void btnCereate_Click(object sender, EventArgs e) { if (txtFindData.Text == "") { return; } if (txtSourceData.Text == "") { return; } //保存路径 //string combineMca = "Combine" + Path.GetFileNameWithoutExtension(txtSourceData.Text) + ".tmp"; //string filePath = Path.GetDirectoryName(txtSourceData.Text); combineMcaPath = Path.Combine(txtSourceData.Text, "Combine.tmp"); //获取mca文件列表 List <string> sourceFiles = Mca.GetMcaList(txtSourceData.Text); Mca.CombineMCA(sourceFiles, combineMcaPath); //获取补卡卡号文件列表 FileHandle fileHandle = new FileHandle(txtFindData.Text); List <string> findFiles = fileHandle.GetFileList("*.*"); Threadcounts = findFiles.Count;//补卡文件总和 //同时开启多线程工作 foreach (string files in findFiles) { myPath mypath = new myPath(); mypath.pathone = combineMcaPath; //txtSourceData.Text; mypath.pathtwo = files; //txtFindData.Text; Thread t = new Thread(FindDataAll); t.Start(mypath); } //string path=TrimMca(txtFindData.Text); //MessageBox.Show(path); }
private void AddListViewItems(string path) { lvList.Items.Clear(); if (path.Trim() == "") { return; } List <string> fileLists = Mca.GetMcaList(path); int count = 0; //数据更新,UI暂时挂起,直到EndUpdate绘制控件,可以有效避免闪烁并大大提高加载速度 this.lvList.BeginUpdate(); foreach (string file in fileLists) { count++; ListViewItem lvi = new ListViewItem(); lvi.Text = count.ToString(); lvi.SubItems.Add(Mca.GetFileName(file)); lvi.SubItems.Add((Mca.GetFileLineCount(file) - 2).ToString()); lvList.Items.Add(lvi); } this.lvList.EndUpdate();//结束数据处理,UI界面一次性绘制。 }