Exemplo n.º 1
0
    public Product RunToGetProduct()
    {
        bool           exit           = false;
        ListOfProducts listOfProducts = new ListOfProducts();
        int            currentRecord  = 0;
        string         separator      = new string('_', Console.WindowWidth);

        do
        {
            Console.Clear();
            EnhancedConsole.WriteAt(0, 0, "PRODUCTSS  " + (currentRecord + 1).ToString("000")
                                    + "/" + listOfProducts.Amount.ToString("000"), "white");
            EnhancedConsole.WriteAt(0, 1, separator, "gray");

            WriteProduct(listOfProducts, currentRecord);

            EnhancedConsole.WriteAt(0, Console.WindowHeight - 4, separator, "gray");
            EnhancedConsole.WriteAt(0, Console.WindowHeight - 3, "1.-Previous Product" +
                                    "      2.-Next Product" + "     3.-Search", "white");
            EnhancedConsole.WriteAt(0, Console.WindowHeight - 2,
                                    "PRESS ENTER TO SELECT THE PRODUCT", "white");

            switch (Console.ReadKey().Key)
            {
            case ConsoleKey.LeftArrow:
            case ConsoleKey.NumPad1:
            case ConsoleKey.D1:     //Previus
                if (currentRecord != 0)
                {
                    currentRecord--;
                }
                break;

            case ConsoleKey.RightArrow:
            case ConsoleKey.NumPad2:
            case ConsoleKey.D2:     //Next
                //I cant allProducts[count+1] != null
                if (currentRecord != listOfProducts.Amount - 1)
                {
                    currentRecord++;
                }
                break;

            case ConsoleKey.NumPad3:
            case ConsoleKey.D3:     //Search
                SearchByText(listOfProducts, ref currentRecord);
                break;

            case ConsoleKey.Enter:
                exit = true;
                break;
            }
        } while (!exit);
        return(listOfProducts.Get(currentRecord));
    }
Exemplo n.º 2
0
    private static void WriteProduct(ListOfProducts listOfProducts, int count)
    {
        int y = 5;

        EnhancedConsole.WriteAt(0, y, "CODE: ", "gray");
        EnhancedConsole.WriteAt(15, y, listOfProducts.Get(count).GetCode(), "white");
        y++;

        EnhancedConsole.WriteAt(0, y, "DESCRIPTION: ", "gray");
        EnhancedConsole.WriteAt(15, y, listOfProducts.Get(count).GetDescription(), "white");
        y++;

        EnhancedConsole.WriteAt(0, y, "CATEGORY: ", "gray");
        EnhancedConsole.WriteAt(15, y, listOfProducts.Get(count).GetCategory(), "white");
        y++;

        EnhancedConsole.WriteAt(0, y, "SELL PRICE: ", "gray");
        EnhancedConsole.WriteAt(15, y, listOfProducts.Get(count).GetSellPrice()
                                .ToString() + "$", "white");
        y++;

        EnhancedConsole.WriteAt(0, y, "BUY PRICE: ", "gray");
        EnhancedConsole.WriteAt(15, y, listOfProducts.Get(count).GetBuyPrice()
                                .ToString() + "$", "white");
        y++;

        EnhancedConsole.WriteAt(0, y, "STOCK: ", "gray");
        EnhancedConsole.WriteAt(15, y, listOfProducts.Get(count).GetStock()
                                .ToString(), "white");
        y++;

        EnhancedConsole.WriteAt(0, y, "MINIMUM STOCK: ", "gray");
        EnhancedConsole.WriteAt(15, y, listOfProducts.Get(count).GetMinStock()
                                .ToString(), "white");
        y++;
    }
