private void ProductEditorDialog_AddClosed(object sender, EventArgs e) { ProductEditor dialog = (ProductEditor)sender; // stop if they clicked cancel if (dialog.DialogResult == false) { return; } StatusBarPanel.BeginUpdateMessage("Creating new item..."); SP.List products = Globals.ClientContext.Web.Lists.GetByTitle("Products"); SP.ListItemCreationInformation newProductInfo = new SP.ListItemCreationInformation(); SP.ListItem newProduct = products.AddItem(newProductInfo); newProduct["Title"] = dialog.ProductNameTextBox.Text; newProduct["Product_x0020_Number"] = dialog.ProductNumberTextBox.Text; newProduct["Price"] = dialog.ProductPriceTextBox.Text; SP.FieldLookupValue fieldValue = new SP.FieldLookupValue(); foreach (SP.ListItem item in Globals.ProductCategories) { if (item["Title"].ToString() == ((SP.ListItem)dialog.ProductCategoryComboBox.SelectedItem)["Title"].ToString()) { fieldValue.LookupId = item.Id; } } newProduct["Category"] = fieldValue; newProduct.Update(); Globals.ClientContext.ExecuteQuery(); this.Dispatcher.BeginInvoke(new Action(OnProducteditorAddUIUpdater), DispatcherPriority.Normal); }
private void AddProductButton_Click(object sender, System.Windows.RoutedEventArgs e) { ProductEditor dialog = new ProductEditor(); dialog.Closed += new EventHandler(ProductEditorDialog_AddClosed); dialog.DataContext = null; // show the dialog dialog.SetForAdd(); dialog.ShowDialog(); }
private void UpdateProductButton_Click(object sender, System.Windows.RoutedEventArgs e) { ProductEditor dialog = new ProductEditor(); dialog.Closed += new EventHandler(ProductEditorDialog_UpdateClosed); // wire up the context of the dialog to be the same as this editor dialog.DataContext = this.DataContext; // show the dialog dialog.SetForUpdate(); dialog.ShowDialog(); }
protected void ProductEditorDialog_UpdateClosed(object sender, EventArgs e) { ProductEditor dialog = (ProductEditor)sender; // stop if they clicked cancel if (dialog.DialogResult == false) { return; } StatusBarPanel.BeginUpdateMessage("Updateing item..."); selectedCategory = new SP.FieldLookupValue(); foreach (SP.ListItem item in Globals.ProductCategories) { if (item["Title"].ToString() == ((SP.ListItem)dialog.ProductCategoryComboBox.SelectedItem)["Title"].ToString()) { selectedCategory.LookupId = item.Id; } } ThreadPool.QueueUserWorkItem(OnProducteditorUpdateWorker, DataContext); }