コード例 #1
0
ファイル: StoreDAO.cs プロジェクト: gllortc/railwaystudio
        /// <summary>
        /// Get all stores.
        /// </summary>
        /// <returns>A list filled with all requested instances.</returns>
        public List <Store> GetAll()
        {
            string       sql    = string.Empty;
            Store        store  = null;
            List <Store> stores = new List <Store>();

            try
            {
                Connect();

                sql = @"SELECT 
                        " + StoreDAO.SQL_FIELDS_SELECT + @" 
                    FROM 
                        " + StoreDAO.SQL_TABLE + @" 
                    ORDER BY 
                        storename ASC";

                using (SQLiteDataReader reader = ExecuteReader(sql))
                {
                    while (reader.Read())
                    {
                        store = StoreDAO.ReadEntityRecord(reader);
                        if (store != null)
                        {
                            stores.Add(store);
                        }
                    }
                }

                return(stores);
            }
            catch (Exception ex)
            {
                Logger.LogError(this, ex);

                throw;
            }
            finally
            {
                Disconnect();
            }
        }
コード例 #2
0
ファイル: StoreDAO.cs プロジェクト: gllortc/railwaystudio
        /// <summary>
        /// Recupera un modelo de la colección.
        /// </summary>
        /// <param name="itemid">Identificador del modelo.</param>
        /// <returns>Una instáncia de RCStore.</returns>
        public Store GetByName(string name)
        {
            string sql = string.Empty;

            try
            {
                Connect();

                sql = @"SELECT 
                        " + StoreDAO.SQL_FIELDS_SELECT + @" 
                    FROM 
                        " + StoreDAO.SQL_TABLE + @" 
                    WHERE 
                        storename=@storename";


                SetParameter("storename", name);

                using (SQLiteDataReader reader = ExecuteReader(sql))
                {
                    if (reader.Read())
                    {
                        return(StoreDAO.ReadEntityRecord(reader));
                    }
                }

                return(null);
            }
            catch (Exception ex)
            {
                Logger.LogError(this, ex);

                throw;
            }
            finally
            {
                Disconnect();
            }
        }