public List <TrainerModel> loadAllTrainersFromDataBase()
        {
            List <TrainerModel> trainerList = new List <TrainerModel>();

            try
            {
                using (OracleConnection connection = new OracleConnection(OracleSQLConnector.GetConnectionString()))
                {
                    connection.Open();
                    OracleCommand cmd;
                    string        sql = String.Format("select * from trainer_table");

                    cmd             = new OracleCommand(sql, connection);
                    cmd.CommandType = CommandType.Text;

                    OracleDataReader reader = cmd.ExecuteReader();
                    try
                    {
                        while (reader.Read())
                        {
                            TrainerModel trainer = new TrainerModel();
                            trainer.setID(reader.GetInt32(0));
                            trainer.setFirstName(reader.GetString(1));
                            trainer.setLastName(reader.GetString(2));
                            trainer.setEmailAddress(reader.GetString(3));
                            trainer.setPhoneNumber(reader.GetString(4));
                            try
                            {
                                trainer.setPricePerhour(reader.GetInt32(5));
                            }
                            catch
                            {
                                trainer.setPricePerhour(0);
                            }
                            try
                            {
                                trainer.setImageBlob((byte[])reader["image"]);
                            }
                            catch
                            {
                                //trainer.setImageBlob(null);
                            }
                            trainerList.Add(trainer);
                        }
                    }
                    finally
                    {
                        reader.Close();
                    }
                }
            }catch
            {
            }
            return(trainerList);
        }
コード例 #2
0
        /// <summary>
        /// Load currently logged in Trainer Data
        /// </summary>
        /// <returns></returns>
        public TrainerModel loadTrainerFromDataBase()
        {
            TrainerModel trainer = new TrainerModel();

            try
            {
                using (OracleConnection connection = new OracleConnection(OracleSQLConnector.GetConnectionString()))
                {
                    connection.Open();
                    OracleCommand cmd;
                    string        sql = String.Format("select * from trainer_table WHERE id = {0}", GlobalClass.getTrainerID());

                    cmd             = new OracleCommand(sql, connection);
                    cmd.CommandType = CommandType.Text;

                    OracleDataReader reader = cmd.ExecuteReader();
                    try
                    {
                        while (reader.Read())
                        {
                            trainer = new TrainerModel(reader.GetString(1), reader.GetString(2), reader.GetString(3), reader.GetString(4));
                            try
                            {
                                trainer.setPricePerhour(reader.GetInt32(5));
                            }
                            catch
                            {
                                trainer.setPricePerhour(0);
                            }
                            try
                            {
                                trainer.setImageBlob((byte[])reader["image"]);
                            }
                            catch
                            {
                                trainer.setImageBlob(null);
                            }
                        }
                    }
                    finally
                    {
                        reader.Close();
                    }
                }
            }
            catch
            {
            }
            return(trainer);
        }