コード例 #1
0
 /// <summary>
 /// Handle the delete invoice button being clicked
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnDeleteInvoice_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         if (!sqlProvider.DeleteInvoiceLineItems(invoice))
         {
             MessageBox.Show("Failed to remove line items from the database.");
             return;
         }
         if (!sqlProvider.DeleteInvoice(invoice))
         {
             MessageBox.Show("Failed to remove the invoice from the database. Line items removed successfully");
             return;
         }
         isNewInvoice               = false;
         lblInvoiceNum.Content      = "Invoice";
         dgInvoiceItems.ItemsSource = null;
         dgInvoiceItems.Items.Refresh();
         invoice = null;
         btnEditInvoice.IsEnabled   = false;
         btnDeleteInvoice.IsEnabled = false;
         dpInvoiceDate.SelectedDate = null;
         lblTotalCost.Content       = "";
         btnEditInvoice.IsEnabled   = false;
         btnDeleteInvoice.IsEnabled = false;
         UpdateIsEnabledField(false);
         MessageBox.Show("Invoice deleted successfully.");
     }
     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);
     }
 }
コード例 #2
0
 /// <summary>
 /// Handle the add invoice button being clicked
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnAddInvoice_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         UpdateIsEnabledField(true);
         ItemsHeader.IsEnabled      = false;
         isNewInvoice               = true;
         lblInvoiceNum.Content      = "Invoice #TBD";
         lineItems                  = new List <clsItemDescObj> {
         };
         dgInvoiceItems.ItemsSource = lineItems;
         invoice = new clsInvoiceObj();
         btnEditInvoice.IsEnabled   = false;
         btnDeleteInvoice.IsEnabled = false;
         //reset in case an invoice was already being editted
         dpInvoiceDate.SelectedDate = null;
         lblTotalCost.Content       = "";
     }
     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
 private void LockInvoice()
 {
     try
     {
         //if this is a new invoice, clear all the fields. Otherwise, just lock the data
         if (isNewInvoice)
         {
             lineItems.Clear();
             dgInvoiceItems.Items.Refresh();
             dgInvoiceItems.SelectedIndex = -1;
             lblTotalCost.Content         = "";
             lblInvoiceNum.Content        = "Invoice";
             dpInvoiceDate.SelectedDate   = null;
             invoice = null;
         }
         //set the add item combobox to display nothing
         cbAddItem.SelectedIndex = -1;
         //always remove the item cost since no item should be selected
         lblItemCost.Content = "";
         //make it so nothing can be editted
         UpdateIsEnabledField(false);
         //allow editing items again
         ItemsHeader.IsEnabled = true;
     }
     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);
     }
 }
コード例 #4
0
 /// <summary>
 /// Gets the invoice based on an invoice ID
 /// </summary>
 /// <param name="invoiceID">Invoice ID to load</param>
 /// <returns>The invoice as a clsInvoiceObj</returns>
 public clsInvoiceObj GetInvoice(string invoiceID)
 {
     try
     {
         int           rowsReturned = 0;
         string        sql          = sqlProvider.GetInvoiceQuery(invoiceID);
         clsInvoiceObj invoice;
         DataSet       ds = da.ExecuteSQLStatement(sql, ref rowsReturned);
         if (rowsReturned > 1)
         {
             throw new Exception("More than one invoice was found for the invoice ID, expected one.");
         }
         else if (rowsReturned == 0)
         {
             throw new Exception("No invoice was found for the ID, expected one.");
         }
         else
         {
             invoice              = new clsInvoiceObj();
             invoice.sInvoiceNum  = ds.Tables[0].Rows[0]["InvoiceNum"].ToString();
             invoice.sInvoiceDate = ds.Tables[0].Rows[0]["InvoiceDate"].ToString();
             invoice.sTotalCost   = ds.Tables[0].Rows[0]["TotalCost"].ToString();
         }
         return(invoice);
     }
     catch (Exception ex)
     {
         System.IO.File.AppendAllText("C:\\Error.txt", Environment.NewLine +
                                      "HandleError Exception: " + ex.Message);
         return(null);
     }
 }
コード例 #5
0
 /// <summary>
 /// Gets the sql for deleting an invoice
 /// </summary>
 /// <param name="invoice">Invoice to be deleted</param>
 /// <returns>Sql for the query that can be ran</returns>
 public string DeleteInvoiceQuery(clsInvoiceObj invoice)
 {
     try
     {
         return($"DELETE FROM Invoices WHERE InvoiceNum = {invoice.sInvoiceNum}");
     }
     catch (Exception ex)
     {
         System.IO.File.AppendAllText("C:\\Error.txt", Environment.NewLine +
                                      "HandleError Exception: " + ex.Message);
         // return empty string because something is wrong
         return("");
     }
 }
