/// <summary> /// Populate business objects from the data reader /// </summary> /// <param name="dataReader">data reader</param> /// <returns>list of CCells_attach_file</returns> internal List <CCells_attach_file> PopulateObjectsFromReader(IDataReader dataReader) { List <CCells_attach_file> list = new List <CCells_attach_file>(); while (dataReader.Read()) { CCells_attach_file businessObject = new CCells_attach_file(); 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(CCells_attach_file businessObject) { NpgsqlCommand sqlCommand = new NpgsqlCommand(); sqlCommand.CommandText = "public.sp_cells_attach_file_Insert"; sqlCommand.CommandType = CommandType.StoredProcedure; // Use connection object of base class sqlCommand.Connection = MainConnection; try { sqlCommand.Parameters.AddWithValue("p_idcells_attach_file", businessObject.Idcells_attach_file); sqlCommand.Parameters["p_idcells_attach_file"].NpgsqlDbType = NpgsqlDbType.Bigint; sqlCommand.Parameters["p_idcells_attach_file"].Direction = ParameterDirection.InputOutput; sqlCommand.Parameters.AddWithValue("p_idrecep_sample_attach", businessObject.Idrecep_sample_attach); sqlCommand.Parameters["p_idrecep_sample_attach"].NpgsqlDbType = NpgsqlDbType.Bigint; 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_idtemplate_method", businessObject.Idtemplate_method); sqlCommand.Parameters["p_idtemplate_method"].NpgsqlDbType = NpgsqlDbType.Integer; 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.Idcells_attach_file = Convert.ToInt64(sqlCommand.Parameters["p_idcells_attach_file"].Value); return(true); } catch (Exception ex) { throw new Exception("CCells_attach_file::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_attach_file businessObject, IDataReader dataReader) { businessObject.Idcells_attach_file = dataReader.GetInt64(dataReader.GetOrdinal(CCells_attach_file.CCells_attach_fileFields.Idcells_attach_file.ToString())); if (!dataReader.IsDBNull(dataReader.GetOrdinal(CCells_attach_file.CCells_attach_fileFields.Idrecep_sample_attach.ToString()))) { businessObject.Idrecep_sample_attach = dataReader.GetInt64(dataReader.GetOrdinal(CCells_attach_file.CCells_attach_fileFields.Idrecep_sample_attach.ToString())); } if (!dataReader.IsDBNull(dataReader.GetOrdinal(CCells_attach_file.CCells_attach_fileFields.Idrecep_sample_detail_elem.ToString()))) { businessObject.Idrecep_sample_detail_elem = dataReader.GetInt64(dataReader.GetOrdinal(CCells_attach_file.CCells_attach_fileFields.Idrecep_sample_detail_elem.ToString())); } if (!dataReader.IsDBNull(dataReader.GetOrdinal(CCells_attach_file.CCells_attach_fileFields.Idtemplate_method.ToString()))) { businessObject.Idtemplate_method = dataReader.GetInt32(dataReader.GetOrdinal(CCells_attach_file.CCells_attach_fileFields.Idtemplate_method.ToString())); } if (!dataReader.IsDBNull(dataReader.GetOrdinal(CCells_attach_file.CCells_attach_fileFields.Usernew.ToString()))) { businessObject.Usernew = dataReader.GetString(dataReader.GetOrdinal(CCells_attach_file.CCells_attach_fileFields.Usernew.ToString())); } if (!dataReader.IsDBNull(dataReader.GetOrdinal(CCells_attach_file.CCells_attach_fileFields.Datenew.ToString()))) { businessObject.Datenew = dataReader.GetDateTime(dataReader.GetOrdinal(CCells_attach_file.CCells_attach_fileFields.Datenew.ToString())); } if (!dataReader.IsDBNull(dataReader.GetOrdinal(CCells_attach_file.CCells_attach_fileFields.Useredit.ToString()))) { businessObject.Useredit = dataReader.GetString(dataReader.GetOrdinal(CCells_attach_file.CCells_attach_fileFields.Useredit.ToString())); } if (!dataReader.IsDBNull(dataReader.GetOrdinal(CCells_attach_file.CCells_attach_fileFields.Dateedit.ToString()))) { businessObject.Dateedit = dataReader.GetDateTime(dataReader.GetOrdinal(CCells_attach_file.CCells_attach_fileFields.Dateedit.ToString())); } if (!dataReader.IsDBNull(dataReader.GetOrdinal(CCells_attach_file.CCells_attach_fileFields.Status.ToString()))) { businessObject.Status = dataReader.GetBoolean(dataReader.GetOrdinal(CCells_attach_file.CCells_attach_fileFields.Status.ToString())); } }
/// <summary> /// Select by primary key /// </summary> /// <param name="keys">primary keys</param> /// <returns>CCells_attach_file business object</returns> public CCells_attach_file SelectByPrimaryKey(CCells_attach_fileKeys keys) { NpgsqlCommand sqlCommand = new NpgsqlCommand(); sqlCommand.CommandText = "public.sp_cells_attach_file_SelectByPrimaryKey"; sqlCommand.CommandType = CommandType.StoredProcedure; // Use connection object of base class sqlCommand.Connection = MainConnection; try { sqlCommand.Parameters.Add(new NpgsqlParameter("p_idcells_attach_file", NpgsqlDbType.Bigint, 8, "", ParameterDirection.Input, false, 0, 0, DataRowVersion.Proposed, keys.Idcells_attach_file)); MainConnection.Open(); NpgsqlDataReader dataReader = sqlCommand.ExecuteReader(); if (dataReader.Read()) { CCells_attach_file businessObject = new CCells_attach_file(); PopulateBusinessObjectFromReader(businessObject, dataReader); return(businessObject); } else { return(null); } } catch (Exception ex) { throw new Exception("CCells_attach_file::SelectByPrimaryKey::Error occured.", ex); } finally { MainConnection.Close(); sqlCommand.Dispose(); } }
private void repButtons_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e) { if (e.Button.Index == 0) { // tasks // 1. guardar archivo en dirección del disco // 2. cambiar de estado de creación a guardado // 3. vincular celdas a archivos adjuntos short attach_status = Convert.ToInt16(gvAttachFile.GetFocusedRowCellValue(gcAtt_Attach_status)); CRecep_sample_attach oRecep_sample_attach = new CRecep_sample_attach(); CRecep_sample_attachFactory faRecep_sample_attach = new CRecep_sample_attachFactory(); if (attach_status == Convert.ToInt16(Comun.AttachStatus.EnCreacion)) // --- creacion { oRecep_sample_attach = new CRecep_sample_attach(); gvAttachFile.SetFocusedRowCellValue(gcAtt_Attach_status, Convert.ToInt16(Comun.AttachStatus.Adjuntado)); oRecep_sample_attach.Idrecep_sample = oRecep_sample.Idrecep_sample; oRecep_sample_attach.Idrecep_sample_attach = Convert.ToInt64(gvAttachFile.GetFocusedRowCellValue(gcAtt_Idrecep_sample_attach)); oRecep_sample_attach.Iddocument_recep = Convert.ToInt32(gvAttachFile.GetFocusedRowCellValue(gcAtt_Iddocument_recep)); bool result_attach = faRecep_sample_attach.Insert(oRecep_sample_attach); if (result_attach) { // --- create the partial report List<CpositionValueAttach> lstPositionAttachValue = new List<CpositionValueAttach>(); foreach (GridCell[] cells in lstItemsSelAttach) { foreach (GridCell cell in cells) { CTagInfoMethod tagMethod = (CTagInfoMethod)cell.Column.Tag; int idtempladte_method = tagMethod.IDTemplate_method; long idrecep_sample_detail = Convert.ToInt64(gvReception.GetRowCellValue(cell.RowHandle, gcRec_idrecep_sample_detail)); long idrecep_sample_attach = oRecep_sample_attach.Idrecep_sample_attach; CpositionValueAttach position = GetObjectPositionAttach(idrecep_sample_detail, tagMethod.IDTemplate_method); CCells_attach_fileFactory faCells_attach = new CCells_attach_fileFactory(); CCells_attach_file oCell_attach_file = new CCells_attach_file(); oCell_attach_file.Idtemplate_method = idtempladte_method; oCell_attach_file.Idrecep_sample_attach = idrecep_sample_attach; oCell_attach_file.Idrecep_sample_detail_elem = position.idrecep_sample_detail_elem; bool result_cell_attached = false; if (!(result_cell_attached = faCells_attach.Update(oCell_attach_file))) result_cell_attached = faCells_attach.Insert(oCell_attach_file); if (result_cell_attached) { position.idrecep_sample_attach = idrecep_sample_attach; position.row = cell.RowHandle; position.col = cell.Column; position.idcell_attach_file = oCell_attach_file.Idcells_attach_file; position.color = Color.YellowGreen; if (!lstPositionAttachValue.Exists(c => c.idrecep_sample_detail_elem == position.idrecep_sample_detail_elem)) lstPositionAttachValue.Add(position); } } } DicCellsSavedAttach.Add(Convert.ToInt16(oRecep_sample_attach.Order_file), lstPositionAttachValue); } } } }