Exemplo n.º 3
0
    public void Load(ListOfCustomers customers, ListOfProducts products)
    {
        DirectoryInfo d = new DirectoryInfo("invoices/");

        foreach (FileInfo f in d.GetFiles("*.dat"))
        {
            StreamReader invoicesInput = new StreamReader(f.FullName);
            string       line;
            string[]     invoicessAux;
            int          invoiceMax = 1;
            try
            {
                do
                {
                    line = invoicesInput.ReadLine();
                    if (line != null)
                    {
                        invoicessAux = line.Split(';');

                        int invoiceNumber = Int32.Parse(invoicessAux[0]);
                        if (invoiceNumber > invoiceMax)
                        {
                            invoiceMax = invoiceNumber;
                        }
                        Invoice.invoiceCount = invoiceMax;

                        string[] dateAux = invoicessAux[1].Split('/');

                        DateTime date = new DateTime(Int32.Parse(dateAux[2]),
                                                     Int32.Parse(dateAux[1]),
                                                     Int32.Parse(dateAux[0]));
                        string key = invoicessAux[2];

                        int  countCustomers = 0;
                        bool found          = false;
                        do
                        {
                            if (key == customers.Get(countCustomers).GetKey())
                            {
                                found = true;
                                countCustomers--;
                            }

                            countCustomers++;
                        }while (countCustomers < customers.Amount && !found);

                        myInvoices.Add(new Invoice(invoiceNumber, date,
                                                   customers.Get(countCustomers)));
                        Product p;
                        string  code;
                        double  price;
                        int     amount;
                        int     countProduct;
                        if (invoicessAux.Length > 3)
                        {
                            for (int i = 3; i < invoicessAux.Length; i += 3)
                            //We start at 1, to not get out of the array size
                            {
                                countProduct = 0;
                                found        = false;
                                code         = invoicessAux[i];
                                do
                                {
                                    if (code == products.Get(countProduct).GetCode())
                                    {
                                        found = true;
                                        countProduct--;
                                    }

                                    countProduct++;
                                }while (countProduct < products.Amount && !found);
                                p      = products.Get(countProduct);
                                amount = Int32.Parse(invoicessAux[i + 1]);
                                price  = Double.Parse(invoicessAux[i + 2]);

                                myInvoices.Last().AddLine(p, amount, price);
                            }
                        }
                    }
                }while (line != null);
                invoicesInput.Close();
            }
            catch (PathTooLongException)
            {
                Console.WriteLine("Error: Path Too Long.");
                throw;
            }
            catch (FileNotFoundException)
            {
                Console.WriteLine("Error: File not found.");
                throw;
            }
            catch (IOException e)
            {
                Console.WriteLine("I/O error: " + e);
                throw;
            }
            catch (Exception e)
            {
                Console.WriteLine("Error: " + e);
                throw;
            }
        }
    }
Exemplo n.º 4
0
    public void Modify(ListOfProducts listOfProducts, int count)
    {
        int y = 5;

        Console.Clear();
        Console.SetCursorPosition(0, Console.WindowHeight - 2);
        Console.WriteLine("To not change something, just press Enter");
        Console.SetCursorPosition(0, 5);
        string aux;

        aux = listOfProducts.Get(count).GetCode();

        EnhancedConsole.WriteAt(0, y,
                                "Code: " + listOfProducts.Get(count).GetCode()
                                .ToString(), "white");
        y++;
        string code = EnhancedConsole.GetAt(0, y, 20);

        if (code == "")
        {
            code = aux;
        }
        listOfProducts.Get(count).SetCode(code);
        y++;

        aux = listOfProducts.Get(count).GetDescription();
        EnhancedConsole.WriteAt(0, y,
                                "Description: " + listOfProducts.Get(count).GetDescription()
                                .ToString(), "white");
        y++;
        string description = EnhancedConsole.GetAt(0, y, 10);

        if (description == "")
        {
            description = aux;
        }
        listOfProducts.Get(count).SetDescription(description);
        y++;

        aux = listOfProducts.Get(count).GetCategory();
        EnhancedConsole.WriteAt(0, y,
                                "Category: " + listOfProducts.Get(count).GetCategory()
                                .ToString(), "white");
        y++;
        string category = EnhancedConsole.GetAt(0, y, 10);

        if (category == "")
        {
            category = aux;
        }
        listOfProducts.Get(count).SetCategory(category);
        y++;

        double auxDouble = listOfProducts.Get(count).GetSellPrice();

        EnhancedConsole.WriteAt(0, y,
                                "Sell Price: " + listOfProducts.Get(count).GetSellPrice()
                                .ToString(), "white");
        y++;
        string sellPriceSTR;
        double sellPrice;

        do
        {
            sellPriceSTR = EnhancedConsole.GetAt(0, y, 9);
        } while ((!Double.TryParse(sellPriceSTR, out sellPrice)) && sellPriceSTR != "");
        if (sellPriceSTR == "")
        {
            sellPrice = auxDouble;
        }
        listOfProducts.Get(count).SetSellPrice(sellPrice);
        y++;

        auxDouble = listOfProducts.Get(count).GetBuyPrice();
        EnhancedConsole.WriteAt(0, y,
                                "Buy Price: " + listOfProducts.Get(count).GetBuyPrice()
                                .ToString(), "white");
        y++;
        string buyPriceSTR;
        double buyPrice;

        do
        {
            buyPriceSTR = EnhancedConsole.GetAt(0, y, 9);
        } while ((!Double.TryParse(buyPriceSTR, out buyPrice)) && buyPriceSTR != "");
        if (buyPriceSTR == "")
        {
            buyPrice = auxDouble;
        }
        listOfProducts.Get(count).SetBuyPrice(buyPrice);
        y++;

        uint auxUINT = listOfProducts.Get(count).GetStock();

        EnhancedConsole.WriteAt(0, y,
                                "Stock: " + listOfProducts.Get(count).GetStock()
                                .ToString(), "white");
        y++;
        string stockSTR;
        uint   stock;

        do
        {
            stockSTR = EnhancedConsole.GetAt(0, y, 9);
        } while ((!UInt32.TryParse(stockSTR, out stock)) && stockSTR != "");
        if (stockSTR == "")
        {
            stock = auxUINT;
        }
        listOfProducts.Get(count).SetStock(stock);
        y++;

        auxUINT = listOfProducts.Get(count).GetMinStock();
        EnhancedConsole.WriteAt(0, y,
                                "Minimum Stock: " + listOfProducts.Get(count).GetMinStock()
                                .ToString(), "white");
        y++;
        string minStockSTR;
        uint   minStock;

        do
        {
            minStockSTR = EnhancedConsole.GetAt(0, y, 9);
        } while ((!UInt32.TryParse(minStockSTR, out minStock)) && minStockSTR != "");
        if (minStockSTR == "")
        {
            minStock = auxUINT;
        }
        listOfProducts.Get(count).SetMinStock(minStock);
        y++;
    }
