private void button12_Click(object sender, EventArgs e) { access.Open(); if (this.dataGridView1.SelectedRows.Count == -1) { return; } //更新数据库名称 foreach (DataGridViewRow item in this.dataGridView1.SelectedRows) { string newName = item.Cells["Name2"].Value.ToString(); string MD5 = item.Cells["MD5"].Value.ToString(); string DataType = item.Cells["Type1"].Value.ToString(); bool IsDel = Convert.ToBoolean(item.Cells["IsDel"].Value); //更新Del状态 access.UpdateAccess("update " + DataType + " set [IsDel] = " + IsDel + " where [MD5] = '" + MD5 + "'"); //如果Name2为空,则跳过 if (newName.Replace(" ", "") == "") { continue; } //更新数据库文件名 access.UpdateAccess("update " + DataType + " set [Name] = '" + newName + "' where [MD5] = '" + MD5 + "'"); } //更新Datatable文件名称(所有行) Name IsDel foreach (DataGridViewRow item in this.dataGridView1.Rows) { string MD5 = item.Cells["MD5"].Value.ToString(); string DataType = item.Cells["Type1"].Value.ToString(); access.AccessType AT = access.CheckData("", DataType, MD5); string Name = AT.Name; item.Cells["Name1"].Value = Name; string newName = item.Cells["Name2"].Value.ToString(); if (Name == newName) { item.Cells["Name2"].Value = ""; } item.Cells["IsDel"].Value = AT.isDel; } access.Close(); }
//检查文件是否存在数据库 private void button10_Click(object sender, EventArgs e) { access.Open(); int n = 0; this.listBoxMD5.Items.Clear(); for (int i = 0; i < this.listBoxFile.Items.Count; i++) { string path = this.listBoxFile.Items[i].ToString(); //校验MD5数值 string MD5 = CodeAll.GetMD5(path); //检查数据库是否存在 string DataType = "G"; access.AccessType AT = access.CheckData(path, DataType, MD5); if (AT == null) { DataType = "F"; AT = access.CheckData(path, DataType, MD5); } if (AT == null) { DataType = "J"; AT = access.CheckData(path, DataType, MD5); } if (AT == null) { DataType = "TV"; AT = access.CheckData(path, DataType, MD5); } if (AT == null)//不存在,添加listboxMD5值 { this.listBoxMD5.Items.Add(MD5); n++; } else//存在,从listboxfile中移除,并添加Datatable { this.listBoxFile.Items.RemoveAt(i); i--; FileInfo fi = new FileInfo(path); string Size = fi.Length.ToString(); string NewName = ""; if (AT.Name != System.IO.Path.GetFileNameWithoutExtension(path)) { NewName = System.IO.Path.GetFileNameWithoutExtension(path); } this.dataGridView1.Rows.Add( AT.isDel, AT.Name, NewName, DataType, GetDataType(), AT.Size, Size, MD5, path ); } this.label2.Text = n.ToString() + "/" + this.listBoxFile.Items.Count.ToString(); Application.DoEvents(); } //检查MD5数量和文件数量 if (this.listBoxMD5.Items.Count != this.listBoxFile.Items.Count) { MessageBox.Show("MD5数据数量和文件不一致"); } //检查MD5是否有重复 List <string> lst = new List <string>(); CheckSameMD5List(); access.Close(); }