Пример #1
0
        public void Add(InternetShopFilter filter)
        {
            FilesProvider.OpenWriter("InternetShop");
            InternetShop newCollection = new InternetShop();

            if (filter.Id.HasValue)
            {
                newCollection.Id = (int)filter.Id;
            }
            if (!string.IsNullOrEmpty(filter.Name))
            {
                newCollection.Name = filter.Name;
            }
            if (!string.IsNullOrEmpty(filter.Category))
            {
                newCollection.Category = filter.Category;
            }
            if (!string.IsNullOrEmpty(filter.Price))
            {
                newCollection.Price = filter.Price;
            }

            FilesProvider.WriteMusicCollection(newCollection);
            FilesProvider.CloseWriter();
        }
Пример #2
0
        static void ProxyInvoke()
        {
            // 创建一个代理对象并发出请求
            InternetShop proxy = new InternetShop();

            proxy.Sell();
        }
Пример #3
0
 public static void WriteMusicCollection(InternetShop collection)
 {
     Writer.WriteLine("Id: {0}", collection.Id);
     Writer.WriteLine("Name: {0}", collection.Name);
     Writer.WriteLine("Category: {0}", collection.Category);
     Writer.WriteLine("Price: {0}", collection.Price);
     Writer.WriteLine();
 }
Пример #4
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);
        }
Пример #5
0
        public List <InternetShop> Get(InternetShopFilter filter)
        {
            List <InternetShop> ResultInternetShop = new List <InternetShop>();

            FilesProvider.OpenReader("InternetShop");

            int peek = FilesProvider.Peek();

            while (peek != -1)
            {
                string IdRow = FilesProvider.ReadRow();
                if (string.IsNullOrEmpty(IdRow))
                {
                    break;                              // means that if file is empty
                }
                string[] IdParts = IdRow.Split(':');
                int      id      = Convert.ToInt32(IdParts[1].Trim());


                string   NameRow   = FilesProvider.ReadRow();
                string[] NameParts = NameRow.Split(':');
                string   name      = NameParts[1].Trim();


                string   CategoryRow   = FilesProvider.ReadRow();
                string[] CategoryParts = NameRow.Split(':');
                string   category      = CategoryParts[1].Trim();

                string   PriceRow   = FilesProvider.ReadRow();
                string[] PriceParts = PriceRow.Split(':');
                string   price      = PriceParts[1].Trim();


                InternetShop Collection = new InternetShop(id, name, category, price);
                ResultInternetShop.Add(Collection);

                peek = FilesProvider.Peek();
                if (FilesProvider.ReadRow() == "")
                {
                    continue;
                }
            } // while

            FilesProvider.CloseReader();
            return(ResultInternetShop);
        }