public void WriteFixedIDs(string FolderPath, string FileName) { string fileName = Path.Combine(FolderPath, FileName); var file2UnknownID_Datas = File2Datas.Where((data) => ErrorIDs.Contains(data.ID)); file2UnknownID_Datas.ToList().Sort((a, b) => a.ID.CompareTo(b.ID)); //fixed foreach (var item in file2UnknownID_Datas) { var data = File1Datas.FirstOrDefault((_data) => _data.Name == item.Name); if (data != null) { item.ID = data.ID; item.Dep = data.Dep; } } file2UnknownID_Datas.ToList().Sort((a, b) => a.Dep.CompareTo(b.Dep)); using (var file = new StreamWriter(File.OpenWrite(fileName), Encoding.UTF8)) { file.WriteLine(File2Fields); foreach (var item in file2UnknownID_Datas) { var data = File1Datas.FirstOrDefault((_data) => _data.Name == item.Name); if (data != null) { file.WriteLine(item.ToString()); } } } }
public void FixedOkIDsDep() { OKFile2Datas.Clear(); OKFile2Datas.AddRange(File2Datas.Where((data) => OkIDs.Contains(data.ID))); foreach (var data in OKFile2Datas) { data.Dep = File1Datas.First((item) => item.ID == data.ID).Dep; data.Name = File1Datas.First((item) => item.ID == data.ID).Name; } }
public void WriteUnKnownIDs_SortByID(string FolderPath, string FileName) { string fileName = Path.Combine(FolderPath, FileName); var file2UnknownID_Datas = File2Datas.Where((data) => ErrorIDs.Contains(data.ID)); file2UnknownID_Datas.ToList().Sort((a, b) => a.ID.CompareTo(b.ID)); using (var file = new StreamWriter(File.OpenWrite(fileName), Encoding.UTF8)) { file.WriteLine(File2Fields); foreach (var item in file2UnknownID_Datas) { if (int.TryParse(item.ID, out int _id)) { file.WriteLine(item.ToString()); } } } }