コード例 #1
0
        public static Researcher fetchFullResearcherDetails(int Id)
        {
            Researcher researcher = new Researcher();

            MySqlConnection conn = GetConnection();
            MySqlDataReader rdr  = null;

            try
            {
                conn.Open();
                //When referenceing                         0   1     2           3            4      5     6       7      8      9       10             11     12          13
                MySqlCommand cmd = new MySqlCommand("select id, type, given_name, family_name, title, unit, campus, email, photo, degree, supervisor_id, level, utas_start, current_start from researcher", conn);

                List <String> Students;
                Students = LoadStdntSupervised(cmd, Id);

                List <Publication> publications;
                String             name = rdr.GetString(2) + " " + rdr.GetString(3);
                publications = fetchBasicPublicationDetails(name);

                rdr = cmd.ExecuteReader();

                while (rdr.Read())
                {
                    if (rdr.GetInt32(0) == Id)
                    {
                        if (rdr.GetString(1) == "Staff")
                        {
                            researcher = new Staff
                            {
                                Id                 = rdr.GetInt32(0),
                                GivenName          = rdr.GetString(2),
                                FamilyName         = rdr.GetString(3),
                                Title              = ParseEnum <Title>(rdr.GetString(4)),
                                Unit               = rdr.GetString(5),
                                Campus             = ParseEnum <Campus>(rdr.GetString(6)),
                                Email              = rdr.GetString(7),
                                Photo              = rdr.GetString(8),
                                level              = rdr.GetChar(11),
                                CommenceInstDate   = DateTime.Parse(rdr.GetString(12)),
                                CommencePosDate    = DateTime.Parse(rdr.GetString(13)),
                                StudentsSupervised = Students,
                                Publications       = publications
                            };
                        }
                        else
                        {
                            researcher = new Student
                            {
                                Id               = rdr.GetInt32(0),
                                GivenName        = rdr.GetString(2),
                                FamilyName       = rdr.GetString(3),
                                Title            = ParseEnum <Title>(rdr.GetString(4)),
                                Unit             = rdr.GetString(5),
                                Campus           = ParseEnum <Campus>(rdr.GetString(6)),
                                Email            = rdr.GetString(7),
                                Photo            = rdr.GetString(8),
                                Degree           = rdr.GetString(9),
                                level            = 's',
                                CommenceInstDate = DateTime.Parse(rdr.GetString(12)),
                                CommencePosDate  = DateTime.Parse(rdr.GetString(13)),
                                Publications     = publications
                            };
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Error loading in full researcher details:" + e);
            }
            finally
            {
                if (rdr != null)
                {
                    rdr.Close();
                }

                if (conn != null)
                {
                    conn.Close();
                }
            }



            return(researcher);
        }