Example #1
0
        public void SetControls(List <Answers> _listAns)
        {
            ansPanel.Controls.Clear();
            var x = 46; var y = 14;
            var XValue = x; var YValue = y;

            for (int i = 0; i < _listAns.Count; i++)
            {
                var pcm  = new Control();
                var item = _listAns[i];

                if (item.Ans_Image != null)
                {
                    btnMute.Visible = false;
                    if ((x * ((i * 6) + 1)) + 241 > ansPanel.Width)
                    {
                        x      = 46;
                        XValue = x * (((i - 4) * 6) + 1); YValue = 173;
                    }
                    else
                    {
                        XValue = x * ((i * 6) + 1); YValue = y;
                    }

                    pcm = new PictureBox
                    {
                        Image     = ConvertByteToImage(_listAns[i].Ans_Image),
                        SizeMode  = PictureBoxSizeMode.Zoom,
                        Size      = new System.Drawing.Size(241, 119),
                        BackColor = Color.Silver,
                        // Padding=Padding.All(3),
                        Location = new Point(XValue, YValue),
                        Name     = item.Ans_id.ToString()
                    };
                }

                else
                {
                    btnMute.Visible = true;
                    pcm             = new Button
                    {
                        Width     = 1150,
                        Height    = 82,
                        Location  = new Point(18, 18 + (82 * i)),
                        Name      = item.Ans_id.ToString(),
                        BackColor = Color.Silver,
                        Font      = new Font("Arial", 30, FontStyle.Bold),
                        Text      = item.Ans_text
                    };
                }
                //pcm.KeyUp += (obj, s) =>
                //{
                //     Next();
                //};

                pcm.Click += (obj, s) =>
                {
                    var options = new List <Control>();
                    for (int j = 0; j < _listAns.Count; j++)
                    {
                        var btn = ansPanel.Controls.Find(_listAns[j].Ans_id.ToString(), true);
                        options.Add(btn[0]);
                    }

                    var wtf = obj.GetType();
                    if (obj.GetType().Name == "Button")
                    {
                        options.ForEach(e =>
                        {
                            if (e.Name != ((Button)obj).Name)
                            {
                                e.BackColor = Color.Silver;
                            }
                            else
                            {
                                e.BackColor = Color.Maroon;
                            }
                        });
                    }
                    else
                    {
                        // options.FirstOrDefault(e => e.Name == ((PictureBox)obj).Name).BackColor = Color.Red;
                        options.ForEach(e =>
                        {
                            if (e.Name != ((PictureBox)obj).Name)
                            {
                                e.BackColor = Color.Silver;
                            }
                            else
                            {
                                e.BackColor = Color.Maroon;
                            }
                        });
                    }


                    btnNext.Enabled = true;
                    btnNext.Focus();
                    curr_obj = _listAns.FirstOrDefault(_ans => _ans.Qus_id == _listQ[index_glob].Qus_id && _ans.Ans_id == int.Parse(pcm.Name));
                };
                ansPanel.Controls.Add(pcm);
            }
        }
Example #2
0
        public void GetQuestionsIfExamined()
        {
            try
            {
                cmd.GetCMDConnection(String.Format(@"GetExaminedQuestions"), _cmd =>
                {
                    _cmd.CommandType = CommandType.StoredProcedure;
                    _cmd.Parameters.AddWithValue("@examiner", _examiner.Barcode);

                    var _reader = _cmd.ExecuteReader();
                    int count   = 0;
                    while (_reader.Read())
                    {
                        count++;
                        var question = new Questions
                        {
                            Exam_id   = int.Parse(_reader.GetValue(2).ToString()),
                            Duration  = int.Parse(_reader.GetValue(4).ToString()),
                            Exam_name = _reader.GetValue(3).ToString()
                        };
                        var obj = new Answers
                        {
                            Ans_text  = _reader.GetValue(0).ToString(),
                            Ans_value = int.Parse(_reader.GetValue(1).ToString()),
                            Qus_id    = int.Parse(_reader.GetValue(5).ToString()),
                            Ans_id    = int.Parse(_reader.GetValue(6).ToString())
                        };

                        var _checked = _listResults.FirstOrDefault(rs => rs.Exam_id == question.Exam_id && rs.Sold_id == _examiner.Sold_id);
                        if (_checked != null)
                        {
                            var listAnswers = _checked.ListAnswers.FirstOrDefault(ans => ans.Qus_id == obj.Qus_id);
                            if (listAnswers != null)
                            {
                                listAnswers.Ans_value = obj.Ans_value;
                                listAnswers.Ans_text  = obj.Ans_text;
                            }
                            else
                            {
                                _checked.ListAnswers.Add(obj);
                            }
                        }
                        else
                        {
                            var listAns = new List <Answers>();
                            listAns.Add(obj);
                            _listResults.Add(new Results
                            {
                                Barcode       = _examiner.Barcode,
                                Sold_id       = _examiner.Sold_id,
                                Exam_id       = question.Exam_id,
                                Exam_duration = question.Duration,
                                Exam_name     = question.Exam_name,
                                ListAnswers   = listAns
                            });
                        }
                    }

                    GetItem((count == 0) ? 1 : count);
                });
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }