/// <summary> /// /// </summary> /// <param name="ctr"></param> /// <returns></returns> public static ControlRenderMode GetControlRenderMode(Control ctr) { PageRenderMode pageRenderMode = Request.GetRequestPageRenderMode(); ControlRenderMode renderMode = new ControlRenderMode(pageRenderMode); PageRenderModePageCache currentPageCache = PageRenderModeHelper.GetPageRenderModeCache(ctr.Page); PageRenderModePageCache requestPageCache = renderMode.PageCache; int currentPageLevel = GetPageLevel(currentPageCache); string currentPageUniqueID = GetPageUniqueID(currentPageCache); int requestPageLevel = GetPageLevel(requestPageCache); string requestPageUniqueID = GetPageUniqueID(requestPageCache); if (requestPageLevel == currentPageLevel) { if (ctr.UniqueID == pageRenderMode.RenderControlUniqueID) { renderMode.OnlyRenderSelf = true; } } else if (requestPageLevel > currentPageLevel) { string id = requestPageUniqueID.Split(',')[currentPageLevel]; if (ctr.UniqueID == id) { renderMode.OnlyRenderSelf = true; } } return(renderMode); }
/// <summary> /// /// </summary> /// <param name="ctr"></param> /// <param name="renderMode"></param> public static void CheckOnlyRenderSelf(Control ctr, ControlRenderMode renderMode) { if (renderMode.OnlyRenderSelf && renderMode.UseNewPage && ctr.Page.Items[PageExtension.PageRenderControlItemKey] != ctr) { Page currentPage = ctr.Page; ctr.Parent.Controls.GetType().GetMethod("SetCollectionReadOnly", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(ctr.Parent.Controls, new object[1] { null }); Page page = new Page(); PageRenderModePageCache currentPageCache = PageRenderModeHelper.GetPageRenderModeCache(currentPage); PageRenderModePageCache pageCache = PageRenderModeHelper.GetPageRenderModeCache(page); SetPageLevel(pageCache, GetPageLevel(currentPageCache) + 1); string currentPageUniqueID = GetPageUniqueID(currentPageCache); if (currentPageUniqueID != string.Empty) { currentPageUniqueID += ","; } SetPageUniqueID(pageCache, string.Format("{0}{1}", GetPageUniqueID(currentPageCache), ctr.UniqueID)); page.AppRelativeVirtualPath = ctr.Page.AppRelativeVirtualPath; page.EnableEventValidation = false; InitNewPageContent(page, ctr); page.AttachPageModules(); page.ProcessRequest(HttpContext.Current); HttpContext.Current.Response.End(); } }
/// <summary> /// /// </summary> /// <param name="ctr"></param> /// <returns></returns> public static ControlRenderMode GetControlRenderMode(Control ctr) { PageRenderMode pageRenderMode = Request.GetRequestPageRenderMode(); ControlRenderMode renderMode = new ControlRenderMode(pageRenderMode); PageRenderModePageCache currentPageCache = PageRenderModeHelper.GetPageRenderModeCache(ctr.Page); PageRenderModePageCache requestPageCache = renderMode.PageCache; int currentPageLevel = GetPageLevel(currentPageCache); string currentPageUniqueID = GetPageUniqueID(currentPageCache); int requestPageLevel = GetPageLevel(requestPageCache); string requestPageUniqueID = GetPageUniqueID(requestPageCache); if (requestPageLevel == currentPageLevel) { if (ctr.UniqueID == pageRenderMode.RenderControlUniqueID) renderMode.OnlyRenderSelf = true; } else if (requestPageLevel > currentPageLevel) { string id = requestPageUniqueID.Split(',')[currentPageLevel]; if (ctr.UniqueID == id) renderMode.OnlyRenderSelf = true; } return renderMode; }
/// <summary> /// /// </summary> /// <param name="ctr"></param> /// <param name="renderMode"></param> public static void CheckOnlyRenderSelf(Control ctr, ControlRenderMode renderMode) { if (renderMode.OnlyRenderSelf && renderMode.UseNewPage && ctr.Page.Items[PageExtension.PageRenderControlItemKey] != ctr) { Page currentPage = ctr.Page; ctr.Parent.Controls.GetType().GetMethod("SetCollectionReadOnly", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(ctr.Parent.Controls, new object[1] { null }); Page page = new Page(); PageRenderModePageCache currentPageCache = PageRenderModeHelper.GetPageRenderModeCache(currentPage); PageRenderModePageCache pageCache = PageRenderModeHelper.GetPageRenderModeCache(page); SetPageLevel(pageCache, GetPageLevel(currentPageCache) + 1); string currentPageUniqueID = GetPageUniqueID(currentPageCache); if (currentPageUniqueID != string.Empty) currentPageUniqueID += ","; SetPageUniqueID(pageCache, string.Format("{0}{1}", GetPageUniqueID(currentPageCache), ctr.UniqueID)); page.AppRelativeVirtualPath = ctr.Page.AppRelativeVirtualPath; page.EnableEventValidation = false; InitNewPageContent(page, ctr); page.AttachPageModules(); page.ProcessRequest(HttpContext.Current); HttpContext.Current.Response.End(); } }
/// <summary> /// Converts a stronlgy typed MatrixChildQuestionData dataset /// to a webcontrol collection /// </summary> /// <param name="childQuestions">The questions / answers data</param> /// <param name="parentControlUniqueID"> /// Unique ID required to identify global groups /// like radiobutton groups /// </param> /// <returns>a web control collection of MatrixChildQuestion</returns> public static MatrixChildCollection CreateQuestionChildCollection(MatrixChildQuestionData childQuestions, Section sectionContainer, string languageCode, string parentControlUniqueID, AnswerSelectionMode selectionMode, Style answerStyle, ControlRenderMode renderMode, VoterAnswersData.VotersAnswersDataTable voterAnswersState, bool enableAnswersDefault) { MatrixChildCollection childs = new MatrixChildCollection(); foreach (MatrixChildQuestionData.ChildQuestionsRow row in childQuestions.ChildQuestions.Rows) { MatrixChildQuestion question = new MatrixChildQuestion(); question.QuestionId = row.QuestionId; question.Text = new PipeManager().PipeValuesInText(row.QuestionId, row.QuestionText, voterAnswersState, languageCode); AnswerData answers = new AnswerData(); // answers.Merge(row.GetAnswersRows()); MatrixChildQuestionData.AnswersRow[] ar = row.GetAnswersRows(); foreach (MatrixChildQuestionData.AnswersRow r in ar) { r.Table.Namespace = answers.Namespace; } answers.Merge(ar); question.Answers = AnswerItemFactory.CreateAnswerItemCollection(answers, question, sectionContainer, selectionMode, answerStyle, renderMode, languageCode, parentControlUniqueID, false, voterAnswersState, enableAnswersDefault); childs.Add(question); } return childs; }
/// <summary> /// 根据控件输出模式,输出控件 /// </summary> /// <param name="ctr">要输出的控件</param> /// <param name="baseRenderString">控件原输出内容</param> /// <param name="renderMode">输出模式</param> /// <remarks>根据控件输出模式,输出控件</remarks> internal static void RenderControlOnlySelf(Control ctr, string baseRenderString, ControlRenderMode renderMode) { HttpResponse response = HttpContext.Current.Response; response.ClearContent(); response.ContentEncoding = Encoding.UTF8; response.Charset = "utf-8"; string htmlContentType = WebUtility.GetContentTypeByKey(ResponseContentTypeKey.HTML); string contentType = WebUtility.GetContentTypeByKey(renderMode.ContentTypeKey); if (contentType == string.Empty) { contentType = htmlContentType; } response.ContentType = contentType; string renderStr = contentType == htmlContentType? GetRenderSingleControlString(ctr, baseRenderString) : GetFileRenderSingleControlString(baseRenderString, contentType); switch (renderMode.DispositionType) { case ResponseDispositionType.Inline: case ResponseDispositionType.Attachment: response.AppendHeader("CONTENT-DISPOSITION", string.Format("{0};filename={1}", renderMode.DispositionType, response.EncodeFileNameInContentDisposition(renderMode.AttachmentFileName))); break; } response.Write(renderStr); response.End(); }
/// <summary> /// Creates a new answer item instance from the db answer data /// </summary> /// <param name="answer">The data source to create the instance from</param> /// <param name="question">The question container</param> /// <param name="defaultSelectionMode">The default selection mode for the /// item (Radio, checkbox etc...)</param> /// <param name="parentControlUniqueID"> /// Unique ID required to identify global selection groups /// like radiobutton groups /// </param> /// <param name="showAnswerText"> /// Assigns the text to the answeritem control ? /// </param> /// <param name="enableDefaults"> /// Does the answer set the user default values of fields to the answer web controls /// </param> public static AnswerItem Create(AnswerData.AnswersRow answer, QuestionItem question, Section section, AnswerSelectionMode defaultSelectionMode, Style answerStyle, ControlRenderMode renderMode, string languageCode, string parentControlUniqueID, bool showAnswerText, VoterAnswersData.VotersAnswersDataTable voterAnswersState, bool enableDefaults) { AnswerItem item = null; try { if (answer.TypeAssembly != null) { item = (AnswerItem) Assembly.Load(answer.TypeAssembly).CreateInstance(answer.TypeNameSpace); item.AnswerId = answer.AnswerId; item.ImageUrl = answer.IsImageURLNull() ? null : answer.ImageURL; item.ID = (section == null) ? (GlobalConfig.AnswerItemName + answer.AnswerId) : string.Concat(new object[] { GlobalConfig.AnswerItemName, answer.AnswerId, GlobalConfig.AnswerSectionName, section.SectionUid }); item.AnswerStyle = answerStyle; item.Question = question; item.QuestionId = answer.QuestionId; item.RenderMode = renderMode; item.Text = new PipeManager().PipeValuesInText(answer.QuestionId, answer.AnswerText, voterAnswersState, languageCode); item.ShowAnswerText = showAnswerText; item.SectionContainer = section; item.LanguageCode = languageCode; } } catch (FileNotFoundException) { item = new AnswerTextItem(); item.AnswerId = -1; item.Text = string.Format(ResourceManager.GetString("AnswerTypeAssemblyNotFoundMessage"), answer.TypeAssembly); return item; } catch (NullReferenceException) { item = new AnswerTextItem(); item.AnswerId = -1; item.Text = string.Format(ResourceManager.GetString("AnswerTypeNotFoundMessage"), answer.TypeNameSpace, answer.TypeAssembly); return item; } catch (InvalidCastException) { item = new AnswerTextItem(); item.AnswerId = -1; item.Text = string.Format(ResourceManager.GetString("AnswerTypeInvalidMessage"), answer.TypeNameSpace, answer.TypeAssembly); return item; } if (item is IClientScriptValidator) { IClientScriptValidator validator = (IClientScriptValidator) item; validator.JavascriptCode = answer.JavascriptCode; validator.JavascriptFunctionName = answer.JavascriptFunctionName; if (answer.JavascriptErrorMessage != null) { validator.JavascriptErrorMessage = (ResourceManager.GetString(answer.JavascriptErrorMessage, languageCode) == null) ? answer.JavascriptErrorMessage : ResourceManager.GetString(answer.JavascriptErrorMessage, languageCode); } else { validator.JavascriptErrorMessage = null; } validator.EnableValidation = true; } if (item is IMandatoryAnswer) { ((IMandatoryAnswer) item).Mandatory = answer.Mandatory; } if ((item is IRegExValidator) && (answer.RegExpression != null)) { ((IRegExValidator) item).RegExpression = answer.RegExpression; ((IRegExValidator) item).RegExpressionErrorMessage = answer.RegExMessage; } AnswerSelectionItem item2 = item as AnswerSelectionItem; if (item2 != null) { item2.UniqueGroupId = parentControlUniqueID; item2.AnswerId = answer.AnswerId; item2.TypeMode = (AnswerTypeMode) answer.TypeMode; item2.SelectionMode = defaultSelectionMode; bool flag = (section == null) ? IsUserSelected(answer.AnswerId, 0, voterAnswersState) : IsUserSelected(answer.AnswerId, section.SectionNumber, voterAnswersState); if (flag) { item2.Selected = flag; } else { item2.Selected = enableDefaults ? answer.Selected : false; } } if (item is IFieldItem) { IFieldItem item3 = (IFieldItem) item; item3.FieldHeight = answer.FieldHeight; item3.FieldWidth = answer.FieldWidth; item3.FieldLength = answer.FieldLength; } else if (item is AnswerDataSourceItem) { AnswerDataSourceItem item4 = (AnswerDataSourceItem) item; item4.QuestionId = answer.QuestionId; item4.AnswerId = answer.AnswerId; if (item4 is AnswerXmlItem) { item4.DataSource = answer.XmlDatasource; } else if (answer.DataSource != null) { item4.DataSource = ParseDefaultAnswerText(answer.QuestionId, answer.DataSource, voterAnswersState, languageCode); } item4.ImageUrl = answer.IsImageURLNull() ? null : answer.ImageURL; } string str = (section == null) ? GetUserText(answer.AnswerId, 0, voterAnswersState) : GetUserText(answer.AnswerId, section.SectionNumber, voterAnswersState); if (str != null) { item.DefaultText = str; } else if ((enableDefaults && !answer.IsDefaultTextNull()) && (answer.DefaultText.Length > 0)) { item.DefaultText = ParseDefaultAnswerText(answer.QuestionId, answer.DefaultText, voterAnswersState, languageCode); } if (item is ExtendedAnswerItem) { ((ExtendedAnswerItem) item).RestoreProperties(); } return item; }
/// <summary> /// Parse an AnswerDataCollection, converts the data and /// returns an AnswerItemCollection filled with the correct /// child controls /// </summary> /// <param name="answers">A collection of answerdata entities</param> /// <param name="defaultSelectionMode">The default selection mode for the /// item (Radio, checkbox etc...)</param> /// <param name="parentcontrolUniqueID"> /// Unique ID required to identify global groups /// like radiobutton groups /// </param> /// <param name="showAnswerText"> /// Assigns the text to the answeritem control ? /// </param> /// <param name="voterAnswersState"> /// Current state of answers, used for piping. If not available /// leave it to null /// </param> /// <param name="enableDefaults"> /// Does the answer set the user default values of fields to the answer web controls /// </param> /// <returns>A collection of answeritem web controls</returns> public static AnswerItemCollection CreateAnswerItemCollection(AnswerData answers, QuestionItem question, Section section, AnswerSelectionMode defaultSelectionMode, Style answerStyle, ControlRenderMode renderMode, string languageCode, string parentControlUniqueID, bool showAnswerText, VoterAnswersData.VotersAnswersDataTable voterAnswersState, bool enableDefaults) { AnswerItemCollection items = new AnswerItemCollection(); foreach (AnswerData.AnswersRow row in answers.Answers.Rows) { items.Add(Create(row, question, section, defaultSelectionMode, answerStyle, renderMode, languageCode, parentControlUniqueID, showAnswerText, voterAnswersState, enableDefaults)); } return items; }
/// <summary> /// Converts a stronlgy typed MatrixChildQuestionData dataset /// to a webcontrol collection /// </summary> /// <param name="childQuestions">The questions / answers data</param> /// <param name="parentControlUniqueID"> /// Unique ID required to identify global groups /// like radiobutton groups /// </param> /// <returns>a web control collection of MatrixChildQuestion</returns> public static MatrixChildCollection CreateQuestionChildCollection(MatrixChildQuestionData childQuestions, Section sectionContainer, string languageCode, string parentControlUniqueID, AnswerSelectionMode selectionMode, Style answerStyle, ControlRenderMode renderMode, VoterAnswersData.VotersAnswersDataTable voterAnswersState, bool enableAnswersDefault) { MatrixChildCollection childs = new MatrixChildCollection(); foreach (MatrixChildQuestionData.ChildQuestionsRow row in childQuestions.ChildQuestions.Rows) { MatrixChildQuestion question = new MatrixChildQuestion(); question.QuestionId = row.QuestionId; question.Text = new PipeManager().PipeValuesInText(row.QuestionId, row.QuestionText, voterAnswersState, languageCode); AnswerData answers = new AnswerData(); // answers.Merge(row.GetAnswersRows()); MatrixChildQuestionData.AnswersRow[] ar = row.GetAnswersRows(); foreach (MatrixChildQuestionData.AnswersRow r in ar) { r.Table.Namespace = answers.Namespace; } answers.Merge(ar); question.Answers = AnswerItemFactory.CreateAnswerItemCollection(answers, question, sectionContainer, selectionMode, answerStyle, renderMode, languageCode, parentControlUniqueID, false, voterAnswersState, enableAnswersDefault); childs.Add(question); } return(childs); }
/// <summary> /// Creates a new answer item instance from the db answer data /// </summary> /// <param name="answer">The data source to create the instance from</param> /// <param name="question">The question container</param> /// <param name="defaultSelectionMode">The default selection mode for the /// item (Radio, checkbox etc...)</param> /// <param name="parentControlUniqueID"> /// Unique ID required to identify global selection groups /// like radiobutton groups /// </param> /// <param name="showAnswerText"> /// Assigns the text to the answeritem control ? /// </param> /// <param name="enableDefaults"> /// Does the answer set the user default values of fields to the answer web controls /// </param> public static AnswerItem Create(AnswerData.AnswersRow answer, QuestionItem question, Section section, AnswerSelectionMode defaultSelectionMode, Style answerStyle, ControlRenderMode renderMode, string languageCode, string parentControlUniqueID, bool showAnswerText, VoterAnswersData.VotersAnswersDataTable voterAnswersState, bool enableDefaults) { AnswerItem item = null; try { if (answer.TypeAssembly != null) { item = (AnswerItem)Assembly.Load(answer.TypeAssembly).CreateInstance(answer.TypeNameSpace); item.AnswerId = answer.AnswerId; item.ImageUrl = answer.IsImageURLNull() ? null : answer.ImageURL; item.ID = (section == null) ? (GlobalConfig.AnswerItemName + answer.AnswerId) : string.Concat(new object[] { GlobalConfig.AnswerItemName, answer.AnswerId, GlobalConfig.AnswerSectionName, section.SectionUid }); item.AnswerStyle = answerStyle; item.Question = question; item.QuestionId = answer.QuestionId; item.RenderMode = renderMode; item.Text = new PipeManager().PipeValuesInText(answer.QuestionId, answer.AnswerText, voterAnswersState, languageCode); item.ShowAnswerText = showAnswerText; item.SectionContainer = section; item.LanguageCode = languageCode; } } catch (FileNotFoundException) { item = new AnswerTextItem(); item.AnswerId = -1; item.Text = string.Format(ResourceManager.GetString("AnswerTypeAssemblyNotFoundMessage"), answer.TypeAssembly); return(item); } catch (NullReferenceException) { item = new AnswerTextItem(); item.AnswerId = -1; item.Text = string.Format(ResourceManager.GetString("AnswerTypeNotFoundMessage"), answer.TypeNameSpace, answer.TypeAssembly); return(item); } catch (InvalidCastException) { item = new AnswerTextItem(); item.AnswerId = -1; item.Text = string.Format(ResourceManager.GetString("AnswerTypeInvalidMessage"), answer.TypeNameSpace, answer.TypeAssembly); return(item); } if (item is IClientScriptValidator) { IClientScriptValidator validator = (IClientScriptValidator)item; validator.JavascriptCode = answer.JavascriptCode; validator.JavascriptFunctionName = answer.JavascriptFunctionName; if (answer.JavascriptErrorMessage != null) { validator.JavascriptErrorMessage = (ResourceManager.GetString(answer.JavascriptErrorMessage, languageCode) == null) ? answer.JavascriptErrorMessage : ResourceManager.GetString(answer.JavascriptErrorMessage, languageCode); } else { validator.JavascriptErrorMessage = null; } validator.EnableValidation = true; } if (item is IMandatoryAnswer) { ((IMandatoryAnswer)item).Mandatory = answer.Mandatory; } if ((item is IRegExValidator) && (answer.RegExpression != null)) { ((IRegExValidator)item).RegExpression = answer.RegExpression; ((IRegExValidator)item).RegExpressionErrorMessage = answer.RegExMessage; } AnswerSelectionItem item2 = item as AnswerSelectionItem; if (item2 != null) { item2.UniqueGroupId = parentControlUniqueID; item2.AnswerId = answer.AnswerId; item2.TypeMode = (AnswerTypeMode)answer.TypeMode; item2.SelectionMode = defaultSelectionMode; bool flag = (section == null) ? IsUserSelected(answer.AnswerId, 0, voterAnswersState) : IsUserSelected(answer.AnswerId, section.SectionNumber, voterAnswersState); if (flag) { item2.Selected = flag; } else { item2.Selected = enableDefaults ? answer.Selected : false; } } if (item is IFieldItem) { IFieldItem item3 = (IFieldItem)item; item3.FieldHeight = answer.FieldHeight; item3.FieldWidth = answer.FieldWidth; item3.FieldLength = answer.FieldLength; } else if (item is AnswerDataSourceItem) { AnswerDataSourceItem item4 = (AnswerDataSourceItem)item; item4.QuestionId = answer.QuestionId; item4.AnswerId = answer.AnswerId; if (item4 is AnswerXmlItem) { item4.DataSource = answer.XmlDatasource; } else if (answer.DataSource != null) { item4.DataSource = ParseDefaultAnswerText(answer.QuestionId, answer.DataSource, voterAnswersState, languageCode); } item4.ImageUrl = answer.IsImageURLNull() ? null : answer.ImageURL; } string str = (section == null) ? GetUserText(answer.AnswerId, 0, voterAnswersState) : GetUserText(answer.AnswerId, section.SectionNumber, voterAnswersState); if (str != null) { item.DefaultText = str; } else if ((enableDefaults && !answer.IsDefaultTextNull()) && (answer.DefaultText.Length > 0)) { item.DefaultText = ParseDefaultAnswerText(answer.QuestionId, answer.DefaultText, voterAnswersState, languageCode); } if (item is ExtendedAnswerItem) { ((ExtendedAnswerItem)item).RestoreProperties(); } return(item); }
/// <summary> /// Parse an AnswerDataCollection, converts the data and /// returns an AnswerItemCollection filled with the correct /// child controls /// </summary> /// <param name="answers">A collection of answerdata entities</param> /// <param name="defaultSelectionMode">The default selection mode for the /// item (Radio, checkbox etc...)</param> /// <param name="parentcontrolUniqueID"> /// Unique ID required to identify global groups /// like radiobutton groups /// </param> /// <param name="showAnswerText"> /// Assigns the text to the answeritem control ? /// </param> /// <param name="voterAnswersState"> /// Current state of answers, used for piping. If not available /// leave it to null /// </param> /// <param name="enableDefaults"> /// Does the answer set the user default values of fields to the answer web controls /// </param> /// <returns>A collection of answeritem web controls</returns> public static AnswerItemCollection CreateAnswerItemCollection(AnswerData answers, QuestionItem question, Section section, AnswerSelectionMode defaultSelectionMode, Style answerStyle, ControlRenderMode renderMode, string languageCode, string parentControlUniqueID, bool showAnswerText, VoterAnswersData.VotersAnswersDataTable voterAnswersState, bool enableDefaults) { AnswerItemCollection items = new AnswerItemCollection(); foreach (AnswerData.AnswersRow row in answers.Answers.Rows) { items.Add(Create(row, question, section, defaultSelectionMode, answerStyle, renderMode, languageCode, parentControlUniqueID, showAnswerText, voterAnswersState, enableDefaults)); } return(items); }