예제 #1
0
        private string tempLabel = ""; //如果label = "" 時,會造成 SubjectUIMaker 中的 Dictionary 會重覆""

        #endregion Fields

        #region Constructors

        public QuestionGroup(XmlElement elmQGDef)
        {
            this.elmQGDef = elmQGDef;

            //parse titleName
            this.label = elmQGDef.GetAttribute("label");

            this.labelWidth = elmQGDef.GetAttribute("width");

            //如果label = "" 時,可能會造成 Subject 中的 Dictionary 會重覆"",所以先給他一個 Guid 值
            if (string.IsNullOrEmpty(this.label))
                this.tempLabel = Guid.NewGuid().ToString();
            else
                this.tempLabel = this.label;

            //parse hideLabel attribute
            this.showLabel = (elmQGDef.GetAttribute("hideLabel").ToUpper() != "TRUE");

            //parse ListItems
            this.listItems = new List<QuestionListItem>();
            foreach (XmlElement elm in elmQGDef.SelectNodes("Choices/Item"))
            {
                this.listItems.Add(new QuestionListItem(elm));
            }

            //Questions
            this.questions = new List<Question>();
            foreach (XmlElement elm in elmQGDef.SelectNodes("Qs/Q"))
            {
                Question q = new Question(this.label, this.listItems, elm);
                this.questions.Add(q);
            }
        }
예제 #2
0
 //確認 TextBoxDropDown 的 DropDownControl 一定會有值
 private Control getDropDownControl(Question q)
 {
     if (this.chkBox == null)
     {
         this.chkBox = new CheckedListBox();
         this.chkBox.CheckOnClick = true;
         this.chkBox.Width = 150;
         this.chkBox.Height = 100;
         this.textBoxDropDownDecorator = new TextBoxDropDownDecorator(this.chkBox);
         foreach (QuestionListItem s in q.GetListItems())
         {
             this.chkBox.Items.Add(s.GetLabel());
         }
     }
     return this.chkBox;
 }
예제 #3
0
        //Factory Method
        private Control makeQuestionControl(Question q)
        {
            Control result = null;
            try
            {
                string qType = q.GetQuestionType();

                switch (qType.ToLower())
                {
                    case "combobox":
                        result = createComboBox(q);
                        break;
                    case "checkbox":
                        result = createCheckedListBox(q);
                        break;
                    case "text":
                        result = createTextBox(q);
                        break;
                    case "textarea":
                        result = createTextArea(q);
                        break;
                    case "grid":
                        result = createGrid(q);
                        break;
                    case "textboxdropdown":
                        result = createTextBoxDropDown(q);
                        break;
                    default:
                        result = createTextBox(q);
                        break;
                }
            }
            catch (Exception ex)
            {
                FISCA.Presentation.Controls.MsgBox.Show(ex.Message);
            }
            return result;
        }
예제 #4
0
        private Control createTextBoxDropDown(Question q)
        {
            int innerPanelLength = 0;
            FlowLayoutPanel pnlInner = new FlowLayoutPanel();
            pnlInner.FlowDirection = FlowDirection.LeftToRight;
            pnlInner.Width = 120;
            //pnl.BackColor = System.Drawing.Color.Green;

            Label lbl = this.createLabel(q.GetQuestionLabel());
            pnlInner.Controls.Add(lbl);
            innerPanelLength += lbl.Width + 6;

            TextBoxDropDown txt = new TextBoxDropDown();
            txt.Enabled = false;
            txt.Name = q.GetQuestionName();
            txt.DropDownControl = this.getDropDownControl(q);
            txt.ButtonDropDown.Text = "...";
            txt.ButtonDropDown.Visible = true;
            txt.Width = 150;
            txt.Height = 20;
            txt.TextAlign = HorizontalAlignment.Left;
            txt.Tag = q;
            txt.TextChanged += new EventHandler(txt_TextChanged);
            txt.ButtonDropDownClick += new System.ComponentModel.CancelEventHandler(txt_ButtonDropDownClick);

            //調整寬度
            pnlInner.Width = innerPanelLength + txt.Width + 6;

            if (!string.IsNullOrEmpty(q.GetWidth()))
            {
                if (q.GetWidth().ToUpper() == "FILL")
                {
                    pnlInner.Width = this.contentPanel.Width - 12;
                    txt.Width = pnlInner.Width - innerPanelLength - 12;
                }
                else
                {
                    int width = 0;
                    bool isnum = int.TryParse(q.GetWidth(), out width);
                    if (isnum)
                    {
                        txt.Width = width;
                        pnlInner.Width = innerPanelLength + txt.Width + 6;
                    }
                }
            }

            //txt.Text = q.GetQuestionName();
            pnlInner.Controls.Add(txt);
            this.allQControls.Add(txt.Name, txt);

            //pnlInner.Width = innerPanelLength + txt.Width + 6;
            pnlInner.Height = txt.Height + 6;

            //adjust height
            int periodCount = 4;
            this.contentPanel.Height = 6 + 20 * ((this.questionGroup.GetQuestions().Count % periodCount == 0) ? (this.questionGroup.GetQuestions().Count / periodCount + 1) : (this.questionGroup.GetListItems().Count / periodCount + 2));

            this.pnlQGroup.Height = this.contentPanel.Height + 6;
            return pnlInner;
        }
