コード例 #1
0
ファイル: Order.cs プロジェクト: NguyenVuNhan/ProP2018
        public void ClearRow(int index, ref double balanceleft)
        {
            if (OrderList.Count() != 0)
            {
                int    quantity = OrderList[index].Quantity;
                double price    = OrderList[index].Price;
                OrderList[index].LeftInStock = OrderList[index].LeftInStock + quantity;
                OrderList.RemoveAt(index);
                balanceleft = balanceleft + ((double)quantity * price);
            }

            CalculateTotal();
        }
コード例 #2
0
ファイル: LoanOrder.cs プロジェクト: NguyenVuNhan/ProP2018
        public void ClearList(ref double balanceleft)
        {
            if (OrderList.Count() != 0)
            {
                foreach (LoanItem p in OrderList)
                {
                    balanceleft = balanceleft + ((double)(p.Quantity)) * p.Price;
                }

                OrderList.Clear();
            }

            CalculateTotal();
        }
コード例 #3
0
 public bool CanConfirmOrderExecute()
 {
     if (OrderList != null)
     {
         if (OrderList.Count() > 0)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     else
     {
         return(false);
     }
 }
コード例 #4
0
 /// <summary>
 /// Method to check if execution of confirm command is possible
 /// </summary>
 /// <returns></returns>
 public bool CanConfirmOrderExecute()
 {
     //if there is any item in order list execution of confirm is true
     if (OrderList != null)
     {
         if (OrderList.Count() > 0)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     else
     {
         return(false);
     }
 }
コード例 #5
0
ファイル: LoanOrder.cs プロジェクト: NguyenVuNhan/ProP2018
        public void Deduct(int itemid, ref double balanceleft)
        {
            int    index = -1;
            double price = 0;

            if (OrderList.Count() != 0)
            {
                foreach (LoanItem p in OrderList)
                {
                    if (p.ID == itemid)
                    {
                        price = p.Price;

                        if (p.Quantity > 1)
                        {
                            p.UpdateQuantity(-1);
                            p.LeftInStock = p.LeftInStock + 1;
                            balanceleft   = balanceleft + p.Price;
                        }

                        else
                        {
                            index = OrderList.IndexOf(p);
                        }
                    }
                }

                if (index != -1)
                {
                    OrderList[index].LeftInStock = OrderList[index].LeftInStock + 1;
                    OrderList.RemoveAt(index);
                    balanceleft = balanceleft + price;
                }
            }

            CalculateTotal();
        }
コード例 #6
0
ファイル: LoanOrder.cs プロジェクト: NguyenVuNhan/ProP2018
        public void Add(int itemid, ref double balanceleft)
        {
            try
            {
                List <string> ItemData    = OrderDataBase.GetItem("borrowable", itemid);
                bool          InOrder     = false;
                int           LeftInStock = Convert.ToInt32(ItemData[3]);

                if (OrderList.Count() != 0)
                {
                    foreach (LoanItem p in OrderList)
                    {
                        if (p.ID == itemid)
                        {
                            LeftInStock = p.LeftInStock;
                        }
                    }
                }

                if (balanceleft >= Convert.ToDouble(ItemData[2]))
                {
                    if (1 <= LeftInStock)
                    {
                        if (OrderList.Count() != 0)
                        {
                            foreach (LoanItem p in OrderList)
                            {
                                if (p.ID == itemid)
                                {
                                    p.UpdateQuantity(1);
                                    InOrder       = true;
                                    p.LeftInStock = p.LeftInStock - 1;
                                    balanceleft   = balanceleft - Convert.ToDouble(ItemData[2]);
                                }
                            }
                        }

                        else
                        {
                            OrderList.Add(new LoanItem(itemid, ItemData[1], Convert.ToDouble(ItemData[2]), Convert.ToInt32(ItemData[3]), Convert.ToDouble(ItemData[4])));
                            foreach (LoanItem p in OrderList)
                            {
                                if (p.ID == itemid)
                                {
                                    p.UpdateQuantity(1);
                                    InOrder       = true;
                                    p.LeftInStock = p.LeftInStock - 1;
                                    balanceleft   = balanceleft - Convert.ToDouble(ItemData[2]);
                                }
                            }
                        }

                        if (InOrder == false)
                        {
                            OrderList.Add(new LoanItem(itemid, ItemData[1], Convert.ToDouble(ItemData[2]), Convert.ToInt32(ItemData[3]), Convert.ToDouble(ItemData[4])));
                            foreach (LoanItem p in OrderList)
                            {
                                if (p.ID == itemid)
                                {
                                    p.UpdateQuantity(1);
                                    p.LeftInStock = p.LeftInStock - 1;
                                    balanceleft   = balanceleft - Convert.ToDouble(ItemData[2]);
                                }
                            }
                        }

                        CalculateTotal();
                    }

                    else
                    {
                        OnError("Not enough products in stock.");
                    }
                }

                else
                {
                    OnError("Balance not enough to add product.");
                }
            }

            catch
            {
                OnError("Check your connection. Unable to reach the database.");
            }
        }
コード例 #7
0
ファイル: Order.cs プロジェクト: NguyenVuNhan/ProP2018
        public void Add(int itemid, int quantity, int age, ref double balanceleft)
        {
            try
            {
                List <string> ItemData      = OrderDataBase.GetItem("product", itemid);
                bool          InOrder       = false;
                int           IsAdult       = 0;
                int           OnlyForAdults = 0;
                int           LeftInStock   = Convert.ToInt32(ItemData[3]);

                if (ItemData[4] == "True")
                {
                    OnlyForAdults = 1;
                }

                if (age >= 18)
                {
                    IsAdult = 1;
                }

                if (OrderList.Count() != 0)
                {
                    foreach (Item p in OrderList)
                    {
                        if (p.ID == itemid)
                        {
                            LeftInStock = p.LeftInStock;
                        }
                    }
                }

                if (IsAdult >= OnlyForAdults)
                {
                    if (balanceleft >= Convert.ToDouble(quantity) * Convert.ToDouble(ItemData[2]))
                    {
                        if (quantity <= LeftInStock)
                        {
                            if (OrderList.Count() != 0)
                            {
                                foreach (Item p in OrderList)
                                {
                                    if (p.ID == itemid)
                                    {
                                        p.UpdateQuantity(quantity);
                                        InOrder       = true;
                                        p.LeftInStock = p.LeftInStock - quantity;
                                        balanceleft   = balanceleft - (Convert.ToDouble(quantity) * Convert.ToDouble(ItemData[2]));
                                    }
                                }
                            }

                            else
                            {
                                OrderList.Add(new Item(itemid, ItemData[1], Convert.ToDouble(ItemData[2]), Convert.ToInt32(ItemData[3]), Convert.ToBoolean(ItemData[4])));
                                foreach (Item p in OrderList)
                                {
                                    if (p.ID == itemid)
                                    {
                                        p.UpdateQuantity(quantity);
                                        InOrder       = true;
                                        p.LeftInStock = p.LeftInStock - quantity;
                                        balanceleft   = balanceleft - (Convert.ToDouble(quantity) * Convert.ToDouble(ItemData[2]));
                                    }
                                }
                            }

                            if (InOrder == false)
                            {
                                OrderList.Add(new Item(itemid, ItemData[1], Convert.ToDouble(ItemData[2]), Convert.ToInt32(ItemData[3]), Convert.ToBoolean(ItemData[4])));
                                foreach (Item p in OrderList)
                                {
                                    if (p.ID == itemid)
                                    {
                                        p.UpdateQuantity(quantity);
                                        p.LeftInStock = p.LeftInStock - quantity;
                                        balanceleft   = balanceleft - (Convert.ToDouble(quantity) * Convert.ToDouble(ItemData[2]));
                                    }
                                }
                            }

                            CalculateTotal();
                        }

                        else
                        {
                            OnError("Not enough products in stock.");
                        }
                    }

                    else
                    {
                        OnError("Balance not enough to add product.");
                    }
                }

                else
                {
                    OnError("Product is only available for adults.");
                }
            }

            catch
            {
                OnError("Check your connection. Unable to reach the database.");
            }
        }