Beispiel #1
0
        /// <summary>
        /// Populate business objects from the data reader
        /// </summary>
        /// <param name="dataReader">data reader</param>
        /// <returns>list of CType_solution</returns>
        internal List <CType_solution> PopulateObjectsFromReader(IDataReader dataReader)
        {
            List <CType_solution> list = new List <CType_solution>();

            while (dataReader.Read())
            {
                CType_solution businessObject = new CType_solution();
                PopulateBusinessObjectFromReader(businessObject, dataReader);
                list.Add(businessObject);
            }
            return(list);
        }
        protected override bool Grabar_Registro()
        {
            CType_solutionFactory faType_solution = new CType_solutionFactory();

            try
            {
                // --- remove all
                List <CType_solution> lstType_solution = new List <CType_solution>(new CType_solutionFactory().GetAll());

                for (int i = 0; i < lstType_solution.Count; i++)
                {
                    CType_solution current_row = lstType_solution[i];

                    if (current_row.Idtype_solution > 0)
                    {
                        current_row.Status = false;
                        faType_solution.Update(current_row);
                    }
                }

                // --- save all
                for (int i = 0; i < gvTypeSolution.RowCount; i++)
                {
                    CType_solution current_row = gvTypeSolution.GetRow(i) as CType_solution;

                    if (current_row.Idtype_solution == 0)
                    {
                        current_row.Usernew = Comun.GetUser();
                        current_row.Datenew = Comun.GetDate();
                        current_row.Status  = true;
                    }
                    else
                    {
                        current_row.Useredit = Comun.GetUser();
                        current_row.Dateedit = Comun.GetDate();
                        current_row.Status   = true;
                    }


                    if (!faType_solution.Update(current_row))
                    {
                        faType_solution.Insert(current_row);
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                ComunForm.Send_message(this.Text, TypeMsg.error, ex.Message);
                return(false);
            }
        }
Beispiel #3
0
        /// <summary>
        /// insert new row in the table
        /// </summary>
        /// <param name="businessObject">business object</param>
        /// <returns>true of successfully insert</returns>
        public bool Insert(CType_solution businessObject)
        {
            NpgsqlCommand sqlCommand = new NpgsqlCommand();

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

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

            try
            {
                sqlCommand.Parameters.AddWithValue("p_idtype_solution", businessObject.Idtype_solution);
                sqlCommand.Parameters["p_idtype_solution"].NpgsqlDbType = NpgsqlDbType.Integer;
                sqlCommand.Parameters["p_idtype_solution"].Direction    = ParameterDirection.InputOutput;

                sqlCommand.Parameters.AddWithValue("p_name_type_solution", businessObject.Name_type_solution);
                sqlCommand.Parameters["p_name_type_solution"].NpgsqlDbType = NpgsqlDbType.Varchar;
                sqlCommand.Parameters.AddWithValue("p_num_days_expiration", businessObject.Num_days_expiration);
                sqlCommand.Parameters["p_num_days_expiration"].NpgsqlDbType = NpgsqlDbType.Smallint;
                sqlCommand.Parameters.AddWithValue("p_observation", businessObject.Observation);
                sqlCommand.Parameters["p_observation"].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;


                MainConnection.Open();

                sqlCommand.ExecuteNonQuery();
                businessObject.Idtype_solution = Convert.ToInt32(sqlCommand.Parameters["p_idtype_solution"].Value);

                return(true);
            }
            catch (Exception ex)
            {
                throw new Exception("CType_solution::Insert::Error occured.", ex);
            }
            finally
            {
                MainConnection.Close();
                sqlCommand.Dispose();
            }
        }
Beispiel #4
0
        /// <summary>
        /// Populate business object from data reader
        /// </summary>
        /// <param name="businessObject">business object</param>
        /// <param name="dataReader">data reader</param>
        internal void PopulateBusinessObjectFromReader(CType_solution businessObject, IDataReader dataReader)
        {
            businessObject.Idtype_solution = dataReader.GetInt32(dataReader.GetOrdinal(CType_solution.CType_solutionFields.Idtype_solution.ToString()));

            if (!dataReader.IsDBNull(dataReader.GetOrdinal(CType_solution.CType_solutionFields.Name_type_solution.ToString())))
            {
                businessObject.Name_type_solution = dataReader.GetString(dataReader.GetOrdinal(CType_solution.CType_solutionFields.Name_type_solution.ToString()));
            }

            if (!dataReader.IsDBNull(dataReader.GetOrdinal(CType_solution.CType_solutionFields.Num_days_expiration.ToString())))
            {
                businessObject.Num_days_expiration = (short?)dataReader.GetInt16(dataReader.GetOrdinal(CType_solution.CType_solutionFields.Num_days_expiration.ToString()));
            }

            if (!dataReader.IsDBNull(dataReader.GetOrdinal(CType_solution.CType_solutionFields.Observation.ToString())))
            {
                businessObject.Observation = dataReader.GetString(dataReader.GetOrdinal(CType_solution.CType_solutionFields.Observation.ToString()));
            }

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

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

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

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

            if (!dataReader.IsDBNull(dataReader.GetOrdinal(CType_solution.CType_solutionFields.Status.ToString())))
            {
                businessObject.Status = dataReader.GetBoolean(dataReader.GetOrdinal(CType_solution.CType_solutionFields.Status.ToString()));
            }
        }
Beispiel #5
0
        /// <summary>
        /// Select by primary key
        /// </summary>
        /// <param name="keys">primary keys</param>
        /// <returns>CType_solution business object</returns>
        public CType_solution SelectByPrimaryKey(CType_solutionKeys keys)
        {
            NpgsqlCommand sqlCommand = new NpgsqlCommand();

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

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

            try
            {
                sqlCommand.Parameters.Add(new NpgsqlParameter("p_idtype_solution", NpgsqlDbType.Integer, 4, "", ParameterDirection.Input, false, 0, 0, DataRowVersion.Proposed, keys.Idtype_solution));


                MainConnection.Open();

                NpgsqlDataReader dataReader = sqlCommand.ExecuteReader();

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

                    PopulateBusinessObjectFromReader(businessObject, dataReader);

                    return(businessObject);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("CType_solution::SelectByPrimaryKey::Error occured.", ex);
            }
            finally
            {
                MainConnection.Close();
                sqlCommand.Dispose();
            }
        }