Пример #1
0
        /// <summary>
        /// When a datagrid selection is changed.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dgLineItems_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            //Check if an update occured
            if (bWasUpdated)
            {
                bWasUpdated = false;
                return;
            }
            if (bWasDeleted)
            {
                bWasDeleted = false;
                return;
            }

            //Cast dgLineItems to object
            clsItemDescObj itemDesc = (clsItemDescObj)dgLineItems.SelectedItem;

            //Put the itemDesc object into deletion labels
            lblItemCode.Content = itemDesc.sItemCode;
            lblItemDesc.Content = itemDesc.sItemDesc;
            lblCost.Content     = itemDesc.sCost;

            //Put the itemDesc object into edit textboxes
            txtEditItemDescription.Text = itemDesc.sItemDesc;
            txtEditCost.Text            = itemDesc.sCost;
        }
Пример #2
0
 /// <summary>
 /// Handle when the remove button is clicked, removes the selected item from the invoice
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnRemoveItem_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         clsItemDescObj selectedItem = (clsItemDescObj)dgInvoiceItems.SelectedItem;
         //account for selecting the empty value
         if (selectedItem != null)
         {
             lineItems.Remove(selectedItem);
             //need to manually force a refresh
             dgInvoiceItems.Items.Refresh();
             //if this isn't set, the next selection is multiple rows.
             dgInvoiceItems.SelectedIndex = -1;
             CalculateInvoiceTotal();
         }
         else
         {
             MessageBox.Show("No item was selected so an item was not removed.");
         }
     }
     catch (Exception ex)
     {
         //This is the top level method so we want to handle the exception
         HandleError(MethodInfo.GetCurrentMethod().DeclaringType.Name,
                     MethodInfo.GetCurrentMethod().Name, ex.Message);
     }
 }
Пример #3
0
        /// <summary>
        /// Grab all rows from items desc database table.
        /// </summary>
        /// <returns></returns>
        public List <clsItemDescObj> SelectItemDescData()
        {
            try
            {
                int    rowsReturned = 0;
                string sSql         = "SELECT * FROM ItemDesc ORDER BY ItemCode";

                DataSet ds = da.ExecuteSQLStatement(sSql, ref rowsReturned);
                List <clsItemDescObj> itemList = new List <clsItemDescObj> {
                };

                if (rowsReturned == 0)
                {
                    throw new Exception("No itmes were found.");
                }
                int row = 0;
                while (row < rowsReturned)
                {
                    clsItemDescObj item = new clsItemDescObj();
                    item.sItemCode = ds.Tables[0].Rows[row]["ItemCode"].ToString();
                    item.sItemDesc = ds.Tables[0].Rows[row]["ItemDesc"].ToString();
                    item.sCost     = ds.Tables[0].Rows[row]["Cost"].ToString();
                    itemList.Add(item);
                    row++;
                }
                return(itemList);
            }
            catch (Exception ex)
            {
                System.IO.File.AppendAllText("C:\\Error.txt", Environment.NewLine +
                                             "HandleError Exception: " + ex.Message);
                // return empty string because something is wrong
                return(null);
            }
        }
Пример #4
0
 /// <summary>
 /// Get the line items for an invoice as a list of clsItemDescObj
 /// </summary>
 /// <param name="invoiceID">Invoice ID that the items will be from</param>
 /// <returns>Items in the invoice as a clsItemDescObj list</returns>
 public List <clsItemDescObj> GetInvoiceLineItems(string invoiceID)
 {
     try
     {
         int     rowsReturned            = 0;
         string  sql                     = sqlProvider.GetInvoiceLineItemsQuery(invoiceID);
         DataSet ds                      = da.ExecuteSQLStatement(sql, ref rowsReturned);
         List <clsItemDescObj> lineItems = new List <clsItemDescObj> {
         };
         if (rowsReturned == 0)
         {
             throw new Exception("No line items were found for the invoice ID, expected at least one");
         }
         int row = 0;
         while (row < rowsReturned)
         {
             clsItemDescObj lineItem = new clsItemDescObj();
             lineItem.sItemCode = ds.Tables[0].Rows[row]["ItemCode"].ToString();
             lineItem.sItemDesc = ds.Tables[0].Rows[row]["ItemDesc"].ToString();
             lineItem.sCost     = ds.Tables[0].Rows[row]["Cost"].ToString();
             lineItems.Add(lineItem);
             row++;
         }
         return(lineItems);
     }
     catch (Exception ex)
     {
         System.IO.File.AppendAllText("C:\\Error.txt", Environment.NewLine +
                                      "HandleError Exception: " + ex.Message);
         return(null);
     }
 }
Пример #5
0
 /// <summary>
 /// Get all items from the database.
 /// </summary>
 /// <returns>A list of items from the database as clsItemDescObj</returns>
 public List <clsItemDescObj> GetAllItems()
 {
     try
     {
         int    rowsReturned         = 0;
         string sql                  = sqlProvider.GetAllitemsQuery();
         List <clsItemDescObj> items = new List <clsItemDescObj> {
         };
         DataSet ds                  = da.ExecuteSQLStatement(sql, ref rowsReturned);
         if (rowsReturned == 0)
         {
             throw new Exception("No items were returned from the database, expected at least 1");
         }
         int row = 0;
         while (row < rowsReturned)
         {
             clsItemDescObj currentItem = new clsItemDescObj();
             currentItem.sItemCode = ds.Tables[0].Rows[row]["ItemCode"].ToString();
             currentItem.sItemDesc = ds.Tables[0].Rows[row]["ItemDesc"].ToString();
             currentItem.sCost     = ds.Tables[0].Rows[row]["Cost"].ToString();
             items.Add(currentItem);
             row++;
         }
         return(items);
     }
     catch (Exception ex)
     {
         System.IO.File.AppendAllText("C:\\Error.txt", Environment.NewLine +
                                      "HandleError Exception: " + ex.Message);
         return(null);
     }
 }
