private void txtCtrlNoiDungCauHoi_SelectionChanged(object sender, EventArgs e)
        {
            var lenght = txtCtrlNoiDungCauHoi.SelectionLength;

            txtCtrlNoiDungCauHoi.ReadOnly = false;
            var index = txtCtrlNoiDungCauHoi.SelectionStart;
            var line  = txtCtrlNoiDungCauHoi.GetLineFromCharIndex(index);

            if (CauHoiCurent.ListCauTraLoi.Any(n => (n.IndexEx <= index && (n.IndexEx + UICommon.GetLengthRtf(n.NoiDung)) >= index) ||
                                               (n.IndexEx <= (index + lenght) && (n.IndexEx + UICommon.GetLengthRtf(n.NoiDung)) >= (index + lenght)) ||
                                               (n.IndexEx >= index && (n.IndexEx + UICommon.GetLengthRtf(n.NoiDung)) <= (index + lenght))
                                               ))
            {
                txtCtrlNoiDungCauHoi.ReadOnly = true;
                return;
            }
            if (txtCtrlNoiDungCauHoi.GetLineFromCharIndex(index + lenght) != line)
            {
                txtCtrlNoiDungCauHoi.ReadOnly = true;
                return;
            }

            //RichTextBox richTextBox = (RichTextBox)sender;
            //var selectionLenghNow = richTextBox.SelectionLength;

            //if (_cauHoiCurent.ListCauTraLoi.Count < 2)
            //    _textLength = richTextBox.TextLength;
            //richTextBox.ReadOnly = false;
            //foreach (var ctl in _cauHoiCurent.ListCauTraLoi)
            //{
            //    if (richTextBox.SelectionStart >= ctl.IndexEx && richTextBox.SelectionStart <= ctl.IndexEx + UICommon.GetLengthRtf(ctl.NoiDung) || richTextBox.SelectionStart + selectionLenghNow >= ctl.IndexEx && richTextBox.SelectionStart + selectionLenghNow <= ctl.IndexEx + UICommon.GetLengthRtf(ctl.NoiDung))
            //    {
            //        richTextBox.ReadOnly = true;
            //        break;
            //    }
            //    if (richTextBox.SelectionStart < ctl.IndexEx && richTextBox.SelectionStart + selectionLenghNow > ctl.IndexEx + UICommon.GetLengthRtf(ctl.NoiDung) && selectionLenghNow != richTextBox.TextLength)
            //    {
            //        richTextBox.ReadOnly = true;
            //        break;
            //    }
            //    richTextBox.ReadOnly = false;
            //}
        }
        private void OnUnderlineClicked(object sender, EventArg e)
        {
            var obj = (EditorControl)sender;

            if (obj != null && obj.Name == "txtCtrlNoiDungCauHoi")
            {
                var lenght = txtCtrlNoiDungCauHoi.SelectionLength;
                if (lenght > 0 && !string.IsNullOrEmpty(txtCtrlNoiDungCauHoi.SelectedText.Trim()))
                {
                    var index = txtCtrlNoiDungCauHoi.SelectionStart;
                    var line  = txtCtrlNoiDungCauHoi.GetLineFromCharIndex(index);
                    if (CauHoiCurent.ListCauTraLoi.Any(n => (n.IndexEx <= index && (n.IndexEx + UICommon.GetLengthRtf(n.NoiDung)) >= index) ||
                                                       (n.IndexEx <= (index + lenght) && (n.IndexEx + UICommon.GetLengthRtf(n.NoiDung)) >= (index + lenght)) ||
                                                       (n.IndexEx >= index && (n.IndexEx + UICommon.GetLengthRtf(n.NoiDung)) <= (index + lenght))
                                                       ))
                    {
                        UICommon.ShowMsgWarningString("Vị trí gạch chân không hợp lệ");
                        txtCtrlNoiDungCauHoi.ReadOnly = false;
                        txtCtrlNoiDungCauHoi.Undo();
                        txtCtrlNoiDungCauHoi.ReadOnly = true;
                        return;
                    }
                    if (txtCtrlNoiDungCauHoi.GetLineFromCharIndex(index + lenght) != line)
                    {
                        UICommon.ShowMsgWarningString("Vị trí gạch chân không hợp lệ");
                        txtCtrlNoiDungCauHoi.ReadOnly = false;
                        txtCtrlNoiDungCauHoi.Undo();
                        txtCtrlNoiDungCauHoi.ReadOnly = true;
                        return;
                    }
                    // Xóa hết câu trả lời để add lại
                    ClearAllCauTraLoi();
                    // nếu như là hợp lệ
                    CauHoiCurent.ListCauTraLoi.Add(new EX_CauTraLoi {
                        NoiDung = txtCtrlNoiDungCauHoi.SelectedRtf, IndexEx = index, Line = line
                    });
                    //Add lại câu trả lời
                    CauHoiCurent.ListCauTraLoi = CauHoiCurent.ListCauTraLoi.OrderBy(n => n.IndexEx).ToList();
                    for (int i = 1; i <= CauHoiCurent.ListCauTraLoi.Count; i++)
                    {
                        var ctraLoi = CauHoiCurent.ListCauTraLoi[i - 1];
                        ctraLoi.IdEx = i;
                        ThemCauTraLoi(ctraLoi);
                    }
                }
                else if (lenght > 0)
                {
                    UICommon.ShowMsgWarningString("Vị trí gạch chân không hợp lệ");
                    txtCtrlNoiDungCauHoi.ReadOnly = false;
                    txtCtrlNoiDungCauHoi.Undo();
                    txtCtrlNoiDungCauHoi.ReadOnly = true;
                }
            }
            else
            {
                if (txtCtrlNoiDungCauHoi.SelectionLength > 0)
                {
                    txtCtrlNoiDungCauHoi.ReadOnly = false;
                    txtCtrlNoiDungCauHoi.Undo();
                    txtCtrlNoiDungCauHoi.ReadOnly = true;
                }
            }
        }
        private void txtCtrlNoiDungCauHoi_KeyDown(object sender, KeyEventArgs e)
        {
            RichTextBox richTextBox1 = (RichTextBox)sender;

            if (richTextBox1.ReadOnly)
            {
                return;
            }
            bool flag1          = e.Modifiers == Keys.Control && e.KeyCode == Keys.V;
            bool flag2          = e.Modifiers == Keys.Shift && e.KeyCode == Keys.Insert;
            bool flag3          = e.KeyCode == Keys.Delete;
            bool flag4          = e.KeyCode == Keys.Back;
            int  selectionStart = richTextBox1.SelectionStart;

            if (flag3)
            {
                foreach (var ctl in CauHoiCurent.ListCauTraLoi)
                {
                    if (ctl.IndexEx == selectionStart)
                    {
                        richTextBox1.ReadOnly = true;
                        break;
                    }
                    richTextBox1.ReadOnly = false;
                }
            }
            if (flag4)
            {
                foreach (var ctl in CauHoiCurent.ListCauTraLoi)
                {
                    if (ctl.IndexEx + UICommon.GetLengthRtf(ctl.NoiDung) == selectionStart)
                    {
                        richTextBox1.ReadOnly = true;
                        break;
                    }
                    richTextBox1.ReadOnly = false;
                }
            }

            if (richTextBox1.SelectionLength == richTextBox1.TextLength)
            {
                if (flag1 | flag2)
                {
                    RichTextBox richTextBox2 = new RichTextBox();
                    richTextBox2.Clear();
                    richTextBox2.Paste();
                    Clipboard.Clear();
                    richTextBox2.SelectAll();
                    richTextBox2.SelectionColor = Color.Black;
                    richTextBox2.SelectionFont  = new Font("Times New Roman", 11.25f, FontStyle.Regular);
                    richTextBox2.Copy();
                    richTextBox1.Visible = false;
                    richTextBox1.Clear();
                    richTextBox1.Paste();
                    richTextBox1.Focus();
                    richTextBox1.Visible         = true;
                    richTextBox1.SelectionLength = 0;
                    richTextBox1.Select(richTextBox1.TextLength, 0);
                    Clipboard.Clear();
                }
                else if (flag3 | flag4)
                {
                    RichTextBox richTextBox2 = new RichTextBox();
                    Clipboard.Clear();
                    richTextBox2.Clear();
                }
            }
        }