コード例 #6
0
 /// <summary>
 /// Gets the sql for updating an invoice
 /// </summary>
 /// <param name="invoice">Represents the invoice to be updated</param>
 /// <returns>Sql for the query that can be ran</returns>
 public string UpdateInvoiceQuery(clsInvoiceObj invoice)
 {
     try
     {
         return($"UPDATE Invoices SET InvoiceDate = #{invoice.sInvoiceDate}#, TotalCost = {invoice.sTotalCost} WHERE InvoiceNum = {invoice.sInvoiceNum}");
     }
     catch (Exception ex)
     {
         System.IO.File.AppendAllText("C:\\Error.txt", Environment.NewLine +
                                      "HandleError Exception: " + ex.Message);
         // return empty string because something is wrong
         return("");
     }
 }
コード例 #7
0
 /// <summary>
 /// Gets the sql for inserting a single invoice row
 /// </summary>
 /// <param name="invoice">Represents the invoice to be inserted</param>
 /// <returns>Sql for the query that can be ran</returns>
 public string InsertInvoiceQuery(clsInvoiceObj invoice)
 {
     try
     {
         return($"Insert INTO Invoices(InvoiceDate, TotalCost) VALUES(#{invoice.sInvoiceDate}#, {invoice.sTotalCost})");
     }
     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>
 /// Deletes an invoice from the database
 /// </summary>
 /// <param name="invoice">Invoice to be deleted</param>
 /// <returns>Status for if the invoice has been deleted successfully</returns>
 public bool DeleteInvoice(clsInvoiceObj invoice)
 {
     try
     {
         string sql          = sqlProvider.DeleteInvoiceQuery(invoice);
         int    affectedRows = da.ExecuteNonQuery(sql);
         //If no rows are affected, something went wrong. Otherwise, it worked
         return(affectedRows > 0);
     }
     catch (Exception ex)
     {
         System.IO.File.AppendAllText("C:\\Error.txt", Environment.NewLine +
                                      "HandleError Exception: " + ex.Message);
         return(false);
     }
 }
コード例 #9
0
 private void LoadInvoice(int invoiceID)
 {
     try
     {
         invoice = sqlProvider.GetInvoice(invoiceID.ToString());
         if (invoice == null)
         {
             throw new Exception("Failed to retrieve the invoice from the database");
         }
         lineItems = sqlProvider.GetInvoiceLineItems(invoiceID.ToString());
         if (lineItems == null)
         {
             throw new Exception("Failed to retrieve line items from the database");
         }
         DateTime invoiceDate;
         if (DateTime.TryParse(invoice.sInvoiceDate, out invoiceDate))
         {
             dpInvoiceDate.SelectedDate = invoiceDate;
         }
         else
         {
             MessageBox.Show("Failed to load invoice date.");
         }
         int totalCost;
         if (int.TryParse(invoice.sTotalCost, out totalCost))
         {
             lblTotalCost.Content = $"{totalCost:C}";
         }
         else
         {
             MessageBox.Show("Failed to load the invoice total cost");
         }
         dgInvoiceItems.ItemsSource = lineItems;
         btnEditInvoice.IsEnabled   = true;
         btnDeleteInvoice.IsEnabled = true;
         lblInvoiceNum.Content      = $"Invoice #{invoiceID}";
     }
     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);
     }
 }
コード例 #10
0
        } // end of constructor

        public List <clsInvoiceObj> LoadInvoices(string sInvoiceNumInput = "", string sInvoiceDateInput = "", string sTotalInput = "")
        {
            try
            {
                // initial invoice object
                clsInvoiceObj invoice;

                // pass in the feilds needed to get the results correct
                ds = db.ExecuteSQLStatement(searchSql.SelectInvoiceByParamsData(sInvoiceNumInput, sInvoiceDateInput, sTotalInput), ref iINum);

                //list of invoice objects
                invoiceList = new List <clsInvoiceObj>();

                // loop through the data and create invoice classes
                for (int i = 0; i < iINum; i++)
                {
                    // new invoice object
                    invoice = new clsInvoiceObj();

                    // fill invoice attributes
                    invoice.sInvoiceNum  = ds.Tables[0].Rows[i][0].ToString();
                    invoice.sInvoiceDate = ds.Tables[0].Rows[i]["InvoiceDate"].ToString();
                    invoice.sTotalCost   = ds.Tables[0].Rows[i]["TotalCost"].ToString();

                    // add the flight to the list
                    invoiceList.Add(invoice);
                }
                // return the list of invoices
                return(invoiceList);
            }
            catch (Exception ex)
            {
                System.IO.File.AppendAllText("C:\\Error.txt", Environment.NewLine +
                                             "HandleError Exception: " + ex.Message);
                // return list of invoices that is empty
                return(invoiceList);
            }
        } // end of LoadInvoices method