示例#1
0
        private void buttonDeleteCategory_Click(object sender, EventArgs e)
        {
            TreeNode treeNode = this.treeViewAllCategories.SelectedNode;

            if (treeNode != null)
            {
                int categoryId = -1;
                if (treeNode.Tag != null)
                {
                    ItemCategoryType categoryType = (ItemCategoryType)treeNode.Tag;
                    if (categoryType != null)
                    {
                        categoryId = categoryType.CategoryId;
                    }
                }

                bool result = ItemCategoryDAL.DeleteOneCategory(categoryId);
                if (result)
                {
                    // Remove from category tree.
                    this.treeViewAllCategories.Nodes.Remove(treeNode);

                    MessageBox.Show("删除类别成功!\r\n注意其子类别已经一并被删除!", "恭喜", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("删除类别失败", "失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
示例#2
0
        private void LoadAllCategories()
        {
            DataTable dtCategories = ItemCategoryDAL.GetAllCategories();

            if (dtCategories.Rows.Count == 0)
            {
                return;
            }

            this.treeViewAllCategories.Nodes.Clear();

            foreach (DataRow dr in dtCategories.Rows)
            {
                int    catId        = StringUtil.GetSafeInt(dr["CategoryId"]);
                int    parentCatId  = StringUtil.GetSafeInt(dr["ParentCategoryId"]);
                string catName      = StringUtil.GetSafeString(dr["CategoryName"]);
                string catSkuPrefix = StringUtil.GetSafeString(dr["CategorySkuPrefix"]);

                ItemCategoryType catType = new ItemCategoryType();
                catType.CategoryId        = catId;
                catType.ParentCategoryId  = parentCatId;
                catType.CategoryName      = catName;
                catType.CategorySkuPrefix = catSkuPrefix;

                TreeNode newNode = new TreeNode();
                newNode.Tag  = catType;
                newNode.Text = catName;
                newNode.Name = catId.ToString();

                if (parentCatId == -1)
                {
                    this.treeViewAllCategories.Nodes.Add(newNode);
                }
                else
                {
                    TreeNode[] parentNodes = this.treeViewAllCategories.Nodes.Find(parentCatId.ToString(), true);
                    if (parentNodes.Length == 1)
                    {
                        parentNodes[0].Nodes.Add(newNode);
                    }
                }

                int catSkuPrefixVal = -1;
                if (Int32.TryParse(catSkuPrefix, out catSkuPrefixVal) && catSkuPrefixVal > maxSkuPrefix)
                {
                    maxSkuPrefix = catSkuPrefixVal;
                }
            }

            this.treeViewAllCategories.ExpandAll();
            return;
        }
示例#3
0
        }   // class ItemCompactInfo

        private void LoadAllCategories()
        {
            DataTable dtCategories = ItemCategoryDAL.GetAllCategories();

            if (dtCategories.Rows.Count == 0)
            {
                return;
            }

            this.treeViewItems.Nodes.Clear();

            for (int itNum = 0; itNum < 2; ++itNum)
            {
                foreach (DataRow dr in dtCategories.Rows)
                {
                    int    catId       = (int)dr["CategoryId"];
                    int    parentCatId = (int)dr["ParentCategoryId"];
                    string catName     = dr["CategoryName"].ToString();

                    ItemCategoryType catType = new ItemCategoryType();
                    catType.CategoryId       = catId;
                    catType.ParentCategoryId = parentCatId;
                    catType.CategoryName     = catName;

                    TreeNode newNode = new TreeNode();
                    newNode.Tag  = catType;
                    newNode.Text = catName;
                    newNode.Name = catId.ToString();

                    if (parentCatId == -1 && itNum == 0)
                    {
                        this.treeViewItems.Nodes.Add(newNode);
                    }
                    else if (parentCatId != -1 && itNum == 1)
                    {
                        TreeNode[] parentNodes = this.treeViewItems.Nodes.Find(parentCatId.ToString(), true);
                        if (parentNodes.Length == 1)
                        {
                            parentNodes[0].Nodes.Add(newNode);
                        }
                    }
                }
            }


            this.treeViewItems.ExpandAll();
            return;
        }
示例#4
0
        private void buttonAddNewCategory_Click(object sender, EventArgs e)
        {
            int parentCategoryId = -1;

            if (this.textBoxParentCategory.Text == "无" || this.textBoxParentCategory.Text.Trim() == "")
            {
                parentCategoryId = -1;
            }
            else
            {
                TreeNode treeNode = this.treeViewAllCategories.SelectedNode;
                if (treeNode != null)
                {
                    if (treeNode.Tag != null)
                    {
                        ItemCategoryType parentCatType = (ItemCategoryType)treeNode.Tag;
                        if (parentCatType != null)
                        {
                            parentCategoryId = parentCatType.CategoryId;
                        }
                    }
                }
            }

            string categoryName = this.textBoxCategoryName.Text;

            if (categoryName == "")
            {
                MessageBox.Show("请输入类别名称");
                return;
            }

            ItemCategoryType newCategory = new ItemCategoryType();

            newCategory.ParentCategoryId  = parentCategoryId;
            newCategory.CategoryName      = categoryName;
            newCategory.CategorySkuPrefix = string.Format("{0}", maxSkuPrefix + 1);
            ItemCategoryDAL.InsertOneCategory(newCategory);

            LoadAllCategories();

            MessageBox.Show("添加新类别成功!", "恭喜", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }