Example #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);
                }
            }
        }
Example #2
0
        public static bool InsertOneCategory(ItemCategoryType cat)
        {
            IDbCommand cmd = DataFactory.CreateCommand(null);
            cmd.CommandText = @"Insert into [Category] (ParentCategoryId, CategoryName, CategorySkuPrefix) values (@ParentCategoryId, @CategoryName, @CategorySkuPrefix)";

            DataFactory.AddCommandParam(cmd, "@ParentCategoryId", DbType.Int32, cat.ParentCategoryId);
            DataFactory.AddCommandParam(cmd, "@CategoryName", DbType.String, StringUtil.GetSafeString(cat.CategoryName));
            DataFactory.AddCommandParam(cmd, "@CategorySkuPrefix", DbType.String, StringUtil.GetSafeString(cat.CategorySkuPrefix));

            bool result = DataFactory.ExecuteCommandNonQuery(cmd);
            return result;
        }
Example #3
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;
        }
Example #4
0
        public static bool InsertOneCategory(ItemCategoryType cat)
        {
            IDbCommand cmd = DataFactory.CreateCommand(null);

            cmd.CommandText = @"Insert into [Category] (ParentCategoryId, CategoryName, CategorySkuPrefix) values (@ParentCategoryId, @CategoryName, @CategorySkuPrefix)";

            DataFactory.AddCommandParam(cmd, "@ParentCategoryId", DbType.Int32, cat.ParentCategoryId);
            DataFactory.AddCommandParam(cmd, "@CategoryName", DbType.String, StringUtil.GetSafeString(cat.CategoryName));
            DataFactory.AddCommandParam(cmd, "@CategorySkuPrefix", DbType.String, StringUtil.GetSafeString(cat.CategorySkuPrefix));

            bool result = DataFactory.ExecuteCommandNonQuery(cmd);

            return(result);
        }
Example #5
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;
        }
Example #6
0
        private void treeViewCategories_DragDrop(object sender, DragEventArgs e)
        {
            TreeNode oldNode;

            if (e.Data.GetDataPresent("System.Windows.Forms.TreeNode", false))
            {
                Point    pt         = ((TreeView)sender).PointToClient(new Point(e.X, e.Y));
                TreeNode targetNode = ((TreeView)sender).GetNodeAt(pt);

                object tag = targetNode.Tag;
                if (tag == null || tag.GetType() != typeof(ItemCategoryType))
                {
                    return;
                }
                ItemCategoryType catInfo = (ItemCategoryType)tag;

                oldNode = (TreeNode)e.Data.GetData("System.Windows.Forms.TreeNode");
                if (oldNode.Tag == null || oldNode.Tag.GetType() != typeof(ItemCompactInfo))
                {
                    return;
                }

                ItemCompactInfo itemInfo = (ItemCompactInfo)oldNode.Tag;
                if (itemInfo == null)
                {
                    return;
                }

                InventoryItemType item = ItemDAL.GetItemById(itemInfo.ItemId);
                if (item == null)
                {
                    return;
                }

                if (item.CategoryId == catInfo.CategoryId)
                {
                    return;
                }

                ItemDAL.ModifyItemCategory(item.ItemId, catInfo.CategoryId);

                targetNode.Nodes.Add((TreeNode)oldNode.Clone());
                targetNode.Expand();
                //Remove Original Node
                oldNode.Remove();
            }
        }
Example #7
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);
        }
        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;
        }
Example #9
0
        private void treeViewAllCategories_AfterSelect(object sender, TreeViewEventArgs e)
        {
            TreeNode node = this.treeViewAllCategories.SelectedNode;

            if (node == null)
            {
                this.textBoxParentCategory.Text = "无";
                return;
            }

            ItemCategoryType selectedCatType = (ItemCategoryType)node.Tag;

            if (selectedCatType == null)
            {
                this.textBoxParentCategory.Text = "无";
                return;
            }

            this.textBoxParentCategory.Text = selectedCatType.CategoryName;
        }
Example #10
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);
        }
Example #11
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;
        }
