コード例 #1
0
        public static void ReadKvittoShort(DateTime time)
        {
            DateTime Time        = time;
            String   DatumFormat = Time.ToString("yyyMMdd");
            String   ReceiptPath = @"../../RECEIPT_" + DatumFormat + ".txt";

            double Rabatt      = 0;
            double TotalRabatt = 0;
            int    Number      = 0;

            if (System.IO.File.Exists(ReceiptPath))
            {
                string   Text       = System.IO.File.ReadAllText(ReceiptPath);
                string[] KvittoList = Text.Split('#');
                Console.Clear();

                foreach (string K in KvittoList)
                {
                    var ItemListan = new List <KassaItem>();

                    string[] ItemList = K.Split('*');
                    foreach (String S in ItemList)
                    {
                        if (S == "\r\n" || S == "")
                        {
                        }
                        else
                        {
                            string[] DataList = S.Split(',');

                            string Namn      = DataList[0];
                            double Pris      = double.Parse(DataList[1]);
                            string Typ       = DataList[2];
                            double Amount    = double.Parse(DataList[3]);
                            int    productID = int.Parse(DataList[4]);
                            TotalRabatt = double.Parse(DataList[6]);
                            Rabatt      = double.Parse(DataList[7]);
                            Number      = int.Parse(DataList[8]);

                            var Item = new KassaItem(DataList[0], Pris, Typ, Amount, productID, TotalRabatt, Rabatt, Number);
                            ItemListan.Add(Item);
                        }
                    }

                    if (K == "\r\n" || K == "")
                    {
                    }
                    else
                    {
                        string Datum = Time.ToString("yyyy-MM-dd");
                        Console.WriteLine("KVITTO: {1}    {0}", Datum, Number);

                        if (ItemListan.Count > 0)
                        {
                            double TotalSumma = 0;
                            foreach (KassaItem C in ItemListan)
                            {
                                TotalSumma += C.Total;
                            }

                            Console.WriteLine("Total: {0}\n", TotalSumma.ToString("0.00"));
                        }
                    }
                }
            }
            else
            {
                Console.WriteLine("Kunde ej hitta kvitto från det datumet"); return;
            }
        }
コード例 #2
0
        public static void ReadKvitto(DateTime time)
        {
            DateTime Time        = time;
            String   DatumFormat = Time.ToString("yyyMMdd");
            String   ReceiptPath = @"../../RECEIPT_" + DatumFormat + ".txt";

            double Rabatt      = 0;
            double TotalRabatt = 0;
            int    Number      = 0;
            int    UserNumber;
            string userInput;
            bool   NotPosted = false;

            if (System.IO.File.Exists(ReceiptPath))
            {
                string   Text       = System.IO.File.ReadAllText(ReceiptPath);
                string[] KvittoList = Text.Split('#');


                Console.WriteLine("Ange löpnummer för att se hela kvittot. Avsluta med endast Enter..");
                while (!int.TryParse(userInput = Console.ReadLine(), out UserNumber))
                {
                    if (userInput == "")
                    {
                        return;
                    }
                    Console.WriteLine("Ange endast siffror för att hitta kvitto");
                }

                Console.Clear();

                foreach (string K in KvittoList)
                {
                    var ItemListan = new List <KassaItem>();

                    string[] ItemList = K.Split('*');
                    foreach (String S in ItemList)
                    {
                        if (S == "\r\n" || S == "")
                        {
                        }
                        else
                        {
                            string[] DataList = S.Split(',');

                            string Namn      = DataList[0];
                            double Pris      = double.Parse(DataList[1]);
                            string Typ       = DataList[2];
                            double Amount    = double.Parse(DataList[3]);
                            int    productID = int.Parse(DataList[4]);
                            TotalRabatt = double.Parse(DataList[6]);
                            Rabatt      = double.Parse(DataList[7]);
                            Number      = int.Parse(DataList[8]);

                            var Item = new KassaItem(DataList[0], Pris, Typ, Amount, productID, TotalRabatt, Rabatt, Number);
                            ItemListan.Add(Item);
                        }
                    }

                    if (K == "\r\n" || K == "")
                    {
                    }
                    else
                    {
                        if (ItemListan.Count > 0)
                        {
                            double TotalSumma = 0;
                            foreach (KassaItem C in ItemListan)
                            {
                                if (C.Number == UserNumber)
                                {
                                    if (!NotPosted)
                                    {
                                        string Datum = Time.ToString("yyyy-MM-dd");
                                        Console.WriteLine("KVITTO: {1}    {0}", Datum, UserNumber);
                                        NotPosted = true;
                                    }


                                    String Namn = C.Namn.Replace("\r\n", string.Empty);
                                    Console.WriteLine("{0} {1}{2} * {3} = {4}", Namn, C.Amount, C.Typ, C.Pris.ToString("0.00"), C.Total.ToString("0.00"));
                                    TotalSumma += C.Total;
                                }
                            }


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

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

                                if (TotalSumma >= 2000)
                                {
                                    Rabatt      = ((TotalSumma / 100) * 2) * -1;
                                    TotalRabatt = TotalSumma - (TotalSumma / 100);
                                    Console.WriteLine("Rabatt: {0}", Rabatt.ToString("0.00"));
                                    Console.WriteLine("Total: {0}", TotalRabatt.ToString("0.00"));
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #3
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;
                            }
                        }
                    }
                }
            }
        }