Exemplo n.º 1
0
        /// <summary>
        /// Populate business object from data reader
        /// </summary>
        /// <param name="businessObject">business object</param>
        /// <param name="dataReader">data reader</param>
        internal void PopulateBusinessObjectFromReader(CBatchicp businessObject, IDataReader dataReader)
        {
            businessObject.Idbatchicp = dataReader.GetInt32(dataReader.GetOrdinal(CBatchicp.CBatchicpFields.Idbatchicp.ToString()));

            if (!dataReader.IsDBNull(dataReader.GetOrdinal(CBatchicp.CBatchicpFields.Datecreation.ToString())))
            {
                businessObject.Datecreation = dataReader.GetDateTime(dataReader.GetOrdinal(CBatchicp.CBatchicpFields.Datecreation.ToString()));
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Populate business objects from the data reader
        /// </summary>
        /// <param name="dataReader">data reader</param>
        /// <returns>list of CBatchicp</returns>
        internal List <CBatchicp> PopulateObjectsFromReader(IDataReader dataReader)
        {
            List <CBatchicp> list = new List <CBatchicp>();

            while (dataReader.Read())
            {
                CBatchicp businessObject = new CBatchicp();
                PopulateBusinessObjectFromReader(businessObject, dataReader);
                list.Add(businessObject);
            }
            return(list);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Select by primary key
        /// </summary>
        /// <param name="keys">primary keys</param>
        /// <returns>CBatchicp business object</returns>
        public CBatchicp SelectByPrimaryKey(CBatchicpKeys keys)
        {
            NpgsqlCommand sqlCommand = new NpgsqlCommand();

            sqlCommand.CommandText = "public.sp_batchicp_SelectByPrimaryKey";
            sqlCommand.CommandType = CommandType.StoredProcedure;

            // Use connection object of base class
            sqlCommand.Connection = MainConnection;

            try
            {
                sqlCommand.Parameters.Add(new NpgsqlParameter("p_idbatchicp", NpgsqlDbType.Integer, 4, "", ParameterDirection.Input, false, 0, 0, DataRowVersion.Proposed, keys.Idbatchicp));


                MainConnection.Open();

                NpgsqlDataReader dataReader = sqlCommand.ExecuteReader();

                if (dataReader.Read())
                {
                    CBatchicp businessObject = new CBatchicp();

                    PopulateBusinessObjectFromReader(businessObject, dataReader);

                    return(businessObject);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("CBatchicp::SelectByPrimaryKey::Error occured.", ex);
            }
            finally
            {
                MainConnection.Close();
                sqlCommand.Dispose();
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// insert new row in the table
        /// </summary>
        /// <param name="businessObject">business object</param>
        /// <returns>true of successfully insert</returns>
        public bool Insert(CBatchicp businessObject)
        {
            NpgsqlCommand sqlCommand = new NpgsqlCommand();

            sqlCommand.CommandText = "public.sp_batchicp_Insert";
            sqlCommand.CommandType = CommandType.StoredProcedure;

            // Use connection object of base class
            sqlCommand.Connection = MainConnection;

            try
            {
                sqlCommand.Parameters.AddWithValue("p_idbatchicp", businessObject.Idbatchicp);
                sqlCommand.Parameters["p_idbatchicp"].NpgsqlDbType = NpgsqlDbType.Integer;
                sqlCommand.Parameters["p_idbatchicp"].Direction    = ParameterDirection.InputOutput;

                sqlCommand.Parameters.AddWithValue("p_datecreation", businessObject.Datecreation);
                sqlCommand.Parameters["p_datecreation"].NpgsqlDbType = NpgsqlDbType.Timestamp;


                MainConnection.Open();

                sqlCommand.ExecuteNonQuery();
                businessObject.Idbatchicp = Convert.ToInt32(sqlCommand.Parameters["p_idbatchicp"].Value);

                return(true);
            }
            catch (Exception ex)
            {
                throw new Exception("CBatchicp::Insert::Error occured.", ex);
            }
            finally
            {
                MainConnection.Close();
                sqlCommand.Dispose();
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// update row in the table
        /// </summary>
        /// <param name="businessObject">business object</param>
        /// <returns>true for successfully updated</returns>
        public bool Update(CBatchicp businessObject)
        {
            NpgsqlCommand sqlCommand = new NpgsqlCommand();

            sqlCommand.CommandText = "public.sp_batchicp_Update";
            sqlCommand.CommandType = CommandType.StoredProcedure;

            // Use connection object of base class
            sqlCommand.Connection = MainConnection;

            try
            {
                sqlCommand.Parameters.AddWithValue("p_idbatchicp", businessObject.Idbatchicp);
                sqlCommand.Parameters["p_idbatchicp"].NpgsqlDbType = NpgsqlDbType.Integer;
                sqlCommand.Parameters.AddWithValue("p_datecreation", businessObject.Datecreation);
                sqlCommand.Parameters["p_datecreation"].NpgsqlDbType = NpgsqlDbType.Timestamp;


                MainConnection.Open();

                if (Convert.ToInt32(sqlCommand.ExecuteScalar()) > 0)
                {
                    return(true);
                }
                return(false);
            }
            catch (Exception ex)
            {
                throw new Exception("CBatchicp::Update::Error occured.", ex);
            }
            finally
            {
                MainConnection.Close();
                sqlCommand.Dispose();
            }
        }