当前位置: 首页>>代码示例>>C#>>正文


C# Product.setData方法代码示例

本文整理汇总了C#中Product.setData方法的典型用法代码示例。如果您正苦于以下问题:C# Product.setData方法的具体用法?C# Product.setData怎么用?C# Product.setData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Product的用法示例。


在下文中一共展示了Product.setData方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: btnUserControlCheckbox1_tryToSave

        /// <summary>
        /// Trigger save product.
        /// We're using a custom UserControl.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnUserControlCheckbox1_tryToSave(object sender, EventArgs e)
        {
            dynamic selectedCategory = comboBoxCategory.SelectedItem;
            List<KeyValuePair<String, String>> formData = new List<KeyValuePair<String, String>>
            {
                new KeyValuePair<String, String>("product_id", textBoxId.Text),
                new KeyValuePair<String, String>("name", textBoxNume.Text),
                new KeyValuePair<String, String>("price", textBoxPrice.Text),
                new KeyValuePair<String, String>("sku", textBoxSku.Text),
                new KeyValuePair<String, String>("stock_qty", textBoxStock.Text),
                new KeyValuePair<String, String>("category_id", selectedCategory.category_id.ToString()),
            };

            Product product = new Product();
            product.setData(formData);

            if (textBoxId.Text != "")
            {
                Product compare = new Product();
                compare.load(textBoxId.Text);
                if (product.CompareTo(compare) == 1)
                {
                    MessageBox.Show("Trebuie sa faceti cel putin o modificare!", "Atentie");
                    return;
                }
            }

            if (product.save())
            {
                MessageBox.Show("Produsul a fost salvat!");
                this.Dispose();
            }
            else
            {
                MessageBox.Show("A intervenit o eroare!");
            }
        }
开发者ID:replsv,项目名称:minierp,代码行数:43,代码来源:EditProductForm.cs

示例2: _importXml

        /// <summary>
        /// Import XML file of products into the database.
        /// </summary>
        /// <param name="content"></param>
        protected void _importXml(string content)
        {
            try
            {
                int imported = 0;

                var doc = XDocument.Parse(content.ToString());
                List<Product> data = new List<Product>();
                foreach(var item in doc.Root.Elements("results")) {

                    string categoryName = item.Element("category").Value.ToString();
                    string categoryId = string.Empty;
                    /**
                     * Load new product's category in order to assign the category id to it.
                     */
                    Category category = new Category();
                    category.load(categoryName, "name");
                    /**
                     * We should create the new category if it doesn't exist
                     */
                    if (category.isNew())
                    {
                        category.setData(new List<KeyValuePair<String, String>>{
                            new KeyValuePair<String, String>("name", categoryName)
                        });
                        category.save();
                        category.load(categoryName, "name");

                    }
                    /**
                     * Get the category id
                     */
                    foreach (KeyValuePair<string, string> k in category.getData())
                    {
                        if (k.Key.Equals("category_id") && k.Value.ToString() != "")
                        {
                            categoryId = k.Value.ToString();
                        }
                    }

                    /**
                     * Add in the Product type list the new product. We will persist later.
                     */
                    List<KeyValuePair<String, String>> productData = new List<KeyValuePair<String, String>>
                    {
                        new KeyValuePair<String, String>("name", item.Element("name").Value.ToString()),
                        new KeyValuePair<String, String>("price", item.Element("price").Value.ToString()),
                        new KeyValuePair<String, String>("sku", item.Element("sku").Value.ToString()),
                        new KeyValuePair<String, String>("stock_qty", item.Element("stock_qty").Value.ToString()),
                        new KeyValuePair<String, String>("category_id", categoryId.ToString()),
                    };

                    Product product = new Product();
                    product.setData(productData);

                    data.Add(product);

                }

                /**
                 * Persist products in the database now.
                 */
                foreach (Product p in data)
                {
                    try
                    {
                        p.save();
                        imported++;
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show(e.ToString());
                    }
                }

                /**
                 * Display a message.
                 */
                if (imported > 0)
                {
                    MessageBox.Show(@"Fisierul a fost importat! Au fost importate " + imported.ToString() + " produse.", "Succes");
                }
                else
                {
                    MessageBox.Show("Fisierul nu a putut fi importat!", "Eroare");
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString(), "Eroare!");
            }
        }
开发者ID:replsv,项目名称:minierp,代码行数:96,代码来源:Form1.cs


注:本文中的Product.setData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。