private void AddDefaultQuestionItems()
        {
            List <QuestionData> qdList = new List <QuestionData>();

            XElement elmRoot = XElement.Parse(Properties.Resources.Questions);

            foreach (XElement elm in elmRoot.Elements("Question"))
            {
                QuestionData qd = new QuestionData(null);
                qd.Group          = elm.Element("Group").Value;
                qd.Name           = elm.Element("Name").Value;
                qd.QuestionType   = elm.Element("QuestionType").Value;
                qd.ControlType    = elm.Element("ControlType").Value;
                qd.CanPrint       = bool.Parse(elm.Element("CanPrint").Value);
                qd.CanStudentEdit = bool.Parse(elm.Element("CanStudentEdit").Value);
                qd.CanTeacherEdit = bool.Parse(elm.Element("CanTeacherEdit").Value);
                qd.DisplayOrder   = int.Parse(elm.Element("DisplayOrder").Value);
                if (elm.Element("Items") != null)
                {
                    qd.Items = elm.Element("Items").ToString();
                }
                qdList.Add(qd);
            }
            InsertUDT(qdList);
        }
        /// <summary>
        /// 依群組名稱取的資料
        /// </summary>
        /// <param name="Name"></param>
        /// <returns></returns>
        public Dictionary<string, QuestionData> GetQuestionDataByGroupName(string Name)
        {
            Dictionary<string, QuestionData> retVal = new Dictionary<string, QuestionData>();
            List<UDTQuestionsDataDef> dataList = UDTTransfer.ABUDTQuestionsDataSelectByGroupName(Name);
            dataList=(from da in dataList orderby da.Group,da.Name select da).ToList();

            foreach (UDTQuestionsDataDef ud in dataList)
            {
                QuestionData qd = new QuestionData (ud);
                if (!retVal.ContainsKey(qd.Name))
                    retVal.Add(qd.Name, qd);
            }

            return retVal;
        }
        public ABCardQuestionDataManager()
        {
            _QuestionDataList = new List<QuestionData>();
            _UDTQuestionsDataList = UDTTransfer.ABUDTQuestionsDataSelectAll();
            //UDTTransfer.ABUDTQuestionsDataDelete(_UDTQuestionsDataList);

            //_UDTQuestionsDataList = UDTTransfer.ABUDTQuestionsDataSelectAll();

            foreach (UDTQuestionsDataDef UQ in _UDTQuestionsDataList)
            {
                QuestionData qd = new QuestionData(UQ);
                _QuestionDataList.Add(qd);
            }

            // 當沒有資料放入預設
            if (_UDTQuestionsDataList.Count < 1)
                AddDefaultQuestionItems();
        }
        /// <summary>
        /// 依群組名稱取的資料
        /// </summary>
        /// <param name="Name"></param>
        /// <returns></returns>
        public Dictionary <string, QuestionData> GetQuestionDataByGroupName(string Name)
        {
            Dictionary <string, QuestionData> retVal   = new Dictionary <string, QuestionData>();
            List <UDTQuestionsDataDef>        dataList = UDTTransfer.ABUDTQuestionsDataSelectByGroupName(Name);

            dataList = (from da in dataList orderby da.Group, da.Name select da).ToList();

            foreach (UDTQuestionsDataDef ud in dataList)
            {
                QuestionData qd = new QuestionData(ud);
                if (!retVal.ContainsKey(qd.Name))
                {
                    retVal.Add(qd.Name, qd);
                }
            }

            return(retVal);
        }
        public ABCardQuestionDataManager()
        {
            _QuestionDataList     = new List <QuestionData>();
            _UDTQuestionsDataList = UDTTransfer.ABUDTQuestionsDataSelectAll();
            //UDTTransfer.ABUDTQuestionsDataDelete(_UDTQuestionsDataList);

            //_UDTQuestionsDataList = UDTTransfer.ABUDTQuestionsDataSelectAll();

            foreach (UDTQuestionsDataDef UQ in _UDTQuestionsDataList)
            {
                QuestionData qd = new QuestionData(UQ);
                _QuestionDataList.Add(qd);
            }

            // 當沒有資料放入預設
            if (_UDTQuestionsDataList.Count < 1)
            {
                AddDefaultQuestionItems();
            }
        }
        private void AddDefaultQuestionItems()
        {
            List<QuestionData> qdList = new List<QuestionData>();

            XElement elmRoot = XElement.Parse(Properties.Resources.Questions);
            foreach (XElement elm in elmRoot.Elements("Question"))
            {
                QuestionData qd = new QuestionData(null);
                qd.Group = elm.Element("Group").Value;
                qd.Name = elm.Element("Name").Value;
                qd.QuestionType = elm.Element("QuestionType").Value;
                qd.ControlType = elm.Element("ControlType").Value;
                qd.CanPrint = bool.Parse(elm.Element("CanPrint").Value);
                qd.CanStudentEdit = bool.Parse(elm.Element("CanStudentEdit").Value);
                qd.CanTeacherEdit = bool.Parse(elm.Element("CanTeacherEdit").Value);
                qd.DisplayOrder = int.Parse(elm.Element("DisplayOrder").Value);
                if(elm.Element("Items") !=null)
                    qd.Items=elm.Element("Items").ToString();
                qdList.Add(qd);
            }
            InsertUDT(qdList);
        }
        void item_Click(object sender, EventArgs e)
        {
            if (itmPnlNameList.SelectedItems.Count > 0)
            {
                controlEnable();
                ButtonItem item = itmPnlNameList.SelectedItems[0] as ButtonItem;
                if (item != null)
                {
                    QuestionData data = item.Tag as QuestionData;
                    _QuestionData = data;
                    if(data !=null)
                    {
                        gp1.Text = data.Name;
                        chkCanPrint.Checked = data.CanPrint;
                        chkCanTeacherEdit.Checked = data.CanTeacherEdit;
                        chkCanStudentEdit.Checked = data.CanStudentEdit;
                        cbxControlType.Text = data.ControlType;
                        cbxQuestionType.Text = data.QuestionType;

                        if (data.QControlType == EnumControlType.GRID_TEXTBOX || data.QControlType == EnumControlType.TEXTBOX)
                            dgItemEnable(false);
                        else
                            dgItemEnable(true);

                        // 當 checkbox radio 才可以使用可備註
                        if (data.QControlType == EnumControlType.CHECKBOX || data.QControlType == EnumControlType.RADIO_BUTTON)
                            dgItems.Columns[colHasRemark.Index].Visible = true;
                        else
                            dgItems.Columns[colHasRemark.Index].Visible = false;

                        if (data.DisplayOrder.HasValue)
                            intDisplayOrder.Value = data.DisplayOrder.Value;
                        else
                            intDisplayOrder.IsEmpty = true;

                        if (data.itemList.Count > 0)
                        {
                            int rowidx;
                            foreach (QuestionItem qi in data.itemList)
                            {
                                rowidx = dgItems.Rows.Add();
                                dgItems.Rows[rowidx].Cells[colName.Index].Value = qi.Key;
                                dgItems.Rows[rowidx].Cells[colHasRemark.Index].Value = qi.hasRemark;
                            }
                        }
                        // 存、歿特殊處理
                        if (data.Name == "直系血親_存、歿")
                        {
                            dgItems.Rows.Clear();
                            dgItemEnable(false);
                        }
                    }
                }

            }
        }