protected void AddQuestionBtn_Click(object sender, EventArgs e) { // Determine the TypeOption string TypeOption; if (this.RdBtnRadio.Checked) { TypeOption = "RD"; } else { TypeOption = "CH"; } // new question go to the end of the list QuestionItem t = new QuestionItem(); t.QuestionName = this.txtNewQuestion.Text; t.QuestionID = -1; t.QuestionOrder = 999; portalQuestion.Add(t); // write tab to database SurveyDB NewQuestion = new SurveyDB(); t.QuestionID = NewQuestion.AddQuestion(ModuleID, t.QuestionName, t.QuestionOrder, TypeOption); // Reset the order numbers for the tabs within the list OrderQuestions(); // Redirect to edit page Response.Redirect(Request.RawUrl); }
//private void AddOptionBtn_Click( System.object sender, System.EventArgs e) AddOptionBtn.Click { protected void AddOptionBtn_Click(object sender, EventArgs e) { // Determine QuestioID int QuestionID = 0; // get { QuestionID from querystring if (!(Request.Params["QuestionID"] == null)) { QuestionID = int.Parse(Request.Params["QuestionID"]); } // new option go to the end of the list OptionItem o = new OptionItem(); o.OptionName = this.TxtNewOption.Text; o.OptionID = -1; o.OptionOrder = 999; portalOption.Add(o); // write tab to database SurveyDB NewOption = new SurveyDB(); o.OptionID = NewOption.AddOption(QuestionID, o.OptionName, o.OptionOrder); // Reset the order numbers for the tabs within the list OrderOptions(); // Redirect to edit page Response.Redirect(Request.RawUrl); }
private void Page_Load(object sender, System.EventArgs e) { if (!Page.IsPostBack) { // Set the ImageUrl for controls from current Theme upBtn.ImageUrl = this.CurrentTheme.GetImage("Buttons_Up", "Up.gif").ImageUrl; downBtn.ImageUrl = this.CurrentTheme.GetImage("Buttons_Down", "Down.gif").ImageUrl; deleteBtn.ImageUrl = this.CurrentTheme.GetImage("Buttons_Delete", "Delete.gif").ImageUrl; } //TBD: Create a sproc that gets these fields: //CreatedBy.Text = (string) dr["CreatedByUser"]; //CreatedDate.Text = ((DateTime) dr["CreatedDate"]).ToShortDateString(); // get { QuestionID from querystring if (!(Request.Params["QuestionID"] == null)) { int QuestionID = 0; QuestionID = int.Parse(Request.Params["QuestionID"]); SurveyDB OptList = new SurveyDB(); SqlDataReader OList = OptList.GetOptionList(QuestionID); try { while (OList.Read()) { OptionItem o = new OptionItem(); o.OptionName = OList["OptionDesc"].ToString(); o.OptionID = (int)OList["OptionID"]; o.OptionOrder = (int)OList["ViewOrder"]; portalOption.Add(o); } } finally { OList.Close(); //by Manu, fixed bug 807858 } if (!Page.IsPostBack) { this.OptionList.DataTextField = "OptionName"; this.OptionList.DataValueField = "OptionID"; this.OptionList.DataSource = portalOption; this.OptionList.DataBind(); this.lblQuestion.Text = Request.Params["Question"]; if (Request.Params["TypeOption"] == "RD") { this.lblTypeOption.Text = Esperantus.Localize.GetString("SURVEY_RADIOBUTTONS", "Radio buttons", this); } else { this.lblTypeOption.Text = Esperantus.Localize.GetString("SURVEY_CHECKBOXES", "Checkboxes", this); } } } }
private void Page_Load(object sender, System.EventArgs e) { if (!Page.IsPostBack) { // Set the ImageUrl for controls from current Theme upBtn.ImageUrl = this.CurrentTheme.GetImage("Buttons_Up", "Up.gif").ImageUrl; downBtn.ImageUrl = this.CurrentTheme.GetImage("Buttons_Down", "Down.gif").ImageUrl; editBtn.ImageUrl = this.CurrentTheme.GetImage("Buttons_Edit", "Edit.gif").ImageUrl; deleteBtn.ImageUrl = this.CurrentTheme.GetImage("Buttons_Delete", "Delete.gif").ImageUrl; } //********************************************************* // Checks whether the survey exist, if not it creates one //********************************************************* SurveyDB SurveyCheck = new SurveyDB(); // puts the desc of Survey in the title this.lblDescSurvey.Text = SurveyCheck.ExistAddSurvey(ModuleID, PortalSettings.CurrentUser.Identity.Email); //TBD: Create a sproc that gets these fields: //CreatedBy.Text = (string) dr["CreatedByUser"]; //CreatedDate.Text = ((DateTime) dr["CreatedDate"]).ToShortDateString(); // Fill the Question Listbox SurveyDB QuestionList = new SurveyDB(); SqlDataReader QList = QuestionList.GetQuestionList(ModuleID); try { while (QList.Read()) { QuestionItem t = new QuestionItem(); t.QuestionName = QList["Question"].ToString(); t.QuestionID = (int)QList["QuestionID"]; t.QuestionOrder = (int)QList["ViewOrder"]; t.TypeOption = QList["TypeOption"].ToString(); portalQuestion.Add(t); } } finally { QList.Close(); //by Manu, fixed bug 807858 } // if ( this is the first visit to the page, bind the tab data to the page listbox if (Page.IsPostBack == false) { this.QuestionList.DataTextField = "QuestionName"; this.QuestionList.DataValueField = "QuestionID"; this.QuestionList.DataSource = portalQuestion; this.QuestionList.DataBind(); } }
public void SubmitButton_Click(object sender, System.EventArgs e) { Array ArrRadioButton = (Array)ViewState["arrRadioButton"]; Array ArrCheckButton = (Array)ViewState["arrCheckButton"]; int MaxRdIndex = (int)ViewState["MaxRdIndex"]; Array arrRadioQuestionID = (Array)ViewState["arrRadioQuestionID"]; Array arrRadioOptionID = (Array)ViewState["arrRadioOptionID"]; int MaxChIndex = (int)ViewState["MaxChIndex"]; Array arrCheckQuestionID = (Array)ViewState["arrCheckQuestionID"]; Array arrCheckOptionID = (Array)ViewState["arrCheckOptionID"]; for (int i = 1; i <= MaxRdIndex; i++) { RadioButton RadioButtonID = new RadioButton(); RadioButtonID = (RadioButton)SurveyHolder.Controls[((int)(ArrRadioButton.GetValue(i))) - 1]; if (RadioButtonID.Checked) { // get { The QuestionID and OptionID int QuestionID = (int)arrRadioQuestionID.GetValue(i); int OptionID = (int)arrRadioOptionID.GetValue(i); int SurveyID = (int)ViewState["SurveyID"]; SurveyDB AddAnswer = new SurveyDB(); AddAnswer.AddAnswer(SurveyID, QuestionID, OptionID); } } for (int j = 1; j <= MaxChIndex; j++) { CheckBox CheckButtonID = new CheckBox(); CheckButtonID = (CheckBox)SurveyHolder.Controls[((int)(ArrCheckButton.GetValue(j))) - 1]; if (CheckButtonID.Checked) { int QuestionID = (int)arrCheckQuestionID.GetValue(j); int OptionID = (int)arrCheckOptionID.GetValue(j); int SurveyID = (int)ViewState["SurveyID"]; SurveyDB AddAnswer = new SurveyDB(); AddAnswer.AddAnswer(SurveyID, QuestionID, OptionID); } } // Store a cookie to show the chart after the submit string CookieName = "Survey" + ModuleID.ToString(); Response.Cookies[CookieName].Value = ViewState["SurveyID"].ToString(); Response.Cookies[CookieName].Expires = DateTime.Now.AddDays(VoteDayPeriod); Response.Redirect(ViewState["URL"].ToString()); }
//******************************************************* // // The DeleteBtn_Click server event handler is used to delete // the selected question // //******************************************************* protected void DeleteBtn_Click(object sender, ImageClickEventArgs e) { if (QuestionList.SelectedIndex != -1) { // must delete from database too QuestionItem t = (QuestionItem)portalQuestion[QuestionList.SelectedIndex]; SurveyDB DelQuestion = new SurveyDB(); DelQuestion.DelQuestion(t.QuestionID); // remove item from list portalQuestion.RemoveAt(QuestionList.SelectedIndex); // reorder list OrderQuestions(); // Redirect to this site to refresh Response.Redirect(Request.RawUrl); } }
protected void deleteBtn_Click(object sender, System.Web.UI.ImageClickEventArgs e) { OptionItem o; o = (OptionItem)portalOption[OptionList.SelectedIndex]; SurveyDB DelOpt = new SurveyDB(); DelOpt.DelOption(o.OptionID); // remove item from list portalOption.RemoveAt(OptionList.SelectedIndex); // reorder list OrderOptions(); // Redirect to this site to refresh Response.Redirect(Request.RawUrl, false); }
//******************************************************* // // The OrderQuestions helper method is used to reset the display // order for the questions // //*******************************************************// void OrderQuestions() { int i = 1; // sort the arraylist portalQuestion.Sort(); // renumber the order and save to database foreach (QuestionItem t in portalQuestion) { // number the items 1, 3, 5, etc. to provide an empty order // number when moving items up and down in the list. t.QuestionOrder = i; i += 2; // rewrite tab to database SurveyDB Order = new SurveyDB(); Order.UpdateQuestionOrder(t.QuestionID, t.QuestionOrder); } // t }
private void Page_Load(object sender, System.EventArgs e) { test = int.Parse(Settings["Test"].ToString()); VoteDayPeriod = int.Parse(Settings["VoteDayPeriod"].ToString()); // Creation of the Survey - Begin // It uses cookies to find out whether the user has already done it string CookieName = "Survey" + ModuleID.ToString(); if (test == 1) { CookieName += "Test"; } if (Request.Cookies[CookieName] == null) { // Finds the dimension of the arrays SurveyDB DimArray = new SurveyDB(); int DimArrRadio = DimArray.GetDimArray(ModuleID, "RD"); DimArrRadio = DimArrRadio + 1; int DimArrCheck = DimArray.GetDimArray(ModuleID, "CH"); DimArrCheck = DimArrCheck + 1; // Declaration of the ARRAYS Array ArrRadioButton = Array.CreateInstance(typeof(Int32), DimArrRadio); Array ArrCheckButton = Array.CreateInstance(typeof(Int32), DimArrCheck); Array arrRadioQuestionID = Array.CreateInstance(typeof(Int32), DimArrRadio); Array arrRadioOptionID = Array.CreateInstance(typeof(Int32), DimArrRadio); Array arrCheckQuestionID = Array.CreateInstance(typeof(Int32), DimArrCheck); Array arrCheckOptionID = Array.CreateInstance(typeof(Int32), DimArrCheck); // Indexes of the Arrays int i = 0; int j = 0; int ControlIndex = 0; if (SurveyHolder.Controls.Count > 0) { ControlIndex = SurveyHolder.Controls.Count; } SurveyDB Questions = new SurveyDB(); SqlDataReader result = Questions.GetQuestions(ModuleID); bool FirstTime = true; int GroupQuestionPrev = 0; bool GetSurveyID = true; try { while (result.Read()) // Reads the list one-by-one { if (GetSurveyID) { ViewState["SurveyID"] = (int)result["SurveyID"]; GetSurveyID = false; } if (!FirstTime) { if (GroupQuestionPrev != (int)result["QuestionID"]) { Label lbl = new Label(); lbl.Visible = true; lbl.Text = "<br />" + result["Question"].ToString(); lbl.CssClass = "SurveyQuestion"; SurveyHolder.Controls.Add(lbl); ControlIndex = ControlIndex + 1; SurveyHolder.Controls.Add(new LiteralControl("<br /><br />")); ControlIndex = ControlIndex + 1; GroupQuestionPrev = (int)result["QuestionID"]; } } else { Label lbl = new Label(); lbl.Visible = true; lbl.Text = "<br />" + result["Question"].ToString(); lbl.CssClass = "SurveyQuestion"; SurveyHolder.Controls.Add(lbl); ControlIndex = ControlIndex + 1; SurveyHolder.Controls.Add(new LiteralControl("<br /><br />")); ControlIndex = ControlIndex + 1; GroupQuestionPrev = (int)result["QuestionID"]; FirstTime = false; } // Finds the Type of Option if (result["TypeOption"].ToString() == "RD") { i++; RadioButton RdButton = new RadioButton(); RdButton.ID = "RdButton_" + i.ToString(); RdButton.GroupName = "Option_" + GroupQuestionPrev.ToString(); RdButton.Text = result["OptionDesc"].ToString(); RdButton.CssClass = "SurveyOption"; SurveyHolder.Controls.Add(RdButton); ControlIndex = ControlIndex + 1; // Save RadioButton position ArrRadioButton.SetValue(ControlIndex, i); arrRadioQuestionID.SetValue((int)result["QuestionID"], i); arrRadioOptionID.SetValue((int)result["OptionID"], i); // Adds a Literal SurveyHolder.Controls.Add(new LiteralControl("<br>")); ControlIndex = ControlIndex + 1; } else { j++;; CheckBox ChButton = new CheckBox(); ChButton.ID = "ChButton_" + j.ToString(); ChButton.Text = result["OptionDesc"].ToString(); ChButton.CssClass = "SurveyOption"; SurveyHolder.Controls.Add(ChButton); ControlIndex++; // Saves Checkbox position ArrCheckButton.SetValue(ControlIndex, j); arrCheckQuestionID.SetValue((int)result["QuestionID"], j); arrCheckOptionID.SetValue((int)result["OptionID"], j); // Adds a literal SurveyHolder.Controls.Add(new LiteralControl("<br>")); ControlIndex++; } } } finally { result.Close(); //by Manu, fixed bug 807858 } // Checks whether the Survey exist SurveyDB SurveyCheck = new SurveyDB(); int RowCount = 0; RowCount = SurveyCheck.ExistSurvey(ModuleID); if (RowCount > 0) { SurveyHolder.Controls.Add(new LiteralControl("<br />")); ControlIndex = ControlIndex + 1; SubmitButton = new LinkButton(); SubmitButton.ID = "Submit"; SubmitButton.Text = Esperantus.Localize.GetString("SURVEY_SUBMIT", "Submit", this); SubmitButton.CssClass = "SurveyButton"; SurveyHolder.Controls.Add(SubmitButton); this.SubmitButton.Click += new System.EventHandler(this.SubmitButton_Click); } ViewState["arrRadioButton"] = ArrRadioButton; ViewState["arrRadioQuestionID"] = arrRadioQuestionID; ViewState["arrRadioOptionID"] = arrRadioOptionID; ViewState["MaxRdIndex"] = i; ViewState["arrCheckButton"] = ArrCheckButton; ViewState["arrCheckQuestionID"] = arrCheckQuestionID; ViewState["arrCheckOptionID"] = arrCheckOptionID; ViewState["MaxChIndex"] = j; ViewState["URL"] = Request.Url.AbsoluteUri; } else { // Creation of Chart Survey - Begin int SurveyID = int.Parse(Request.Cookies[CookieName].Value); SurveyDB Answers = new SurveyDB(); SqlDataReader result = Answers.GetAnswers(SurveyID); bool FirstTime = true; int GroupQuestionPrev = 0; int tot = 0; float perc; try { while (result.Read()) // Reads the list one-by-one { if (!FirstTime) // Shows the Question { if (GroupQuestionPrev != (int)result["QuestionID"]) { Label lbl = new Label(); lbl.Visible = true; lbl.Text = result["Question"].ToString(); lbl.CssClass = "SurveyQuestion"; SurveyHolder.Controls.Add(lbl); SurveyHolder.Controls.Add(new LiteralControl("<br /><br />")); GroupQuestionPrev = (int)result["QuestionID"]; tot = GetTotAnswer(SurveyID, GroupQuestionPrev); // get the tot } } else { Label lbl = new Label(); lbl.Visible = true; lbl.Text = result["Question"].ToString(); lbl.CssClass = "SurveyQuestion"; SurveyHolder.Controls.Add(lbl); SurveyHolder.Controls.Add(new LiteralControl("<br /><br />")); GroupQuestionPrev = (int)result["QuestionID"]; FirstTime = false; tot = GetTotAnswer(SurveyID, GroupQuestionPrev); } if (tot == 0) { perc = 0; } else { perc = (float.Parse(result["Num"].ToString()) / (float)tot) * 100; } // Shows the AnswerOptions Panel Pan = new Panel(); Pan.CssClass = "SurveyPanel"; Pan.Visible = true; Pan.Width = System.Web.UI.WebControls.Unit.Percentage(perc); SurveyHolder.Controls.Add(Pan); Label lblOptDesc = new Label(); lblOptDesc.Visible = true; lblOptDesc.Text = result["OptionDesc"].ToString() + " " + perc.ToString("0") + "% " + result["Num"].ToString() + " " + Esperantus.Localize.GetString("SURVEY_VOTES", "votes", this) + "<br />"; lblOptDesc.CssClass = "SurveyOption"; SurveyHolder.Controls.Add(lblOptDesc); SurveyHolder.Controls.Add(new LiteralControl("<br />")); } } finally { result.Close(); //by Manu, fixed bug 807858 } } }