public bool Submit() { var success = true; var id = string.IsNullOrEmpty(hidQuestionId.Value) ? Guid.NewGuid() : Guid.Parse(hidQuestionId.Value); try { using (var dataContext = new nChangerDb()) { var question = new DefineQuestion() { Id = id, ProvinceCategoryId = string.IsNullOrEmpty(hidProvinceCategoryId.Value)?Guid.Parse(ddlCategoryAdd.SelectedValue):Guid.Parse(hidProvinceCategoryId.Value), Question = hidQuestion.Value, QuestionType = hidQuestionType.Value, DataSource = string.IsNullOrEmpty(hidPreset.Value)?null:hidPreset.Value, IsActive =true, EntryDate = DateTime.Now, EntryIP = CommonFunctions.GetIpAddress(), EntryId = UserId, }; dataContext.DefineQuestions.AddOrUpdate(question); #region Options... dataContext.Database.ExecuteSqlCommand("DELETE FROM QuestionOptions WHERE DefineQuestionsId='" + id + "'"); if (!string.IsNullOrEmpty(hidOptions.Value)) { if (!hidOptions.Value.Contains(",")) { var option = new QuestionOption { Id = Guid.NewGuid(), DefineQuestionsId = id, OptionLabel = hidOptions.Value, EntryDate = DateTime.Now, EntryIP = CommonFunctions.GetIpAddress(), EntryId = UserId, IsActive = true }; dataContext.QuestionOptions.AddOrUpdate(option); } else { var optionsArray = hidOptions.Value.EndsWith(",")? hidOptions.Value.Substring(0, hidOptions.Value.Length - 1).Split(','): hidOptions.Value.Split(','); foreach (var option in optionsArray.Select(item => new QuestionOption { Id = Guid.NewGuid(), DefineQuestionsId = id, OptionLabel = item, EntryDate = DateTime.Now, EntryIP = CommonFunctions.GetIpAddress(), EntryId = UserId, IsActive = true })) { dataContext.QuestionOptions.AddOrUpdate(option); } } } #endregion Package Features... dataContext.SaveChanges(); lblMsg.Text = "Question " + (string.IsNullOrEmpty(hidQuestionId.Value) ? "added" : "updated") + " successfully."; ScriptManager.RegisterStartupScript(this, this.GetType(), Guid.NewGuid().ToString(), "showAlert()", true); } } catch (DbEntityValidationException ex) { lblMsg.Text = ex.Message; success = false; } return success; }
private void GenerateRadioButton(DefineQuestion question) { var row = new HtmlTableRow(); row.Attributes.Add("class", "field"); var cellControl = new HtmlTableCell(); if (question.QuestionOptions == null) return; if (question.QuestionOptions.Count > 1) { var rdList = new RadioButtonList { ID = question.Id.ToString().Substring(0, 8), RepeatDirection=RepeatDirection.Horizontal, RepeatColumns=2 }; rdList.Attributes.Add("Question",question.Question); rdList.Attributes.Add("DB_ID", question.Id.ToString()); foreach (var option in question.QuestionOptions) { rdList.Items.Add(new ListItem { Text = option.OptionLabel, Value = option.Id.ToString() }); } cellControl.InnerHtml ="<label>"+ question.Question+ "</label>"; cellControl.Controls.Add(rdList); } else { QuestionOption first = question.QuestionOptions.FirstOrDefault(); var radio = new RadioButton { ID = question.Id.ToString().Substring(0, 8), Text=first.OptionLabel, }; cellControl.Controls.Add(radio); } row.Cells.Add(cellControl); tblFields.Rows.Add(row); }
private void GenerateDropdown(DefineQuestion question) { var dataContext = new nChangerDb(); var row = new HtmlTableRow(); row.Attributes.Add("class", "field"); var cellControl = new HtmlTableCell(); var ddl = new DropDownList { ID = question.Id.ToString().Substring(0, 8), CssClass= "ui fluid search selection dropdown" }; ddl.Attributes.Add("DB_ID", question.Id.ToString()); ddl.Attributes.Add("Question", question.Question); if (question.QuestionOptions.Count > 1) { foreach (var option in question.QuestionOptions.OrderBy(q => q.EntryDate)) { ddl.Items.Add(new ListItem { Text=option.OptionLabel, Value = option.OptionLabel, }); } } else if(!string.IsNullOrEmpty(question.DataSource) && question.DataSource!="SEL") { switch (question.DataSource) { case "COUNTRIES": ddl.DataSource = GetCountriesList(); ddl.DataBind(); ddl.Items.Insert(0, new ListItem("--SELECT--", "SEL")); break; case "US_STATES": ddl.DataSource = dataContext.States.Where(s => s.CountryId.Equals("US")).OrderBy(s => s.StateName).ToList(); ddl.DataTextField = "StateName"; ddl.DataValueField = "StateId"; ddl.DataBind(); ddl.Items.Insert(0, new ListItem("--SELECT--", "SEL")); break; case "CN_STATES": ddl.DataSource = dataContext.States.Where(s => s.CountryId.Equals("CA")).OrderBy(s => s.StateName).ToList(); ddl.DataTextField = "StateName"; ddl.DataValueField = "StateId"; ddl.DataBind(); ddl.Items.Insert(0, new ListItem("--SELECT--", "SEL")); break; case "US_STATES_CN_STATES": ddl.DataSource = dataContext.States.Where(s => s.CountryId.Equals("CA") || s.CountryId.Equals("US")).OrderBy(s => s.StateName).ToList(); ddl.DataTextField = "StateName"; ddl.DataValueField = "StateId"; ddl.DataBind(); ddl.Items.Insert(0, new ListItem("--SELECT--", "SEL")); break; case "MONTH": ddl.DataSource = DateTimeFormatInfo.CurrentInfo.MonthNames.ToList(); ddl.DataBind(); ddl.Items.Insert(0, new ListItem("--SELECT--", "SEL")); break; case "YEARS": ddl.DataSource = GetYears(); ddl.DataBind(); ddl.Items.Insert(0, new ListItem("--SELECT--", "SEL")); break; } } var lbl = new HtmlGenericControl("label") {InnerText = question.Question}; cellControl.Controls.Add(lbl); cellControl.Controls.Add(ddl); row.Cells.Add(cellControl); tblFields.Rows.Add(row); }
private void GenerateTextBox(DefineQuestion question) { var row = new HtmlTableRow(); row.Attributes.Add("class", "field"); var cellControl = new HtmlTableCell(); var txt = new TextBox { ID = question.Id.ToString().Substring(0, 8), MaxLength = 500 }; txt.Attributes.Add("placeholder", question.Question); txt.Attributes.Add("DB_ID", question.Id.ToString()); cellControl.Controls.Add(txt); row.Cells.Add(cellControl); tblFields.Rows.Add(row); }