protected void GrdLetter_RowDeleting(object sender, GridViewDeleteEventArgs e) { Label lblId = (Label)GrdLetter.Rows[e.RowIndex].FindControl("lblId"); int letter_id = Convert.ToInt32(lblId.Text); Letter letter = LetterDB.GetByID(letter_id); LetterTreatmentTemplate[] sysLetters = LetterTreatmentTemplateDB.GetAll(); for (int i = 0; i < sysLetters.Length; i++) { if (sysLetters[i].FirstLetter.LetterID == letter_id) { SetErrorMessage("The letter '<b>" + letter.Docname + "</b>' is set as a Referrer '<b>first treatement letter</b>'. <br />Please unset it in menu '<b>Letters</b>' -> '<b>Treatment Letters</b>' before deleting this letter."); return; } if (sysLetters[i].LastLetter.LetterID == letter_id) { SetErrorMessage("The letter '<b>" + letter.Docname + "</b>' is set as a Referrer '<b>last treatment letter</b>'. <br />Please unset it in menu '<b>Letters</b>' -> '<b>Treatment Letters</b>' before deleting this letter."); return; } if (sysLetters[i].LastLetterWhenReplacingEPC.LetterID == letter_id) { SetErrorMessage("The letter '<b>" + letter.Docname + "</b>' is set as a Referrer '<b>last treatement when replacing EPC letter</b>'. <br />Please unset it in menu '<b>Letters</b>' -> '<b>Treatment Letters</b>' before deleting this letter."); return; } if (sysLetters[i].TreatmentNotesLetter.LetterID == letter_id) { SetErrorMessage("The letter '<b>" + letter.Docname + "</b>' is set as a Referrer '<b>treatment notes letter</b>'. <br />Please unset it in menu '<b>Letters</b>' -> '<b>Treatment Letters</b>' before deleting this letter."); return; } } bool canBeDeleted = false; try { LetterDB.Delete(letter_id); canBeDeleted = true; } catch (ForeignKeyConstraintException fkcEx) { //SetErrorMessage("Can not delete this letter because there are letters in the letter history that refer to this letter."); /* * if (Utilities.IsDev()) * SetErrorMessage("Can not delete because other records depend on this : " + fkcEx.Message); * else * SetErrorMessage("Can not delete because other records depend on this"); */ } if (!canBeDeleted) { LetterDB.SetAsDeleted(letter_id, true); } FillGrid(); }