我需要讓用戶菜單,如果該文件存在,將顯示消息,「該文件存在,你想覆蓋?Y/N」我對數據訪問層這個方法,可以」 t發送消息直接表示層。首先,消息將發送到業務層,然後發送到表示層。那麼做這件事的最好方法是什麼?我嘗試了例外情況,但並不高尚,並且效率不高。我能怎麼做?用戶菜單選項
/*This method is in data access layer*/
public void MenuControl(string binaryfilePath)
{
if (File.Exists(binaryFilePath))
{
string overwrite = "-2";
Program.DisplayUserOptionMessage("The file: " + binaryFileName
+ " exist. You want to overwrite it? Y/N");
overwrite = Console.ReadLine();
while (overwrite != null)
{
if (overwrite.ToUpper() == "Y")
{
WriteBinaryFile(frameCodes, binaryFilePath);
break;
}
else if (overwrite.ToUpper() == "N")
{
throw new CustomException("Aborted by User...");
}
else
throw new CustomException("!!Please Select a Valid Option!!");
overwrite = Console.ReadLine();
//continue;
}
}
}