private async void menuCreate_Click(object sender, RoutedEventArgs e) { if (sender is MenuItem) { try { if ((sender as MenuItem).Tag is Type) { Type t = (sender as MenuItem).Tag as Type; NPart newPart = (NPart)Activator.CreateInstance(t); newPart.ClassName = ((sender as MenuItem).Tag as Type).FullName; newPart.Name = "New item"; newPart.LastModified = DateTime.Now; newPart.Currency = "NZD"; newPart.CategoryID = cat.id; await insert(newPart, t); await refreshList(); } else { throw new Exception("Internal error, no type of object was provided."); } } catch (Exception ex) { MessageBox.Show(ex.GetBaseException().Message); } } }
public BaseParts(NPart prt) { InitializeComponent(); part = prt; DataContext = part; List <SubItem> lst = new List <SubItem> { new SubItem { itemType = typeof(NWiredPart), DisplayComponent = typeof(PartsWired), TPHtype = typeof(NPart) }, new SubItem { itemType = typeof(NWiredWirelesspart), DisplayComponent = typeof(PartsWiredWireless), TPHtype = typeof(NPart) }, new SubItem { itemType = typeof(NWirelesspart), DisplayComponent = typeof(PartsWireless), TPHtype = typeof(NPart) } }; bool found = false; lst.ForEach(item => { if (prt.GetType().Name == item.itemType.Name) { found = true; InitEditing(part, item.itemType, item.TPHtype); try { NPartContainer container = (NPartContainer)Activator.CreateInstance(item.DisplayComponent, new object[] { part }); extraSpecs.Content = container; } catch (Exception e) { MessageBox.Show($"Cannot create instance of {item.DisplayComponent.Name} Erorr:{e.GetBaseException().Message}"); } } }); if (!found) { MessageBox.Show($"Type: {prt.GetType().Name} not handled in BaseParts constructor."); } }
public PartsWiredWireless(NPart part) : base(part) { InitializeComponent(); }
public NPartContainer(NPart part) { _part = part; DataContext = _part; }