/// <summary>
        /// Inserts the new item into the DataBase
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAddSubmit_Click(object sender, RoutedEventArgs e)
        {
            double num;                                                 //parsded to double from txtAddPrice.Text
            bool   parsed = double.TryParse(txtAddPrice.Text, out num); //attempts to parsde to double from txtAddPrice.Text

            if (txtAddId.Text == "" || txtAddDesc.Text == "" || txtAddPrice.Text == "")
            {
                MessageBox.Show("All fields must contain a value.", "Missing Data Alert", MessageBoxButton.OK);
            }
            else if (num < 0)
            {
                MessageBox.Show("You can't enter a negative value for Price.", "Negative Value Alert", MessageBoxButton.OK);
            }
            else if (!parsed)
            {
                MessageBox.Show("Price must only contain numbers and decimals.", "Invalid Format Alert", MessageBoxButton.OK);
            }
            else
            {
                if (BusCtrl.canInsert(txtAddId.Text))
                {
                    BusCtrl.addProduct(txtAddId.Text, txtAddDesc.Text, txtAddPrice.Text);
                    this.Close();
                }
                else
                {
                    MessageBox.Show("ItemCode alredy exists, try again", "Alert", MessageBoxButton.OK);
                }
            }
        }
 /// <summary>
 /// populate product drop down with data from db
 /// </summary>
 private void populateProductDropdown()
 {
     comboProductSelect.Items.Clear();
     foreach (Product product in BusCtrl.getProductList())
     {
         product.inDB = false;
         comboProductSelect.Items.Add(product);
     }
 }
 /// <summary>
 /// Called on a click of the Edit button. Edits the existing Invoice in the DB.
 /// </summary>
 /// <param name="sender">The Edit button.</param>
 /// <param name="e">The RoutedEventArgs.</param>
 private void btn_edit_invoice_click(object sender, RoutedEventArgs e)
 {
     try
     {
         BusCtrl.updateInvoice(CurrentInvoice, CurrentInvoice.products);
         lblStatus.Content = "Updated Invoice " + CurrentInvoice.ID;
     }
     catch (Exception ex)
     {
         SearchWindow.HandleError(MethodInfo.GetCurrentMethod().DeclaringType.Name,
                                  MethodInfo.GetCurrentMethod().Name, ex.Message);
     }
     //update current invoice in db. This will proably be done by passing the relavant info into a manager class
 }