Пример #6
0
        /// <summary>
        /// Button to delete selected item
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                //Cast dgLineItems to object
                clsItemDescObj itemDesc = (clsItemDescObj)dgLineItems.SelectedItem;

                //If nothing is selected and delete is clicked.
                if (itemDesc == null)
                {
                    return;
                }

                //Check to make sure the item isn't on a invoice, if true it's on an invoice.
                if (itemsLogic.CheckInvoiceData(itemDesc.sItemCode))
                {
                    //Display message so the user knows what item is in what invoice
                    List <clsLineItemsObj> invoices = itemsLogic.lineItemsListGet;

                    //String for invoices
                    string invoiceString = "";

                    for (int i = 0; i < invoices.Count(); i++)
                    {
                        invoiceString += invoices[i].sInvoiceNum + "\n";
                    }

                    //If it is then don't delete, and give message, return which item the invoice is currently on
                    MessageBox.Show("Cannot delete item. This item is located in invoices:\n" + invoiceString, "Deletion Error");

                    return;
                }

                //Pass itemcode to sql logic for deletion
                bWasDeleted = itemsLogic.DeleteItemDesc(itemDesc.sItemCode, itemDesc.sItemDesc);

                //Update data grid information
                dgLineItems.ItemsSource = itemsLogic.itemDescListGet;

                //Display success
                MessageBox.Show(itemDesc.sItemDesc + " has been deleted.", "Delete Confirmation");

                //Restore labels and edit textbox
                lblItemCode.Content = "N/A";
                lblItemDesc.Content = "N/A";
                lblCost.Content     = "N/A";

                //Put the itemDesc object into edit textboxes
                txtEditItemDescription.Text = "";
                txtEditCost.Text            = "";
            }
            catch (Exception ex)
            {
                //This is the top level method so we want to handle the exception
                HandleError(MethodInfo.GetCurrentMethod().DeclaringType.Name,
                            MethodInfo.GetCurrentMethod().Name, ex.Message);
            }
        }
Пример #7
0
 /// <summary>
 /// Gets the Sql for inserting a single line item
 /// </summary>
 /// <returns>Sql for the query that can be ran</returns>
 public string InsertIndividualLineItemQuery(string invoiceID, int iteration, clsItemDescObj lineItem)
 {
     try
     {
         return($"INSERT INTO LineItems (InvoiceNum, LineItemNum, ItemCode) VALUES ({invoiceID}, {iteration}, '{lineItem.sItemCode}')");
     }
     catch (Exception ex)
     {
         System.IO.File.AppendAllText("C:\\Error.txt", Environment.NewLine +
                                      "HandleError Exception: " + ex.Message);
         // return empty string because something is wrong
         return("");
     }
 }
Пример #8
0
 /// <summary>
 /// Handle when the selected item is changed. Displays the current item's cost
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void cbAddItem_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     try
     {
         clsItemDescObj selectedItem = (clsItemDescObj)cbAddItem.SelectedItem;
         //account for selecting the empty value
         if (selectedItem != null)
         {
             lblItemCost.Content = $"{Convert.ToInt32(selectedItem.sCost):C}";
         }
     }
     catch (Exception ex)
     {
         //This is the top level method so we want to handle the exception
         HandleError(MethodInfo.GetCurrentMethod().DeclaringType.Name,
                     MethodInfo.GetCurrentMethod().Name, ex.Message);
     }
 }
Пример #9
0
        /// <summary>
        /// Button to edit selected item
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnEdit_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                //Cast dgLineItems to object
                clsItemDescObj itemDesc = (clsItemDescObj)dgLineItems.SelectedItem;

                //If nothing is selected and delete is clicked.
                if (itemDesc == null)
                {
                    return;
                }

                //Keep track of updated description and cost for messagebox purposes
                string sNewItemDescription = txtEditItemDescription.Text;
                string sNewItemCost        = txtEditCost.Text;

                //Pass the itemcode, itemdesc and itemcost for update
                bWasUpdated = itemsLogic.UpdateItemDesc(itemDesc.sItemCode, txtEditItemDescription.Text, txtEditCost.Text);

                //Update data grid information
                dgLineItems.ItemsSource = itemsLogic.itemDescListGet;

                //Display success
                MessageBox.Show("Item Desciprition '" + itemDesc.sItemDesc + "' has been updated to '" + sNewItemDescription + "'\n" +
                                "Item Cost '" + itemDesc.sCost + "' has been updated to '" + sNewItemCost + "'"
                                , "Update Confirmation");

                //Restore labels and edit textbox
                lblItemCode.Content = "N/A";
                lblItemDesc.Content = "N/A";
                lblCost.Content     = "N/A";

                //Put the itemDesc object into edit textboxes
                txtEditItemDescription.Text = "";
                txtEditCost.Text            = "";
            }
            catch (Exception ex)
            {
                //This is the top level method so we want to handle the exception
                HandleError(MethodInfo.GetCurrentMethod().DeclaringType.Name,
                            MethodInfo.GetCurrentMethod().Name, ex.Message);
            }
        }