//loop through all pages/controls in the database and generate a template from it. public void GenerateTemplateFile(int formID) { DataAccess oDataAccess = new DataAccess(); FQDNN_Form oForm = oDataAccess.GetFullForm(formID); oForm.FQDNN_FormSetting.ToList(); string FormTemplateName = oForm.FormID.ToString(); if (!String.IsNullOrEmpty(oForm.FormTemplate)) { FormTemplateName = oForm.FormTemplate; } string FormTemplatePath = CommonLogic.PathToTemplates + FormTemplateName + ".ascx"; StringBuilder sb = new StringBuilder(); sb.Append("<%@ Control Language=\"C#\" AutoEventWireup=\"true\" Inherits=\"HristoEvtimov.DNN.Modules.FormsQuestionnaireDNN.Components.FormBase\" %>" + NewLine); foreach (FQDNN_FormPage oFormPage in oForm.FQDNN_FormPage) { sb.Append(String.Format("<!-- PAGE {0} START -->", oFormPage.PageNumber) + NewLine); if (oFormPage.FQDNN_FormControl.Count > 0) { int maxColumn = oFormPage.FQDNN_FormControl.Max(c => c.Column); int maxRow = oFormPage.FQDNN_FormControl.Max(c => c.Row); List<FQDNN_FormControl> oControls = oFormPage.FQDNN_FormControl.ToList(); sb.Append(String.Format("<asp:Panel ID=\"{0}\" runat=\"server\">", oFormPage.GetControlID()) + NewLine); sb.Append("<table>" + NewLine); for (int currentRow = 1; currentRow <= maxRow; currentRow++) { sb.Append("<tr>" + NewLine); for (int currentColumn = 1; currentColumn <= maxColumn; currentColumn++) { sb.Append("<td>" + NewLine); sb.Append(GetControlMarkup(oControls, currentRow, currentColumn) + NewLine); sb.Append("</td>" + NewLine); } sb.Append("</tr>" + NewLine); } sb.Append("</table>" + NewLine); sb.Append(String.Format("<asp:Button ID=\"{0}\" runat=\"server\" ResourceKey=\"PreviousPage\"/>", oFormPage.GetPreviousPageControlID()) + NewLine); sb.Append(String.Format("<asp:Button ID=\"{0}\" runat=\"server\" ResourceKey=\"NextPage\"/>", oFormPage.GetNextPageControlID()) + NewLine); sb.Append("</asp:Panel>" + NewLine); } sb.Append(String.Format("<!-- PAGE {0} END -->", oFormPage.PageNumber) + NewLine); } sb.Append(String.Format("<asp:Button ID=\"{0}\" runat=\"server\" ResourceKey=\"Submit\"/>", oForm.GetSubmitButtonControlID()) + NewLine); sb.Append(String.Format("<asp:Panel ID=\"{0}\" runat=\"server\" ><asp:Label ID=\"lblGenericMessage\" ResourceKey=\"lblGenericMessage\" runat=\"server\"/></asp:Panel>", oForm.GetGenericMessageControlID()) + NewLine); StreamWriter writer = new StreamWriter(HttpContext.Current.Server.MapPath(FormTemplatePath)); writer.Write(sb.ToString()); writer.Close(); }
private void SetupForm() { DataAccess oDataAccess = new DataAccess(); FQDNN_Form oForm = oDataAccess.GetFullForm(FormID); FQDNN_FormPage oCurrentPage = null; TotalPages = oForm.FQDNN_FormPage.Count; //find current page foreach (FQDNN_FormPage oFormPage in oForm.FQDNN_FormPage) { this.FindControl(oFormPage.GetControlID()).Visible = false; if (oFormPage.PageNumber == PageNumber) { oCurrentPage = oFormPage; } } if (oCurrentPage != null) { SetupPage(oForm, oCurrentPage); } //display or hide the submit button this.FindControl(oForm.GetSubmitButtonControlID()).Visible = false; if (PageNumber == TotalPages) { FormSettings oFormSettings = new FormSettings(); if (oFormSettings.GetRedirectAction(oForm.FQDNN_FormSetting.ToList()) != FormSettings.FormRedirectActions.LastPageIsFinal) { this.FindControl(oForm.GetSubmitButtonControlID()).Visible = true; ((Button)this.FindControl(oForm.GetSubmitButtonControlID())).Click += SubmitForm; } } //display final generic message if there is not redirect or last page System.Web.UI.Control GenericMessageControl = this.FindControl(oForm.GetGenericMessageControlID()); if (GenericMessageControl != null) { GenericMessageControl.Visible = false; if (PageNumber == GenericMessagePageNumber) { GenericMessageControl.Visible = true; } } }
private void SavePage() { DataAccess oDataAccess = new DataAccess(); FQDNN_Form oForm = oDataAccess.GetFullForm(FormID); FQDNN_FormPage oCurrentPage = null; foreach (FQDNN_FormPage oFormPage in oForm.FQDNN_FormPage) { if (oFormPage.PageNumber == PageNumber) { oCurrentPage = oFormPage; break; } } if (oCurrentPage != null) { FQDNN_FormFiling oFormFiling = GetCurrentFormFilingFromViewState(oForm); if (oFormFiling == null) { CommonLogic oCommonLogic = new CommonLogic(); oFormFiling = oDataAccess.InsertNewFiling(Request.Browser.Browser, oCommonLogic.GetUserIPAddress(), false, Request.Browser.Platform, UserId, oForm.FormID); } if (oFormFiling != null) { //loop through each control on page and save the result. List<FQDNN_FormFilingRecord> oNewFilingRecords = new List<FQDNN_FormFilingRecord>(); foreach (FQDNN_FormControl oFormControl in oCurrentPage.FQDNN_FormControl) { System.Web.UI.Control control = this.FindControl(oFormControl.GetControlID()); if (control != null) { Type type = control.GetType(); FQDNN_FormFilingRecord oNewFilingRecord = new FQDNN_FormFilingRecord(); oNewFilingRecord.FormControlID = oFormControl.FormControlID; oNewFilingRecord.FormPageID = oCurrentPage.FormPageID; PropertyInfo valuePropery = type.GetProperty(oFormControl.FQDNN_ControlDefinition.ValuePropertyName); if (valuePropery != null) { oNewFilingRecord.Value = valuePropery.GetValue(control, null).ToString(); } oNewFilingRecords.Add(oNewFilingRecord); } } oDataAccess.InsertFilingRecords(oNewFilingRecords, oFormFiling.FormFilingID); } } }
protected void SubmitForm(object sender, EventArgs e) { SavePage(); DataAccess oDataAccess = new DataAccess(); FQDNN_Form oForm = oDataAccess.GetFullForm(FormID); FormSettings oFormSettings = new FormSettings(); FormSettings.FormRedirectActions redirection = oFormSettings.GetRedirectAction(oForm.FQDNN_FormSetting.ToList()); //perform different redirects after submitting form if (redirection == FormSettings.FormRedirectActions.RedirectToUrl) { string redirectUrl = oFormSettings.GetRedirectUrlAfterFiling(oForm.FQDNN_FormSetting.ToList()); if(!String.IsNullOrEmpty(redirectUrl)) { Response.Redirect(redirectUrl); } else { redirection = FormSettings.FormRedirectActions.GenericFinishedMessage; } } if (redirection == FormSettings.FormRedirectActions.RedirectToTab) { int redirectTabID = oFormSettings.GetRedirectTabAfterFiling(oForm.FQDNN_FormSetting.ToList()); if (redirectTabID > 0) { Response.Redirect(DotNetNuke.Common.Globals.NavigateURL(redirectTabID)); } else { redirection = FormSettings.FormRedirectActions.GenericFinishedMessage; } } if (redirection == FormSettings.FormRedirectActions.GenericFinishedMessage) { PageNumber = GenericMessagePageNumber; SetupForm(); } }
/// ----------------------------------------------------------------------------- /// <summary> /// Page_Load runs when the control is loaded /// </summary> /// ----------------------------------------------------------------------------- private void Page_Load(object sender, System.EventArgs e) { try { //check settings to decide which form to load if(Settings["FormGUID"] != null) { DataAccess oDataAccess = new DataAccess(); FQDNN_Form Form = oDataAccess.GetActiveForm(Settings["FormGUID"].ToString(), new CommonLogic().GetCurrentLocale(), PortalId, PortalSettings.DefaultLanguage); if (Form != null) { Form = oDataAccess.GetFullForm(Form.FormID); FormSettings oFormSettings = new FormSettings(); //load the form and place it on this page if the user is allowed to file. if (UserCanFileForm(UserInfo, Form)) { string FormTemplateName = Form.FormID.ToString(); if (!String.IsNullOrEmpty(Form.FormTemplate)) { FormTemplateName = Form.FormTemplate; } string FormTemplatePath = CommonLogic.PathToTemplates + FormTemplateName + ".ascx"; FormBase Template = (FormBase)LoadControl(FormTemplatePath); Template.ModuleConfiguration = this.ModuleConfiguration; Template.LocalResourceFile = this.LocalResourceFile; Template.FormID = Form.FormID; this.Controls.Add(Template); } } } } catch (Exception exc) //Module failed to load { Exceptions.ProcessModuleLoadException(this, exc); } }