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(); }
protected void GrdTreatmentTemplateLetters_RowUpdating(object sender, GridViewUpdateEventArgs e) { Label lblId = (Label)GrdTreatmentTemplateLetters.Rows[e.RowIndex].FindControl("lblId"); DropDownList ddlField = (DropDownList)GrdTreatmentTemplateLetters.Rows[e.RowIndex].FindControl("ddlField"); DropDownList ddlFirstLetter = (DropDownList)GrdTreatmentTemplateLetters.Rows[e.RowIndex].FindControl("ddlFirstLetter"); DropDownList ddlLastLetter = (DropDownList)GrdTreatmentTemplateLetters.Rows[e.RowIndex].FindControl("ddlLastLetter"); DropDownList ddlLastLetterWhenReplacingEPC = (DropDownList)GrdTreatmentTemplateLetters.Rows[e.RowIndex].FindControl("ddlLastLetterWhenReplacingEPC"); DropDownList ddlLastLetterPT = (DropDownList)GrdTreatmentTemplateLetters.Rows[e.RowIndex].FindControl("ddlLastLetterPT"); DropDownList ddlTreatmentNoteLetter = (DropDownList)GrdTreatmentTemplateLetters.Rows[e.RowIndex].FindControl("ddlTreatmentNoteLetter"); DataTable dt = Session["treatment_template_letters_data"] as DataTable; DataRow[] foundRows = dt.Select("lettertreatmenttemplate_letter_treatment_template_id=" + lblId.Text); DataRow thisRow = foundRows[0]; LetterTreatmentTemplateDB.Update( Convert.ToInt32(lblId.Text), Convert.ToInt32(thisRow["lettertreatmenttemplate_field_id"]), Convert.ToInt32(ddlFirstLetter.SelectedValue), Convert.ToInt32(ddlLastLetter.SelectedValue), Convert.ToInt32(ddlLastLetterPT.SelectedValue), Convert.ToInt32(ddlLastLetterWhenReplacingEPC.SelectedValue), Convert.ToInt32(ddlTreatmentNoteLetter.SelectedValue)); GrdTreatmentTemplateLetters.EditIndex = -1; FillGrid(); }
protected void FillGrid() { DataTable dt = LetterTreatmentTemplateDB.GetDataTable(Convert.ToInt32(Session["SiteID"])); Session["treatment_template_letters_data"] = dt; if (dt.Rows.Count > 0) { if (IsPostBack && Session["treatment_template_letters_sortexpression"] != null && Session["treatment_template_letters_sortexpression"].ToString().Length > 0) { DataView dataView = new DataView(dt); dataView.Sort = Session["treatment_template_letters_sortexpression"].ToString(); GrdTreatmentTemplateLetters.DataSource = dataView; } else { GrdTreatmentTemplateLetters.DataSource = dt; } try { GrdTreatmentTemplateLetters.DataBind(); } catch (Exception ex) { HideTableAndSetErrorMessage("", ex.ToString()); } } else { dt.Rows.Add(dt.NewRow()); GrdTreatmentTemplateLetters.DataSource = dt; GrdTreatmentTemplateLetters.DataBind(); int TotalColumns = GrdTreatmentTemplateLetters.Rows[0].Cells.Count; GrdTreatmentTemplateLetters.Rows[0].Cells.Clear(); GrdTreatmentTemplateLetters.Rows[0].Cells.Add(new TableCell()); GrdTreatmentTemplateLetters.Rows[0].Cells[0].ColumnSpan = TotalColumns; GrdTreatmentTemplateLetters.Rows[0].Cells[0].Text = "No Record Found"; } if (GrdTreatmentTemplateLetters.FooterRow != null) { GrdTreatmentTemplateLetters.FooterRow.Visible = !hideFotter; } }
protected void GrdTreatmentTemplateLetters_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName.Equals("Insert")) { DropDownList ddlField = (DropDownList)GrdTreatmentTemplateLetters.FooterRow.FindControl("ddlNewField"); DropDownList ddlFirstLetter = (DropDownList)GrdTreatmentTemplateLetters.FooterRow.FindControl("ddlNewFirstLetter"); DropDownList ddlLastLetter = (DropDownList)GrdTreatmentTemplateLetters.FooterRow.FindControl("ddlNewLastLetter"); DropDownList ddlLastLetterPT = (DropDownList)GrdTreatmentTemplateLetters.FooterRow.FindControl("ddlNewLastLetterPT"); DropDownList ddlLastLetterWhenReplacingEPC = (DropDownList)GrdTreatmentTemplateLetters.FooterRow.FindControl("ddlNewLastLetterWhenReplacingEPC"); DropDownList ddlTreatmentNoteLetter = (DropDownList)GrdTreatmentTemplateLetters.FooterRow.FindControl("ddlNewTreatmentNoteLetter"); LetterTreatmentTemplateDB.Insert( Convert.ToInt32(ddlField.SelectedValue), Convert.ToInt32(ddlFirstLetter.SelectedValue), Convert.ToInt32(ddlLastLetter.SelectedValue), Convert.ToInt32(ddlLastLetterPT.SelectedValue), Convert.ToInt32(ddlLastLetterWhenReplacingEPC.SelectedValue), Convert.ToInt32(ddlTreatmentNoteLetter.SelectedValue), Convert.ToInt32(Session["SiteID"])); FillGrid(); } }
protected void GrdTreatmentTemplateLetters_RowDeleting(object sender, GridViewDeleteEventArgs e) { Label lblId = (Label)GrdTreatmentTemplateLetters.Rows[e.RowIndex].FindControl("lblId"); int letter_treatment_template_id = Convert.ToInt32(lblId.Text); try { LetterTreatmentTemplateDB.Delete(letter_treatment_template_id); } catch (ForeignKeyConstraintException fkcEx) { 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"); } } FillGrid(); }