コード例 #1
0
        private void XoaCauTraLoi(object sender, EventArgs e)
        {
            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;

            //get id cau hoi bi xoa
            int idEx      = Convert.ToInt32(button.Tag);
            var cauTraLoi = CauHoiCurent.ListCauTraLoi.FirstOrDefault(m => m.IdEx == idEx);

            if (cauTraLoi != null)
            {
                // Xóa gạch chân trên câu hỏi
                txtCtrlNoiDungCauHoi.SelectionStart  = cauTraLoi.IndexEx ?? 0;
                txtCtrlNoiDungCauHoi.SelectionLength = UICommon.GetLengthRtf(cauTraLoi.NoiDung);
                if (txtCtrlNoiDungCauHoi.IsUnderline())
                {
                    txtCtrlNoiDungCauHoi.Underline();
                }
                CauHoiCurent.ListCauTraLoi = CauHoiCurent.ListCauTraLoi.Except(new List <EX_CauTraLoi> {
                    cauTraLoi
                }).ToList();
                // Nhập những câu hỏi có Id bị xóa
                if (cauTraLoi.Id > 0)
                {
                    ListIdCauHoiBiXoa.Add(cauTraLoi.Id);
                    IsChanged = true;
                }
            }
            // Xóa hết trên màn hình
            ClearAllCauTraLoi();
            // Hiển thị lại
            for (int i = 1; i <= CauHoiCurent.ListCauTraLoi.Count; i++)
            {
                var ctraLoi = CauHoiCurent.ListCauTraLoi[i - 1];
                ctraLoi.IdEx = i;
                ThemCauTraLoi(ctraLoi);
            }
        }
コード例 #2
0
        private void XoaCauHoiCon(object sender, EventArgs e)
        {
            //Nếu trái it nhất phải = 1
            if (_lstTablePanelCauHoi.Count == 2)
            {
                UICommon.ShowMsgWarningString("Số câu hỏi con không được nhỏ hơn 2 \nBạn không thể xóa!");
                return;
            }

            if (UICommon.ShowMsgQuestionString("Bạn có chắc muốn xóa câu hỏi này không ?") != DialogResult.Yes)
            {
                return;
            }

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

            //get id cau hoi bi xoa
            int idEx = Convert.ToInt32(button.Tag);

            //neu khac 0 la cau hoi da ton tai, can xoa
            var cauHoi = CauHoiCurent.ListCauHoi.FirstOrDefault(m => m.IDEx == idEx);

            if (cauHoi != null && cauHoi.Id > 0)
            {
                ListIdCauHoiBiXoa.Add((int)cauHoi.Id);
                ListIdCauTraLoiBiXoa.Add((int)cauHoi.ListCauTraLoi.FirstOrDefault()?.Id);

                IsChanged = true;
            }

            //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[_nameTablePanelCauHoi + i] as TableLayoutPanel;

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

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

            // Reset text
            this.ResetTextCauTraLoi();
            ResizeLayoutCauTraLoi(false);
        }
コード例 #3
0
        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;
        }
コード例 #4
0
        private void XoaCauTraLoi(object sender, EventArgs e)
        {
            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);

            //get id cau hoi bi xoa
            int idCauHoiBiXoa = Convert.ToInt32(button.Tag);

            int idCauTraLoiEx = 0;

            try { idCauTraLoiEx = Convert.ToInt32(tblPanelDapAn.Tag); } catch { }
            //Xoa cau tra loi trong lstCauHoi
            var cauHoi = ListCauHoi.FirstOrDefault(m => m.IDEx == IdCauHoiCurent);

            if (cauHoi != null)
            {
                var cauTraLoi = cauHoi.ListCauTraLoi.FirstOrDefault(m => m.IdEx == idCauTraLoiEx);
                if (cauTraLoi != null)
                {
                    cauHoi.ListCauTraLoi.Remove(cauTraLoi);
                }
                int idEx = 1;
                //Reset lai idEx = bắt đầu từ 1 => nhớ phải reset tag của tblPanelDapAn ở phần reset text
                foreach (var item in cauHoi.ListCauTraLoi)
                {
                    item.IdEx = idEx++;
                }
            }

            //neu khac 0 la cau hoi da ton tai, can xoa
            if (idCauHoiBiXoa != 0)
            {
                ListIdCauHoiBiXoa.Add(idCauHoiBiXoa);
                IsChanged = true;
            }

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

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

            //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--;

            // Reset text
            ResetTextCauTraLoi();
            ResizeLayoutCauTraLoi(false);
        }
コード例 #5
0
        private void XoaCauTraLoiTrai(object sender, EventArgs e)
        {
            //Nếu trái it nhất phải = 1
            if (_lstTablePanelDapAnTrai.Count == 1)
            {
                UICommon.ShowMsgWarningString("Mệnh đề ở vế trái không được nhỏ hơn một \nBạn không thể xóa!");
                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);

            //get id cau hoi bi xoa
            int idCauHoiBiXoa = Convert.ToInt32(button.Tag);

            //neu khac 0 la cau hoi da ton tai, can xoa
            if (idCauHoiBiXoa != 0)
            {
                ListIdCauHoiBiXoa.Add(idCauHoiBiXoa);
            }

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

            tblPanelMain.Controls.Remove(tblPanelDapAn);
            _lstTablePanelDapAnTrai.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--;

            // Reset text
            ResetTextCauTraLoiTrai();
            ResizeLayoutCauTraLoiTrai(false);
            SetTextSoLuongCauHoi();
        }
コード例 #6
0
        private void XoaCauTraLoiPhai(object sender, EventArgs e)
        {
            ////Nếu bên phải = bên trái thì ko cho xóa
            //if (_lstTablePanelDapAnPhai.Count <= _lstTablePanelDapAnTrai.Count)
            //{
            //    UICommon.ShowMsgWarningString("Mệnh đề ở vế phải không được ít hơn vế trái \nBạn không thể xóa!");
            //    return;
            //}

            if (UICommon.ShowMsgQuestionString("Bạn có chắc muốn xóa câu trả lời gây nhiễu này không ?", MessageBoxButtons.YesNo) != DialogResult.Yes)
            {
                return;
            }

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

            //get id cau hoi bi xoa
            int idCauTraLoiBiXoa = Convert.ToInt32(button.Tag);
            //IDEx xác định id ex de xoa trong list cau tra loi
            int idEx           = Convert.ToInt32(tblPanelDapAn.Tag);
            var cauTraLoiBiXoa = CauHoiCurent.ListCauTraLoi.FirstOrDefault(m => m.IdEx == idEx);

            CauHoiCurent.ListCauTraLoi.Remove(cauTraLoiBiXoa);

            //neu khac 0 la cau hoi da ton tai, can xoa
            if (idCauTraLoiBiXoa != 0)
            {
                ListIdCauHoiBiXoa.Add(idCauTraLoiBiXoa);
            }

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

            tblPanelMain2.Controls.Remove(tblPanelDapAn);
            _lstTablePanelDapAnPhai.Remove(tblPanelDapAn);

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

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

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

            //xoa lai cau tra loi dien khuyet
            ResetTextCauTraLoiPhai();
            ResizeLayoutCauTraLoiPhai(false);
            SetTextSoLuongCauHoi();
        }