Exemplo n.º 1
0
        public List <GardenEntity> ListPlantsInZone(GardenEntity.hardinessZone myZone)
        {
            GardenDAO           gardenDAO        = new GardenDAO();
            List <GardenEntity> gardenEntityList = new List <GardenEntity>();

            if (gardenDAO != null)
            {
                gardenEntityList = gardenDAO.ListPlantsInZone(myZone);
            }
            else
            {
                throw new Exception("GardenDAO is null. ListPlantsInZone");
            }
            return(gardenEntityList);
        }
Exemplo n.º 2
0
        public List <GardenEntity> ListPlantsInZone(GardenEntity.hardinessZone myZone)
        {
            List <GardenEntity> gardenEntities = new List <GardenEntity>();

            using (SqlCeConnection con = new SqlCeConnection(conString))
            {
                try
                {
                    con.Open();
                }
                catch (SqlCeException ee)
                {
                    //unable to open SqlCe connection
                    SqlCeErrorCollection errorCollection = ee.Errors;
                    StringBuilder        bld             = new StringBuilder();
                    Exception            inner           = ee.InnerException;

                    if (inner != null)
                    {
                        bld.AppendLine("Inner Exception: " + inner.ToString());
                    }

                    foreach (SqlCeError err in errorCollection)
                    {
                        bld.AppendLine(err.ToString());
                    }
                }

                using (SqlCeCommand com = new SqlCeCommand("SELECT * FROM Plant WHERE Plant.WithstandColdestZone <= '" + (int)myZone + "' AND Plant.WithstandHottestZone >= '" + (int)myZone + "'", con))
                {
                    SqlCeDataReader reader = com.ExecuteReader();

                    while (reader.Read())
                    {
                        try
                        {
                            AddReaderToGardenEntityList(gardenEntities, reader);
                        }
                        catch (Exception)
                        {
                            //unable to parse datas
                        }
                    }
                }
            }
            return(gardenEntities);
        }