/// <summary> /// insert new row in the table /// </summary> /// <param name="businessObject">business object</param> /// <returns>true of successfully insert</returns> public bool Insert(CCells_reported businessObject) { NpgsqlCommand sqlCommand = new NpgsqlCommand(); sqlCommand.CommandText = "public.sp_cells_reported_Insert"; sqlCommand.CommandType = CommandType.StoredProcedure; // Use connection object of base class sqlCommand.Connection = MainConnection; try { sqlCommand.Parameters.AddWithValue("p_idcell_reported", businessObject.Idcell_reported); sqlCommand.Parameters["p_idcell_reported"].NpgsqlDbType = NpgsqlDbType.Bigint; sqlCommand.Parameters["p_idcell_reported"].Direction = ParameterDirection.InputOutput; sqlCommand.Parameters.AddWithValue("p_idrecep_sample_detail_elem", businessObject.Idrecep_sample_detail_elem); sqlCommand.Parameters["p_idrecep_sample_detail_elem"].NpgsqlDbType = NpgsqlDbType.Bigint; sqlCommand.Parameters.AddWithValue("p_idrecep_sample_report", businessObject.Idrecep_sample_report); sqlCommand.Parameters["p_idrecep_sample_report"].NpgsqlDbType = NpgsqlDbType.Bigint; sqlCommand.Parameters.AddWithValue("p_idtemplate_method", businessObject.Idtemplate_method); sqlCommand.Parameters["p_idtemplate_method"].NpgsqlDbType = NpgsqlDbType.Integer; sqlCommand.Parameters.AddWithValue("p_idrecep_sample_detail", businessObject.Idrecep_sample_detail); sqlCommand.Parameters["p_idrecep_sample_detail"].NpgsqlDbType = NpgsqlDbType.Bigint; sqlCommand.Parameters.AddWithValue("p_flag_confirm_report", businessObject.Flag_confirm_report); sqlCommand.Parameters["p_flag_confirm_report"].NpgsqlDbType = NpgsqlDbType.Boolean; 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; MainConnection.Open(); sqlCommand.ExecuteNonQuery(); businessObject.Idcell_reported = Convert.ToInt64(sqlCommand.Parameters["p_idcell_reported"].Value); return(true); } catch (Exception ex) { throw new Exception("CCells_reported::Insert::Error occured.", ex); } finally { MainConnection.Close(); sqlCommand.Dispose(); } }
/// <summary> /// Populate business object from data reader /// </summary> /// <param name="businessObject">business object</param> /// <param name="dataReader">data reader</param> internal void PopulateBusinessObjectFromReader(CCells_reported businessObject, IDataReader dataReader) { businessObject.Idcell_reported = dataReader.GetInt64(dataReader.GetOrdinal(CCells_reported.CCells_reportedFields.Idcell_reported.ToString())); if (!dataReader.IsDBNull(dataReader.GetOrdinal(CCells_reported.CCells_reportedFields.Idrecep_sample_detail_elem.ToString()))) { businessObject.Idrecep_sample_detail_elem = dataReader.GetInt64(dataReader.GetOrdinal(CCells_reported.CCells_reportedFields.Idrecep_sample_detail_elem.ToString())); } if (!dataReader.IsDBNull(dataReader.GetOrdinal(CCells_reported.CCells_reportedFields.Idrecep_sample_report.ToString()))) { businessObject.Idrecep_sample_report = dataReader.GetInt64(dataReader.GetOrdinal(CCells_reported.CCells_reportedFields.Idrecep_sample_report.ToString())); } if (!dataReader.IsDBNull(dataReader.GetOrdinal(CCells_reported.CCells_reportedFields.Idtemplate_method.ToString()))) { businessObject.Idtemplate_method = dataReader.GetInt32(dataReader.GetOrdinal(CCells_reported.CCells_reportedFields.Idtemplate_method.ToString())); } if (!dataReader.IsDBNull(dataReader.GetOrdinal(CCells_reported.CCells_reportedFields.Idrecep_sample_detail.ToString()))) { businessObject.Idrecep_sample_detail = dataReader.GetInt64(dataReader.GetOrdinal(CCells_reported.CCells_reportedFields.Idrecep_sample_detail.ToString())); } if (!dataReader.IsDBNull(dataReader.GetOrdinal(CCells_reported.CCells_reportedFields.Flag_confirm_report.ToString()))) { businessObject.Flag_confirm_report = dataReader.GetBoolean(dataReader.GetOrdinal(CCells_reported.CCells_reportedFields.Flag_confirm_report.ToString())); } if (!dataReader.IsDBNull(dataReader.GetOrdinal(CCells_reported.CCells_reportedFields.Usernew.ToString()))) { businessObject.Usernew = dataReader.GetString(dataReader.GetOrdinal(CCells_reported.CCells_reportedFields.Usernew.ToString())); } if (!dataReader.IsDBNull(dataReader.GetOrdinal(CCells_reported.CCells_reportedFields.Datenew.ToString()))) { businessObject.Datenew = dataReader.GetDateTime(dataReader.GetOrdinal(CCells_reported.CCells_reportedFields.Datenew.ToString())); } if (!dataReader.IsDBNull(dataReader.GetOrdinal(CCells_reported.CCells_reportedFields.Useredit.ToString()))) { businessObject.Useredit = dataReader.GetString(dataReader.GetOrdinal(CCells_reported.CCells_reportedFields.Useredit.ToString())); } if (!dataReader.IsDBNull(dataReader.GetOrdinal(CCells_reported.CCells_reportedFields.Dateedit.ToString()))) { businessObject.Dateedit = dataReader.GetDateTime(dataReader.GetOrdinal(CCells_reported.CCells_reportedFields.Dateedit.ToString())); } if (!dataReader.IsDBNull(dataReader.GetOrdinal(CCells_reported.CCells_reportedFields.Status.ToString()))) { businessObject.Status = dataReader.GetBoolean(dataReader.GetOrdinal(CCells_reported.CCells_reportedFields.Status.ToString())); } }
/// <summary> /// Populate business objects from the data reader /// </summary> /// <param name="dataReader">data reader</param> /// <returns>list of CCells_reported</returns> internal List <CCells_reported> PopulateObjectsFromReader(IDataReader dataReader) { List <CCells_reported> list = new List <CCells_reported>(); while (dataReader.Read()) { CCells_reported businessObject = new CCells_reported(); PopulateBusinessObjectFromReader(businessObject, dataReader); list.Add(businessObject); } return(list); }
/// <summary> /// Select by primary key /// </summary> /// <param name="keys">primary keys</param> /// <returns>CCells_reported business object</returns> public CCells_reported SelectByPrimaryKey(CCells_reportedKeys keys) { NpgsqlCommand sqlCommand = new NpgsqlCommand(); sqlCommand.CommandText = "public.sp_cells_reported_SelectByPrimaryKey"; sqlCommand.CommandType = CommandType.StoredProcedure; // Use connection object of base class sqlCommand.Connection = MainConnection; try { sqlCommand.Parameters.Add(new NpgsqlParameter("p_idcell_reported", NpgsqlDbType.Bigint, 8, "", ParameterDirection.Input, false, 0, 0, DataRowVersion.Proposed, keys.Idcell_reported)); MainConnection.Open(); NpgsqlDataReader dataReader = sqlCommand.ExecuteReader(); if (dataReader.Read()) { CCells_reported businessObject = new CCells_reported(); PopulateBusinessObjectFromReader(businessObject, dataReader); return(businessObject); } else { return(null); } } catch (Exception ex) { throw new Exception("CCells_reported::SelectByPrimaryKey::Error occured.", ex); } finally { MainConnection.Close(); sqlCommand.Dispose(); } }
private void repReportOption_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e) { // --- save partial or final report if (e.Button.Index == 0) { // --- report data #region save report bool result_report = false; CRecep_sample_report oRecep_sample_report = new CRecep_sample_report(); CRecep_sample_reportFactory faRecep_sample_report = new CRecep_sample_reportFactory(); Reception oReception = new Reception(); oRecep_sample_report = faRecep_sample_report.GetByPrimaryKey( new CRecep_sample_reportKeys(Convert.ToInt64(gvReport.GetFocusedRowCellValue(gcRep_idrecep_sample_report)))); short report_status = Convert.ToInt16(gvReport.GetFocusedRowCellValue(gcRep_report_status)); // si es un reporte en creación poner como reservado if (report_status == Convert.ToInt16(Comun.ReportStatus.EnCreacion)) // --- creacion { oRecep_sample_report = new CRecep_sample_report(); gvReport.SetFocusedRowCellValue(gcRep_report_status, Convert.ToInt16(Comun.ReportStatus.Reportado)); oRecep_sample_report.Idrecep_sample = oRecep_sample.Idrecep_sample; oRecep_sample_report.Idrecep_sample_report = Convert.ToInt64(gvReport.GetFocusedRowCellValue(gcRep_idrecep_sample_report)); oRecep_sample_report.Order_report = Convert.ToInt16(gvReport.GetFocusedRowCellValue(gcRep_order_report)); oRecep_sample_report.Report_status = Convert.ToInt16(Comun.ReportStatus.Reportado); oRecep_sample_report.Type_report = Convert.ToInt16(gvReport.GetFocusedRowCellValue(gcRep_type_report)); // --- 1:parcial, 2:final oRecep_sample_report.Cod_recep_sample_report = oReception.GetNewCodReport(Convert.ToInt16(gvReport.GetFocusedRowCellValue(gcRep_type_report))); oRecep_sample_report.Date_report = DateTime.Now; oRecep_sample_report.Time_report = DateTime.Now; result_report = faRecep_sample_report.Insert(oRecep_sample_report); gvReport.SetFocusedRowCellValue(gcRep_idrecep_sample_report, oRecep_sample_report.Idrecep_sample_report); gvReport.SetFocusedRowCellValue(gcRep_cod_recep_sample_report, oRecep_sample_report.Cod_recep_sample_report); gvReport.SetFocusedRowCellValue(gcRep_Str_cod_recep_sample_report, oReception.GetFormatReportCode(oRecep_sample_report.Type_report, oRecep_sample_report.Cod_recep_sample_report)); if (result_report) { // --- create the partial report List<CPositionValue> lstPositionValue = new List<CPositionValue>(); foreach (GridCell[] cells in lstItemsSelReport) { foreach (GridCell cell in cells) { CTagInfoMethod tagMethod = (CTagInfoMethod)cell.Column.Tag; int idtemplate_method = tagMethod.IDTemplate_method; long idrecep_sample_detail = Convert.ToInt64(gvReception.GetRowCellValue(cell.RowHandle, gcRec_idrecep_sample_detail)); long idrecep_sample_report = oRecep_sample_report.Idrecep_sample_report; CPositionValue position = GetObjectPosition(idrecep_sample_detail, tagMethod.IDTemplate_method); CCells_reportedFactory faCells_reported = new CCells_reportedFactory(); CCells_reported oCell_reported = new CCells_reported(); oCell_reported.Idtemplate_method = idtemplate_method; oCell_reported.Idrecep_sample_detail = idrecep_sample_detail; oCell_reported.Idrecep_sample_report = idrecep_sample_report; oCell_reported.Idrecep_sample_detail_elem = position.idrecep_sample_detail_elem; bool result_cell_reported = false; if (!(result_cell_reported = faCells_reported.Update(oCell_reported))) result_cell_reported = faCells_reported.Insert(oCell_reported); if (result_cell_reported) { position.idrecep_sample_report = idrecep_sample_report; position.row = cell.RowHandle; position.col = cell.Column; position.idcell_reported = oCell_reported.Idcell_reported; if (oRecep_sample_report.Type_report == 1) position.color = Partial_report_color; else position.color = Final_report_color; if (!lstPositionValue.Exists(c => c.idrecep_sample_detail_elem == position.idrecep_sample_detail_elem)) lstPositionValue.Add(position); } } } lstItemsSelReport.Clear(); DicCellsSavedReport.Add(Convert.ToInt16(oRecep_sample_report.Order_report), lstPositionValue); GetUnreportData(oRecep_sample.Idrecep_sample); } } #endregion lstItemsSelReport.Clear(); gvReception.Focus(); } else if (e.Button.Index == 1) { // --- INFORME DE ENSAYO LAS-13-01299 CReportTestFactory faReportTest = new CReportTestFactory(); DataTable dtResults = faReportTest.GetReportResults(Convert.ToInt64(gvReport.GetFocusedRowCellValue(gcRep_idrecep_sample_report))); DataTable dtHead = faReportTest.GetReportHead(Convert.ToInt64(gvReport.GetFocusedRowCellValue(gcRep_idrecep_sample_report))); DataTable dtMethods = faReportTest.GetReportMethods(Convert.ToInt64(gvReport.GetFocusedRowCellValue(gcRep_idrecep_sample_report))); oFastReportMethods.AddParameter("Attention", GetContactAttention(oRecep_sample.Idrecep_sample)); oFastReportMethods.AddParameter("Cod_report", gvReport.GetFocusedRowCellValue(gcRep_Str_cod_recep_sample_report).ToString()); oFastReportMethods.AddParameter("Date_report", Convert.ToDateTime(gvReport.GetFocusedRowCellValue(gcRep_Date_report))); oFastReportMethods.ReportName = "ReportTest.frx"; oFastReportMethods.RegisterDataTable(dtHead, "Head"); oFastReportMethods.RegisterDataTable(dtMethods, "Methods"); oFastReportMethods.RegisterDataTable(dtResults, "Results"); oFastReportMethods.ShowPreviewReport(); } else if (e.Button.Index == 2) { CReportTestFactory faReportTest = new CReportTestFactory(); DataTable dtResults = faReportTest.GetReportResults(Convert.ToInt64(gvReport.GetFocusedRowCellValue(gcRep_idrecep_sample_report))); DataTable dtHead = faReportTest.GetReportHead(Convert.ToInt64(gvReport.GetFocusedRowCellValue(gcRep_idrecep_sample_report))); DataTable dtMethods = faReportTest.GetReportMethods(Convert.ToInt64(gvReport.GetFocusedRowCellValue(gcRep_idrecep_sample_report))); oFastReportMethods.AddParameter("Attention", GetContactAttention(oRecep_sample.Idrecep_sample)); oFastReportMethods.AddParameter("Cod_report", gvReport.GetFocusedRowCellValue(gcRep_Str_cod_recep_sample_report).ToString()); oFastReportMethods.AddParameter("Date_report", Convert.ToDateTime(gvReport.GetFocusedRowCellValue(gcRep_Date_report))); oFastReportMethods.ReportName = "ReportTest.frx"; oFastReportMethods.RegisterDataTable(dtHead, "Head"); oFastReportMethods.RegisterDataTable(dtMethods, "Methods"); oFastReportMethods.RegisterDataTable(dtResults, "Results"); oFastReportMethods.DesignReport(); } }