CapDemo.GUI.User_Controls.ImportQuestions.CheckQuestion C# (CSharp) Метод

CheckQuestion() публичный Метод

public CheckQuestion ( ) : void
Результат void
        public void CheckQuestion()
        {
            WrongQuestion = 0;
            //int CheckQuestion = 0;
            Question question = new Question();
            Answer answer = new Answer();
            QuestionBL questionBL = new QuestionBL();

            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                    if ( row.Cells["QuestionTitle"].Value.ToString().Trim() != "" && row.Cells["NameQuestion"].Value.ToString().Trim() != "" && row.Cells["AnswerContent"].Value.ToString().Trim() != "" && row.Cells["TypeQuestion"].Value.ToString().Trim() != "")
                    {
                        if (row.Cells["TypeQuestion"].Value.ToString().Trim() == "shortanswer" || row.Cells["TypeQuestion"].Value.ToString().Trim() == "multichoice")
                        {
                            if (row.Cells["TypeQuestion"].Value.ToString().Trim() == "shortanswer")
                            {
                                string[] AnswerContent = row.Cells["AnswerContent"].Value.ToString().Trim().Split(new string[] { "</answer>" }, StringSplitOptions.None);
                                int NumAnswer = AnswerContent.Length - 1;
                                if (NumAnswer == 1)
                                {
                                    string[] AnswerItem = AnswerContent[0].Split(new string[] { "---" }, StringSplitOptions.None);

                                    if (AnswerItem[1].ToString().Trim() != "" && AnswerItem[1].ToString().Trim().Contains("</span>")==false && AnswerItem[0].ToString().Trim() != "")
                                    {
                                        int PointAnswer;
                                        bool isNum = int.TryParse(AnswerItem[0].ToString().Trim(), out PointAnswer);
                                        if (isNum = true && Convert.ToInt32(AnswerItem[0].ToString().Trim()) > 0)
                                        {
                                            row.DefaultCellStyle.BackColor = Color.LightSkyBlue ;
                                        }
                                        else
                                        {
                                            row.DefaultCellStyle.BackColor = Color.LightCoral;
                                            row.ReadOnly = true;
                                            WrongQuestion++;
                                        }
                                    }
                                    else
                                    {
                                        row.DefaultCellStyle.BackColor = Color.LightCoral;
                                        row.ReadOnly = true;
                                        WrongQuestion++;
                                    }
                                }
                                else
                                {
                                    row.DefaultCellStyle.BackColor = Color.LightCoral;
                                    row.ReadOnly = true;
                                    WrongQuestion++;
                                }
                            }
                            else
                            {
                                string[] AnswerContent = row.Cells["AnswerContent"].Value.ToString().Trim().Split(new string[] { "</answer>" }, StringSplitOptions.None);
                                int Numanswer = AnswerContent.Length - 1;
                                if (Numanswer < 2)
                                {
                                    row.DefaultCellStyle.BackColor = Color.LightCoral;
                                    row.ReadOnly = true;
                                    WrongQuestion++;
                                }
                                else
                                {
                                    int empty = 0;
                                    int CountNumberOfIncorrect = 0;
                                    int TotalAnswer = 0;

                                    for (int i = 0; i < AnswerContent.Length - 1; i++)
                                    {
                                        string[] AnswerItem = AnswerContent[i].Split(new string[] { "---" }, StringSplitOptions.None);
                                        int PointAnswer;
                                        bool isNum = int.TryParse(AnswerItem[0].ToString().Trim(), out PointAnswer);
                                        //check null answer or invalid answer
                                        if (AnswerItem[1].ToString().Trim() == "" || AnswerItem[1].ToString().Trim().Contains("</span>") == true || AnswerItem[0].ToString().Trim() == "" || isNum == false)
                                        {
                                            empty++;
                                        }
                                        //check don't have any correct answer
                                        if (int.TryParse(AnswerItem[0].ToString().Trim(), out PointAnswer))
                                        {
                                            if (Convert.ToInt32(AnswerItem[0].ToString().Trim()) == 0)
                                            {
                                                CountNumberOfIncorrect++;
                                            }
                                        }
                                        TotalAnswer++;
                                    }

                                    if (empty > 0 || TotalAnswer == CountNumberOfIncorrect)
                                    {
                                        row.DefaultCellStyle.BackColor = Color.LightCoral;
                                        row.ReadOnly = true;
                                        WrongQuestion++;
                                    }
                                    else
                                    {
                                        row.DefaultCellStyle.BackColor = Color.LightSkyBlue ;
                                    }
                                }
                            }
                        }
                        else
                        {
                            row.DefaultCellStyle.BackColor = Color.LightCoral;
                            row.ReadOnly = true;
                            WrongQuestion++;
                        }
                    }
                    else
                    {
                        row.DefaultCellStyle.BackColor = Color.LightCoral;
                        row.ReadOnly = true;
                        WrongQuestion++;
                    }

            }//end foreach
        }