using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace CitySunlight
{
    public partial class ProductClassEdit : System.Web.UI.Page
    {
        public String msg;
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        public String GetOption(String name)
        {
            return ProductClassManager.getOptionString(name);
        }

        protected void add_Click(object sender, EventArgs e)
        {
            String cname = HttpUtils.getElementsbyName("customclass");
            int pid = int.Parse(HttpUtils.getElementsbyName("addclassfather"));
            if (cname == "")
            {
                msg = "请输入分类的名称!";
                return;
            }
            if (ProductClassManager.isExist(cname))
            {
                msg = "分类 [" + cname + "] 已存在!";
                return;
            }
            if (ProductClassManager.addclass(pid, cname))
            {
                msg = "分类 [" + cname + "] 添加成功!";
                return;
            }
        }
        protected void remove_Click(object sender, EventArgs e)
        {
            int id = int.Parse(HttpUtils.getElementsbyName("deleteclass"));
            String cname = ProductClassManager.getClassName(id);
            if (id == 0)
            {
                msg = "请选择需要删除的分类!";
                return;
            }
            if (ProductClassManager.removeclass(id))
            {
                msg = "分类 [" + cname + "] 删除成功!";
            }
        }

        protected void edit_Click(object sender, EventArgs e)
        {
            int id = int.Parse(HttpUtils.getElementsbyName("editclassid"));
            String ocname = ProductClassManager.getClassName(id);
            String cname = HttpUtils.getElementsbyName("editclassname");
            if (ProductClassManager.isExist(cname))
            {
                msg = "修改失败 分类名称 [" + cname + "] 已存在!";
                return;
            }
            if (ProductClassManager.editclass(id, cname))
            {
                msg = "修改成功 分类名称 [" + ocname + "] 已修改为 [" + cname + "]!";
                return;
            }
        }
    }
}