示例#1
0
        private Control CreateWebSurveyControl(XmlNode _node)
        {
            string localName = _node.LocalName;
            if (localName == "Question")
            {
                string strId = _node.Attributes["id"].Value;
                string text3 = _node.Attributes["type"].Value;
                string strQuestion = "";
                XmlNode node = _node.SelectSingleNode("Statement");
                if (node != null)
                {
                    strQuestion = node.InnerXml;
                }
                int nCols = 20;
                XmlAttribute attribute = _node.Attributes["cols"];
                if (attribute != null)
                {
                    nCols = int.Parse(attribute.Value);
                }
                int nRows = 4;
                XmlAttribute attribute2 = _node.Attributes["rows"];
                if (attribute2 != null)
                {
                    nRows = int.Parse(attribute2.Value);
                }
                RepeatDirection rdLayout = RepeatDirection.Vertical;
                XmlAttribute attribute3 = _node.Attributes["layout"];
                if (attribute3 != null)
                {
                    rdLayout = (attribute3.Value == "horizontal") ? RepeatDirection.Horizontal : RepeatDirection.Vertical;
                }
                string strControlBase = "";
                XmlAttribute attribute4 = _node.Attributes["basecontrol"];
                if (attribute4 != null)
                {
                    strControlBase = attribute4.Value;
                }
                bool bRequired = false;
                XmlAttribute attribute5 = _node.Attributes["required"];
                if (attribute5 != null)
                {
                    bRequired = attribute5.Value == "true";
                }
                string strRequiredText = "*";
                XmlAttribute attribute6 = _node.Attributes["requiredtext"];
                if (attribute6 != null)
                {
                                    strRequiredText = attribute6.Value;
                }

                WebQuestion wq;
                string[] strResponses = null;
                switch (text3)
                {
                    case "shortans":
                        wq = new ShortAnsWebQuestion(strId, bRequired, strRequiredText, strQuestion, nCols);
                        break;

                    case "essay":
                        wq = new EssayWebQuestion(strId, bRequired, strRequiredText, strQuestion, nRows, nCols);
                        break;

                    case "mcss":
                        if (strControlBase == "")
                        {
                            strControlBase = "radio";
                        }
                        strResponses = this.GetResponses(_node);
                        wq = new McssWebQuestion(strId, bRequired, strRequiredText, strQuestion, strControlBase, rdLayout, strResponses);
                        break;

                    case "mcms":
                        if (strControlBase == "")
                        {
                            strControlBase = "checkbox";
                        }
                        strResponses = this.GetResponses(_node);
                        wq = new McmsWebQuestion(strId, bRequired, strRequiredText, strQuestion, strControlBase, rdLayout, strResponses);
                        break;

                    case "hidden":
                        wq = new HiddenWebQuestion(strId);
                        break;

                    default:
                        wq = new WebQuestion();
                        break;
                }

                m_questions.Add(wq);
                return wq;
            }
            if (localName == "Separator")
            {
                return new LiteralControl(_node.InnerXml);
            }
            return new LiteralControl("");
        }
 public void Add(WebQuestion wq)
 {
     base.BaseAdd(wq.Id, wq);
 }