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


C# Category.setData方法代码示例

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


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

示例1: buttonSave_Click

        /// <summary>
        /// Save button.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonSave_Click(object sender, EventArgs e)
        {
            List<KeyValuePair<String, String>> formData = new List<KeyValuePair<String, String>>
            {
                new KeyValuePair<String, String>("category_id", textBoxId.Text),
                new KeyValuePair<String, String>("name", textBoxNume.Text),
            };

            Category category = new Category();
            category.setData(formData);

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

            if (category.save())
            {
                MessageBox.Show("Categoria a fost salvata!");
                this.Dispose();
            }
            else
            {
                MessageBox.Show("A intervenit o eroare!");
            }
        }
开发者ID:replsv,项目名称:minierp,代码行数:37,代码来源:EditCategoryForm.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


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