예제 #1
0
        public void addClientOrder(int id, string classofProd, string category, string type, string name, int quantity, string clientName, string clientAddress, double price, DateTime date)
        {
            Product product = new Product(classofProd, category, type, name);
            Store   store   = Store.getInstance();
            int     count   = 0;

            if (!store.Products.TryGetValue(product, out count))
            {
                throw new ServiceException("Не найдено такого проудкта");
            }
            if (count > quantity)
            {
                count = count - quantity;
                store.Products.Remove(product);
                store.Products.Add(product, count);
                ClientOrderList clientorderList = ClientOrderList.getInstance();
                clientorderList.addClientOrder(new ClientOrder(id, product, quantity, clientName, clientAddress, true, 0, price, date));
                return;
            }
            if (count < quantity)
            {
                count = quantity - count;
                store.Products.Remove(product);
                store.Products.Add(product, 0);
                ClientOrderList clientorderList = ClientOrderList.getInstance();
                ClientOrder     clientOrder     = new ClientOrder(id, product, quantity, clientName, clientAddress, false, count, price, date);
                clientorderList.addClientOrder(clientOrder);
                ProviderOrderList providerOrderList = ProviderOrderList.getInstance();
                ProviderOrder     providerOrder     = new ProviderOrder(providerOrderList.generateId(), product, count, 0, date);
                providerOrder.ClientOrder = clientOrder;
                providerOrderList.addProviderOrder(providerOrder);
                return;
            }

            if (count == quantity)
            {
                count = quantity - count;
                store.Products.Remove(product);
                store.Products.Add(product, 0);
                ClientOrderList clientorderList = ClientOrderList.getInstance();
                clientorderList.addClientOrder(new ClientOrder(id, product, quantity, clientName, clientAddress, true, 0, price, date));
                return;
            }
        }