Beispiel #4
0
        public bool SaveUpdateCauHoi()
        {
            try
            {
                #region Update cau hoi

                //cap nhat noi dung cau hoi
                EX_CauHoi ch = _business.GetById(IdCauHoiCurent);
                if (ch == null)
                {
                    return(false);
                }
                ch.DoKho        = IdMucDoNhanThuc;
                ch.IDChuong     = IdDanhMuc;
                ch.IsKhongDao   = ckbKhongDaoCauHoi.Checked;
                ch.IDLoaiCauHoi = (int)LoaiCauHoi.CauHoiDungSai;
                //save lai
                _business.UpdateCauHoi(IdCauHoiCurent, ch);

                #endregion

                #region update dap an

                List <EX_CauTraLoi> lstCauTraLoi = new List <EX_CauTraLoi>();
                foreach (var tblPanelDapAn in _lstTablePanelDapAn)
                {
                    SimpleButton  btnXoa      = tblPanelDapAn.Controls[_nameButtonXoa] as SimpleButton;
                    EditorControl txtDapAn    = tblPanelDapAn.Controls[_nameTextNoiDungDapAn] as EditorControl;
                    SimpleButton  btnDapAn    = tblPanelDapAn.Controls[_nameButtonDapAn] as SimpleButton;
                    CheckBox      chkKhongDao = tblPanelDapAn.Controls[_nameCheckBox] as CheckBox;

                    EX_CauTraLoi cauTraLoi = new EX_CauTraLoi();
                    cauTraLoi.IDCauHoi   = ch.Id;
                    cauTraLoi.IdEx       = Convert.ToInt32(btnXoa.Tag);
                    cauTraLoi.NoiDung    = txtDapAn.Rtf;
                    cauTraLoi.IsDung     = Convert.ToBoolean(btnDapAn.Tag);
                    cauTraLoi.IsKhongDao = chkKhongDao.Checked;

                    lstCauTraLoi.Add(cauTraLoi);
                }

                #region Kiểm tra trùng câu hỏi

                // Kiểm tra trùng đáp án
                if (lstCauTraLoi.GroupBy(o => o.NoiDung).ToList().Count < _lstTablePanelDapAn.Count &&
                    UICommon.ShowMsgQuestionString("Tồn tại đáp án trùng nhau. Bạn có muốn tiếp tục lưu không?") == DialogResult.No)
                {
                    return(false);
                }

                #endregion

                // Cập nhật câu trả lời
                foreach (var esCauTraLoi in lstCauTraLoi)
                {
                    if (esCauTraLoi.IdEx == 0)
                    {
                        _business.AddNewCauTraLoi(esCauTraLoi);
                    }
                    else
                    {
                        _business.UpdateCauTraLoi(esCauTraLoi.IdEx, esCauTraLoi);
                    }
                }

                // Xoa cau tra loi
                foreach (int IdCauTraLoiBiXoa in ListIdCauHoiBiXoa)
                {
                    _business.DeleteCauTraLoiById(IdCauTraLoiBiXoa);
                }

                #endregion


                IsChanged = false;
            }
            catch (Exception)
            {
                return(false);
            }

            return(true);
        }
