Esempio n. 1
0
        public IEnumerable <ThisYearsDate> SelThisYearsDates()
        {
            int intRC = 0;

            objThisYearsDate = new List <ThisYearsDate>();

            IParameterFactory objParams = new ThisYearsDateParameterFactory();

            System.Data.SqlClient.SqlCommand objCmd = new SqlCommand("pSelThisYearsDates", new ADOConnectionFactory().Connection);
            objCmd.CommandType = CommandType.StoredProcedure;

            objCmd.Parameters.Add(objParams.Parmeters["RC"]);

            try
            {
                objCmd.Connection.Open();
                System.Data.SqlClient.SqlDataReader objDR = objCmd.ExecuteReader();
                while (objDR.Read())
                {
                    ThisYearsDate objTYD = new ThisYearsDate();
                    objTYD.DateID   = (int)objDR["DateID"];
                    objTYD.DateName = (string)objDR["PDateName"];
                    ((List <ThisYearsDate>)objThisYearsDate).Add(objTYD);
                }
                objDR.Close();
                intRC = (int)objParams.Parmeters["RC"].Value;
                if (intRC < 0)
                {
                    throw new Exception("Error reported in Stored Procedure: " + objParams.Parmeters["RC"].Value.ToString());
                }
                objCmd.Connection.Close();
            }
            catch (Exception) { throw; }
            return(objThisYearsDate);
        }
Esempio n. 2
0
        public IEnumerable<ThisYearsDate> SelThisYearsDates()
        {
            //Set up the variables
            int intRC = 0;
            SqlDataReader dr;
            List<ThisYearsDate> retVal = new List<ThisYearsDate>();

            //Set up the parameters using my custom parameter factory
            IParameterFactory objParams = new ThisYearsDateParameterFactory();

            try
            {
                using (SqlConnection sqlConnection = new ADOConnectionFactory().Connection)
                {
                    sqlConnection.Open();
                    using (SqlCommand sqlCommand = new SqlCommand())
                    {

                        sqlCommand.Connection = sqlConnection;

                        sqlCommand.Parameters.Add((objParams.Parameters["RC"]));

                        //call stored procedure to insert record
                        sqlCommand.CommandType = CommandType.StoredProcedure;
                        sqlCommand.CommandText = "pSelThisYearsDates";

                        dr = sqlCommand.ExecuteReader();

                        while (dr.Read())
                        {
                            ThisYearsDate tyd = new ThisYearsDate();
                            tyd._dateID = (int)dr["dateID"];
                            tyd._dateName = (string)dr["dateName"];
                            retVal.Add(tyd);
                        }

                        dr.Close();

                        //check the return code for errors
                        intRC = (int)objParams.Parameters["RC"].Value;
                        if (intRC < 0)
                        {
                            throw new Exception("Error reported in Stored Procedure: " + objParams.Parameters["RC"].Value.ToString());
                        }

                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            return retVal;
        }
Esempio n. 3
0
        static void TestThisYearsDate()
        {
            int intRC;
            ThisYearsDate objTyd = new ThisYearsDate();


            foreach (ThisYearsDate tyd in objTyd.SelThisYearsDates())
            {
                Console.WriteLine("Date ID: {0}, Date Name {1}", tyd.DateID, tyd.DateName);
            }

        }
Esempio n. 4
0
        public IEnumerable<ThisYearsDate> SelThisYearsDates()
        {
            int intRC = 0;
            objThisYearsDates = new List<ThisYearsDate>();

            IParameterFactory objParams = new ValidHourEntryParameterFactory();
            System.Data.SqlClient.SqlCommand objCmd = new SqlCommand("pSelThisYearsDates", new ADOConnectionFactory().Connection);
            objCmd.CommandType = CommandType.StoredProcedure;

            objCmd.Parameters.Add(objParams.Parmeters["RC"]);
            try
            {
                objCmd.Connection.Open();
                System.Data.SqlClient.SqlDataReader objDR = objCmd.ExecuteReader();
                while (objDR.Read())
                {
                    ThisYearsDate objTYD = new ThisYearsDate();
                    objTYD.DateID = (int)objDR["DateID"];
                    objTYD.DateName = (string)objDR["DateName"];
                    ((List<ThisYearsDate>)objThisYearsDates).Add(objTYD);
                }

                objDR.Close(); //You cannot get the return value if the reader is not closed!
                intRC = (int)objParams.Parmeters["RC"].Value;
                if (intRC < 0)
                { throw new Exception("Error reported in Stored Procedure: " + objParams.Parmeters["RC"].Value.ToString()); }
                objCmd.Connection.Close();
            }
            catch (Exception) { throw; }
            return objThisYearsDates;
        }