示例#1
0
        /// <summary>
        /// Adds a new item
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAddItem_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                //Check to make sure item has been selected
                if (curItem.Equals(" ") || curItem.Equals(null))
                {
                    return;
                }
                //Create variable for Item Description
                string itemDesc = cmbInvoiceItem.SelectedItem.ToString();
                //Add Item to List of Invoice Added Items
                addeditems.Add(itemDesc);

                //Get Item Code from Description
                string itemCode = ml.getItemCode(itemDesc);

                //Add cost of Item to Total
                double cost;
                cost   = ml.getItemCost(itemCode);
                total += cost;

                //Get Line Item Number
                string lineItemNum = ml.GenerateLineItemNum(InvoiceNum);
                //Check to make sure it is not 0
                if (lineItemNum.Equals("0") || lineItemNum.Equals(null))
                {
                    lineItemNum = "1";
                }
                //Insert Item into Line Item DB
                ml.InsertLineItem(InvoiceNum, lineItemNum, itemCode);
                //Clear Combo Box and Reload
                cmbxItemsAdded.ClearValue(ItemsControl.ItemsSourceProperty);
                cmbxItemsAdded.ItemsSource = addeditems;
                //Clear Selected Item
                cmbInvoiceItem.SelectedIndex = -1;
                //Change Add Item Button IsEnabled to false
                btnAddItem.IsEnabled = false;

                //Change Total
                txtbxTotalCost.Text = "$ " + String.Format("{0:N2}", total);
            }
            catch (Exception ex)
            {
                HandleError(MethodInfo.GetCurrentMethod().DeclaringType.Name,
                            MethodInfo.GetCurrentMethod().Name, ex.Message);
            }
        }