Beispiel #5
0
 /// <summary>
 /// Create browser
 /// </summary>
 /// <param name="publisherService"></param>
 /// <param name="serializer"></param>
 /// <param name="logger"></param>
 public Publisher(IPublisherServiceApi publisherService, ITwinServiceApi twinService, IJsonSerializer serializer, ILogger logger, UICommon commonHelper)
 {
     _serializer       = serializer ?? throw new ArgumentNullException(nameof(serializer));
     _publisherService = publisherService ?? throw new ArgumentNullException(nameof(publisherService));
     _logger           = logger ?? throw new ArgumentNullException(nameof(logger));
     _commonHelper     = commonHelper ?? throw new ArgumentNullException(nameof(commonHelper));
     _twinService      = twinService ?? throw new ArgumentNullException(nameof(twinService));
 }
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            if (needsUpdate)
            {
                if (headSlot != null)
                {
                    UICommon.AddOrRemoveChild(this, headSlot, showItems);
                }
                if (bodySlot != null)
                {
                    UICommon.AddOrRemoveChild(this, bodySlot, showItems);
                }
                if (legsSlot != null)
                {
                    UICommon.AddOrRemoveChild(this, legsSlot, showItems);
                }

                if (showItems)
                {
                    this.Height.Set(defaultBackgroundTexture.Height * 4.6f * scale, 0f);                     // 50 heigh
                }
                else
                {
                    this.Height.Set(defaultBackgroundTexture.Height * 1.6f * scale, 0f);
                }

                needsUpdate = false;
            }

            if (Main.GameUpdateCount != lastUpdate)
            {
                lastUpdate = Main.GameUpdateCount;
                if (drawPlayer == null)
                {
                    drawPlayer = new Player();
                }
                drawPlayer.skinVariant     = Main.LocalPlayer.skinVariant;
                drawPlayer.Male            = Main.LocalPlayer.Male;
                drawPlayer.eyeColor        = Main.LocalPlayer.eyeColor;
                drawPlayer.hairColor       = Main.LocalPlayer.hairColor;
                drawPlayer.skinColor       = Main.LocalPlayer.skinColor;
                drawPlayer.shirtColor      = Main.LocalPlayer.shirtColor;
                drawPlayer.underShirtColor = Main.LocalPlayer.underShirtColor;
                drawPlayer.shoeColor       = Main.LocalPlayer.shoeColor;
                drawPlayer.pantsColor      = Main.LocalPlayer.pantsColor;
                drawPlayer.direction       = 1;
                drawPlayer.gravDir         = 1f;
                drawPlayer.head            = -1;
                drawPlayer.body            = -1;
                drawPlayer.legs            = -1;
                drawPlayer.handon          = -1;
                drawPlayer.handoff         = -1;
                drawPlayer.back            = -1;
                drawPlayer.front           = -1;
                drawPlayer.shoe            = -1;
                drawPlayer.waist           = -1;
                drawPlayer.shield          = -1;
                drawPlayer.neck            = -1;
                drawPlayer.face            = -1;
                drawPlayer.balloon         = -1;
                drawPlayer.wings           = -1;

                if (useDye)
                {
                    for (int i = 0; i < 10; i++)
                    {
                        drawPlayer.dye[i] = Main.LocalPlayer.dye[i].Clone();
                    }
                }
                else
                {
                    for (int i = 0; i < 10; i++)
                    {
                        drawPlayer.dye[i].TurnToAir();
                        drawPlayer.dye[i].dye = 0;
                    }
                }

                if (accessories)
                {
                    for (int i = 0; i < 20; i++)
                    {
                        drawPlayer.armor[i] = Main.LocalPlayer.armor[i].Clone();
                        if (i < 10)
                        {
                            drawPlayer.hideVisual[i] = Main.LocalPlayer.hideVisual[i];
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < 20; i++)
                    {
                        drawPlayer.armor[i].TurnToAir();
                        if (i < 10)
                        {
                            drawPlayer.hideVisual[i] = true;
                        }
                    }
                }

                drawPlayer.PlayerFrame();
                drawPlayer.socialIgnoreLight = true;

                if (animate)
                {
                    drawPlayer.bodyFrame = Main.LocalPlayer.bodyFrame;
                    drawPlayer.legFrame  = Main.LocalPlayer.legFrame;
                }
            }
        }
        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);

            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
            this.ResetTextCauTraLoi();

            IsChanged = true;
            ResizeLayoutCauTraLoi(false);
        }