protected void Page_Load(object sender, EventArgs e) { _IssueKey = QueryIssue; _QuestionKey = QueryQuestion; if (!IsPostBack) { H1.InnerText = Page.Title = "Issues and Questions"; if (IsNullOrWhiteSpace(StateCode)) { UpdateControls.Visible = false; NoJurisdiction.CreateStateLinks("/admin/Issues.aspx?state={StateCode}"); NoJurisdiction.ShowHeadOptional(false); NoJurisdiction.Visible = true; return; } try { // Page Title PageTitle.Text = Empty; if (StateCode == "LL") { PageTitle.Text += "<br>All Candidates"; } else if (StateCode == "US") { PageTitle.Text += "<br>National Candidates"; } else { PageTitle.Text += $"<br>{StateCache.GetStateName(StateCode)} Candidates"; } if (!IsNullOrEmpty(_IssueKey)) { PageTitle.Text += $"<br><span style=color:red>{Issue_Desc(_IssueKey)}</span>"; } //On initial entry there is only a StateCode Anchor //Anchors on Issues and Questions Reports have 4 possible query string prameters: //Issue Link => db.QueryString("Issue") //Issue Ok/Omit Link => db.QueryString("Issue") & db.QueryString("Omit") //Question Link => db.QueryString("Issue") & db.QueryString("Question") //Question Ok/Omit Link => db.QueryString("Issue") & db.QueryString("Question") & db.QueryString("Omit") if (IsNullOrEmpty(QueryIssue)) { MakeAllControlsNotVisible(); } else { // Entry from Link on Issues or Question Reports if (IsNullOrEmpty(QueryQuestion) && IsNullOrEmpty(GetQueryString("Omit"))) { // Issue Link to edit issue and/or issue questions MakeAllControlsNotVisible(); Table_Issue_Edit.Visible = true; Table_Question.Visible = true; Table_Questions_Report.Visible = true; TextBox_Issue_Description.Text = Issue_Desc(QueryIssue); TextBox_Issue_Order.Text = Issues.GetIssueOrder(QueryIssue, 0) .ToString(CultureInfo.InvariantCulture); CreateQuestionsReport(); } else if (IsNullOrEmpty(QueryQuestion) && !IsNullOrEmpty(GetQueryString("Omit"))) { // Issue Ok/Omit Link to change status to ok or omit MakeAllControlsNotVisible(); Issues.UpdateIsIssueOmit(GetQueryString("Omit").IsEqIgnoreCase("true"), QueryIssue); } else if (!IsNullOrEmpty(QueryQuestion) && IsNullOrEmpty(GetQueryString("Omit"))) { // Question Link to edit question MakeAllControlsNotVisible(); Table_Question_Edit.Visible = true; Table_Question.Visible = true; Table_Questions_Report.Visible = true; TextBox_Question_Description.Text = Questions.GetQuestion(_QuestionKey); TextBox_Question_Order.Text = Questions.GetQuestionOrder(_QuestionKey, 0) .ToString(CultureInfo.InvariantCulture); RenumberQuestions(); CreateQuestionsReport(); } else if (!IsNullOrEmpty(QueryQuestion) && !IsNullOrEmpty(GetQueryString("Omit"))) { // Question Ok/Omit Link to change status to ok or omit MakeAllControlsNotVisible(); Table_Question.Visible = true; Table_Questions_Report.Visible = true; Questions.UpdateIsQuestionOmit(GetQueryString("Omit").IsEqIgnoreCase("true"), QueryQuestion); RenumberQuestions(); CreateQuestionsReport(); } } RenumberIssues(); // Only Master controls if (IsSuperUser) { Table_Delete_Issue.Visible = true; if (!IsNullOrEmpty(QueryIssue) && IsNullOrEmpty(GetQueryString("Omit"))) { Table_Delete_Question.Visible = true; } } } catch (Exception ex) { Msg.Text = Fail(ex.Message); LogAdminError(ex); } } CreateIssuesReport(); }
// Buttons //Issues protected void ButtonAddIssue_Click(object sender, EventArgs e) { try { CheckForDangerousInput(); if (!Table_Issue_Add.Visible) { // 1st Step in Adding an Issue //Only Add Issue Table Visible Table_Issue_Add.Visible = true; Table_Issue_Edit.Visible = false; TextBox_Issue_Description_Add.Text = Empty; TextBox_Issue_Order_Add.Text = Empty; Msg.Text = Message( "To complete the add, enter the issue description and optional order." + " Then click the 'Add an Issue' Button."); } else { // 2nd Step - Complete the Issue Addition var descripton = TextBox_Issue_Description_Add.Text.Trim(); var order = TextBox_Issue_Order_Add.Text.Trim(); // Checks if (descripton == Empty) { throw new ApplicationException("The Description Textbox is empty."); } if (!IsNullOrEmpty(order) && !order.IsValidInteger()) { throw new ApplicationException( "The Order Textbox needs to be an integer."); } if (descripton.Length > 40) { var tooLongBy = descripton.Length - 40; throw new ApplicationException( "When adding a new issue, the Issue description must be 40 characters" + $" or less. You need to shorten by {tooLongBy} characters"); } // Make IssueKey and check its unique var issueKey = MakeIssueKey(Empty, Empty, descripton.SimpleRecase()); if (Issues.IsValidIssue(issueKey)) { throw new ApplicationException("Issue ({descripton}) already exists"); } _IssueKey = issueKey; // Issue Order var issueOrder = order != Empty ? Convert.ToInt16(order) : 1; // Add the Issue Issues.Insert(_IssueKey, issueOrder, descripton, GetIssueLevelInIssueKey(_IssueKey), StateCode, CountyCode, Empty, false, false); RenumberIssues(); //CreateIssuesReport(); // Edit Issue Table and load Table_Issue_Add.Visible = false; Table_Issue_Edit.Visible = true; TextBox_Issue_Description.Text = Issue_Desc(_IssueKey); TextBox_Issue_Order.Text = Issues.GetIssueOrder(_IssueKey, 0).ToString(CultureInfo.InvariantCulture); Msg.Text = Ok("The issue has been added and is in the report below."); } } catch (Exception ex) { Msg.Text = Fail(ex.Message); LogAdminError(ex); } }