private void dgTransactionItems_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (dgTransactionItems.SelectedIndex > -1)
            {
                InventoryTransactionItemBinding obj = (InventoryTransactionItemBinding)dgTransactionItems.SelectedCells[0].Item;
                mTransactionItem = (InventoryTransactionItem)mTransactionItems[obj.itemID];
                if (mTransactionItem.GetInventoryItem() == null)
                {
                    try
                    {
                        DataSet data = db.Select("*", InventoryItem.Table, InventoryItem.Fields.itemID.ToString() + " = '" + mTransactionItem.GetItemID() + "'");
                        data.Read();
                        mTransactionItem.SetInventoryItem(new InventoryItem(data.GetRecordDataSet()));

                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Loading Item Data - " + msgCodes.GetString("M2102") + ex.Message, "Error - 2102", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
                ClearFields();
                SelectedItem();
                lockItemFields();
                txtQuantity.Text = "" + mTransactionItem.GetQuantity();
                cmdSaveEditItem.IsEnabled = true;
                cmdRemoveItem.IsEnabled = true;
                cmdCancelItem.IsEnabled = false;
                cmdSaveEditItem.Content = unlockBtnTxt;
                if (isFormHidden)
                {
                    displayOrHideForm();
                }
            }
        }
 private void RecalculateAverage(InventoryItem item)
 {
     try
     {
         DataSet dataSet = db.Select("inventory_item_transactions.*", "inventory_transactions, inventory_item_transactions", "inventory_transactions.transactionID = inventory_item_transactions.transactionID AND inventory_transactions.ClientType = 2 AND inventory_item_transactions.itemID = '" + item.getItemID() + "'",InventoryTransaction.Fields.DateOfTransaction.ToString());
         item.setQuantity(0);
         item.setCurrentCost(0);
         item.setAverageCost(0);
         item.SaveObject(db);
         float qty = 0;
         float avg = 0;
         while (dataSet.Read())
         {
             InventoryTransactionItem transItem = new InventoryTransactionItem(dataSet.GetRecordDataSet());
             if (!transItem.GetTransactionID().Equals(mTransaction.GetTransactionID()))
             {
                 qty += transItem.GetQuantity();
                 avg = (avg * qty) + (transItem.GetUnitPrice() * transItem.GetQuantity());
                 avg = avg / (qty + transItem.GetQuantity());
                 item.setCurrentCost(transItem.GetUnitPrice());
             }
         }
         item.setAverageCost(avg);
         item.setQuantity(qty);
         item.SaveObject(db);
     }
     catch (Exception ex)
     {
         MessageBox.Show("Failed to Recalculate new average of item - " + msgCodes.GetString("M2102") + " " + ex.Message, "Error - 2102", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }