public bool ValidateNoiDung()
        {
            SaveNewCauHoiTemp(IdCauHoiCurent);

            if (txtNoiDungCauHoiCha.IsEmpty)
            {
                UICommon.ShowMsgWarningString("Bạn hãy nhập nội dung câu hỏi cha.");
                return(false);
            }

            foreach (var item in ListCauHoi)
            {
                if (string.IsNullOrEmpty(UICommon.ConvertRftToText(item.NoiDung)))
                {
                    UICommon.ShowMsgWarningString("Tồn tại câu hỏi bạn chưa nhập nội dung.");
                    return(false);
                }
                //Do kho
                if (!item.DoKho.HasValue)
                {
                    UICommon.ShowMsgWarningString("Bạn chưa chọn độ khó cho câu hỏi.");
                    return(false);
                }
            }
            return(true);
        }
        public bool ValidateNoiDung()
        {
            bool IsEmpty = false;

            IsEmpty = txtNoiDungCauHoiCha.IsEmpty;

            if (IsEmpty)
            {
                UICommon.ShowMsgWarningString("Bạn hãy nhập nội dung câu hỏi cha.");
                return(false);
            }

            //reset IsEmpty
            IsEmpty = false;
            if (ListCauHoi == null || ListCauHoi.Count == 0)
            {
                UICommon.ShowMsgWarningString("Bạn chưa tạo số lượng câu hỏi");
                return(false);
            }

            SaveNewCauHoiTemp(IdCauHoiCurent);

            foreach (var item in ListCauHoi)
            {
                //Noi dung cau hoi
                if (string.IsNullOrEmpty(UICommon.ConvertRftToText(item.NoiDung)))
                {
                    UICommon.ShowMsgWarningString("Tồn tại câu hỏi bạn chưa nhập nội dung.");
                    return(false);
                }
                //Do kho
                if (!item.DoKho.HasValue)
                {
                    UICommon.ShowMsgWarningString("Bạn chưa chọn độ khó cho câu hỏi.");
                    return(false);
                }
                //noi dung cau tra loi
                foreach (var cauTl in item.ListCauTraLoi)
                {
                    if (string.IsNullOrEmpty(UICommon.ConvertRftToText(cauTl.NoiDung)))
                    {
                        UICommon.ShowMsgWarningString("Tồn tại câu trả lời bạn chưa nhập nội dung.");
                        return(false);
                    }
                }
                //Dap dan dung
                if (!item.ListCauTraLoi.Any(m => m.IsDung ?? false))
                {
                    UICommon.ShowMsgWarningString("Tồn tại câu hỏi không có đáp án đúng.");
                    return(false);
                }
            }
            return(true);
        }
        private void XoaCauTraLoi(object sender, EventArgs e)
        {
            if (ListCauHoi.Count == 1)
            {
                UICommon.ShowMsgWarningString("Số lượng câu hỏi không thể nhỏ hơn 1 \nBạn không thể xóa câu hỏi này");
                return;
            }
            if (UICommon.ShowMsgQuestionString("Bạn có chắc muốn xóa câu trả lời này không ?", MessageBoxButtons.YesNo) != DialogResult.Yes)
            {
                return;
            }

            SimpleButton     button        = sender as SimpleButton;
            TableLayoutPanel tblPanelDapAn = button.Parent as TableLayoutPanel;
            int rowIndex = tblPanelMain.GetRow(tblPanelDapAn);

            ListIdCauHoiBiXoa.Add(CauHoiCurent.Id);

            //remove old controls
            foreach (Control ctrl in tblPanelDapAn.Controls)
            {
                ctrl.Dispose();
            }
            tblPanelDapAn.Controls.Clear();
            tblPanelDapAn.Dispose();

            tblPanelMain.Controls.Remove(tblPanelDapAn);
            _lstTablePanelCauHoi.Remove(tblPanelDapAn);

            //decrease row index of panels down 2
            //rename panel
            for (int i = rowIndex + 2; i < tblPanelMain.RowStyles.Count; i = i + 2)
            {
                tblPanelDapAn = tblPanelMain.Controls[_nameTablePanelDapAn + i] as TableLayoutPanel;

                if (tblPanelDapAn != null)
                {
                    tblPanelMain.SetRow(tblPanelDapAn, i - 2);
                    tblPanelDapAn.Name = _nameTablePanelDapAn + (i - 2);
                }
            }

            //remove 2 last rows
            tblPanelMain.RowStyles.RemoveAt(tblPanelMain.RowStyles.Count - 2);
            tblPanelMain.RowCount--;
            tblPanelMain.RowStyles.RemoveAt(tblPanelMain.RowStyles.Count - 2);
            tblPanelMain.RowCount--;

            //Tìm vị trí điền khuyết
            var noiDungReply = CauHoiCurent.ListCauTraLoi.FirstOrDefault();
            var textReply    = (string.Format("({0})_____", CauHoiCurent.IDEx));

            txtCtrlNoiDungCauHoi.Focus();
            txtCtrlNoiDungCauHoi.Find(textReply, RichTextBoxFinds.MatchCase);
            txtCtrlNoiDungCauHoi.Cut();
            Clipboard.Clear();
            //Tra lai noi dung cho text box cau hoi
            if (noiDungReply == null)
            {
                return;
            }
            var noiDungText = UICommon.ConvertRftToText(noiDungReply.NoiDung).Trim();

            Clipboard.SetText(noiDungText);
            txtCtrlNoiDungCauHoi.Paste();
            txtCtrlNoiDungCauHoi.Refresh();
            Clipboard.Clear();
            ListCauHoi.Remove(CauHoiCurent);
            int idEx = 1;

            foreach (var viTri in ListCauHoi)
            {
                var textFind    = (string.Format("({0})_____", viTri.IDEx));
                var textRepalce = (string.Format("({0})_____", idEx));
                txtCtrlNoiDungCauHoi.Find(textFind, RichTextBoxFinds.MatchCase);
                txtCtrlNoiDungCauHoi.Focus();
                txtCtrlNoiDungCauHoi.Cut();
                Clipboard.Clear();
                Clipboard.SetText(textRepalce);
                txtCtrlNoiDungCauHoi.Paste();
                txtCtrlNoiDungCauHoi.Refresh();
                viTri.IDEx = idEx++;
            }

            SetDataToCboCauHoi();
            var cauHoiKeTiep = ListCauHoi.LastOrDefault();

            //Xoa het du lieu cau hoi
            ClearAllCauTraLoi();
            ClearAllCauTraLoiGayNhieu();

            cboCauHoi.EditValueChanged -= CboCauHoi_EditValueChanged;;
            if (cauHoiKeTiep != null)
            {
                CauHoiCurent   = cauHoiKeTiep;
                IdCauHoiCurent = cauHoiKeTiep.IDEx;
                LoadCauHoiNew(IdCauHoiCurent);
                cboCauHoi.CategoryID = cauHoiKeTiep.IDEx;
            }
            else
            {
                cboCauHoi.CategoryID = null;
            }
            cboCauHoi.EditValueChanged += CboCauHoi_EditValueChanged;
            _mathCollection             = _parsing.ParseDienKhuyet2(txtCtrlNoiDungCauHoi.Text);
            IsChanged = true;
        }
        private void ThemCauTraLoi(EX_CauTraLoi cauTraLoi = null)
        {
            int rowIndex = 0;

            if (_lstTablePanelDapAn.Count == 0 || _lstTablePanelDapAn.Count % 2 == 0)
            {
                tblPanelMain.RowCount += 2;
                rowIndex = tblPanelMain.RowStyles.Add(new RowStyle(SizeType.Absolute, 65F));
                tblPanelMain.RowStyles.Add(new RowStyle(SizeType.Absolute, 10));
                _rowInsert = rowIndex;
            }

            // Đáp án đúng
            var text     = Convert.ToChar(65 + _lstTablePanelDapAn.Count).ToString();
            var btnDapAn = new DevExpress.XtraEditors.SimpleButton();

            btnDapAn.Appearance.Font            = new System.Drawing.Font("Tahoma", 11F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            btnDapAn.Appearance.Options.UseFont = true;
            btnDapAn.Dock    = System.Windows.Forms.DockStyle.Right;
            btnDapAn.Margin  = new System.Windows.Forms.Padding(2);
            btnDapAn.Name    = _nameButtonDapAn;
            btnDapAn.Text    = text;
            btnDapAn.Tag     = 0;
            btnDapAn.ToolTip = "Đáp án " + text;
            btnDapAn.Click  += new EventHandler(btnDapAn_Click);

            // Xóa câu trả lời
            var btnXoa = new DevExpress.XtraEditors.SimpleButton();

            btnXoa.ImageOptions.Image = global::SimpleTest.Properties.Resources.tsbDelete;
            btnXoa.ImageOptions.ImageToTextAlignment = DevExpress.XtraEditors.ImageAlignToText.LeftCenter;
            btnXoa.Dock    = System.Windows.Forms.DockStyle.Left;
            btnXoa.Margin  = new System.Windows.Forms.Padding(2);
            btnXoa.Name    = _nameButtonXoa;
            btnXoa.Text    = "";
            btnXoa.Width   = 40;
            btnXoa.ToolTip = "Xóa câu trả lời";
            btnXoa.Click  += new EventHandler(XoaCauTraLoi);

            //EditorControl
            EditorControl txtCtrl = new EditorControl()
            {
                Dock = DockStyle.Fill, Name = _nameTextNoiDungDapAn, BorderStyle = BorderStyle.FixedSingle
            };

            txtCtrl.ReadOnly  = true;
            txtCtrl.BackColor = Color.White;
            txtCtrl.Margin    = new Padding(2);
            txtCtrl.GotFocus += txtCtrlNoiDungCauHoi_GotFocus;

            // Table panel
            TableLayoutPanel tblPanelDapAn = new TableLayoutPanel();

            tblPanelDapAn.Name        = _nameTablePanelDapAn + rowIndex;
            tblPanelDapAn.ColumnCount = 3;
            tblPanelDapAn.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 40F));
            tblPanelDapAn.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F));
            tblPanelDapAn.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 42F));
            tblPanelDapAn.RowCount = 1;
            tblPanelDapAn.RowStyles.Add(new RowStyle(SizeType.Percent, 100F));
            tblPanelDapAn.Dock = DockStyle.Top;

            tblPanelDapAn.Controls.Add(btnDapAn, 0, 0);
            tblPanelDapAn.Controls.Add(txtCtrl, 1, 0);
            tblPanelDapAn.Controls.Add(btnXoa, 2, 0);

            if ((_lstTablePanelDapAn.Count == 0 || _lstTablePanelDapAn.Count % 2 == 0))
            {
                tblPanelMain.Controls.Add(tblPanelDapAn, 0, _rowInsert);
            }
            else
            {
                tblPanelMain.Controls.Add(tblPanelDapAn, 3, _rowInsert);
            }
            _rowInsert = rowIndex == 0 ? _rowInsert : rowIndex;

            //add panel to list
            _lstTablePanelDapAn.Add(tblPanelDapAn);

            if (cauTraLoi != null)
            {
                // Tô màu đáp án đúng
                if (cauTraLoi.IsDung ?? false)
                {
                    btnDapAn.BackColor = Color.Red;
                    btnDapAn.ForeColor = Color.Red;
                    btnDapAn.Font      = new Font(btnDapAn.Font.FontFamily, 11F, FontStyle.Bold);
                    btnDapAn.Tag       = 1;
                }

                // Load noi dung dap an
                txtCtrl.Text = UICommon.ConvertRftToText(cauTraLoi.NoiDung);
            }
            // Gán id câu trả lời
            txtCtrl.Tag  = cauTraLoi.IdEx;
            btnDapAn.Tag = cauTraLoi.IdEx;
            btnXoa.Tag   = cauTraLoi.IdEx;

            ResizeLayoutCauTraLoi(true);
            IsChanged = true;
        }