Example #1
0
    public void Search(ListOfInvoice listOfInvoices, 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;

        count = 0;
        do
        {
            if (listOfInvoices.Get(count).GetHeader().
                GetCustomer().GetName().ToLower().
                Contains(search))
            {
                found = true;
                Console.Clear();
                EnhancedConsole.WriteAt(1, 20,
                                        "Found on the record " + (count + 1).ToString("000"),
                                        "yellow");
                Console.ReadLine();
                count--;
            }
            count++;
        }while (!found && count < listOfInvoices.Amount);
        if (!found)
        {
            Console.Clear();
            count = 0;
            SearchByItem(listOfInvoice, ref count, search);
        }
    }
Example #2
0
    public InvoiceManager()
    {
        listOfInvoice   = new ListOfInvoice();
        listOfProducts  = new ListOfProducts();
        listOfCustomers = new ListOfCustomers();

        listOfInvoice.Load(listOfCustomers, listOfProducts);
    }
Example #3
0
    public void SearchByItem(ListOfInvoice list, ref int count, string search)
    {
        bool           found  = false;
        int            count2 = 0;
        Queue <string> founds = new Queue <string>();
        int            y      = 8;

        do
        {
            Invoice i = list.Get(count);
            count2 = 0;
            do
            {
                if (i.GetLines().ElementAt(count2).
                    GetProduct().GetDescription().
                    ToLower().Contains(search.ToLower()) ||
                    i.GetLines().ElementAt(count2).
                    GetProduct().GetCode().
                    ToLower().Contains(search.ToLower()) ||
                    i.GetLines().ElementAt(count2).
                    GetProduct().GetCategory().
                    ToLower().Contains(search.ToLower()))
                {
                    found = true;
                    founds.Enqueue("Find at " + (count + 1));
                }
                count2++;
            }while (count2 < i.GetLines().Count);
            count++;
        }while (count < list.Amount);
        if (!found)
        {
            EnhancedConsole.WriteAt(30, 16,
                                    "Not Found!", "red");
        }
        else
        {
            foreach (string s in founds)
            {
                EnhancedConsole.WriteAt(2, y,
                                        s, "white");
                y++;
            }
            Console.ReadLine();
        }
        count = 0;
    }
Example #4
0
    public void SearchByNumber(ListOfInvoice list, ref int count)
    {
        string numberSTR;
        ushort number;

        do
        {
            Console.Clear();
            Console.SetCursorPosition(0, 10);
            EnhancedConsole.WriteAt(0, 10,
                                    "Enter the number you are looking for", "white");
            numberSTR = EnhancedConsole.GetAt(0, 11, 3);
        }while (!UInt16.TryParse(numberSTR, out number));
        if (number > 0 && number <= list.Amount)
        {
            count = number - 1;
        }
        else
        {
            EnhancedConsole.WriteAt(0, 10,
                                    "Wrong Number!", "white");
            Console.ReadLine();
        }
    }
Example #5
0
        public void updateInvoice()
        {
            if (isValidInvoiceData() == false)
            {
                return;
            }
            currentInvoice.date         = Convert.ToDateTime(txtInvoiceDate.Text);
            currentInvoice.customerName = txtCustomerName.Text;
            currentInvoice.adress       = txtCustomerAdress.Text;
            currentInvoice.email        = txtCustomerEmail.Text;
            if (ShippedChckbox.IsChecked == true)
            {
                currentInvoice.shipped = "Yes";
            }
            else
            {
                currentInvoice.shipped = "No";
            }

            using (SqlConnection connection = new SqlConnection())
            {
                connection.ConnectionString = openSesame;
                connection.Open();

                if (isNewInvoice == false)
                {
                    string updateSesame = $"UPDATE Invoices SET " +
                                          $"InvoiceDate = '{currentInvoice.date.ToString("yyyy-MM-dd")}'," +
                                          $"Shipped = '{ShippedChckbox.IsChecked}'," +
                                          $"CustomerName = '{currentInvoice.customerName}'," +
                                          $"CustomerAdress = '{currentInvoice.adress}'," +
                                          $"CustomerEmail = '{currentInvoice.email}'" +
                                          $"WHERE InvoiceID = {currentInvoice.invoiceId};";
                    using (SqlCommand UpdateCommand = new SqlCommand(updateSesame, connection))
                    {
                        UpdateCommand.ExecuteNonQuery();
                        connection.Close();
                    }
                    loadInvoice();
                }

                if (isNewInvoice == true)
                {
                    Invoice newInvoice = new Invoice();
                    //calculate the default invoiceid for the new record
                    string findMax = $"SELECT MAX(InvoiceID) FROM Invoices;";
                    using (SqlCommand SelectCommand = new SqlCommand(findMax, connection))
                    {
                        newInvoice.invoiceId = Convert.ToInt32(SelectCommand.ExecuteScalar()) + 1;
                    }

                    newInvoice.date         = Convert.ToDateTime(txtInvoiceDate.Text);
                    newInvoice.customerName = txtCustomerName.Text;
                    newInvoice.adress       = txtCustomerAdress.Text;
                    newInvoice.email        = txtCustomerEmail.Text;
                    if (ShippedChckbox.IsChecked == true)
                    {
                        newInvoice.shipped = "Yes";
                    }
                    else
                    {
                        newInvoice.shipped = "No";
                    }
                    string insertSesame = $"INSERT INTO Invoices " +
                                          "(InvoiceID, InvoiceDate, Shipped, CustomerName, CustomerAdress, CustomerEmail)" +
                                          "VALUES " +
                                          $"('{newInvoice.invoiceId}', " +
                                          $"'{newInvoice.date.ToString("yyyy-MM-dd")}'," +
                                          $"'{ShippedChckbox.IsChecked}', " +
                                          $"'{newInvoice.customerName}', " +
                                          $"'{newInvoice.adress}', " +
                                          $"'{newInvoice.email}');";
                    using (SqlCommand InsertCommand = new SqlCommand(insertSesame, connection))
                    {
                        InsertCommand.ExecuteNonQuery();
                    }
                    loadInvoice();
                    int NewIndex = ListOfInvoice.Items.IndexOf(newInvoice);

                    //select the new item
                    ListOfInvoice.SelectedIndex = NewIndex;
                    ListOfInvoice.ScrollIntoView(newInvoice);

                    isNewInvoice = false;
                }
            }
        }