예제 #5
0
        private Control createTextArea(Question q)
        {
            int innerPanelLength = 0;
            FlowLayoutPanel pnlInner = new FlowLayoutPanel();
            pnlInner.FlowDirection = FlowDirection.LeftToRight;
            pnlInner.Width = 120;

            //pnl.BackColor = System.Drawing.Color.Green;
            Label lbl = this.createLabel(q.GetQuestionLabel());
            pnlInner.Controls.Add(lbl);
            innerPanelLength += lbl.Width + 6;
            if (string.IsNullOrEmpty(q.GetQuestionLabel()))
                lbl.Height = 0;

            TextBox txt = new TextBox();
            txt.Enabled = false;
            txt.Name = q.GetQuestionName();
            txt.Multiline = true;
            txt.Width = pnlInner.Width - 6;
            txt.Height = q.GetRows() * 20;
            txt.TextAlign = HorizontalAlignment.Left;
            txt.ScrollBars = ScrollBars.Vertical;
            txt.Tag = q;
            txt.TextChanged += new EventHandler(txt_TextChanged);

            //調整寬度 , the default width of textarea  is FILL
            pnlInner.Width = this.contentPanel.Width - 6;
            txt.Width = pnlInner.Width - 6;

            if (!string.IsNullOrEmpty(q.GetWidth()))
            {
                if (q.GetWidth().ToUpper() != "FILL")
                {
                    int width = 0;
                    bool isnum = int.TryParse(q.GetWidth(), out width);
                    if (isnum)
                        txt.Width = width;
                }
            }

            //txt.Text = q.GetQuestionName();
            pnlInner.Controls.Add(txt);
            this.allQControls.Add(txt.Name, txt);

            //pnlInner.Width = this.contentPanel.Width - 6;
            pnlInner.Height = txt.Height + lbl.Height + 10;

            //adjust height
            this.contentPanel.Height = pnlInner.Height + 6;

            this.pnlQGroup.Height = this.contentPanel.Height + 6;
            return pnlInner;
        }
예제 #6
0
        private Control createGrid(Question q)
        {
            FlowLayoutPanel pnl = new FlowLayoutPanel();
            pnl.FlowDirection = FlowDirection.LeftToRight;
            pnl.Width = this.contentPanel.Width - 6;
            pnl.WrapContents = true;

            DataGridViewX dg = new DataGridViewX();
            dg.Enabled = false;
            dg.Tag = q;
            dg.ColumnCount = q.GetColumns().Count;
            dg.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;

            // Set the column header style.
            DataGridViewCellStyle columnHeaderStyle = new DataGridViewCellStyle();
            columnHeaderStyle.BackColor = Color.Aqua;
            dg.BackgroundColor = Color.White;
            columnHeaderStyle.Font = new Font("微軟粗黑體", 9, FontStyle.Regular);
            dg.ColumnHeadersDefaultCellStyle = columnHeaderStyle;

            for (int i = 0; i < q.GetColumns().Count; i++)
            {
                GridColumn gc = q.GetColumns()[i];
                dg.Columns[i].Name = gc.GetName();
                if (!string.IsNullOrEmpty(gc.GetWidth()))
                    dg.Columns[i].Width = int.Parse(gc.GetWidth());
            }

            dg.Width = pnl.Width - 10;
            dg.Height = 120;
            FillGridDefaultRecord(dg);

            dg.CellEndEdit += new DataGridViewCellEventHandler(dg_CellEndEdit);
            pnl.Height = dg.Height + 6;
            this.allQControls.Add(q.GetQuestionName(), dg);
            pnl.Controls.Add(dg);

            this.contentPanel.Height = pnl.Height + 6;
            this.pnlQGroup.Height = this.contentPanel.Height + 6;
            return pnl;
        }
