I have the code below:
if (jumlahiddb < jumlahbuku)
{
DownloadBukuKomik(url);
string KomikUpdate = @"INSERT INTO books (id,title,folder_id,identifier) SELECT " + intID + ",'" + namaFile + ".pdf',67,'" + namaFile +
".pdf' WHERE not exists (select id AND title AND folder_id AND identifier FROM books WHERE id=" + intID + " and title='" + namaFile +
".pdf' AND folder_id=67 and identifier='" + namaFile + ".pdf')";
Debug.WriteLine(KomikUpdate.ToString());
var komikQuery = objConnUpdate.Prepare(KomikUpdate);
komikQuery.Step();
}
else
{
bool shown = false;
if (!shown)
{
MessageDialog messageDialog1 = new MessageDialog("Jumlah komik bertambah sebanyak " + jumlahbuku + " komik pada menu Komik Pendidikan", "Update Berhasil");
messageDialog1.Commands.Add(new UICommand("OK", (command) =>
{
DownloadBukuVideo.IsOpen = false;
Downloading.IsOpen = false;
ukomikBtn.Visibility = Visibility.Visible;
downloadKomikBtn.Visibility = Visibility.Collapsed;
ukomikText.Visibility = Visibility.Collapsed;
ukomikText.Text = "";
shown = true;
}));
await messageDialog1.ShowAsync();
}
I have a problem, that is when I click the OK button, it will display message dialog again. I want message dialog shown only 1 time. How to solve it?
shownvariable is locally scoped to theelsepart of your conditional. Therefore it will be created and set to false every time that piece of code is called. You need to scope it at a higher level if you're going to use that method - without seeing the rest of your code, perhaps as a class-level variable declared outside of the method with the code shown above. As an aside, the way you are concatenating your SQL query opens you up to SQL injection attacks - take a look at how to use parameterised queries instead.