//
        //Randomly selects questions for each Format-Section specification of the Paper as per the No Of Questions
        //
        public Questions[] getQuestionPaper(Paper[] arr, Questions[] q, Exam_Details ed)
        {
            int maxcount = 0, mincount = 0;
            DataRow dr;
            int index = 0;
            Object[] abc = new Object[11];
            string temp;
            bool[] rand;
            int no = 0;
            int m;
            int param = arr.Length;
            DataTable dt;
            conn.Open();

            for (int l = 0; l < param; l++)
            {
                //Selects questions for each Format-Section specification of the Paper
                cmd = new SqlCommand("Select * from Questions where Exam_Type ='" + ed.exam_Type + "' and Section ='" + arr[l].section + "' and Format ='" + arr[l].format + "'",conn);
                dread = cmd.ExecuteReader();
                dt = new DataTable();
                dt.Load(dread);

                //Random Selection of questions
                maxcount = dt.Rows.Count;
                mincount = arr[l].no_Of_Questions;
                rand = new bool[maxcount];
                no = 0;
                while (no < mincount)
                {
                    Random r = new Random();
                    m = r.Next(maxcount);

                    if (rand[m] == false)
                    {
                        rand[m] = true;
                        no++;
                    }
                }

                //Loads the randomly selected question into Question Array
                for (int i = 0; i < maxcount; i++)
                {
                    if (rand[i] == true)
                    {
                        q[index] = new Questions();
                        dr = dt.Rows[i];
                        abc = dr.ItemArray;

                        q[index].question_ID = (string)abc.ElementAt(0);
                        q[index].exam_Type = (string)abc.ElementAt(1);
                        q[index].format = (string)abc.ElementAt(2);
                        q[index].question = (string)abc.ElementAt(3);
                        q[index].option1 = (string)abc.ElementAt(4);
                        q[index].option2 = (string)abc.ElementAt(5);
                        q[index].option3 = (string)abc.ElementAt(6);
                        q[index].option4 = (string)abc.ElementAt(7);
                        q[index].solution = (string)abc.ElementAt(8);
                        temp = abc.ElementAt(9).ToString();
                        q[index].marks = Convert.ToInt32(temp);
                        q[index].section = (string)abc.ElementAt(10);
                        if((q[index].format.Equals("Picture Question: Single Answer") )|| (q[index].format.Equals("Picture Question: Multiple Answer")))
                            q[index].picture_ID = (string)abc.ElementAt(11);
                        index++;
                    }
                }

            }
            dread.Close();
            conn.Close();
            return q;
        }
        private textfilecontent54_object CreateTextFileContentObject(
            EntityObjectStringType filePath,
            EntityObjectStringType fileName,
            EntityObjectStringType path,
            EntityObjectStringType pattern,
            EntityObjectIntType instance,
            Object[] behaviors)
        {
            var fileContentObject = new textfilecontent54_object();
            object[] items;
            textfilecontent54_ItemsChoices[] itemChoices;
            var hasBehaviors = (behaviors != null) && (behaviors.Count() > 0);
            var behaviorCount = behaviors.Count();

            if (filePath == null)
            {
                if (hasBehaviors)
                {
                    var entityCount = behaviorCount + 4;
                    items = new object[entityCount];
                    itemChoices = new textfilecontent54_ItemsChoices[entityCount];

                    for (int i = 0; i < behaviorCount; i++)
                    {
                        itemChoices[i] = textfilecontent54_ItemsChoices.behaviors;
                        items[i] = behaviors.ElementAt(i);
                    }

                    itemChoices[behaviorCount] = textfilecontent54_ItemsChoices.path;
                    itemChoices[behaviorCount + 1] = textfilecontent54_ItemsChoices.filename;
                    itemChoices[behaviorCount + 2] = textfilecontent54_ItemsChoices.pattern;
                    itemChoices[behaviorCount + 3] = textfilecontent54_ItemsChoices.instance;

                    items[behaviorCount] = path;
                    items[behaviorCount + 1] = fileName;
                    items[behaviorCount + 2] = pattern;
                    items[behaviorCount + 3] = instance;
                }
                else
                {
                    items = new EntitySimpleBaseType[4];
                    itemChoices = new textfilecontent54_ItemsChoices[4];
                    itemChoices[0] = textfilecontent54_ItemsChoices.path;
                    itemChoices[1] = textfilecontent54_ItemsChoices.filename;
                    itemChoices[2] = textfilecontent54_ItemsChoices.pattern;
                    itemChoices[3] = textfilecontent54_ItemsChoices.instance;
                    items[0] = path;
                    items[1] = fileName;
                    items[2] = pattern;
                    items[3] = instance;
                }
            }
            else
            {
                if (hasBehaviors)
                {
                    var entityCount = behaviorCount + 3;
                    items = new object[entityCount];
                    itemChoices = new textfilecontent54_ItemsChoices[entityCount];

                    for (int i = 0; i < behaviorCount; i++)
                    {
                        itemChoices[i] = textfilecontent54_ItemsChoices.behaviors;
                        items[i] = behaviors.ElementAt(i);
                    }

                    itemChoices[behaviorCount] = textfilecontent54_ItemsChoices.filepath;
                    itemChoices[behaviorCount + 1] = textfilecontent54_ItemsChoices.pattern;
                    itemChoices[behaviorCount + 2] = textfilecontent54_ItemsChoices.instance;

                    items[behaviorCount] = filePath;
                    items[behaviorCount + 1] = pattern;
                    items[behaviorCount + 2] = instance;
                }
                else
                {
                    items = new EntitySimpleBaseType[3];
                    itemChoices = new textfilecontent54_ItemsChoices[3];
                    itemChoices[0] = textfilecontent54_ItemsChoices.filepath;
                    itemChoices[1] = textfilecontent54_ItemsChoices.pattern;
                    itemChoices[2] = textfilecontent54_ItemsChoices.instance;
                    items[0] = filePath;
                    items[1] = pattern;
                    items[2] = instance;
                }

            }

            fileContentObject.Items = items;
            fileContentObject.Textfilecontent54ItemsElementName = itemChoices;

            return fileContentObject;
        }
        public Questions getQuestion(int index)
        {
            string constr = @"Server=NIKKHIL-HP\sqlexpress;Integrated Security=true; database=OnlineExamination";
            SqlDataAdapter da = new SqlDataAdapter();
            SqlCommandBuilder sb = new SqlCommandBuilder(da);
            SqlConnection conn = new SqlConnection(constr);
            conn.Open();
            SqlTransaction tran = conn.BeginTransaction();
            String sql = "Select * from Questions";
            da.SelectCommand = new SqlCommand(sql, conn, tran);
            DataSet ds = new DataSet();
            da.Fill(ds, "Questions");
            DataTable dt = ds.Tables["Questions"];

            Questions et = new Questions();

            DataRow dr = dt.Rows[index];
            dr = dt.Rows[index];
            Object[] abc = new Object[11];
            abc = dr.ItemArray;
            et.question_ID = (string)abc.ElementAt(0);
            et.exam_Type = (string)abc.ElementAt(1);
            et.format = (string)abc.ElementAt(2);
            et.question = (string)abc.ElementAt(3);
            et.option1 = (string)abc.ElementAt(4);
            et.option2 = (string)abc.ElementAt(5);
            et.option3 = (string)abc.ElementAt(6);
            et.option4 = (string)abc.ElementAt(7);
            et.solution = (string)abc.ElementAt(8);
            string abcde = abc.ElementAt(9).ToString();
            et.marks = Convert.ToInt32(abcde);
            et.section = (string)abc.ElementAt(10);
            conn.Close();
            return et;
        }