/// <summary>
        /// Handles when the user clicks the save button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void saveInvoiceBtn_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (newInvoiceMode == true)
                {
                    currentInvoice.InvoiceDate = string.Format("{0:MM/dd/yyyy}", DateTime.Today);

                    if (currentInvoice != null && currentInvoice.InvoiceNum != 0)
                    {
                        db.ExecuteNonQuery(clsMainSQL.DeleteOldInvoice(currentInvoice.InvoiceNum));
                    }

                    //Get Invoice Number
                    invoiceNumber = db.ExecuteScalarSQL(clsMainSQL.queryMaxInvoice());

                    //Set Invoice Number to Label
                    invoiceLbl.Content     = "Invoice Number: " + invoiceNumber;
                    invoiceDateLbl.Content = string.Format("{0:MM/dd/yyyy}", DateTime.Today);

                    //Insert new invoice
                    string dateForInsert = currentInvoice.InvoiceDate;
                    db.ExecuteNonQuery(clsMainSQL.insertInvoice(dateForInsert, getInvoiceItemsTotal(currentInvoiceItems)));

                    //This will loop through the list to insert the items one at a time
                    for (int i = 0; i < currentInvoiceItems.Count; i++)
                    {
                        db.ExecuteNonQuery(clsMainSQL.InsertNewInvoice(Convert.ToInt32(invoiceNumber), (i + 1), currentInvoiceItems[i].ItemCode));
                    }

                    newInvoiceMode = false;
                }
                else
                {
                    //Set Invoice Number to Label
                    invoiceLbl.Content = "Invoice Number: " + invoiceNumber;
                    string InvoiceDatePull = db.ExecuteScalarSQL(clsMainSQL.queryDate(Convert.ToInt32(invoiceNumber)));
                    invoiceDateLbl.Content = InvoiceDatePull;

                    //Delete invoice line items
                    if (currentInvoiceItems.Count > 0)
                    {
                        db.ExecuteNonQuery(clsMainSQL.deleteInvoiceLineItem(Convert.ToInt32(invoiceNumber)));
                    }

                    //This will loop through the list to insert the items one at a time
                    for (int i = 0; i < currentInvoiceItems.Count; i++)
                    {
                        db.ExecuteNonQuery(clsMainSQL.InsertNewInvoice(Convert.ToInt32(invoiceNumber), (i + 1), currentInvoiceItems[i].ItemCode));
                    }
                }
            }
            catch (Exception ex)
            {
                ClsHandleError.HandleError(MethodInfo.GetCurrentMethod().DeclaringType.Name,
                                           MethodInfo.GetCurrentMethod().Name, ex.Message);
            }
        }
        /// <summary>
        /// EditItem: Logic for editting item
        /// Date        Version     Name        Comments
        /// 11/16/19    1.0         Dylan       Created Method
        /// </summary>
        internal static void EditItem(string itemCodeEdit, string itemDescEdit, string itemCostEdit)
        {
            try
            {
                //This Method will allow users to edit an existing item
                //ItemDesc, and Cost of the new item will be passed in
                //ItemCode will be used to find the row to be updated, ItemDesc and Cost
                //will be whats changing (ItemCode cannot be changed)
                clsSQL db;

                db = new clsSQL();
                /// <summary>
                /// itemDesc: Stores ItemDesc
                /// </summary>
                string itemDesc = itemDescEdit;
                /// <summary>
                /// itemCost: Stores ItemCost
                /// </summary>
                string itemCost = itemCostEdit;
                /// <summary>
                /// itemCode: Stores ItemCode
                /// </summary>
                string itemCode = itemCodeEdit;
                db.ExecuteNonQuery(clsItemsSQL.EditItemList(itemCodeEdit, itemDesc, itemCost));
            }
            catch (Exception ex)
            {
                throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." +
                                    MethodInfo.GetCurrentMethod().Name + "->" + ex.Message);
            }
        }
        /// <summary>
        /// DeleteItem: Logic for deleting item
        /// Date        Version     Name        Comments
        /// 11/16/19    1.0         Dylan       Created Method
        /// </summary>
        internal static bool DeleteItem(string inputItemCode)
        {
            try
            {
                //This Method will allow users to delete an existing item
                //ItemCodewill be passed in
                //ItemCode will be used to find the row to be deleted
                //If the ItemCode is found in the LineItems table, the row
                //will not be deleted
                clsSQL db;

                db = new clsSQL();
                /// <summary>
                /// inInvoice: Stores returned Scalar count of matching items in invoice
                /// </summary>
                string inInvoice = db.ExecuteScalarSQL(clsItemsSQL.IsItemInInvoice(inputItemCode));
                if (inInvoice != "0")
                {
                    return(false);
                }
                else
                {
                    db.ExecuteNonQuery(clsItemsSQL.DeleteItemList(inputItemCode));
                    return(true);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." +
                                    MethodInfo.GetCurrentMethod().Name + "->" + ex.Message);
            }
        }
        /// <summary>
        /// AddItem: Logic for adding item
        /// Date        Version     Name        Comments
        /// 11/16/19    1.0         Dylan       Created Method
        /// </summary>
        internal static bool AddItem(string itemDescAdd, string itemCostAdd)
        {
            try
            {
                //This Method will allow users to add a new item
                //ItemCode, ItemDesc, and Cost of the new item will be passed in
                //These variables will be put into a new row in the table
                clsSQL db;

                db = new clsSQL();
                /// <summary>
                /// itemDesc: Stores ItemDesc
                /// </summary>
                string itemDesc = itemDescAdd;
                /// <summary>
                /// itemCost: Stores ItemCost
                /// </summary>
                string itemCost = itemCostAdd;
                /// <summary>
                /// sDuplicateItemDesc: Stores returned Scalar Count
                /// </summary>
                string sDuplicateItemDesc = db.ExecuteScalarSQL(clsItemsSQL.IsDuplicateItemDesc(itemDesc));
                if (sDuplicateItemDesc == "1")
                {
                    return(false);
                }
                else
                {
                    /// <summary>
                    /// itemCode: Stores returned new item code
                    /// </summary>
                    string itemCode = CalculateItemCode();
                    db.ExecuteNonQuery(clsItemsSQL.AddItemList(itemCode, itemDesc, itemCost));
                    return(true);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." +
                                    MethodInfo.GetCurrentMethod().Name + "->" + ex.Message);
            }
        }
Exemple #5
0
        /// <summary>
        /// Deletes the current invoice from the database
        /// </summary>
        public static void deleteInvoice(int InvoiceNumber, wndMain wndMain)
        {
            try
            {
                clsSQL  dataAccess = new clsSQL();
                DataSet ds         = new DataSet();
                int     iRet       = 0;

                if (wndMain.currentInvoice != null)
                {
                    // Will delete current invoice
                    dataAccess.ExecuteNonQuery(clsMainSQL.deleteInvoiceLine(InvoiceNumber));

                    // Clear Screen & Refresh Screen
                    wndMain.invoiceItemDataGrid.ItemsSource = null;
                    wndMain.invoiceItemDataGrid.Items.Refresh();
                }
            }
            catch (Exception ex)
            {
                throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." +
                                    MethodInfo.GetCurrentMethod().Name + "->" + ex.Message);
            }
        }