Exemple #1
0
        public static bool CreateForm(OdbcDataReader reader, Student student)
        {
            FieldInfo[] fields = reader.GetType().GetFields(
                BindingFlags.NonPublic |
                BindingFlags.Instance);
            PropertyInfo[] props = reader.GetType().GetProperties(
                BindingFlags.NonPublic |
                BindingFlags.Instance);

            int fCount = reader.FieldCount;

            for (int i = 0; i < fCount; i++)
            {
                string name = reader.GetName(i);
                //Console.WriteLine(name + reader.GetValue(i));

                // Map to DB field. Need to change if db changed
                switch (name)
                {
                case "student_id": student._studentID = reader.GetInt32(i);
                    break;

                case "sex": student._sex = reader.GetString(i);
                    break;

                case "tel": student._tel = reader.GetString(i);
                    break;

                case "tel2": student._tel2 = reader.GetString(i);
                    break;

                case "citizen_id": student._citizenID = reader.GetString(i);
                    break;

                case "email": student._email = reader.GetString(i);
                    break;

                case "addr": student._addr = reader.GetString(i);
                    break;

                case "quiz": student._quiz = reader.GetString(i);
                    break;

                case "birthday": student._birthday = new DateTime(reader.GetDate(i).Ticks);
                    break;

                case "firstname":
                    /*
                     *                      string s= reader.GetDataTypeName(i);
                     *                      byte[] b = new byte[8];
                     *                      reader.GetBytes(i, 0, b, 0, b.Length);
                     *                      //  student._firstname = reader.GetString(i);
                     *                      for (int j=0;j<b.Length;j++)
                     *                      {
                     *                          log.PutLine(Logger.INFO, b[j] + " ");
                     *                      }
                     *                      student._firstname = Encoding.GetEncoding("tis-620").GetString(b);
                     *                      log.PutLine(Logger.INFO,"ä·Âä·Â" + student._firstname);
                     */
                    student._firstname = reader.GetString(i);
                    break;

                case "surname": student._surname = reader.GetString(i);
                    break;

                case "nickname": student._nickname = reader.GetString(i);
                    break;

                case "school": student._school = reader.GetString(i);
                    break;

                case "level": student._level = reader.GetInt32(i);
                    break;

                case "image": student._img = reader.GetString(i);
                    break;

                case "create_date": student._create_date = new DateTime(reader.GetDate(i).Ticks);
                    break;

                case "is_active": student._isActive = reader.GetInt32(i) > 0 ? true : false;
                    break;
                }
            }
            return(reader.HasRows);
        }