private void buttonOrdUpdate_Click(object sender, EventArgs e)
        {
            if (!Validator.IsEmpty(textBoxOrdQuantity))
            {
                MessageBox.Show("Orders must have a valid quantity.", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                textBoxAutID.Clear();
                textBoxAutID.Focus();
                return;
            }

            Order aorder = createOrder();
            Order xorder = OrderDA.SearchByNumber(Convert.ToInt32(textBoxOrdNumber.Text));

            Books   abook   = BooksDA.SearchByTitle(comboBoxOrdProduct.Text);
            Clients aclient = ClientsDA.Search(comboBoxOrdClient.Text);

            abook.QOH = (abook.QOH + xorder.OrdQuantity) - aorder.OrdQuantity;
            BooksDA.Update(abook);

            aclient.creditLimit = (aclient.creditLimit + aorder.OrdTotal) - aorder.OrdTotal;
            ClientsDA.Update(aclient);

            OrderDA.Update(aorder);
            OrderDA.ListOrder(listViewOrd);

            buttonOrdList.PerformClick();
            UpdateComboBoxes();
        }
        private void listViewOrd_MouseClick(object sender, MouseEventArgs e)
        {
            string OrdNumber   = listViewOrd.SelectedItems[0].SubItems[0].Text;
            string OrdEmployee = listViewOrd.SelectedItems[0].SubItems[1].Text;
            string OrdClient   = ClientsDA.Search(listViewOrd.SelectedItems[0].SubItems[2].Text).clientName;
            string OrdProduct  = BooksDA.SearchByTitle(listViewOrd.SelectedItems[0].SubItems[3].Text).title;
            string OrdQuantity = listViewOrd.SelectedItems[0].SubItems[4].Text;
            string OrdTotal    = listViewOrd.SelectedItems[0].SubItems[5].Text;
            string OrdDate     = listViewOrd.SelectedItems[0].SubItems[6].Text;

            string OrdPhoneNumber = ClientsDA.Search(listViewOrd.SelectedItems[0].SubItems[2].Text).phoneNumber;
            string OrdCreditLimit = ClientsDA.Search(listViewOrd.SelectedItems[0].SubItems[2].Text).creditLimit.ToString();
            string OrdAddress     = (ClientsDA.Search(listViewOrd.SelectedItems[0].SubItems[2].Text).postalCode) + ", " + (ClientsDA.Search(listViewOrd.SelectedItems[0].SubItems[2].Text).street);
            string OrdUnitPrice   = BooksDA.SearchByTitle(listViewOrd.SelectedItems[0].SubItems[3].Text).unitPrice.ToString();


            textBoxOrdNumber.Text      = OrdNumber;
            textBoxOrdClient.Text      = OrdClient;
            comboBoxOrdProduct.Text    = OrdProduct;
            textBoxOrdQuantity.Text    = OrdQuantity;
            textBoxOrdTotal.Text       = OrdTotal;
            dateTimePicker1.Text       = OrdDate;
            textBoxOrdPhoneNumber.Text = OrdPhoneNumber;
            textBoxOrdCreditLimit.Text = OrdCreditLimit;
            textBoxOrdAdress.Text      = OrdAddress;
            textBoxOrdUnitPrice.Text   = OrdUnitPrice;


            buttonOrdDelete.Enabled = true;
            buttonOrdUpdate.Enabled = true;
        }
        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            Books result = BooksDA.SearchByTitle(comboBoxOrdProduct.Text);

            if (result != null)
            {
                textBoxOrdUnitPrice.Text = ("$ " + result.unitPrice.ToString());
            }
        }
        private void buttonOrdPlaceOrder_Click(object sender, EventArgs e)
        {
            //Order Validators
            if (!Validator.IsEmptyComboBox(comboBoxOrdClient))
            {
                MessageBox.Show("Order must have a valid Client.", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                textBoxAutID.Clear();
                textBoxAutID.Focus();
                return;
            }

            if (!Validator.IsEmptyComboBox(comboBoxOrdProduct))
            {
                MessageBox.Show("Order must have a valid Product.", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                textBoxAutID.Clear();
                textBoxAutID.Focus();
                return;
            }

            if (!Validator.IsEmpty(textBoxOrdQuantity))
            {
                MessageBox.Show("Orders must have a valid quantity.", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                textBoxAutID.Clear();
                textBoxAutID.Focus();
                return;
            }

            int temp = 0;

            if ((!int.TryParse((textBoxOrdQuantity.Text), out temp)))
            {
                MessageBox.Show("Quantity of Products must be a integer number.", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                textBoxOrdQuantity.Clear();
                textBoxOrdQuantity.Focus();
                return;
            }

            Order   aOrder  = createOrder();
            Books   aBook   = BooksDA.SearchByTitle(comboBoxOrdProduct.Text);
            Clients aClient = ClientsDA.Search(comboBoxOrdClient.Text);

            aBook.QOH = aBook.QOH - aOrder.OrdQuantity;
            BooksDA.Update(aBook);

            aClient.creditLimit = aClient.creditLimit - aOrder.OrdTotal;
            ClientsDA.Update(aClient);

            OrderDA.SaveOrder(aOrder);
            buttonOrdList.PerformClick();
            UpdateComboBoxes();
        }
        //________________ORDER TAB_______________________________________________________________________

        private Order createOrder()
        {
            Order    aOrder    = new Order();
            Clients  aClients  = new Clients();
            Books    aBook     = new Books();
            Employee aEmployee = new Employee();

            aBook     = BooksDA.SearchByTitle(comboBoxOrdProduct.Text);
            aClients  = ClientsDA.Search(comboBoxOrdClient.Text);
            aEmployee = EmployeeDA.Search(Convert.ToInt32(textBoxOrdEmployee.Text));

            aOrder.OrdNumber   = OrderDA.OrderID() + 1;
            aOrder.OrdEmployee = null;
            aOrder.OrdEmployee = aEmployee;
            aOrder.OrdClient   = aClients;
            aOrder.OrdProduct  = aBook;
            aOrder.OrdQuantity = Convert.ToInt32(textBoxOrdQuantity.Text);
            aOrder.OrdTotal    = aOrder.OrdQuantity * BooksDA.SearchByTitle(comboBoxOrdProduct.Text).unitPrice;
            aOrder.OrdDate     = Convert.ToDateTime(dateTimePicker1.Value);
            return(aOrder);
        }
        private void buttonBooSearch_Click(object sender, EventArgs e)
        {
            if (!String.IsNullOrEmpty(textBoxBooSearch.Text))
            {
                int choice = comboBoxBooSearch.SelectedIndex;
                switch (choice)
                {
                case -1:
                    MessageBox.Show("Please select the search option");
                    break;

                case 0:     //Search by ISBN Number
                    Books Boo = BooksDA.Search(Convert.ToInt32(textBoxBooSearch.Text));
                    if (Boo != null)
                    {
                        textBoxBooISBN.Text       = Boo.ISBN.ToString();
                        textBoxBooTitle.Text      = Boo.title;
                        comboBoxBooAuthor.Text    = Boo.author;
                        textBoxBooYPublished.Text = Boo.yearPublished;
                        textBoxBooPrice.Text      = Boo.unitPrice.ToString();
                        textBoxBooQOH.Text        = Boo.QOH.ToString();
                        comboBoxBooSuplier.Text   = Boo.publisher;

                        buttonBooDelete.Enabled = true;
                        buttonBooUpdate.Enabled = true;
                    }

                    else
                    {
                        MessageBox.Show("Client not Found!");
                        textBoxBooSearch.Clear();
                        textBoxBooSearch.Focus();
                    }
                    break;

                case 1:     //Search by Book Title
                    Books BooTitle = BooksDA.SearchByTitle(textBoxBooSearch.Text);
                    if (BooTitle != null)
                    {
                        textBoxBooISBN.Text       = BooTitle.ISBN.ToString();
                        textBoxBooTitle.Text      = BooTitle.title;
                        comboBoxBooAuthor.Text    = BooTitle.author;
                        textBoxBooYPublished.Text = BooTitle.yearPublished;
                        textBoxBooPrice.Text      = BooTitle.unitPrice.ToString();
                        textBoxBooQOH.Text        = BooTitle.QOH.ToString();
                        comboBoxBooSuplier.Text   = BooTitle.publisher;

                        buttonBooDelete.Enabled = true;
                        buttonBooUpdate.Enabled = true;
                    }

                    else
                    {
                        MessageBox.Show("Client not Found!");
                        textBoxBooSearch.Clear();
                        textBoxBooSearch.Focus();
                    }
                    break;


                case 2:     //Search by Book Author
                    Books BooAuthor = BooksDA.SearchByAuthor(textBoxBooSearch.Text);
                    if (BooAuthor != null)
                    {
                        textBoxBooISBN.Text       = BooAuthor.ISBN.ToString();
                        textBoxBooTitle.Text      = BooAuthor.title;
                        comboBoxBooAuthor.Text    = BooAuthor.author;
                        textBoxBooYPublished.Text = BooAuthor.yearPublished;
                        textBoxBooPrice.Text      = BooAuthor.unitPrice.ToString();
                        textBoxBooQOH.Text        = BooAuthor.QOH.ToString();
                        comboBoxBooSuplier.Text   = BooAuthor.publisher;

                        buttonBooDelete.Enabled = true;
                        buttonBooUpdate.Enabled = true;
                    }

                    else
                    {
                        MessageBox.Show("Client not Found!");
                        textBoxBooSearch.Clear();
                        textBoxBooSearch.Focus();
                    }
                    break;

                default:
                    break;
                }
            }
            else
            {
                MessageBox.Show("Please, enter a valid information to search!", "Serach Invalid", MessageBoxButtons.OK, MessageBoxIcon.Information);
                textBoxBooSearch.Clear();
                textBoxBooSearch.Focus();
            }
        }
        private void Multiply()
        {
            if (!Validator.IsEmpty(textBoxOrdQuantity))
            {
                textBoxOrdTotal.Text = "$ ";
                return;
            }

            if (!Validator.IsValidQOH(textBoxOrdQuantity.Text))
            {
                MessageBox.Show("Quantity of Products must be a integer number.", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                textBoxOrdQuantity.Clear();
                textBoxOrdQuantity.Focus();
                textBoxOrdTotal.Text = "$ ";
                return;
            }

            else
            {
                textBoxOrdTotal.Text = "$ " + (Convert.ToInt32(textBoxOrdQuantity.Text) * BooksDA.SearchByTitle(comboBoxOrdProduct.Text).unitPrice).ToString();
            }
        }