public void LoadResearcherDetails(int id)
        {
            var filtered = from Researcher.Researcher res in mainList
                           where res.ID == id
                           select res;

            if (filtered.ToList().LastOrDefault().GetCurrentJob().level == Researcher.EmploymentLevel.Student)
            {
                student = (Researcher.Student)Adapters.ERDAdapter.fetchFullResearcherDetails(id);
                isStaff = false;
            }
            else
            {
                staff   = (Researcher.Staff)Adapters.ERDAdapter.fetchFullResearcherDetails(id);
                isStaff = true;
            }
        }
Ejemplo n.º 2
0
        public static Researcher.Researcher fetchFullResearcherDetails(int id)
        {
            MySqlDataReader            rdr = null;
            List <Researcher.Position> positions;
            List <Researcher.Student>  supervisions = new List <Researcher.Student>();

            Researcher.Student student;
            Researcher.Staff   staff;
            GetConnection();

            try
            {
                // Open the connection
                conn.Open();

                // 1. Instantiate a new command with a query and connection
                //MySqlCommand cmd = new MySqlCommand("select type,given_name,family_name,title,unit,campus,email,photo,degree,supervisor_id,level,utas_start,current_start from researcher where id = "+id, conn);
                MySqlCommand cmd = new MySqlCommand("select * from researcher where id = " + id, conn);

                // 2. Call Execute reader to get query results
                rdr = cmd.ExecuteReader();

                // print the CategoryName of each record
                while (rdr.Read())
                {
                    //This illustrates how the raw data can be obtained using an indexer [] or a particular data type can be obtained using a GetTYPENAME() method.
                    //Console.WriteLine("{0} {1}", rdr[0], rdr.GetString(1));

                    /*var enumerated = rdr[3] != DBNull.Value ? rdr.GetString(3) : "Student";
                     * Researcher.Researcher res = new Researcher.Researcher { GivenName = rdr.GetString(1), FamilyName = rdr.GetString(2), ID = rdr.GetInt32(0), Title = rdr.GetString(4), level = (Researcher.EmploymentLevel)Enum.Parse(typeof(Researcher.EmploymentLevel), enumerated )};*/

                    if (rdr.GetString(1) == "Student")
                    {
                        var enumerated = rdr[11] != DBNull.Value ? rdr.GetString(3) : "Student";
                        int supervisor = rdr.GetInt32(10);

                        student = new Researcher.Student {
                            ID = id, GivenName = rdr.GetString(2), FamilyName = rdr.GetString(3), Title = rdr.GetString(4), School = rdr.GetString(5), Campus = rdr.GetString(6), Email = rdr.GetString(7), Photo = rdr.GetString(8), Degree = rdr.GetString(9)
                        };
                        //student = new Researcher.Student { ID = id, GivenName = rdr.GetString(2), FamilyName = rdr.GetString(3), Title = rdr.GetString(4), School = rdr.GetString(5), Campus = rdr.GetString(6), Email = rdr.GetString(7), Photo = rdr.GetString(8), Degree = rdr.GetString(9)};
                        Researcher.Position studentPos = new Researcher.Position {
                            start = rdr.GetDateTime(12), level = Researcher.EmploymentLevel.Student
                        };
                        conn.Close();
                        student.supervisor = retrieveResearchersName(supervisor);
                        student.positions  = new List <Researcher.Position>();
                        student.positions.Add(studentPos);
                        return(student);
                    }
                    else
                    {
                        var enumerated = rdr[11] != DBNull.Value ? rdr.GetString(3) : "Student";
                        staff = new Researcher.Staff {
                            ID = id, GivenName = rdr.GetString(2), FamilyName = rdr.GetString(3), Title = rdr.GetString(4), School = rdr.GetString(5), Campus = rdr.GetString(6), Email = rdr.GetString(7), Photo = rdr.GetString(8)
                        };
                        conn.Close();
                        positions       = fetchPositions(id);
                        staff.positions = new List <Researcher.Position>(positions);
                        foreach (int iid in getStudentID(id))
                        {
                            //Console.WriteLine(iid);
                            supervisions.Add((Researcher.Student)fetchFullResearcherDetails(iid));
                        }
                        staff.student = new List <Researcher.Student>(supervisions);
                        return(staff);
                    }
                }
            }
            finally
            {
                // close the reader
                if (rdr != null)
                {
                    rdr.Close();
                }

                // Close the connection
                if (conn != null)
                {
                    conn.Close();
                }
            }
            return(new Researcher.Researcher());
        }