Example #1
0
        public IEnumerable <ValidHourEntry> SelValidHourEntries()
        {
            int intRC = 0;

            objValidHourEntries = new List <ValidHourEntry>();

            IParameterFactory objParams = new ValidHourEntryParameterFactory();

            System.Data.SqlClient.SqlCommand objCmd = new SqlCommand("pSelValidHours", 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())
                {
                    ValidHourEntry objVHE = new ValidHourEntry();
                    objVHE.TimePeriodID = (int)objDR["TimePeriodID"];
                    objVHE.TimePeriod   = (string)objDR["TimePeriod"];
                    ((List <ValidHourEntry>)objValidHourEntries).Add(objVHE);
                }
                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(objValidHourEntries);
        }
Example #2
0
        public IEnumerable<ValidHourEntry> SelValidHourEntries()
        {
            //Set up the variables
            int intRC = 0;
            SqlDataReader dr;
            List<ValidHourEntry> retVal = new List<ValidHourEntry>();

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

            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 = "pSelValidHours";

                        dr = sqlCommand.ExecuteReader();

                        while (dr.Read())
                        {
                            ValidHourEntry vhe = new ValidHourEntry();
                            vhe.TimePeriodID = (int)dr["TimePeriodID"];
                            vhe.TimePeriod = (string)dr["TimePeriod"];
                            retVal.Add(vhe);
                        }
                        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;
        }
Example #3
0
        static void TestValidHourEntry()
        {
            int intRC;
            ValidHourEntry objVhe = new ValidHourEntry();

            foreach (ValidHourEntry vhe in objVhe.SelValidHourEntries())
            {
                Console.WriteLine("Time Period ID: {0}, Time Period {1}", vhe.TimePeriodID, vhe.TimePeriod);
            }
        }
Example #4
0
        public IEnumerable<ValidHourEntry> SelValidHourEntries()
        {
            int intRC = 0;
            objValidHourEntries = new List<ValidHourEntry>();

            IParameterFactory objParams = new ValidHourEntryParameterFactory();
            System.Data.SqlClient.SqlCommand objCmd = new SqlCommand("pSelValidHours", 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())
                {
                    ValidHourEntry objVHE = new ValidHourEntry();
                    objVHE.TimePeriodID = (int)objDR["TimePeriodID"];
                    objVHE.TimePeriod = (string)objDR["TimePeriod"];
                    ((List<ValidHourEntry>)objValidHourEntries).Add(objVHE);
                }

                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 objValidHourEntries;
        }