Пример #1
0
 private void AddAnswer_Click(object sender, EventArgs e)
 {
     try
     {
         if (answers.Contains("Ответ тут"))
         {
             throw new Exceptions.ExistedAnswer(true);
         }
         int             counter = answers.Count;
         AnswerComponent ans     = new AnswerComponent(Answer_Type);
         ans.Text     = "Ответ тут";
         ans.Size     = new Size(AnswersPanel.Size.Width, 40);
         ans.Location = new Point(0, counter * 40);
         counter++;
         ans.Font = deffont;
         if (counter < 1)
         {
             ans.Checked = true;
         }
         ans.Inactive += CheckAnswerText;
         ans.Selected += AnswerFocused;
         ans.MaximumUD = AnswersPanel.Controls.Count + 1;
         //ans.CheckedEvent += UpdateDots;
         AnswersPanel.Controls.Add(ans);
         answers.Add(ans.Text);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Ошибка добавления ответа", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
     }
 }
Пример #2
0
 private void CheckAnswerText(object sender, EventArgs e)
 {
     try
     {
         AnswerComponent ans     = (AnswerComponent)sender;
         int             counter = 0;
         answers.Clear();
         foreach (Control ctrls in AnswersPanel.Controls)
         {
             if (ctrls is AnswerComponent)
             {
                 string answer = ctrls.Text;
                 answers.Add(answer);
                 if (answer == ans.Text)
                 {
                     counter++;
                 }
             }
         }
         if (counter > 1)
         {
             ans.Text = ans.Text.Substring(0, ans.Text.Length - 1);
             throw new Exceptions.ExistedAnswer();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Ошибка правки ответа", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
         SystemSounds.Asterisk.Play();
     }
 }
Пример #3
0
 private void ReloadPanel()
 {
     if (Answer_Type == AnswerType.CheckBox || Answer_Type == AnswerType.Radio || Answer_Type == AnswerType.Order)
     {
         stringanswerpanel.Hide();
         foreach (Control ans in AnswersPanel.Controls)
         {
             if (ans is AnswerComponent)
             {
                 AnswerComponent an = (AnswerComponent)ans;
                 an.Answer_Type = Answer_Type;
                 ans.Show();
                 if (Answer_Type == AnswerType.Order)
                 {
                     an.MaximumUD = AnswersPanel.Controls.Count;
                 }
             }
         }
         AddAnswer.Enabled    = true;
         DeleteAnswer.Enabled = true;
     }
     else
     {
         foreach (Control ans in AnswersPanel.Controls)
         {
             if (ans is AnswerComponent)
             {
                 ans.Hide();
             }
         }
         stringanswerpanel.Show();
         AddAnswer.Enabled    = false;
         DeleteAnswer.Enabled = false;
     }
 }
Пример #4
0
        private void AnswerFocused(object sender, EventArgs e)
        {
            foreach (Control ans in AnswersPanel.Controls)
            {
                if (ans is AnswerComponent)
                {
                    AnswerComponent comp = (AnswerComponent)ans;
                    ans.BackColor = Color.FromKnownColor(KnownColor.Control);
                }
            }
            AnswerComponent component = (AnswerComponent)sender;

            component.BackColor = Color.FromArgb(174, 166, 247);
            selected            = component;
        }
Пример #5
0
        private void DeleteAnswer_Click(object sender, EventArgs e)
        {
            answers.Remove(selected.Text);
            AnswersPanel.Controls.Clear();
            int counter = 0;

            foreach (string text in answers)
            {
                AnswerComponent ans = new AnswerComponent(Answer_Type);
                ans.Text     = text;
                ans.Size     = new Size(AnswersPanel.Size.Width, 40);
                ans.Location = new Point(0, counter * 40);
                counter++;
                ans.Font = deffont;
                if (Answer == Task.Answer)
                {
                    ans.Checked = true;
                }
                ans.Inactive += CheckAnswerText;
                ans.Selected += AnswerFocused;
                //ans.CheckedEvent += UpdateDots;
                AnswersPanel.Controls.Add(ans);
            }
        }
Пример #6
0
        public AddAnswers(TaskClass task)
        {
            InitializeComponent();
            Task        = task;
            Answer_Type = task.Answer_Type;
            Answer      = task.Answer;
            MessageBox.Show(Answer);
            switch (Answer_Type)
            {
            case AnswerType.Radio:
                AnswerTypeComboBox.SelectedItem = "Один ответ из нескольких вариантов";
                break;

            case AnswerType.Order:
                AnswerTypeComboBox.SelectedItem = "Порядок";
                break;

            case AnswerType.CheckBox:
                AnswerTypeComboBox.SelectedItem = "Несколько вариантов ответа";
                break;

            default:
                AnswerTypeComboBox.SelectedItem = "Строка";
                Answer_Type = AnswerType.String;
                break;
            }
            if (Answer_Type == AnswerType.String)
            {
                textbox.Text         = Answer;
                AddAnswer.Enabled    = false;
                DeleteAnswer.Enabled = false;
            }
            else
            {
                int counter = 0;
                foreach (string answer in task.Answers)
                {
                    AnswerComponent ans = new AnswerComponent(Answer_Type);
                    ans.Text     = answer;
                    ans.Size     = new Size(AnswersPanel.Size.Width, 40);
                    ans.Location = new Point(0, counter * 40);
                    counter++;
                    ans.Font = deffont;
                    if (answer == Task.Answer)
                    {
                        ans.Checked = true;
                    }
                    ans.Inactive += CheckAnswerText;
                    ans.Selected += AnswerFocused;
                    //ans.CheckedEvent += UpdateDots;
                    AnswersPanel.Controls.Add(ans);
                    answers.Add(answer);
                }
            }
            if (Answer_Type == AnswerType.CheckBox)
            {
                string[] ans = Answer.Split('|');
                foreach (Control an in AnswersPanel.Controls)
                {
                    if (an is AnswerComponent)
                    {
                        AnswerComponent answer = (AnswerComponent)an;
                        foreach (string st in ans)
                        {
                            if (answer.Text == st)
                            {
                                answer.Checked = true;
                                break;
                            }
                        }
                    }
                }
            }
            if (Answer_Type == AnswerType.Order)
            {
                string[] ans = Answer.Split('|');
                foreach (Control an in AnswersPanel.Controls)
                {
                    if (an is AnswerComponent)
                    {
                        AnswerComponent answer = (AnswerComponent)an;
                        foreach (string st in ans)
                        {
                            string key   = st.Substring(st.IndexOf('"') + 1, st.Length - 2 - st.IndexOf('"'));
                            int    value = Convert.ToInt32(st.Split('-')[0]);
                            if (answer.Text == key)
                            {
                                answer.OrderNumber = value;
                            }
                        }
                    }
                }
            }
        }