Пример #1
0
        public static Researcher.Researcher[] fetchBasicResearcherDetails()
        {
            MySqlDataReader rdr = null;
            List <Researcher.Researcher> researcherList = new List <Researcher.Researcher>();

            GetConnection();

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

                // 1. Instantiate a new command with a query and connection
                MySqlCommand cmd = new MySqlCommand("select id, given_name, family_name, level, title from researcher", 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)
                    };
                    res.positions = new List <Researcher.Position>();
                    //https://stackoverflow.com/questions/20547261/database-field-enum-to-c-sharp-list
                    Researcher.Position pos = new Researcher.Position {
                        level = (Researcher.EmploymentLevel)Enum.Parse(typeof(Researcher.EmploymentLevel), enumerated)
                    };
                    res.positions.Add(pos);
                    //Employee e = new Employee { Name = combined, ID = rdr.GetInt32(2) };
                    researcherList.Add(res);
                }
            }
            finally
            {
                // close the reader
                if (rdr != null)
                {
                    rdr.Close();
                }

                // Close the connection
                if (conn != null)
                {
                    conn.Close();
                }
            }
            return(researcherList.ToArray());
        }
Пример #2
0
        public static Researcher.Publication[] fetchBasicPublicationDetails(Researcher.Researcher r)
        {
            int researcherID = r.ID;

            //Fetch Positions
            MySqlDataReader rdr = null;

            GetConnection();
            List <Researcher.Publication> publication = new List <Researcher.Publication>();

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

                // 1. Instantiate a new command with a query and connection
                MySqlCommand cmd = new MySqlCommand("select publication.title, publication.year, publication.DOI from researcher_publication join publication on researcher_publication.doi = publication.doi where researcher_publication.researcher_id = " + researcherID + " order by year DESC, title;", 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));
                    //https://stackoverflow.com/questions/20547261/database-field-enum-to-c-sharp-list
                    publication.Add(new Researcher.Publication {
                        Title = rdr.GetString(0), Year = rdr.GetInt32(1), DOI = rdr.GetString(2)
                    });
                }
            }
            finally
            {
                // close the reader
                if (rdr != null)
                {
                    rdr.Close();
                }

                // Close the connection
                if (conn != null)
                {
                    conn.Close();
                }
            }
            return(publication.ToArray());
        }
Пример #3
0
        public static List <int[]> cumulativeCounts(Researcher.Researcher researcher)
        {
            int id = researcher.ID;

            int currentyear = 0;

            List <int[]>    cumulativeCount             = new List <int[]>();
            MySqlDataReader rdr                         = null;
            List <Researcher.Researcher> researcherList = new List <Researcher.Researcher>();

            GetConnection();

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

                // 1. Instantiate a new command with a query and connection
                MySqlCommand cmd = new MySqlCommand("select publication.year from researcher_publication join publication on researcher_publication.doi = publication.doi where researcher_publication.researcher_id = " + id + " order by year;", 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));
                    if (currentyear == 0)
                    {
                        currentyear = rdr.GetInt32(0);
                        cumulativeCount.Add(new int[] { currentyear, 1 });
                    }
                    else
                    {
                        currentyear = rdr.GetInt32(0);
                        if (currentyear == cumulativeCount.LastOrDefault()[0])
                        {
                            cumulativeCount.LastOrDefault()[1] += 1;
                        }
                        else
                        {
                            cumulativeCount.Add(new int[] { currentyear, 1 });
                        }
                    }
                }
            }
            finally
            {
                // close the reader
                if (rdr != null)
                {
                    rdr.Close();
                }

                // Close the connection
                if (conn != null)
                {
                    conn.Close();
                }
            }
            return(cumulativeCount);
        }
 public Researcher.Publication[] loadPublicationsFor(Researcher.Researcher r)
 {
     return(Adapters.ERDAdapter.fetchBasicPublicationDetails(r));
 }
 public void loadPublications(Researcher.Researcher r)
 {
     mainList    = new List <Researcher.Publication>(loadPublicationsFor(r));
     displayList = new ObservableCollection <Researcher.Publication>(mainList);
 }