Exemplo n.º 5
0
    public void SearchByText(ListOfProducts listOfProducts, ref int count)
    {
        Console.Clear();
        EnhancedConsole.WriteAt(0, 10,
                                "What are you looking for?", "white");
        string search = EnhancedConsole.GetAt(0, 11, 15);

        search = search.ToLower();
        bool found = false;

        do
        {
            if (listOfProducts.Get(count).GetCode().ToLower().
                Contains(search) ||
                listOfProducts.Get(count).GetDescription().ToLower().
                Contains(search) ||
                listOfProducts.Get(count).GetCategory().ToLower().
                Contains(search) ||
                listOfProducts.Get(count).GetSellPrice().ToString().
                Contains(search) ||
                listOfProducts.Get(count).GetBuyPrice().ToString().
                Contains(search))
            {
                found = true;
                Console.Clear();
                EnhancedConsole.WriteAt(0, 10,
                                        "Found on the record " + (count + 1).ToString("000"),
                                        "yellow");
                Console.ReadLine();
                count--;
            }
            count++;
        }while (!found && count < listOfProducts.Amount - 1);
        if (!found)
        {
            Console.Clear();
            EnhancedConsole.WriteAt(0, 10,
                                    "Not Found!", "red");

            EnhancedConsole.WriteAt(0, 12,
                                    "Do you want to search from the first record?", "white");
            count = 0;
            if (Console.ReadKey().Key == ConsoleKey.Y)
            {
                do
                {
                    if (listOfProducts.Get(count).GetCode().ToLower().
                        Contains(search) ||
                        listOfProducts.Get(count).GetDescription().ToLower().
                        Contains(search) ||
                        listOfProducts.Get(count).GetCategory().ToLower().
                        Contains(search) ||
                        listOfProducts.Get(count).GetSellPrice().ToString().
                        Contains(search) ||
                        listOfProducts.Get(count).GetBuyPrice().ToString().
                        Contains(search))
                    {
                        found = true;
                        Console.Clear();
                        EnhancedConsole.WriteAt(0, 10,
                                                "Found on the record " + (count + 1).ToString("000"),
                                                "yellow");
                        Console.ReadLine();
                        count--;
                    }
                    count++;
                }while (!found && count < listOfProducts.Amount - 1);

                if (!found)
                {
                    Console.Clear();
                    EnhancedConsole.WriteAt(0, 10,
                                            "Not Found!", "red");
                    Console.ReadLine();
                    count = 0;
                }
            }
        }
    }