/// <summary> /// Populate business objects from the data reader /// </summary> /// <param name="dataReader">data reader</param> /// <returns>list of CMeasurement_unit</returns> internal List <CMeasurement_unit> PopulateObjectsFromReader(IDataReader dataReader) { List <CMeasurement_unit> list = new List <CMeasurement_unit>(); while (dataReader.Read()) { CMeasurement_unit businessObject = new CMeasurement_unit(); 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(CMeasurement_unit businessObject) { NpgsqlCommand sqlCommand = new NpgsqlCommand(); sqlCommand.CommandText = "public.sp_measurement_unit_Insert"; sqlCommand.CommandType = CommandType.StoredProcedure; // Use connection object of base class sqlCommand.Connection = MainConnection; try { sqlCommand.Parameters.AddWithValue("p_idunit", businessObject.Idunit); sqlCommand.Parameters["p_idunit"].NpgsqlDbType = NpgsqlDbType.Smallint; sqlCommand.Parameters["p_idunit"].Direction = ParameterDirection.InputOutput; sqlCommand.Parameters.AddWithValue("p_name_unit", businessObject.Name_unit); sqlCommand.Parameters["p_name_unit"].NpgsqlDbType = NpgsqlDbType.Varchar; sqlCommand.Parameters.AddWithValue("p_description", businessObject.Description); sqlCommand.Parameters["p_description"].NpgsqlDbType = NpgsqlDbType.Varchar; sqlCommand.Parameters.AddWithValue("p_usernew", businessObject.Usernew); sqlCommand.Parameters["p_usernew"].NpgsqlDbType = NpgsqlDbType.Varchar; sqlCommand.Parameters.AddWithValue("p_datenew", businessObject.Datenew); sqlCommand.Parameters["p_datenew"].NpgsqlDbType = NpgsqlDbType.Date; sqlCommand.Parameters.AddWithValue("p_useredit", businessObject.Useredit); sqlCommand.Parameters["p_useredit"].NpgsqlDbType = NpgsqlDbType.Varchar; sqlCommand.Parameters.AddWithValue("p_dateedit", businessObject.Dateedit); sqlCommand.Parameters["p_dateedit"].NpgsqlDbType = NpgsqlDbType.Date; sqlCommand.Parameters.AddWithValue("p_status", businessObject.Status); sqlCommand.Parameters["p_status"].NpgsqlDbType = NpgsqlDbType.Boolean; sqlCommand.Parameters.AddWithValue("p_concentration_unit", businessObject.Concentration_unit); sqlCommand.Parameters["p_concentration_unit"].NpgsqlDbType = NpgsqlDbType.Integer; MainConnection.Open(); sqlCommand.ExecuteNonQuery(); businessObject.Idunit = Convert.ToInt16(sqlCommand.Parameters["p_idunit"].Value); return(true); } catch (Exception ex) { throw new Exception("CMeasurement_unit::Insert::Error occured.", ex); } finally { MainConnection.Close(); sqlCommand.Dispose(); } }
protected override void Recuperar_Registro() { CMeasurement_unit oMeasurement_unit = new CMeasurement_unit(); CMeasurement_unitFactory faMeasurement_unit = new CMeasurement_unitFactory(); oMeasurement_unit = faMeasurement_unit.GetByPrimaryKey(new CMeasurement_unitKeys(IDUnit)); if (oMeasurement_unit != null) { tbNameUnit.Text = oMeasurement_unit.Name_unit; tbDescription.Text = oMeasurement_unit.Description; cbConcentration_unit.EditValue = oMeasurement_unit.Concentration_unit; } }
protected override bool Grabar_Registro() { bool result = false; CMeasurement_unit oMeasurement_unit = new CMeasurement_unit(); CMeasurement_unitFactory faMeasurement_unit = new CMeasurement_unitFactory(); oMeasurement_unit.Idunit = IDUnit; oMeasurement_unit.Name_unit = tbNameUnit.Text; oMeasurement_unit.Description = tbDescription.Text; oMeasurement_unit.Concentration_unit = Convert.ToInt32(cbConcentration_unit.EditValue); if (!(result = faMeasurement_unit.Update(oMeasurement_unit))) { result = faMeasurement_unit.Insert(oMeasurement_unit); } return result; }
protected override bool Grabar_Registro() { bool result = false; CMeasurement_unit oMeasurement_unit = new CMeasurement_unit(); CMeasurement_unitFactory faMeasurement_unit = new CMeasurement_unitFactory(); oMeasurement_unit.Idunit = IDUnit; oMeasurement_unit.Name_unit = tbNameUnit.Text; oMeasurement_unit.Description = tbDescription.Text; oMeasurement_unit.Concentration_unit = Convert.ToInt32(cbConcentration_unit.EditValue); if (!(result = faMeasurement_unit.Update(oMeasurement_unit))) { result = faMeasurement_unit.Insert(oMeasurement_unit); } return(result); }
/// <summary> /// Populate business object from data reader /// </summary> /// <param name="businessObject">business object</param> /// <param name="dataReader">data reader</param> internal void PopulateBusinessObjectFromReader(CMeasurement_unit businessObject, IDataReader dataReader) { businessObject.Idunit = (short)dataReader.GetInt16(dataReader.GetOrdinal(CMeasurement_unit.CMeasurement_unitFields.Idunit.ToString())); if (!dataReader.IsDBNull(dataReader.GetOrdinal(CMeasurement_unit.CMeasurement_unitFields.Name_unit.ToString()))) { businessObject.Name_unit = dataReader.GetString(dataReader.GetOrdinal(CMeasurement_unit.CMeasurement_unitFields.Name_unit.ToString())); } if (!dataReader.IsDBNull(dataReader.GetOrdinal(CMeasurement_unit.CMeasurement_unitFields.Description.ToString()))) { businessObject.Description = dataReader.GetString(dataReader.GetOrdinal(CMeasurement_unit.CMeasurement_unitFields.Description.ToString())); } if (!dataReader.IsDBNull(dataReader.GetOrdinal(CMeasurement_unit.CMeasurement_unitFields.Usernew.ToString()))) { businessObject.Usernew = dataReader.GetString(dataReader.GetOrdinal(CMeasurement_unit.CMeasurement_unitFields.Usernew.ToString())); } if (!dataReader.IsDBNull(dataReader.GetOrdinal(CMeasurement_unit.CMeasurement_unitFields.Datenew.ToString()))) { businessObject.Datenew = dataReader.GetDateTime(dataReader.GetOrdinal(CMeasurement_unit.CMeasurement_unitFields.Datenew.ToString())); } if (!dataReader.IsDBNull(dataReader.GetOrdinal(CMeasurement_unit.CMeasurement_unitFields.Useredit.ToString()))) { businessObject.Useredit = dataReader.GetString(dataReader.GetOrdinal(CMeasurement_unit.CMeasurement_unitFields.Useredit.ToString())); } if (!dataReader.IsDBNull(dataReader.GetOrdinal(CMeasurement_unit.CMeasurement_unitFields.Dateedit.ToString()))) { businessObject.Dateedit = dataReader.GetDateTime(dataReader.GetOrdinal(CMeasurement_unit.CMeasurement_unitFields.Dateedit.ToString())); } if (!dataReader.IsDBNull(dataReader.GetOrdinal(CMeasurement_unit.CMeasurement_unitFields.Status.ToString()))) { businessObject.Status = dataReader.GetBoolean(dataReader.GetOrdinal(CMeasurement_unit.CMeasurement_unitFields.Status.ToString())); } if (!dataReader.IsDBNull(dataReader.GetOrdinal(CMeasurement_unit.CMeasurement_unitFields.Concentration_unit.ToString()))) { businessObject.Concentration_unit = dataReader.GetInt32(dataReader.GetOrdinal(CMeasurement_unit.CMeasurement_unitFields.Concentration_unit.ToString())); } }
/// <summary> /// Select by primary key /// </summary> /// <param name="keys">primary keys</param> /// <returns>CMeasurement_unit business object</returns> public CMeasurement_unit SelectByPrimaryKey(CMeasurement_unitKeys keys) { NpgsqlCommand sqlCommand = new NpgsqlCommand(); sqlCommand.CommandText = "public.sp_measurement_unit_SelectByPrimaryKey"; sqlCommand.CommandType = CommandType.StoredProcedure; // Use connection object of base class sqlCommand.Connection = MainConnection; try { sqlCommand.Parameters.Add(new NpgsqlParameter("p_idunit", NpgsqlDbType.Smallint, 2, "", ParameterDirection.Input, false, 0, 0, DataRowVersion.Proposed, keys.Idunit)); MainConnection.Open(); NpgsqlDataReader dataReader = sqlCommand.ExecuteReader(); if (dataReader.Read()) { CMeasurement_unit businessObject = new CMeasurement_unit(); PopulateBusinessObjectFromReader(businessObject, dataReader); return(businessObject); } else { return(null); } } catch (Exception ex) { throw new Exception("CMeasurement_unit::SelectByPrimaryKey::Error occured.", ex); } finally { MainConnection.Close(); sqlCommand.Dispose(); } }