/// <summary>
        /// Populate business object from data reader
        /// </summary>
        /// <param name="businessObject">business object</param>
        /// <param name="dataReader">data reader</param>
        internal void PopulateBusinessObjectFromReader(CRecep_sample_program businessObject, IDataReader dataReader)
        {
            businessObject.Idrecep_sample_program = dataReader.GetInt64(dataReader.GetOrdinal(CRecep_sample_program.CRecep_sample_programFields.Idrecep_sample_program.ToString()));

            if (!dataReader.IsDBNull(dataReader.GetOrdinal(CRecep_sample_program.CRecep_sample_programFields.Cod_recep_sample_program.ToString())))
            {
                businessObject.Cod_recep_sample_program = dataReader.GetInt64(dataReader.GetOrdinal(CRecep_sample_program.CRecep_sample_programFields.Cod_recep_sample_program.ToString()));
            }

            if (!dataReader.IsDBNull(dataReader.GetOrdinal(CRecep_sample_program.CRecep_sample_programFields.Order_report.ToString())))
            {
                businessObject.Order_report = (short?)dataReader.GetInt16(dataReader.GetOrdinal(CRecep_sample_program.CRecep_sample_programFields.Order_report.ToString()));
            }

            if (!dataReader.IsDBNull(dataReader.GetOrdinal(CRecep_sample_program.CRecep_sample_programFields.Idrecep_sample.ToString())))
            {
                businessObject.Idrecep_sample = dataReader.GetInt64(dataReader.GetOrdinal(CRecep_sample_program.CRecep_sample_programFields.Idrecep_sample.ToString()));
            }

            if (!dataReader.IsDBNull(dataReader.GetOrdinal(CRecep_sample_program.CRecep_sample_programFields.Program_status.ToString())))
            {
                businessObject.Program_status = (short?)dataReader.GetInt16(dataReader.GetOrdinal(CRecep_sample_program.CRecep_sample_programFields.Program_status.ToString()));
            }

            if (!dataReader.IsDBNull(dataReader.GetOrdinal(CRecep_sample_program.CRecep_sample_programFields.Date_report.ToString())))
            {
                businessObject.Date_report = dataReader.GetDateTime(dataReader.GetOrdinal(CRecep_sample_program.CRecep_sample_programFields.Date_report.ToString()));
            }

            if (!dataReader.IsDBNull(dataReader.GetOrdinal(CRecep_sample_program.CRecep_sample_programFields.Time_report.ToString())))
            {
                businessObject.Time_report = dataReader.GetDateTime(dataReader.GetOrdinal(CRecep_sample_program.CRecep_sample_programFields.Time_report.ToString()));
            }

            if (!dataReader.IsDBNull(dataReader.GetOrdinal(CRecep_sample_program.CRecep_sample_programFields.Usernew.ToString())))
            {
                businessObject.Usernew = dataReader.GetString(dataReader.GetOrdinal(CRecep_sample_program.CRecep_sample_programFields.Usernew.ToString()));
            }

            if (!dataReader.IsDBNull(dataReader.GetOrdinal(CRecep_sample_program.CRecep_sample_programFields.Datenew.ToString())))
            {
                businessObject.Datenew = dataReader.GetDateTime(dataReader.GetOrdinal(CRecep_sample_program.CRecep_sample_programFields.Datenew.ToString()));
            }

            if (!dataReader.IsDBNull(dataReader.GetOrdinal(CRecep_sample_program.CRecep_sample_programFields.Useredit.ToString())))
            {
                businessObject.Useredit = dataReader.GetString(dataReader.GetOrdinal(CRecep_sample_program.CRecep_sample_programFields.Useredit.ToString()));
            }

            if (!dataReader.IsDBNull(dataReader.GetOrdinal(CRecep_sample_program.CRecep_sample_programFields.Dateedit.ToString())))
            {
                businessObject.Dateedit = dataReader.GetDateTime(dataReader.GetOrdinal(CRecep_sample_program.CRecep_sample_programFields.Dateedit.ToString()));
            }

            if (!dataReader.IsDBNull(dataReader.GetOrdinal(CRecep_sample_program.CRecep_sample_programFields.Status.ToString())))
            {
                businessObject.Status = dataReader.GetBoolean(dataReader.GetOrdinal(CRecep_sample_program.CRecep_sample_programFields.Status.ToString()));
            }
        }
        /// <summary>
        /// insert new row in the table
        /// </summary>
        /// <param name="businessObject">business object</param>
        /// <returns>true of successfully insert</returns>
        public bool Insert(CRecep_sample_program businessObject)
        {
            NpgsqlCommand sqlCommand = new NpgsqlCommand();

            sqlCommand.CommandText = "public.sp_recep_sample_program_Insert";
            sqlCommand.CommandType = CommandType.StoredProcedure;

            // Use connection object of base class
            sqlCommand.Connection = MainConnection;

            try
            {
                sqlCommand.Parameters.AddWithValue("p_idrecep_sample_program", businessObject.Idrecep_sample_program);
                sqlCommand.Parameters["p_idrecep_sample_program"].NpgsqlDbType = NpgsqlDbType.Bigint;
                sqlCommand.Parameters["p_idrecep_sample_program"].Direction    = ParameterDirection.InputOutput;

                sqlCommand.Parameters.AddWithValue("p_cod_recep_sample_program", businessObject.Cod_recep_sample_program);
                sqlCommand.Parameters["p_cod_recep_sample_program"].NpgsqlDbType = NpgsqlDbType.Bigint;
                sqlCommand.Parameters.AddWithValue("p_order_report", businessObject.Order_report);
                sqlCommand.Parameters["p_order_report"].NpgsqlDbType = NpgsqlDbType.Smallint;
                sqlCommand.Parameters.AddWithValue("p_idrecep_sample", businessObject.Idrecep_sample);
                sqlCommand.Parameters["p_idrecep_sample"].NpgsqlDbType = NpgsqlDbType.Bigint;
                sqlCommand.Parameters.AddWithValue("p_program_status", businessObject.Program_status);
                sqlCommand.Parameters["p_program_status"].NpgsqlDbType = NpgsqlDbType.Smallint;
                sqlCommand.Parameters.AddWithValue("p_date_report", businessObject.Date_report);
                sqlCommand.Parameters["p_date_report"].NpgsqlDbType = NpgsqlDbType.Date;
                sqlCommand.Parameters.AddWithValue("p_time_report", businessObject.Time_report);
                sqlCommand.Parameters["p_time_report"].NpgsqlDbType = NpgsqlDbType.Timestamp;
                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.Idrecep_sample_program = Convert.ToInt64(sqlCommand.Parameters["p_idrecep_sample_program"].Value);

                return(true);
            }
            catch (Exception ex)
            {
                throw new Exception("CRecep_sample_program::Insert::Error occured.", ex);
            }
            finally
            {
                MainConnection.Close();
                sqlCommand.Dispose();
            }
        }
        /// <summary>
        /// Populate business objects from the data reader
        /// </summary>
        /// <param name="dataReader">data reader</param>
        /// <returns>list of CRecep_sample_program</returns>
        internal List <CRecep_sample_program> PopulateObjectsFromReader(IDataReader dataReader)
        {
            List <CRecep_sample_program> list = new List <CRecep_sample_program>();

            while (dataReader.Read())
            {
                CRecep_sample_program businessObject = new CRecep_sample_program();
                PopulateBusinessObjectFromReader(businessObject, dataReader);
                list.Add(businessObject);
            }
            return(list);
        }
        /// <summary>
        /// Select by primary key
        /// </summary>
        /// <param name="keys">primary keys</param>
        /// <returns>CRecep_sample_program business object</returns>
        public CRecep_sample_program SelectByPrimaryKey(CRecep_sample_programKeys keys)
        {
            NpgsqlCommand sqlCommand = new NpgsqlCommand();

            sqlCommand.CommandText = "public.sp_recep_sample_program_SelectByPrimaryKey";
            sqlCommand.CommandType = CommandType.StoredProcedure;

            // Use connection object of base class
            sqlCommand.Connection = MainConnection;

            try
            {
                sqlCommand.Parameters.Add(new NpgsqlParameter("p_idrecep_sample_program", NpgsqlDbType.Bigint, 8, "", ParameterDirection.Input, false, 0, 0, DataRowVersion.Proposed, keys.Idrecep_sample_program));


                MainConnection.Open();

                NpgsqlDataReader dataReader = sqlCommand.ExecuteReader();

                if (dataReader.Read())
                {
                    CRecep_sample_program businessObject = new CRecep_sample_program();

                    PopulateBusinessObjectFromReader(businessObject, dataReader);

                    return(businessObject);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("CRecep_sample_program::SelectByPrimaryKey::Error occured.", ex);
            }
            finally
            {
                MainConnection.Close();
                sqlCommand.Dispose();
            }
        }
예제 #5
0
        private void repProgramButton_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            // --- save partial or final report
            if (e.Button.Index == 0)
            {
                #region save program

                bool result_insert_program = false;

                CRecep_sample_program oRecep_sample_program = new CRecep_sample_program();
                CRecep_sample_programFactory faRecep_sample_program = new CRecep_sample_programFactory();
                Reception oReception = new Reception();

                oRecep_sample_program = faRecep_sample_program.GetByPrimaryKey(
                    new CRecep_sample_programKeys(Convert.ToInt64(gvProgram.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_program = new CRecep_sample_program();
                    gvReport.SetFocusedRowCellValue(gcProg_Program_status, Convert.ToInt16(Comun.ReportStatus.Reportado));
                    oRecep_sample_program.Idrecep_sample = oRecep_sample.Idrecep_sample;
                    oRecep_sample_program.Idrecep_sample_program = Convert.ToInt64(gvProgram.GetFocusedRowCellValue(gcProg_Idrecep_sample_program));
                    oRecep_sample_program.Order_report = Convert.ToInt16(gvProgram.GetFocusedRowCellValue(gcProg_Order_report));
                    oRecep_sample_program.Program_status = Convert.ToInt16(Comun.ReportStatus.Reportado);
                    oRecep_sample_program.Cod_recep_sample_program = oReception.GetNewCodProgram();
                    oRecep_sample_program.Date_report = Convert.ToDateTime(gvProgram.GetFocusedRowCellValue(gcProg_Date_report));
                    oRecep_sample_program.Time_report = Convert.ToDateTime(gvProgram.GetFocusedRowCellValue(gcProg_Time_report));

                    result_insert_program = faRecep_sample_program.Insert(oRecep_sample_program);

                    gvProgram.SetFocusedRowCellValue(gcProg_Program_status, oRecep_sample_program.Program_status);
                    gvProgram.SetFocusedRowCellValue(gcProg_Idrecep_sample_program, oRecep_sample_program.Idrecep_sample_program);
                    gvProgram.SetFocusedRowCellValue(gcProg_Cod_recep_sample_program, oRecep_sample_program.Cod_recep_sample_program);
                    gvProgram.SetFocusedRowCellValue(gcProg_Str_cod_recep_sample_program, oReception.GetFormatProgramCode(oRecep_sample_program.Cod_recep_sample_program));

                    if (result_insert_program)
                    {
                        // --- create the partial report
                        List<CPositionValueProgram> lstPositionValueProgram = new List<CPositionValueProgram>();

                        foreach (GridCell[] cells in lstItemsSelProgram)
                        {
                            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_program = oRecep_sample_program.Idrecep_sample_program;

                                CPositionValueProgram position = GetObjectPositionProgram(idrecep_sample_detail, tagMethod.IDTemplate_method);
                                CCells_programFactory faCells_reported = new CCells_programFactory();
                                CCells_program oCell_program = new CCells_program();

                                oCell_program.Idtemplate_method = idtemplate_method;
                                oCell_program.Idrecep_sample_detail = idrecep_sample_detail;
                                oCell_program.Idrecep_sample_program = idrecep_sample_program;
                                oCell_program.Idrecep_sample_detail_elem = position.idrecep_sample_detail_elem;

                                bool result_cell_reported = false;

                                if (!(result_cell_reported = faCells_reported.Update(oCell_program)))
                                    result_cell_reported = faCells_reported.Insert(oCell_program);

                                if (result_cell_reported)
                                {
                                    position.idrecep_sample_program = idrecep_sample_program;
                                    position.row = cell.RowHandle;
                                    position.col = cell.Column;
                                    position.idcell_program = oCell_program.Idcell_reported;
                                    position.color = Comun.ColorRojo;

                                    if (!lstPositionValueProgram.Exists(c => c.idrecep_sample_detail_elem == position.idrecep_sample_detail_elem))
                                        lstPositionValueProgram.Add(position);
                                }
                            }
                        }
                        lstItemsSelProgram.Clear();
                        DicCellsSaveProgram.Add(Convert.ToInt32(oRecep_sample_program.Order_report), lstPositionValueProgram);
                    }
                }

                #endregion

                lstItemsSelProgram.Clear();
                gvReception.Focus();
            }
        }