예제 #7
0
        private Control createComboBox(Question q)
        {
            FlowLayoutPanel pnlInner = new FlowLayoutPanel();
            pnlInner.FlowDirection = FlowDirection.LeftToRight;

            int innerPanelLength = 0;

            //如果 Question 有 Label ,則要在前面加上 Label
            if (q.HasLabel)
            {
                Label lbl = this.createLabel(q.GetQuestionLabel());
                pnlInner.Controls.Add(lbl);
                innerPanelLength += lbl.Width + 6;
            }

            //create combobox
            ComboBoxEx cbo = new ComboBoxEx();
            cbo.Enabled = false;
            cbo.Name = q.GetQuestionName();
            cbo.DropDownStyle = ComboBoxStyle.DropDown;
            cbo.Tag = q;
            cbo.TextChanged += new EventHandler(txt_TextChanged); ;
            Graphics g = cbo.CreateGraphics();
            SizeF maxSize = new SizeF();

            Font f = this.pnlQGroup.Font;
            foreach (QuestionListItem item in this.questionGroup.GetListItems())
            {
                int index = cbo.Items.Add(item.GetLabel());
                if (item.Selected)
                    cbo.SelectedText = item.GetLabel();

                SizeF theSize = g.MeasureString(item.GetLabel(), f);
                if (theSize.Width > maxSize.Width)
                    maxSize = theSize;
            }

            cbo.Width = (int)maxSize.Width + 25;
            pnlInner.Controls.Add(cbo);
            this.allQControls.Add(cbo.Name, cbo);

            pnlInner.Width = innerPanelLength + cbo.Width + 6;
            pnlInner.Height = cbo.Height + 6;

            //adjust height
            int periodCount = 4;
            this.contentPanel.Height = 6 + 20 * ((this.questionGroup.GetQuestions().Count % periodCount == 0) ? (this.questionGroup.GetQuestions().Count / periodCount + 1) : (this.questionGroup.GetQuestions().Count / periodCount + 2));

            this.pnlQGroup.Height = this.contentPanel.Height + 6;
            return pnlInner;
        }
예제 #8
0
        private Control createCheckedListBox(Question q)
        {
            FlowLayoutPanel pnl = new FlowLayoutPanel();
            pnl.FlowDirection = FlowDirection.LeftToRight;
            pnl.Width = this.contentPanel.Width - 6;
            pnl.WrapContents = true;

            int totalLength = 0;

            foreach (QuestionListItem item in this.questionGroup.GetListItems())
            {
                FlowLayoutPanel pnlInner = new FlowLayoutPanel();
                pnlInner.FlowDirection = FlowDirection.LeftToRight;

                CheckBox chk = new CheckBox();
                chk.Enabled = false;
                chk.Name = item.GetLabel();
                chk.Width = 15;
                chk.Height = 20;
                chk.Tag = q;
                chk.CheckedChanged += new EventHandler(txt_TextChanged);
                System.Windows.Forms.Padding margin = chk.Margin;
                margin.Top = 3;
                margin.Bottom = 0;
                margin.Right = 0;
                chk.Margin = margin;
                pnlInner.Controls.Add(chk);
                this.allQControls.Add(chk.Name, chk);

                Label lbl = this.createLabel(item.GetLabel());
                pnlInner.Controls.Add(lbl);

                pnlInner.Width = chk.Width + lbl.Width + 25;
                pnlInner.Height = chk.Height + 2;

                if (item.HasText)
                {
                    TextBox txt = new TextBox();
                    txt.Name = chk.Name + "_remark";
                    txt.Width = 80;
                    txt.TextChanged += new EventHandler(txt_TextChanged); ;
                    //txt.Multiline = true;
                    //txt.Height = 26;
                    //txt.Tag = q;  //此 TextBox 請不要設定Tag,只要加入 allQControls 就好。
                    pnlInner.Controls.Add(txt);
                    this.allQControls.Add(txt.Name, txt);
                    pnlInner.Width += txt.Width;
                }

                pnl.Controls.Add(pnlInner);
                totalLength += pnlInner.Width + 10;

            }
            //adjust height
            //int periodCount = 4;
            //pnl.Height = 22 * ((this.questionGroup.GetListItems().Count % periodCount == 0) ? (this.questionGroup.GetListItems().Count / periodCount + 1) : (this.questionGroup.GetListItems().Count / periodCount + 2));
            pnl.Height = 28 * (totalLength / pnl.Width + 1);
            //this.contentPanel.Height = pnl.Height + 6;
            //this.pnlQGroup.Height = this.contentPanel.Height + 6;

            return pnl;
        }