/// <summary> /// Populate business objects from the data reader /// </summary> /// <param name="dataReader">data reader</param> /// <returns>list of CPrice_attach</returns> internal List <CPrice_attach> PopulateObjectsFromReader(IDataReader dataReader) { List <CPrice_attach> list = new List <CPrice_attach>(); while (dataReader.Read()) { CPrice_attach businessObject = new CPrice_attach(); PopulateBusinessObjectFromReader(businessObject, dataReader); list.Add(businessObject); } return(list); }
/// <summary> /// insert new row in the table /// </summary> /// <param name="businessObject">business object</param> /// <returns>true of successfully insert</returns> public bool Insert(CPrice_attach businessObject) { NpgsqlCommand sqlCommand = new NpgsqlCommand(); sqlCommand.CommandText = "public.sp_price_attach_Insert"; sqlCommand.CommandType = CommandType.StoredProcedure; // Use connection object of base class sqlCommand.Connection = MainConnection; try { sqlCommand.Parameters.AddWithValue("p_idattach", businessObject.Idattach); sqlCommand.Parameters["p_idattach"].NpgsqlDbType = NpgsqlDbType.Integer; sqlCommand.Parameters["p_idattach"].Direction = ParameterDirection.InputOutput; sqlCommand.Parameters.AddWithValue("p_idprice", businessObject.Idprice); sqlCommand.Parameters["p_idprice"].NpgsqlDbType = NpgsqlDbType.Integer; sqlCommand.Parameters.AddWithValue("p_idprice_version", businessObject.Idprice_version); sqlCommand.Parameters["p_idprice_version"].NpgsqlDbType = NpgsqlDbType.Integer; sqlCommand.Parameters.AddWithValue("p_name_document", businessObject.Name_document); sqlCommand.Parameters["p_name_document"].NpgsqlDbType = NpgsqlDbType.Varchar; sqlCommand.Parameters.AddWithValue("p_type_document", businessObject.Type_document); sqlCommand.Parameters["p_type_document"].NpgsqlDbType = NpgsqlDbType.Varchar; MainConnection.Open(); sqlCommand.ExecuteNonQuery(); businessObject.Idattach = Convert.ToInt32(sqlCommand.Parameters["p_idattach"].Value); return(true); } catch (Exception ex) { throw new Exception("CPrice_attach::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(CPrice_attach businessObject) { NpgsqlCommand sqlCommand = new NpgsqlCommand(); sqlCommand.CommandText = "public.sp_price_attach_Update"; sqlCommand.CommandType = CommandType.StoredProcedure; // Use connection object of base class sqlCommand.Connection = MainConnection; try { sqlCommand.Parameters.AddWithValue("p_idattach", businessObject.Idattach); sqlCommand.Parameters["p_idattach"].NpgsqlDbType = NpgsqlDbType.Integer; sqlCommand.Parameters.AddWithValue("p_idprice", businessObject.Idprice); sqlCommand.Parameters["p_idprice"].NpgsqlDbType = NpgsqlDbType.Integer; sqlCommand.Parameters.AddWithValue("p_idprice_version", businessObject.Idprice_version); sqlCommand.Parameters["p_idprice_version"].NpgsqlDbType = NpgsqlDbType.Integer; sqlCommand.Parameters.AddWithValue("p_name_document", businessObject.Name_document); sqlCommand.Parameters["p_name_document"].NpgsqlDbType = NpgsqlDbType.Varchar; sqlCommand.Parameters.AddWithValue("p_type_document", businessObject.Type_document); sqlCommand.Parameters["p_type_document"].NpgsqlDbType = NpgsqlDbType.Varchar; MainConnection.Open(); if (Convert.ToInt32(sqlCommand.ExecuteScalar()) > 0) { return(true); } return(false); } catch (Exception ex) { throw new Exception("CPrice_attach::Update::Error occured.", ex); } finally { MainConnection.Close(); sqlCommand.Dispose(); } }
/// <summary> /// Select by primary key /// </summary> /// <param name="keys">primary keys</param> /// <returns>CPrice_attach business object</returns> public CPrice_attach SelectByPrimaryKey(CPrice_attachKeys keys) { NpgsqlCommand sqlCommand = new NpgsqlCommand(); sqlCommand.CommandText = "public.sp_price_attach_SelectByPrimaryKey"; sqlCommand.CommandType = CommandType.StoredProcedure; // Use connection object of base class sqlCommand.Connection = MainConnection; try { sqlCommand.Parameters.Add(new NpgsqlParameter("p_idattach", NpgsqlDbType.Integer, 4, "", ParameterDirection.Input, false, 0, 0, DataRowVersion.Proposed, keys.Idattach)); MainConnection.Open(); NpgsqlDataReader dataReader = sqlCommand.ExecuteReader(); if (dataReader.Read()) { CPrice_attach businessObject = new CPrice_attach(); PopulateBusinessObjectFromReader(businessObject, dataReader); return(businessObject); } else { return(null); } } catch (Exception ex) { throw new Exception("CPrice_attach::SelectByPrimaryKey::Error occured.", ex); } finally { MainConnection.Close(); sqlCommand.Dispose(); } }
public void Save(CPrice price, CPrice_version price_version) { foreach (CItemCopy item in this) { //copiar item if (ComunForm.CopyAndSaveFile(item.Source_file, item.Destiny_directory, item.Filename)) { CPrice_attach price_attach = new CPrice_attach(); price_attach.Idprice = price_version.Idprice; price_attach.Idprice_version = price_version.Idprice_version; price_attach.Name_document = item.Filename; //guardar adjunto if (!new CPrice_attachFactory().Update(price_attach)) { new CPrice_attachFactory().Insert(price_attach); } } } }
/// <summary> /// Populate business object from data reader /// </summary> /// <param name="businessObject">business object</param> /// <param name="dataReader">data reader</param> internal void PopulateBusinessObjectFromReader(CPrice_attach businessObject, IDataReader dataReader) { businessObject.Idattach = dataReader.GetInt32(dataReader.GetOrdinal(CPrice_attach.CPrice_attachFields.Idattach.ToString())); if (!dataReader.IsDBNull(dataReader.GetOrdinal(CPrice_attach.CPrice_attachFields.Idprice.ToString()))) { businessObject.Idprice = dataReader.GetInt32(dataReader.GetOrdinal(CPrice_attach.CPrice_attachFields.Idprice.ToString())); } if (!dataReader.IsDBNull(dataReader.GetOrdinal(CPrice_attach.CPrice_attachFields.Idprice_version.ToString()))) { businessObject.Idprice_version = dataReader.GetInt32(dataReader.GetOrdinal(CPrice_attach.CPrice_attachFields.Idprice_version.ToString())); } if (!dataReader.IsDBNull(dataReader.GetOrdinal(CPrice_attach.CPrice_attachFields.Name_document.ToString()))) { businessObject.Name_document = dataReader.GetString(dataReader.GetOrdinal(CPrice_attach.CPrice_attachFields.Name_document.ToString())); } if (!dataReader.IsDBNull(dataReader.GetOrdinal(CPrice_attach.CPrice_attachFields.Type_document.ToString()))) { businessObject.Type_document = dataReader.GetString(dataReader.GetOrdinal(CPrice_attach.CPrice_attachFields.Type_document.ToString())); } }