Ejemplo n.º 1
0
 public Answer(XmlElement elmAns)
 {
     this.qname  = elmAns.GetAttribute("name");
     this.qvalue = elmAns.GetAttribute("value");
     ansItems    = new List <AnswerItem>();
     foreach (XmlElement elmItem in elmAns.SelectNodes("Item"))
     {
         AnswerItem ai = new AnswerItem(elmItem);
         ansItems.Add(ai);
     }
 }
Ejemplo n.º 2
0
        public void AddAnswerItem(AnswerItem ansItem)
        {
            bool isExisted = false;

            for (int i = 0; i < this.ansItems.Count; i++)
            {
                if (this.ansItems[i].GetValueName().ToUpper() == ansItem.GetValueName().ToUpper())
                {
                    this.ansItems[i] = ansItem;
                    isExisted        = true;
                    break;
                }
            }

            if (!isExisted)
            {
                this.ansItems.Add(ansItem);
            }
        }
Ejemplo n.º 3
0
        public List <Answer> GetAnswer()
        {
            Dictionary <string, Answer> result = new Dictionary <string, Answer>();

            //找出所有 tag 值為 Question type 的控制項,
            foreach (Control ctrl in this.allQControls.Values)
            {
                Question q = ctrl.Tag as Question;
                if (q != null)
                {
                    if (!result.ContainsKey(q.GetQuestionName()))
                    {
                        result.Add(q.GetQuestionName(), new Answer());
                    }
                    Answer ans = result[q.GetQuestionName()];
                    ans.SetName(q.GetQuestionName());

                    if (ctrl is CheckBox)   //如果是 checkbox :
                    {
                        CheckBox chk = (CheckBox)ctrl;

                        if (chk.Checked)
                        {
                            //這是複選題
                            AnswerItem       theAi            = new AnswerItem();
                            string           ctrlName         = ctrl.Name;
                            QuestionListItem questionListItem = q.GetListItemByLable(ctrlName);
                            theAi.SetValueName(ctrlName);
                            if (questionListItem != null)
                            {
                                if (questionListItem.HasText)  //有 remark
                                {
                                    string remarkCtrlName = ctrlName + "_remark";
                                    if (this.allQControls.ContainsKey(remarkCtrlName))
                                    {
                                        theAi.SetValueRemark(this.allQControls[remarkCtrlName].Text);
                                    }
                                    else
                                    {
                                        theAi.SetValueRemark("");
                                    }
                                }
                            }
                            ans.AddAnswerItem(theAi);
                        } //end of (chk.Checked)
                    }
                    else if (ctrl is DataGridView)
                    {
                        DataGridView dg = (DataGridView)ctrl;
                        Dictionary <string, string> value = new Dictionary <string, string>();
                        foreach (DataGridViewRow row in dg.Rows)
                        {
                            if (!row.IsNewRow)
                            {
                                AnswerItem ai = new AnswerItem();
                                Dictionary <string, string> itemContents = new Dictionary <string, string>();
                                foreach (GridColumn gc in q.GetColumns())
                                {
                                    itemContents.Add(gc.GetName(), (row.Cells[gc.GetName()].Value == null) ? "" : row.Cells[gc.GetName()].Value.ToString());
                                }
                                ai.SetContent(itemContents);
                                ans.GetAnswerItems().Add(ai);
                            }
                        }
                    }
                    else   //視為單選題
                    {
                        if (q.GetQuestionType().ToLower() == "textboxdropdown")
                        {
                            ctrl.Text = ctrl.Text.Trim();
                            string[] strArr = ctrl.Text.Split(',');
                            foreach (string str in strArr)
                            {
                                if (!string.IsNullOrEmpty(str))
                                {
                                    XmlElement elm = new XmlDocument().CreateElement("Item");
                                    elm.SetAttribute("value", str.Trim());
                                    AnswerItem ai = new AnswerItem(elm);
                                    ans.AddAnswerItem(ai);
                                }
                            }
                        }
                        else
                        {
                            ans.SetValue(ctrl.Text);
                        }
                    }
                }
            }


            return(result.Values.ToList <Answer>());
        }