/// <summary>
        /// Get collection of Winning Numbers. If no records to return, WinningNumbersCollection will be null.
        /// </summary>
        /// <returns></returns>
        public static WinningNumbersCollection GetCollection()
        {
            WinningNumbersCollection tempList = null;

            using (SqlConnection myConnection = new SqlConnection(AppConfiguration.ConnectionString))
            {
                using (SqlCommand myCommand = new SqlCommand("usp_GetDrawingDate", myConnection))
                {
                    myCommand.CommandType = CommandType.StoredProcedure;

                    myCommand.Parameters.AddWithValue("@QueryId", SelectTypeEnum.GetCollection);

                    myConnection.Open();

                    using (SqlDataReader myReader = myCommand.ExecuteReader())
                    {
                        if (myReader.HasRows)
                        {
                            tempList = new WinningNumbersCollection();

                            while (myReader.Read())
                            {
                                tempList.Add(FillDataRecord(myReader));
                            }
                        }
                        myReader.Close();
                    }
                }
            }
            return tempList;
        }
示例#2
0
        private static void LessonCollections()
        {
            //Generic list
            List<Employee> myEmployeeList = new List<Employee>();
            myEmployeeList.Add(new Employee { FirstName = "Jesse", LastName = "Peterson" });
            myEmployeeList.Add(new Employee { FirstName = "Bob", LastName = "Thomas" });
            myEmployeeList.Add(new Employee { FirstName = "Frank", LastName = "Vasco" });
            myEmployeeList.Add(new Employee { FirstName = "Nick", LastName = "Johnson" });
            myEmployeeList.Add(new Employee { FirstName = "Fred", LastName = "Domingo" });

            //Uses the collections class
            EmployeeCollection myEmployeeCollection = new EmployeeCollection();

            myEmployeeCollection.Add(new Employee { FirstName = "Jesse", LastName = "Peterson" });
            myEmployeeCollection.Add(new Employee { FirstName = "Bob", LastName = "Thomas" });
            myEmployeeCollection.Add(new Employee { FirstName = "Frank", LastName = "Vasco" });
            myEmployeeCollection.Add(new Employee { FirstName = "Nick", LastName = "Johnson" });
            myEmployeeCollection.Add(new Employee { FirstName = "Fred", LastName = "Domingo" });

            WinningNumbersCollection myNumsCollection = new WinningNumbersCollection();

            myNumsCollection.Add(new WinningNumbers { WinningNumbersId = 1, NumberValue = 7, BallTypeName = "Normal" });
            myNumsCollection.Add(new WinningNumbers { WinningNumbersId = 1, NumberValue = 9, BallTypeName = "Normal" });
            myNumsCollection.Add(new WinningNumbers { WinningNumbersId = 1, NumberValue = 17, BallTypeName = "Normal" });
            myNumsCollection.Add(new WinningNumbers { WinningNumbersId = 1, NumberValue = 25, BallTypeName = "Normal" });
            myNumsCollection.Add(new WinningNumbers { WinningNumbersId = 1, NumberValue = 35, BallTypeName = "Normal" });
            myNumsCollection.Add(new WinningNumbers { WinningNumbersId = 1, NumberValue = 2, BallTypeName = "Normal" });

            int i = 1;
            foreach (WinningNumbers item in myNumsCollection)
            {
                Console.WriteLine("Id: " + i + "\n"
                    + "Value: " + item.NumberValue + "\n" + "Ball Type: " + item.BallTypeName);
                i++;
            }
            Console.Read();
        }