Example #1
0
        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);
        }
        public static string GetDisplayValue(this SPClient.FieldLookupValue value)
        {
            if (value == null)
            {
                return(string.Empty);
            }

            return(string.Format("{0};#{1}", value.LookupId, value.LookupValue));
        }
        public bool IsSelected(SPListItem listItem, SP.Field field, string value)
        {
            if (listItem == null)
            {
                return(false);
            }
            object obj = listItem.Value(field.InternalName);

            if (obj == null)
            {
                return(false);
            }
            SP.FieldLookupValue lookupVal = obj as SP.FieldLookupValue;
            if (lookupVal == null)
            {
                return(false);
            }
            return(lookupVal.LookupId.ToString() == value);
        }
Example #4
0
        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);
        }