當前位置: 首頁>>代碼示例>>C#>>正文


C# Category.save方法代碼示例

本文整理匯總了C#中Category.save方法的典型用法代碼示例。如果您正苦於以下問題:C# Category.save方法的具體用法?C# Category.save怎麽用?C# Category.save使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Category的用法示例。


在下文中一共展示了Category.save方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: CreateTst

        public ActionResult CreateTst()
        {
            Category cat1 = new Category("cat1");
            Category cat2 = new Category("cat2");
            Category cat3 = new Category("cat3");

            Product product1 = new Product("prod1");
            Product product2 = new Product("prod2");
            Product product3 = new Product("prod3");

            cat1.addProduct(product1);
            cat2.addProduct(product2);
            cat2.addProduct(product3);

            cat1.save();
            cat2.save();
            cat3.save();

            return RedirectToAction("Index");
        }
開發者ID:peinguin,項目名稱:online_shop,代碼行數:20,代碼來源:HomeController.cs

示例2: 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

示例3: Add

 public ActionResult Add(String Name)
 {
     Category c = new Category(Name);
     c.save();
     return RedirectToAction("Get");
 }
開發者ID:peinguin,項目名稱:online_shop,代碼行數:6,代碼來源:HomeController.cs

示例4: _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.save方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。