Exemplo n.º 4
0
        /// <summary>
        /// Private method to populate the search filters.
        /// </summary>
        private void populateFilters()
        {
            try
            {
                //populate invoice ID combobox
                cbIDNumber.ItemsSource = BusCtrl.getInvoiceIDs();

                //populate invoice Total combobox
                cbInvoiceTotal.ItemsSource = BusCtrl.getInvoiceTotals();
            }
            catch (Exception ex)
            {
                HandleError(MethodInfo.GetCurrentMethod().DeclaringType.Name,
                            MethodInfo.GetCurrentMethod().Name, ex.Message);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Private method to update the datagrid based on the value of the search filters.
        /// </summary>
        private void updateResultsGrid()
        {
            try
            {
                //Set search variables
                int      invoiceID     = cbIDNumber.SelectedIndex == -1 ? cbIDNumber.SelectedIndex : (int)cbIDNumber.SelectedItem;
                DateTime?invoiceDate   = dpInvoiceDate.SelectedDate;
                double   invoiceCharge = cbInvoiceTotal.SelectedIndex == -1 ? cbInvoiceTotal.SelectedIndex : (double)cbInvoiceTotal.SelectedItem;

                //bind to results data grid
                dgResults.ItemsSource = BusCtrl.getInvoiceList(invoiceID, invoiceDate, invoiceCharge).Tables[0].DefaultView;
            }
            catch (Exception ex)
            {
                HandleError(MethodInfo.GetCurrentMethod().DeclaringType.Name,
                            MethodInfo.GetCurrentMethod().Name, ex.Message);
            }
        }
 /// <summary>
 /// Called on a click of the Add button. Inserts a new Invoice into the DB.
 /// </summary>
 /// <param name="sender">The Add button.</param>
 /// <param name="e">The RoutedEventArgs.</param>
 private void btn_add_invoice_click(object sender, RoutedEventArgs e)
 {
     try
     {
         if (DatePickerDate.SelectedDate == null || CurrentInvoice.products.Count == 0)
         {
             lblStatus.Content = "Cannot add an empty invoice";
             return;
         }
         int newId = BusCtrl.addInvoice(DatePickerDate.SelectedDate.Value, CurrentInvoice.products);
         //insert new invoiced data into the db. this will probably be done through a manager class to avoid work on the ui
         lblStatus.Content = "Invoice #" + newId + " added";
         CurrentInvoice    = BusCtrl.getInvoiceByID(newId);
         showInvoiceInfo();
     }
     catch (Exception ex)
     {
         SearchWindow.HandleError(MethodInfo.GetCurrentMethod().DeclaringType.Name,
                                  MethodInfo.GetCurrentMethod().Name, ex.Message);
     }
 }
Exemplo n.º 7
0
        /// <summary>
        /// Submits the changes to the DataBase
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnEditSubmit_Click(object sender, RoutedEventArgs e)
        {
            double num;
            bool   parsed = double.TryParse(txtEditPrice.Text, out num);

            if (txtEditDesc.Text == "" || txtEditPrice.Text == "")
            {
                MessageBox.Show("All fields must contain a value.", "Missing Data Alert", MessageBoxButton.OK);
            }
            else if (num < 0)
            {
                MessageBox.Show("You can't enter a negative value for Price.", "Negative Value Alert", MessageBoxButton.OK);
            }
            else if (!parsed)
            {
                MessageBox.Show("Price must only contain numbers and decimals.", "Invalid Format Alert", MessageBoxButton.OK);
            }
            else
            {
                BusCtrl.updateProductItemDesc(txtEditId.Text, txtEditDesc.Text, txtEditPrice.Text);
                this.Close();
            }
        }
 /// <summary>
 /// Called on a click of the Delete button. Deletes the existing Invoice in the DB.
 /// </summary>
 /// <param name="sender">The Delete button.</param>
 /// <param name="e">The RoutedEventArgs.</param>
 private void btn_delete_invoice_click(object sender, RoutedEventArgs e)
 {
     try
     {
         if (CurrentInvoice.ID == null)
         {
             return;
         }
         BusCtrl.deleteInvoice(CurrentInvoice.ID);
         lblStatus.Content           = "Invoice " + CurrentInvoice.ID + " Deleted";
         txtInvoiceID.Text           = "";
         DatePickerDate.SelectedDate = null;
         txtTotalCost.Text           = "";
         stackPanelInvoiceProducts.Children.Clear();
         CurrentInvoice = new Invoice();
     }
     catch (Exception ex)
     {
         SearchWindow.HandleError(MethodInfo.GetCurrentMethod().DeclaringType.Name,
                                  MethodInfo.GetCurrentMethod().Name, ex.Message);
     }
     //delete the current invoice. this will probalby be done in some object manager class that you pass the id
 }
        /// <summary>
        /// Opens the Invoice Search window.
        /// </summary>
        /// <param name="sender">The Search button.</param>
        /// <param name="e">The RoutedEventArgs.</param>
        private void btn_search_click(object sender, RoutedEventArgs e)
        {
            //this will open the search window. Will need a constructor on the search window that accepts
            //an out variable to be set to the id to populate in the main window

            try
            {
                //CurrentInvoice = BusCtrl.getInvoiceByID(5000);
                //showInvoiceInfo();
                //return;
                int lookUpId = new SearchWindow().ShowDialog();
                if (lookUpId == -1)
                {
                    return;
                }
                CurrentInvoice = BusCtrl.getInvoiceByID(lookUpId);
                showInvoiceInfo();
            }
            catch (Exception ex)
            {
                //handle error
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Deletes the current selection in the dataGrid from DB and refreshes the DataGrid
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnProdDel_Click(object sender, RoutedEventArgs e)
        {
            if (MessageBox.Show("Are you sure you want to DELETE this item?", "Question", MessageBoxButton.YesNo) == MessageBoxResult.No)
            {
                return;
            }
            else
            {
                //get product code
                string sItemCode = ((DataRowView)dgProduct.SelectedItem)[0].ToString();

                //get list of products currently in use
                List <string> prodsInUse = BusCtrl.getAllProductsInUse();

                //if selected product is in use, don't delete
                if (prodsInUse.Contains(sItemCode))
                {
                    //display modal with invoices using the product
                    List <int> invoicesIDs  = BusCtrl.getAllInvoiceIDsByProduct(sItemCode);
                    string     errorMessage = "";
                    foreach (int i in invoicesIDs)
                    {
                        errorMessage += i + " ";
                    }
                    MessageBox.Show("Item cannot be deleted. In use by InvoiceID(s): " + errorMessage, "Can't Delete Product", MessageBoxButton.OK);
                    return;
                }

                //otherwise, delete it
                BusCtrl.deleteProductLineItem(sItemCode);
                BusCtrl.deleteProductItemDesc(sItemCode);

                //refresh datagrid
                loadDataGrid();
            }
        }
Exemplo n.º 11
0
 /// <summary>
 /// Refreshes the data grid of products.
 /// </summary>
 public void loadDataGrid()
 {
     dgProduct.ItemsSource = new DataView(BusCtrl.getProductDataSet(ref iRowCount).Tables[0]);
 }