Method DeleteTester should delete line with selected tester from TestingCompany.txt If the tester is already assigned into Equipment tester shouldn't be deleted.
My code doesn't work properly. When tester is assigned to equipment it shows error message "This testing company is assigned to Equipment" and delete tester. Tester shouldn't be deleted.
public void DeleteTester(string testerData)
{
string line_to_delete = testerData;
string[] line_to_Delete_Array= theEntity.setString(line_to_delete);
string testerToDelete = line_to_Delete_Array[0];
foreach (var line in File.ReadLines(@"C:\\Temp\\Equipment.txt"))
if (line.EndsWith(testerToDelete, StringComparison.CurrentCultureIgnoreCase))
{
MessageBox.Show("This testing company is assigned to Equipment", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
string strFilePath = @"C:\\Temp\\TestingCompany.txt";
string strSearchText = testerData;
string strOldText;
string n = "";
StreamReader sr = File.OpenText(strFilePath);
while ((strOldText = sr.ReadLine()) != null)
{
if (!strOldText.Contains(strSearchText))
{
n += strOldText + Environment.NewLine;
}
}
sr.Close();
File.WriteAllText(strFilePath, n);
}
}
Aucun commentaire:
Enregistrer un commentaire