/// <summary> /// Populate business object from data reader /// </summary> /// <param name="businessObject">business object</param> /// <param name="dataReader">data reader</param> internal void PopulateBusinessObjectFromReader(CCalib businessObject, IDataReader dataReader) { businessObject.Idcalib = dataReader.GetInt64(dataReader.GetOrdinal(CCalib.CCalibFields.Idcalib.ToString())); if (!dataReader.IsDBNull(dataReader.GetOrdinal(CCalib.CCalibFields.Order_calib.ToString()))) { businessObject.Order_calib = (short?)dataReader.GetInt16(dataReader.GetOrdinal(CCalib.CCalibFields.Order_calib.ToString())); } if (!dataReader.IsDBNull(dataReader.GetOrdinal(CCalib.CCalibFields.Name_calib.ToString()))) { businessObject.Name_calib = dataReader.GetString(dataReader.GetOrdinal(CCalib.CCalibFields.Name_calib.ToString())); } if (!dataReader.IsDBNull(dataReader.GetOrdinal(CCalib.CCalibFields.Concentration.ToString()))) { businessObject.Concentration = dataReader.GetDecimal(dataReader.GetOrdinal(CCalib.CCalibFields.Concentration.ToString())); } if (!dataReader.IsDBNull(dataReader.GetOrdinal(CCalib.CCalibFields.Idtemplate_method.ToString()))) { businessObject.Idtemplate_method = dataReader.GetInt32(dataReader.GetOrdinal(CCalib.CCalibFields.Idtemplate_method.ToString())); } if (!dataReader.IsDBNull(dataReader.GetOrdinal(CCalib.CCalibFields.Aliquot.ToString()))) { businessObject.Aliquot = dataReader.GetDecimal(dataReader.GetOrdinal(CCalib.CCalibFields.Aliquot.ToString())); } if (!dataReader.IsDBNull(dataReader.GetOrdinal(CCalib.CCalibFields.Volumen.ToString()))) { businessObject.Volumen = dataReader.GetDecimal(dataReader.GetOrdinal(CCalib.CCalibFields.Volumen.ToString())); } }
/// <summary> /// Populate business objects from the data reader /// </summary> /// <param name="dataReader">data reader</param> /// <returns>list of CCalib</returns> internal List <CCalib> PopulateObjectsFromReader(IDataReader dataReader) { List <CCalib> list = new List <CCalib>(); while (dataReader.Read()) { CCalib businessObject = new CCalib(); 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(CCalib businessObject) { NpgsqlCommand sqlCommand = new NpgsqlCommand(); sqlCommand.CommandText = "public.sp_calib_Insert"; sqlCommand.CommandType = CommandType.StoredProcedure; // Use connection object of base class sqlCommand.Connection = MainConnection; try { sqlCommand.Parameters.AddWithValue("p_idcalib", businessObject.Idcalib); sqlCommand.Parameters["p_idcalib"].NpgsqlDbType = NpgsqlDbType.Bigint; sqlCommand.Parameters["p_idcalib"].Direction = ParameterDirection.InputOutput; sqlCommand.Parameters.AddWithValue("p_order_calib", businessObject.Order_calib); sqlCommand.Parameters["p_order_calib"].NpgsqlDbType = NpgsqlDbType.Smallint; sqlCommand.Parameters.AddWithValue("p_name_calib", businessObject.Name_calib); sqlCommand.Parameters["p_name_calib"].NpgsqlDbType = NpgsqlDbType.Varchar; sqlCommand.Parameters.AddWithValue("p_concentration", businessObject.Concentration); sqlCommand.Parameters["p_concentration"].NpgsqlDbType = NpgsqlDbType.Numeric; sqlCommand.Parameters.AddWithValue("p_idtemplate_method", businessObject.Idtemplate_method); sqlCommand.Parameters["p_idtemplate_method"].NpgsqlDbType = NpgsqlDbType.Integer; sqlCommand.Parameters.AddWithValue("p_aliquot", businessObject.Aliquot); sqlCommand.Parameters["p_aliquot"].NpgsqlDbType = NpgsqlDbType.Numeric; sqlCommand.Parameters.AddWithValue("p_volumen", businessObject.Volumen); sqlCommand.Parameters["p_volumen"].NpgsqlDbType = NpgsqlDbType.Numeric; MainConnection.Open(); sqlCommand.ExecuteNonQuery(); businessObject.Idcalib = Convert.ToInt64(sqlCommand.Parameters["p_idcalib"].Value); return(true); } catch (Exception ex) { throw new Exception("CCalib::Insert::Error occured.", ex); } finally { MainConnection.Close(); sqlCommand.Dispose(); } }
/// <summary> /// Select by primary key /// </summary> /// <param name="keys">primary keys</param> /// <returns>CCalib business object</returns> public CCalib SelectByPrimaryKey(CCalibKeys keys) { NpgsqlCommand sqlCommand = new NpgsqlCommand(); sqlCommand.CommandText = "public.sp_calib_SelectByPrimaryKey"; sqlCommand.CommandType = CommandType.StoredProcedure; // Use connection object of base class sqlCommand.Connection = MainConnection; try { sqlCommand.Parameters.Add(new NpgsqlParameter("p_idcalib", NpgsqlDbType.Bigint, 8, "", ParameterDirection.Input, false, 0, 0, DataRowVersion.Proposed, keys.Idcalib)); MainConnection.Open(); NpgsqlDataReader dataReader = sqlCommand.ExecuteReader(); if (dataReader.Read()) { CCalib businessObject = new CCalib(); PopulateBusinessObjectFromReader(businessObject, dataReader); return(businessObject); } else { return(null); } } catch (Exception ex) { throw new Exception("CCalib::SelectByPrimaryKey::Error occured.", ex); } finally { MainConnection.Close(); sqlCommand.Dispose(); } }
public bool SaveTypeAnalysis(int?pIdtemplate_method) { CTemplate_method_aaFactory faTemplate_method_aa = new CTemplate_method_aaFactory(); IDTemplate_Method = pIdtemplate_method; if (IDTemplate_Method != null && IDTemplate_Method > 0) { bool result_template_method_aa = false; CTemplate_method_aa oTemplate_method_aa = new CTemplate_method_aaFactory().GetByPrimaryKey(new CTemplate_method_aaKeys(Convert.ToInt32(IDTemplate_Method))); if (oTemplate_method_aa == null) { oTemplate_method_aa = new CTemplate_method_aa(); } oTemplate_method_aa.Idtemplate_method = Convert.ToInt32(IDTemplate_Method); oTemplate_method_aa.Weight = tbWeight.Value; oTemplate_method_aa.Weight_incertitude = tbWeight_incertitude.Value; oTemplate_method_aa.Volumen = tbVolumen.Value; oTemplate_method_aa.Reading_min = tbReading_min.Value; oTemplate_method_aa.Reading_max = tbReading_max.Value; oTemplate_method_aa.Dilution2 = tbDilution2.Value; oTemplate_method_aa.Dilution3 = tbDilution3.Value; oTemplate_method_aa.Reason_rep = tbReason_rep.Value; oTemplate_method_aa.Error_allowed = tbError_allowed.Value; oTemplate_method_aa.Symbol = tbSymbol.Text; oTemplate_method_aa.Law_limit_bottom = tbLaw_limit_bottom.Value; oTemplate_method_aa.Law_limit_top = tbLaw_limit_top.Value; oTemplate_method_aa.Idunit_calib = Convert.ToInt16(cbUnit_calib.EditValue); oTemplate_method_aa.Absorvance = tbAbs.Value; oTemplate_method_aa.Abs_incertitude = tbAbs_incertitude.Value; oTemplate_method_aa.Std_verif = tbStd_verif.Value; oTemplate_method_aa.Std_verif_incertitude = tbStd_verif_incertitude.Value; oTemplate_method_aa.Wave_long = tbWave_long.Value; oTemplate_method_aa.Idmr_detail = Convert.ToInt16(cbMaterialRef.EditValue); oTemplate_method_aa.Blk_max = tbBlk_max.Value; oTemplate_method_aa.Reason_rep = tbReason_rep.Value; oTemplate_method_aa.Reproducibility = tbReproducibility.Value; oTemplate_method_aa.Num_decimal = Convert.ToInt16(tbNum_decimal.Value); oTemplate_method_aa.Date_allowed_error = Convert.ToDateTime(deDate_allowed_error.EditValue); oTemplate_method_aa.Rexp2 = tbRexp2.Value; oTemplate_method_aa.Validity_calib = Convert.ToInt16(tbValidity_calib.Value); oTemplate_method_aa.Sol_concentration = Convert.ToDecimal(tbCalibConcen.Text); oTemplate_method_aa.Std_validity_sol1 = Convert.ToInt16(tbValiditySI1.Value); oTemplate_method_aa.Std_validity_sol2 = Convert.ToInt16(tbValiditySI2.Value); oTemplate_method_aa.Std_validity_sv = Convert.ToInt16(tbValiditySV.Value); if (cbTypePattern.EditValue != null) { oTemplate_method_aa.Type_pattern = Convert.ToInt32(cbTypePattern.EditValue); } //if (oTemplate_method_aa.Type_pattern == 1) // mrc // oTemplate_method_aa.Mrorpattern = Convert.ToInt16(cbMrcOrPattern.EditValue); //else if (oTemplate_method_aa.Type_pattern == 2) // solucion // oTemplate_method_aa.Flag_sol_intermedia = true; if (cbMedium.EditValue != null) { oTemplate_method_aa.Medium = Convert.ToInt32(cbMedium.EditValue); oTemplate_method_aa.Medium_conc = Convert.ToDecimal(tbMediumConc.Value); } if (cbModif.EditValue != null) { oTemplate_method_aa.Modif = Convert.ToInt32(cbModif.EditValue); oTemplate_method_aa.Modif_conc = Convert.ToDecimal(tbModifConc.Value); } if (cbStdMrcOrPattern.EditValue != null) { oTemplate_method_aa.Std_mrorpattern = Convert.ToInt32(cbStdMrcOrPattern.EditValue); } oTemplate_method_aa.Std_type_pattern = Convert.ToInt32(cbStdType_pattern.EditValue); oTemplate_method_aa.Std_flag_sol_intermedia1 = ckStdSolIntermOne.Checked; oTemplate_method_aa.Std_flag_sol_intermedia2 = ckStdSolIntermTwo.Checked; oTemplate_method_aa.Std_concentration = Convert.ToDecimal(tbStdConcentration.EditValue); oTemplate_method_aa.Std_concentration_sol1 = Convert.ToDecimal(tbStdConcenOne.EditValue); oTemplate_method_aa.Std_concentration_sol2 = Convert.ToDecimal(tbStdConcenTwo.EditValue); oTemplate_method_aa.Std_sol1_medium = tbMediumSol1.Value; oTemplate_method_aa.Std_sol2_medium = tbMediumSol2.Value; oTemplate_method_aa.Std_stdverif_medium = tbMediumStdVerif.Value; oTemplate_method_aa.Idunit_result = Convert.ToInt16(cbUnit_result.EditValue); oTemplate_method_aa.Num_days = Convert.ToInt16(tbNum_days.Value); oTemplate_method_aa.Num_samples = Convert.ToInt16(tbNum_samples.Value); oTemplate_method_aa.Limit_samples = Convert.ToInt16(tbLimit_samples.Value); if (!(result_template_method_aa = faTemplate_method_aa.Update(oTemplate_method_aa))) { oTemplate_method_aa.Date_allowed_error = DateTime.Now; result_template_method_aa = faTemplate_method_aa.Insert(oTemplate_method_aa); } if (result_template_method_aa) { for (int i = 0; i < gvCalibracion.RowCount; i++) { CCalibFactory faCalib = new CCalibFactory(); CCalib oCalib = gvCalibracion.GetRow(i) as CCalib; oCalib.Idtemplate_method = IDTemplate_Method; if (!faCalib.Update(oCalib)) { faCalib.Insert(oCalib); } } } } return(true); }