Ejemplo n.º 1
0
 public bool AddQuestionTemp(QuestionTemp PQ)
 {
     try
     {
         db.QuestionTemps.Add(PQ);
         db.SaveChanges();
     }
     catch (DbEntityValidationException e)
     {
         foreach (var eve in e.EntityValidationErrors)
         {
             Debug.WriteLine("- Entity of type \"{0}\", in state \"{1}\" has the following validation errors: ", eve.Entry.Entity.GetType().Name, eve.Entry.State);
             foreach (var ve in eve.ValidationErrors)
             {
                 Debug.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage);
             }
         }
         return(false);
     }
     catch (Exception e)
     {
         Debug.WriteLine(e.Message);
         return(false);
     }
     return(true);
 }
        public static bool SaveQuestion(SQLiteDataReader rs, Guid SubjectID, Guid classid)
        {
            string       Campo;
            int          i;
            QuestionTemp q = new QuestionTemp();

            for (i = 0; i < rs.FieldCount; i++)
            {
                Campo = rs.GetName(i);
                var valor = rs.GetValue(i);
                switch (Campo)
                {
                case "QuestionID":
                    q.QuestionID = rs.GetGuid(i);
                    break;

                case "SubjectID":
                    q.SubjectID = SubjectID;
                    break;

                case "ClassID": q.ClassID = classid; break;

                case "MentalityTypeID": break;

                case "OSubjectID": break;

                case "QuestionNbr":
                    q.QuestionNbr = rs.GetString(i);
                    break;

                case "Content":
                    q.Content = (Byte[])rs.GetValue(i);    // != DBNull.Value ? (Byte[])rs.GetValue(i) : null;
                    break;

                case "Question":
                    q.Question = (Byte[])rs.GetValue(i);    // != DBNull.Value ? (Byte[])rs.GetValue(i) : null;
                    //  q.PicQuestion = imageToByteArray(byteArrayToImage((byte[])rs.GetValue(i)));
                    //q.PicQuestion = System.IO.File.ReadAllBytes(((byte[])rs.GetValue(i));
                    break;

                case "Answer1":
                    q.Answer1 = (Byte[])rs.GetValue(i);    // != DBNull.Value ? (Byte[])rs.GetValue(i) : null;
                    //   q.PicAnswer1 = imageToByteArray(byteArrayToImage((byte[])rs.GetValue(i)));
                    break;

                case "Answer2":
                    //q.Answer2 = ReadMsWordHavePic((Byte[])rs.GetValue(i));
                    q.Answer2 = (Byte[])rs.GetValue(i);    // != DBNull.Value ? (Byte[])rs.GetValue(i) : null;
                    // q.PicAnswer2 = imageToByteArray(byteArrayToImage((byte[])rs.GetValue(i)));
                    break;

                case "Answer3":
                    //q.Answer3 = ReadMsWordHavePic((Byte[])rs.GetValue(i));
                    q.Answer3 = (Byte[])rs.GetValue(i);    // != DBNull.Value ? (Byte[])rs.GetValue(i) : null;
                    // q.PicAnswer3 = imageToByteArray(byteArrayToImage((byte[])rs.GetValue(i)));
                    break;

                case "Answer4":
                    //q.Answer4 = ReadMsWordHavePic((Byte[])rs.GetValue(i));
                    q.Answer4 = (Byte[])rs.GetValue(i);    // != DBNull.Value ? (Byte[])rs.GetValue(i) : null;
                    // q.PicAnswer4 = imageToByteArray(byteArrayToImage((byte[])rs.GetValue(i)));
                    break;

                case "NoOfAnswers":
                    q.NoOfAnswers = rs.GetInt32(i);    // (int)rs.GetValue(i);
                    break;

                case "TheAnswer":
                    q.TheAnswer = rs.GetInt32(i);
                    break;

                default:
                    q.Answer1SwapYN = true;
                    q.Answer2SwapYN = true;
                    q.Answer3SwapYN = true;
                    q.Answer4SwapYN = true;
                    break;
                }
            }
            q.Used   = 0;
            q.Active = true;
            q.QID    = (int)i;
            int maxlength = 0;

            int[] a;
            a = new int[4];

            a[0] = q.Answer1.Length;
            a[1] = q.Answer2.Length;
            a[2] = q.Answer3.Length;
            a[3] = q.Answer4.Length;

            for (int j = 0; j < a.Length; j++)
            {
                if (maxlength < a[j])
                {
                    maxlength = a[j];
                }
            }
            q.MaxAnswerLen = maxlength;
            if (!new QuestionDAO().AddQuestionTemp(q))
            {
                return(false);
            }
            return(true);
        }