public int indexList; //Public index from the datagrid public MainWindow() { InvoiceInstance = new InvoiceItemClass();//Invoice instans //The manager keeps track of the two items. //I use the object id from the list to GetAt my genreric list. managerItem = new Invoice_ManagerHandler();//Invoice manager InitializeComponent(); //Initialize start //set false txxtboxes InitializeGUI(); //Set variables for item 1 string descriptionItem = InvoiceInstance.P11_DescriptionItem; int quantityItem = InvoiceInstance.P12_QuantityItem; decimal priceItem = InvoiceInstance.P13_PriceItem; decimal taxItem = InvoiceInstance.P14_TaxItem; //Item 1 //Instantiate by constructor, set item values ItemClass itemObject = new ItemClass(descriptionItem, quantityItem, priceItem, taxItem); managerItem.AddNewInvoice(itemObject); //add item 1 as objet to the item_list AddToItemCollectionOBJECT(itemObject); //Item 2 set properties by constructor ItemClass itemObject2 = new ItemClass( InvoiceInstance.P15_DescriptionItem2, InvoiceInstance.P16_QuantityItem2, InvoiceInstance.P17_PriceItem2, InvoiceInstance.P18_TaxItem2 ); ////add item 2 to manager managerItem.AddNewInvoice(itemObject2); //Add object to List of items AddToItemCollectionOBJECT(itemObject2); //DataGrid_Items.ItemsSource = LoadCollectionData(); DataGrid_Items.ItemsSource = LoadCollectionData(); //Update the cart updateCart(); }
int counterListItem = 0; //Counter to list item private void AddToItemCollectionOBJECT(ItemClass obj) { Invoice_Item_List.Add(new ItemClass() { ID_Item = counterListItem++, ItemC_DecriptionItem = obj.ItemC_DecriptionItem, ItemC_QuantityItem = obj.ItemC_QuantityItem, ItemC_UnitPriceItem = obj.ItemC_UnitPriceItem, ItemC_TaxItem = obj.ItemC_TaxItem, ItemC_TotalPrice = obj.GetPrice_TotalPrice(), Item_C_Tax_As_Decimal = obj.GET_Tax_As_Decimal(),//Math logic Item_C_Tax_Of_Price = obj.GET_Tax_Of_Price(), Item_C_Total_Price_Tax_Included = obj.GET_Total_Price_Tax_Included() }); }
//Update loops, #region Update Grid and Listbox //update the current Invoice list based on the incoming object from generic list. public void updateGrid(ItemClass inObj) { foreach (ItemClass obj in Invoice_Item_List) { if (obj.ID_Item == inObj.ID_Item) { obj.ItemC_DecriptionItem = inObj.ItemC_DecriptionItem; obj.ItemC_QuantityItem = inObj.ItemC_QuantityItem; obj.ItemC_UnitPriceItem = inObj.ItemC_UnitPriceItem; obj.ItemC_TaxItem = inObj.ItemC_TaxItem; obj.ItemC_TotalPrice = inObj.GetPrice_TotalPrice(); //Update match logic obj.Item_C_Tax_As_Decimal = inObj.GET_Tax_As_Decimal(); obj.Item_C_Tax_Of_Price = inObj.GET_Tax_Of_Price(); obj.Item_C_Total_Price_Tax_Included = inObj.GET_Total_Price_Tax_Included(); //refresh data grid DataGrid_Items.Items.Refresh(); //obj.otherProp = newValue; break; } } }