Example #12
0
        private InventoryItemType GetItemInfoFromUI(bool isInsert)
        {
            InventoryItemType item = new InventoryItemType();

            TreeNode node = this.treeViewCategories.SelectedNode;

            if (node == null)
            {
                MessageBox.Show("请选择商品类别");
                return(null);
            }

            if (isInsert)
            {
                if (node.Tag.GetType() != typeof(ItemCategoryType))
                {
                    MessageBox.Show("请选择商品类别");
                    return(null);
                }

                ItemCategoryType category = (ItemCategoryType)node.Tag;
                if (category == null)
                {
                    MessageBox.Show("请选择商品类别");
                    return(null);
                }

                item.CategoryId = category.CategoryId;
                if (item.CategoryId <= 0)
                {
                    MessageBox.Show("请选择商品类别");
                    return(null);
                }
            }
            else
            {
                // modify
                if (node.Tag.GetType() != typeof(ItemCompactInfo))
                {
                    MessageBox.Show("请选择商品");
                    return(null);
                }
            }

            item.ItemName = this.textBoxItemName.Text;
            if (item.ItemName == "")
            {
                MessageBox.Show("请输入商品名");
                return(null);
            }

            item.ItemSKU = this.textBoxItemSKU.Text;
            if (item.ItemSKU == "")
            {
                MessageBox.Show("请输入商品SKU");
                return(null);
            }

            if (this.textBoxItemImagePath.Text.Trim() == "")
            {
                if (isInsert)
                {
                    MessageBox.Show("请选择商品图片");
                    return(null);
                }
            }
            else
            {
                string imagePath = this.textBoxItemImagePath.Text.Trim();
                if (File.Exists(imagePath) == false)
                {
                    MessageBox.Show("商品图片路径错误.");
                    return(null);
                }

                //FileStream fs = new FileStream(imagePath, FileMode.Open, FileAccess.Read);
                //byte[] buffer = new byte[fs.Length];
                //fs.Read(buffer, 0, buffer.Length);
                //fs.Close();
                //item.ItemImage = buffer;
                item.ItemImagePath = imagePath;
            }

            if (this.textBoxItemStockShreshold.Text == "")
            {
                MessageBox.Show("商品库存警戒值错误");
                return(null);
            }

            item.ItemStockShresholdNum = Int32.Parse(this.textBoxItemStockShreshold.Text.Trim());

            string itemStockStr = this.textBoxItemStock.Text;

            if (itemStockStr.Trim() == "")
            {
                MessageBox.Show("商品库存值错误");
                return(null);
            }

            item.ItemStockNum = StringUtil.GetSafeInt(itemStockStr);

            //item.ItemSourcingInfo = this.textBoxItemSourcingInfo.Text;

            //item.ItemSourcingURL = this.textBoxSourcingURL.Text;

            //string itemCostStr = this.textBoxItemCost.Text.Trim();
            //if (itemCostStr == "")
            //{
            //    MessageBox.Show("商品成本值错误");
            //    return null;
            //}
            //item.ItemCost = StringUtil.GetSafeDouble(itemCostStr);

            string itemWeightStr = this.textBoxItemWeight.Text.Trim();

            if (itemWeightStr == "")
            {
                MessageBox.Show("商品重量值错误");
                return(null);
            }
            item.ItemWeight = StringUtil.GetSafeDouble(itemWeightStr);

            item.ItemCustomName = this.textBoxCustomName.Text.Trim();

            string itemCustomWeightStr = this.textBoxItemCustomWeight.Text.Trim();

            if (itemCustomWeightStr == "")
            {
                item.ItemCustomWeight = 0.0;
            }
            else
            {
                item.ItemCustomWeight = StringUtil.GetSafeDouble(itemCustomWeightStr);
            }

            string itemCustomCostStr = this.textBoxItemCustomValue.Text.Trim();

            if (itemCustomCostStr == "")
            {
                item.ItemCustomCost = 0.0;
            }
            else
            {
                item.ItemCustomCost = StringUtil.GetSafeDouble(itemCustomCostStr);
            }

            item.ItemAddDateTime = DateTime.Now;

            // IsGroupItem
            item.IsGroupItem = false;
            item.SubItemSKUs = "";

            return(item);
        }