/// <summary> /// Populate business objects from the data reader /// </summary> /// <param name="dataReader">data reader</param> /// <returns>list of CTemplate_method_format</returns> internal List <CTemplate_method_format> PopulateObjectsFromReader(IDataReader dataReader) { List <CTemplate_method_format> list = new List <CTemplate_method_format>(); while (dataReader.Read()) { CTemplate_method_format businessObject = new CTemplate_method_format(); PopulateBusinessObjectFromReader(businessObject, dataReader); list.Add(businessObject); } return(list); }
/// <summary> /// Populate business object from data reader /// </summary> /// <param name="businessObject">business object</param> /// <param name="dataReader">data reader</param> internal void PopulateBusinessObjectFromReader(CTemplate_method_format businessObject, IDataReader dataReader) { businessObject.Idtemplate_method_format = dataReader.GetInt64(dataReader.GetOrdinal(CTemplate_method_format.CTemplate_method_formatFields.Idtemplate_method_format.ToString())); if (!dataReader.IsDBNull(dataReader.GetOrdinal(CTemplate_method_format.CTemplate_method_formatFields.Idtemplate_method.ToString()))) { businessObject.Idtemplate_method = dataReader.GetInt32(dataReader.GetOrdinal(CTemplate_method_format.CTemplate_method_formatFields.Idtemplate_method.ToString())); } if (!dataReader.IsDBNull(dataReader.GetOrdinal(CTemplate_method_format.CTemplate_method_formatFields.Nom_field.ToString()))) { businessObject.Nom_field = dataReader.GetString(dataReader.GetOrdinal(CTemplate_method_format.CTemplate_method_formatFields.Nom_field.ToString())); } if (!dataReader.IsDBNull(dataReader.GetOrdinal(CTemplate_method_format.CTemplate_method_formatFields.Num_decimal.ToString()))) { businessObject.Num_decimal = (short?)dataReader.GetInt16(dataReader.GetOrdinal(CTemplate_method_format.CTemplate_method_formatFields.Num_decimal.ToString())); } }
/// <summary> /// Select by primary key /// </summary> /// <param name="keys">primary keys</param> /// <returns>CTemplate_method_format business object</returns> public CTemplate_method_format SelectByPrimaryKey(CTemplate_method_formatKeys keys) { NpgsqlCommand sqlCommand = new NpgsqlCommand(); sqlCommand.CommandText = "public.sp_template_method_format_SelectByPrimaryKey"; sqlCommand.CommandType = CommandType.StoredProcedure; // Use connection object of base class sqlCommand.Connection = MainConnection; try { sqlCommand.Parameters.Add(new NpgsqlParameter("p_idtemplate_method_format", NpgsqlDbType.Bigint, 8, "", ParameterDirection.Input, false, 0, 0, DataRowVersion.Proposed, keys.Idtemplate_method_format)); MainConnection.Open(); NpgsqlDataReader dataReader = sqlCommand.ExecuteReader(); if (dataReader.Read()) { CTemplate_method_format businessObject = new CTemplate_method_format(); PopulateBusinessObjectFromReader(businessObject, dataReader); return(businessObject); } else { return(null); } } catch (Exception ex) { throw new Exception("CTemplate_method_format::SelectByPrimaryKey::Error occured.", ex); } finally { MainConnection.Close(); sqlCommand.Dispose(); } }
/// <summary> /// insert new row in the table /// </summary> /// <param name="businessObject">business object</param> /// <returns>true of successfully insert</returns> public bool Insert(CTemplate_method_format businessObject) { NpgsqlCommand sqlCommand = new NpgsqlCommand(); sqlCommand.CommandText = "public.sp_template_method_format_Insert"; sqlCommand.CommandType = CommandType.StoredProcedure; // Use connection object of base class sqlCommand.Connection = MainConnection; try { sqlCommand.Parameters.AddWithValue("p_idtemplate_method_format", businessObject.Idtemplate_method_format); sqlCommand.Parameters["p_idtemplate_method_format"].NpgsqlDbType = NpgsqlDbType.Bigint; sqlCommand.Parameters["p_idtemplate_method_format"].Direction = ParameterDirection.InputOutput; sqlCommand.Parameters.AddWithValue("p_idtemplate_method", businessObject.Idtemplate_method); sqlCommand.Parameters["p_idtemplate_method"].NpgsqlDbType = NpgsqlDbType.Integer; sqlCommand.Parameters.AddWithValue("p_nom_field", businessObject.Nom_field); sqlCommand.Parameters["p_nom_field"].NpgsqlDbType = NpgsqlDbType.Varchar; sqlCommand.Parameters.AddWithValue("p_num_decimal", businessObject.Num_decimal); sqlCommand.Parameters["p_num_decimal"].NpgsqlDbType = NpgsqlDbType.Smallint; MainConnection.Open(); sqlCommand.ExecuteNonQuery(); businessObject.Idtemplate_method_format = Convert.ToInt64(sqlCommand.Parameters["p_idtemplate_method_format"].Value); return(true); } catch (Exception ex) { throw new Exception("CTemplate_method_format::Insert::Error occured.", ex); } finally { MainConnection.Close(); sqlCommand.Dispose(); } }
/// <summary> /// update row in the table /// </summary> /// <param name="businessObject">business object</param> /// <returns>true for successfully updated</returns> public bool Update(CTemplate_method_format businessObject) { NpgsqlCommand sqlCommand = new NpgsqlCommand(); sqlCommand.CommandText = "public.sp_template_method_format_Update"; sqlCommand.CommandType = CommandType.StoredProcedure; // Use connection object of base class sqlCommand.Connection = MainConnection; try { sqlCommand.Parameters.AddWithValue("p_idtemplate_method_format", businessObject.Idtemplate_method_format); sqlCommand.Parameters["p_idtemplate_method_format"].NpgsqlDbType = NpgsqlDbType.Bigint; sqlCommand.Parameters.AddWithValue("p_idtemplate_method", businessObject.Idtemplate_method); sqlCommand.Parameters["p_idtemplate_method"].NpgsqlDbType = NpgsqlDbType.Integer; sqlCommand.Parameters.AddWithValue("p_nom_field", businessObject.Nom_field); sqlCommand.Parameters["p_nom_field"].NpgsqlDbType = NpgsqlDbType.Varchar; sqlCommand.Parameters.AddWithValue("p_num_decimal", businessObject.Num_decimal); sqlCommand.Parameters["p_num_decimal"].NpgsqlDbType = NpgsqlDbType.Smallint; MainConnection.Open(); if (Convert.ToInt32(sqlCommand.ExecuteScalar()) > 0) { return(true); } return(false); } catch (Exception ex) { throw new Exception("CTemplate_method_format::Update::Error occured.", ex); } finally { MainConnection.Close(); sqlCommand.Dispose(); } }