Exemple #1
0
        public static void OpenSearchMenu()
        {
            Console.Clear();
            Console.WriteLine("Input Date: YYYY,MM,DDD\nAnge EXIT för att återvända");

            while (true)
            {
                string DateInput = Console.ReadLine();
                if (DateInput.ToUpper() == "EXIT")
                {
                    break;
                }

                if (DateTime.TryParse(DateInput, out DateTime Datum))
                {
                    Kvitto.ReadKvittoShort(Datum);
                    Kvitto.ReadKvitto(Datum);
                    Console.WriteLine("Tryck Enter för att gå tillbaka..");
                    Console.ReadLine();
                    Console.Clear(); break;
                }
                else
                {
                    Console.WriteLine("Fel typ av inmatning. Följ Formatet!");
                }
            }
        }
Exemple #2
0
        public static void Kassa()
        {
            var ItemList = new List <KassaItem>();


            DateTime KvittoTime  = DateTime.Now;
            var      ProductList = Produkt.GetProducts();


            int    Number = 1000;
            double TotalSumma;
            double Rabatt      = 0;
            double TotalRabatt = 0;
            int    ProductID;
            int    ProductAmount;
            bool   isNotAdded;

            while (true)
            {
                while (true)
                {
                    Console.Clear();
                    Console.WriteLine("KASSA");
                    Console.WriteLine("KVITTO    {0}", KvittoTime);
                    TotalSumma = 0;
                    isNotAdded = true;

                    if (ItemList.Count > 0)
                    {
                        foreach (KassaItem K in ItemList)
                        {
                            Console.WriteLine("{0} {1}{2} * {3} = {4}", K.Namn, K.Amount, K.Typ, K.Pris.ToString("0.00"), K.Total.ToString("0.00"));
                            TotalSumma += K.Total;
                        }

                        Console.WriteLine("Items Total: {0}", TotalSumma.ToString("0.00"));

                        if (TotalSumma >= 1000 && TotalSumma < 2000)
                        {
                            Rabatt      = (TotalSumma * 0.01) * -1;
                            TotalRabatt = TotalSumma * 0.99;
                            Console.WriteLine("Rabatt: {0}", Rabatt.ToString("0.00"));
                            Console.WriteLine("Total: {0}", TotalRabatt.ToString("0.00"));
                        }

                        else if (TotalSumma >= 2000)
                        {
                            Rabatt      = (TotalSumma * 0.02) * -1;
                            TotalRabatt = TotalSumma * 0.98;
                            Console.WriteLine("Rabatt: {0}", Rabatt.ToString("0.00"));
                            Console.WriteLine("Total: {0}", TotalRabatt.ToString("0.00"));
                        }
                    }



                    Console.WriteLine("\nKommandon:\n<ProductID> <Antal>\nRETURN <ProductID>\nPAY - Confirm the Order\nEXIT - Return to Main Menu");
                    Console.Write("Kommando:");

                    string UserInput = Console.ReadLine().ToUpper();
                    if (UserInput == "PAY")
                    {
                        foreach (KassaItem K in ItemList)
                        {
                            K.Rabatt      = Rabatt;
                            K.TotalRabatt = TotalRabatt;
                            K.Pris        = Campaign.CampaignRead(K.ProductID, K.Pris);
                        }
                        Kvitto.CreateKvitto(KvittoTime, ItemList); Console.Clear(); return;
                    }

                    if (UserInput == "EXIT")
                    {
                        Console.Clear(); return;
                    }

                    if (UserInput.Contains(" "))
                    {
                        String[] KommandoInfo = UserInput.Split(' ');
                        if (KommandoInfo[0] == "RETURN")
                        {
                            ProductID = int.Parse(KommandoInfo[1]);
                            foreach (KassaItem P in ItemList)
                            {
                                if (ProductID == P.ProductID && P.Amount <= 1)
                                {
                                    ItemList.Remove(P);
                                    break;
                                }
                                else if (ProductID == P.ProductID && P.Amount > 1)
                                {
                                    P.Amount = P.Amount - 1;
                                    P.Total  = P.Total - P.Pris;
                                }
                            }
                            continue;
                        }
                        try
                        {
                            ProductID     = int.Parse(KommandoInfo[0]);
                            ProductAmount = int.Parse(KommandoInfo[1]);
                            if (ProductAmount <= 0)
                            {
                                continue;
                            }
                            break;
                        }
                        catch (Exception E)
                        { Console.WriteLine(E); Console.ReadLine(); }
                    }
                }

                bool failed  = false;
                int  tempMax = 0;

                foreach (Produkt P in ProductList)
                {
                    if (P.ProductID == ProductID)
                    {
                        tempMax = P.MaxItems;
                    }
                }

                foreach (KassaItem T in ItemList)
                {
                    if (T.ProductID == ProductID && T.Amount > 0)
                    {
                        double TempTotal = T.Amount + ProductAmount;
                        if (TempTotal <= tempMax || tempMax == 0)
                        {
                            T.Amount  += ProductAmount;
                            T.Total    = T.Amount * T.Pris;
                            isNotAdded = false;
                        }
                        else
                        {
                            Console.WriteLine($"Endast {tempMax} tillåtet, med dessa blir det {T.Amount + ProductAmount}. Försök igen..."); Console.ReadLine(); failed = true; break;
                        }
                    }
                }

                if (!failed)
                {
                    foreach (Produkt P in ProductList)
                    {
                        if (ProductID == P.ProductID && isNotAdded)
                        {
                            if (P.MaxItems >= ProductAmount || P.MaxItems == 0)
                            {
                                P.Pris = Campaign.CampaignRead(ProductID, P.Pris);
                                var Item = new KassaItem(P.Namn, P.Pris, P.Typ, ProductAmount, P.ProductID, TotalRabatt, Rabatt, Number);
                                ItemList.Add(Item);
                            }
                            else
                            {
                                Console.WriteLine($"Endast {tempMax} tillåtet, med dessa blir det {ProductAmount}. Försök igen..."); Console.ReadLine(); break;
                            }
                        }
                    }
                }
            }
        }