示例#1
0
        public List <InternetShop> Get(InternetShopFilter filter)
        {
            List <InternetShop> ResultInternetShop = new List <InternetShop>();

            DatabaseProvider.CreateConnectionAndCommand();
            //
            string        cmd        = "SELECT * FROM Names";
            List <string> conditions = new List <string>();

            //
            if (filter.Id.HasValue)
            {
                conditions.Add("Id = " + filter.Id.ToString());
            }
            if (!string.IsNullOrEmpty(filter.Name))
            {
                conditions.Add(string.Format("Name = '{0}'", filter.Name));
            }
            if (!string.IsNullOrEmpty(filter.Category))
            {
                conditions.Add(string.Format("Category = '{0}'", filter.Category));
            }
            if (!string.IsNullOrEmpty(filter.Price))
            {
                conditions.Add(string.Format("Price = '{0}'", filter.Price));
            }

            if (conditions.Count() > 0)
            {
                cmd += " WHERE " + string.Join(" AND ", conditions.ToArray());
            }
            DatabaseProvider.ExecuteCommand(cmd);
            //
            DatabaseProvider.BeginReader();
            while (DatabaseProvider.Reader.Read())
            {
                int    id       = (int)DatabaseProvider.Reader["id"];
                string name     = (string)DatabaseProvider.Reader["name"];
                string category = (string)DatabaseProvider.Reader["category"];
                string price    = (string)DatabaseProvider.Reader["Price"];

                InternetShop collection = new InternetShop(id, name, category, price);
                ResultInternetShop.Add(collection);
            }
            DatabaseProvider.FinishReader();
            //
            DatabaseProvider.CloseConnection();
            return(ResultInternetShop);
        }