Example #1
0
 public static Test GetTestByID(int id)
 {
     Test test = new Test() { ID = id };
     if (SelectTest(ref test))
         return test;
     else
         return null;
 }
Example #2
0
 private static bool SelectUser(ref User user)
 {
     try
     {
         SqlDatabase db = new SqlDatabase(Properties.Settings.Default.connString);
         using (DbCommand cmd = db.GetStoredProcCommand("SelectUser"))
         {
             db.AddInParameter(cmd, "authcode", DbType.String, user.AuthCode);
             using (IDataReader dr = db.ExecuteReader(cmd))
             {
                 bool first = true;
                 while (dr.Read())
                 {
                     if (first)
                     {
                         user.Age = dr["age"] as string;
                         user.AuthCode = dr["authcode"] as string;
                         user.Gender = dr["gender"] as string;
                         first = false;
                     }
                     int? tid = dr["testid"] as int?;
                     if (tid != null)
                     {
                         Test t = null;
                         if (user.Tests.ContainsKey(tid.Value))
                             t = user.Tests[tid.Value];
                         else
                         {
                             t = new Test()
                             {
                                 ID = tid.Value,
                                 TimeEst = (int)dr["timeest"],
                                 MaxArraySize = (int)dr["maxarraysize"],
                                 DelayPeriod = (int)dr["delayperiod"]
                             };
                             user.Tests.Add(tid.Value, t);
                         }
                         t.ImageArrays.Add(new ImageArray()
                         {
                             Index = (int)dr["index"],
                             ImagesDisplayed = (int)dr["imagesdisplayed"],
                             UserInput = (int)dr["userinput"],
                             ImageFile = (string)dr["imagefile"]
                         });
                     }
                 }
             }
             return true;
         }
     }
     catch
     {
         return false;
     }
 }
Example #3
0
 private static bool SelectTest(ref Test test)
 {
     try
     {
         SqlDatabase db = new SqlDatabase(Properties.Settings.Default.connString);
         using (DbCommand cmd = db.GetStoredProcCommand("SelectTest"))
         {
             db.AddInParameter(cmd, "id", DbType.String, test.ID);
             using (IDataReader dr = db.ExecuteReader(cmd))
             {
                 bool first = true;
                 while (dr.Read())
                 {
                     if (first)
                     {
                         test.TimeEst = (int)dr["timeest"];
                         test.MaxArraySize = (int)dr["maxarraysize"];
                         test.DelayPeriod = (int)dr["delayperiod"];
                         first = false;
                     }
                     test.SubTests.Add(new SubTest()
                     {
                         ImageFile = dr["imagefile"] as string,
                         TestID = test.ID
                     });
                 }
             }
             return true;
         }
     }
     catch
     {
         return false;
     }
 }