/// <summary> /// returns a string list of the distinct charges in the database /// </summary> /// <returns></returns> public List <string> GetListCharges() { List <string> listCharges = new List <string>(); try { clsSQL sql = new clsSQL(); DataSet ds; int iRet = 0; ds = sql.ExecuteSQLStatement("SELECT DISTINCT TotalCost FROM Invoices", ref iRet); listCharges.Add(""); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { string invoiceNum = ds.Tables[0].Rows[i][0].ToString(); listCharges.Add(invoiceNum); } } catch (Exception ex) { MessageBox.Show(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." + MethodInfo.GetCurrentMethod().Name + " -> " + ex.Message); } return(listCharges); }
/// <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> /// returns an invoice list that matches the parameters supplied to it /// </summary> /// <param name="invoiceNum"></param> /// <param name="date"></param> /// <param name="total"></param> /// <returns></returns> public List <clsInvoice> GetInvoices(string invoiceNum, string date, string total) { List <clsInvoice> invoices = new List <clsInvoice>(); try { clsSQL sql = new clsSQL(); DataSet ds; int iRet = 0; ds = sql.ExecuteSQLStatement(clsSearchSQL.GetInvoices(invoiceNum, date, total), ref iRet); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { invoices.Add(new clsInvoice() { InvoiceNum = Convert.ToInt32(ds.Tables[0].Rows[i][0].ToString()), InvoiceDate = ds.Tables[0].Rows[i][1].ToString(), InvoiceTotal = Convert.ToInt32(ds.Tables[0].Rows[i][2]) }); } } catch (Exception ex) { MessageBox.Show(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." + MethodInfo.GetCurrentMethod().Name + " -> " + ex.Message); } return(invoices); }
/// <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> /// CalculateItemCode: Logic for new ItemCode /// Date Version Name Comments /// 12/06/19 1.0 Dylan Created Method /// </summary> private static string CalculateItemCode() { clsSQL db; db = new clsSQL(); /// <summary> /// potentialItemCode: Stores itemCode until an unused one is found /// </summary> string potentialItemCode = "0"; string sNumUsedItemCode = db.ExecuteScalarSQL(clsItemsSQL.IsItemCode(potentialItemCode)); if (sNumUsedItemCode != "0") { while (sNumUsedItemCode != "0") { potentialItemCode = (Int32.Parse(potentialItemCode) + 1).ToString(); sNumUsedItemCode = db.ExecuteScalarSQL(clsItemsSQL.IsItemCode(potentialItemCode)); } return(potentialItemCode); } else { return(potentialItemCode); } }
/// <summary> /// Retrieve item list for combo box dropdown /// </summary> /// <param name="wndMain"></param> /// <returns></returns> public static BindingList <clsItem> GetItemsList(wndMain wndMain) { try { BindingList <clsItem> ItemList = new BindingList <clsItem>(); //Make Connection clsSQL dataAccess = new clsSQL(); DataSet ds = new DataSet(); int iRet = 0; //store query result in data set ds = dataAccess.ExecuteSQLStatement(clsMainSQL.queryItems(), ref iRet); //Loop through items creating item object and add to a bound list for (int i = 0; i < iRet; i++) { clsItem item = new clsItem(); item.ItemCode = ds.Tables[0].Rows[i][0].ToString(); item.ItemDescription = ds.Tables[0].Rows[i][1].ToString(); item.ItemCost = Convert.ToDecimal(ds.Tables[0].Rows[i][2].ToString()); ItemList.Add(item); } return(ItemList); } catch (Exception ex) { throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." + MethodInfo.GetCurrentMethod().Name + "->" + ex.Message); } }
/// <summary> /// wndItems: Initializes Form, sets textboxes to "", and calls PopulateDataGrid /// Date Version Name Comments /// 11/16/19 1.0 Dylan Created Method /// </summary> public wndItems() { try { InitializeComponent(); txtAddName.Text = ""; txtAddCost.Text = ""; txtEditName.Text = ""; txtEditCost.Text = ""; db = new clsSQL(); PopulateDataGrid(); } catch (Exception ex) { ClsHandleError.HandleError(MethodInfo.GetCurrentMethod().DeclaringType.Name, MethodInfo.GetCurrentMethod().Name, ex.Message); } }
/// <summary> /// Open Main Window of the program /// </summary> public wndMain() { try { InitializeComponent(); Application.Current.ShutdownMode = ShutdownMode.OnMainWindowClose; db = new clsSQL(); itemList = clsMainLogic.GetItemsList(this); cmbItems.ItemsSource = itemList; //Void selections until menu item is selected EditMode(editInvoiceMode); } catch (Exception ex) { ClsHandleError.HandleError(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); } }
/// <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); } }