/// <summary>
    /// 绑定属性列表
    /// </summary>
    /// <param name="id"></param>
    private void Bind()
    {
        int    pageCount = 0;
        int    Counts    = 0;
        string strWhere  = "and ISNULL(dr,0)=0 and ComPid=" + this.CompID;

        if (ViewState["strWhere"] != null)
        {
            strWhere += ViewState["strWhere"].ToString();
        }
        //每页显示的数据设置
        if (this.txtPageSize.Value.Trim().ToString() != "" && this.txtPageSize.Value.Trim().ToString() != "0")
        {
            if (this.txtPageSize.Value.Trim().Length >= 5)
            {
                Pager.PageSize         = 100;
                this.txtPageSize.Value = "100";
            }
            else
            {
                this.Pager.PageSize = this.txtPageSize.Value.Trim().ToInt(0);
            }
        }
        List <Hi.Model.BD_Template> l = new Hi.BLL.BD_Template().GetList(Pager.PageSize, Pager.CurrentPageIndex, "id", false, strWhere, out pageCount, out Counts);

        this.rptTemplate.DataSource = l;
        this.rptTemplate.DataBind();
        Pager.RecordCount = Counts;
        page = Pager.CurrentPageIndex.ToString();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        object obj = Request["action"];

        if (obj != null)
        {
            string action = obj.ToString();
            if (action == "AttrValueShow")
            {
                string id = Request["id"];//属性id
                Response.Write(GetAttrValue(id));
                Response.End();
            }
        }
        if (!IsPostBack)
        {
            if (Request["tempId"] == null) //新增
            {
                BindAttribute(1, "");      // 属性绑定
            }
            else
            {
                string id = Request["tempId"].ToString();
                if (id != "")
                {
                    Hi.Model.BD_Template model = new Hi.BLL.BD_Template().GetModel(Convert.ToInt32(id));
                    if (model != null)
                    {
                        this.txtTemplate.Value = model.TemplateName;
                        BindAttribute(2, id);// 属性绑定
                    }
                }
            }
        }
    }
    /// <summary>
    /// 保存
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        SqlTransaction Tran = null;

        try
        {
            Hi.Model.BD_Template model = null;
            Tran = DBUtility.SqlHelper.CreateStoreTranSaction();
            string str      = Request["chekAttr"];                          //属性id List
            string template = Common.NoHTML(this.txtTemplate.Value.Trim()); //模板名称
            object obj      = Request["tempId"];
            if (obj != null)
            {
                string tempIds = obj.ToString();
                List <Hi.Model.BD_TemplateAttribute> l = new Hi.BLL.BD_TemplateAttribute().GetList("", "isnull(dr,0)=0 and compid=" + this.CompID + " and templateId=" + tempIds, "", Tran);
                if (l.Count > 0)
                {
                    foreach (Hi.Model.BD_TemplateAttribute item in l)
                    {
                        new Hi.BLL.BD_TemplateAttribute().Delete(item.ID, Tran);
                        new Hi.BLL.BD_TemplateAttrValue().Delete(item.ID, Tran);
                    }
                }
                model = new Hi.BLL.BD_Template().GetModel(Convert.ToInt32(tempIds), Tran);
            }

            model              = new Hi.Model.BD_Template();
            model.CompID       = this.CompID;
            model.CreateDate   = DateTime.Now;
            model.CreateUserID = this.UserID;
            model.modifyuser   = this.UserID;
            model.TemplateName = template;
            model.TemplateCode = "";
            model.ts           = DateTime.Now;
            model.IsEnabled    = 1;
            int tempId = 0;
            if (obj != null)
            {
                tempId   = Convert.ToInt32(obj.ToString());
                model.ID = tempId;
                new Hi.BLL.BD_Template().Update(model, Tran);
            }
            else
            {
                tempId = new Hi.BLL.BD_Template().Add(model, Tran);
            }
            for (int i = 0; i < str.Split(',').Length; i++)
            {
                Hi.Model.BD_TemplateAttribute model2 = new Hi.Model.BD_TemplateAttribute();
                model2.AttributeID  = Convert.ToInt32(str.Split(',')[i]);
                model2.CompID       = this.CompID;
                model2.TemplateID   = tempId;
                model2.CreateDate   = DateTime.Now;
                model2.CreateUserID = this.UserID;
                model2.ts           = DateTime.Now;
                model2.modifyuser   = this.UserID;
                int    TemplateAttrId = new Hi.BLL.BD_TemplateAttribute().Add(model2, Tran);
                string str2           = Request["chekAttrValue" + str.Split(',')[i]];
                for (int x = 0; x < str2.Split(',').Length; x++)
                {
                    Hi.Model.BD_TemplateAttrValue model3 = new Hi.Model.BD_TemplateAttrValue();
                    model3.CompID           = this.CompID;
                    model3.AttributeValueID = Convert.ToInt32(str2.Split(',')[x]);
                    model3.TemplateAttrID   = TemplateAttrId;
                    model3.CreateDate       = DateTime.Now;
                    model3.CreateUserID     = this.UserID;
                    model3.ts         = DateTime.Now;
                    model3.modifyuser = this.UserID;
                    new Hi.BLL.BD_TemplateAttrValue().Add(model3, Tran);
                }
            }
            Tran.Commit();
            // Response.Write("<script>window.parent.CloseDialog(\"2\");window.opener.location=window.opener.location;</script>");
            this.ClientScript.RegisterStartupScript(this.GetType(), "msg", "<script>parent.location.reload();window.parent.CloseDialog(\"2\");</script>");
        }
        catch (Exception ex)
        {
            if (Tran != null)
            {
                if (Tran.Connection != null)
                {
                    Tran.Rollback();
                }
            }
            JScript.AlertMethod(this, "保存失败了", JScript.IconOption.错误);
            return;
        }
        finally
        {
            DBUtility.SqlHelper.ConnectionClose();
        }
    }
    /// <summary>
    /// 删除
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnDel_Click(object sender, EventArgs e)
    {
        SqlTransaction Tran = DBUtility.SqlHelper.CreateStoreTranSaction();

        try
        {
            List <int> l = new List <int>();
            foreach (RepeaterItem row in this.rptTemplate.Items)
            {
                CheckBox cb = row.FindControl("CB_SelItem") as CheckBox;
                if (cb != null && cb.Checked)
                {
                    HiddenField fld = row.FindControl("HF_Id") as HiddenField;
                    if (fld != null)
                    {
                        int id = Convert.ToInt32(fld.Value);
                        l.Add(id);
                        Hi.Model.BD_Template model = new Hi.BLL.BD_Template().GetModel(id, Tran);

                        if (model != null)
                        {
                            model.ts         = DateTime.Now;
                            model.modifyuser = this.UserID;
                            model.dr         = 1;
                            model.CompID     = this.CompID;
                            bool bol = new Hi.BLL.BD_Template().Update(model, Tran);
                            List <Hi.Model.BD_TemplateAttribute> ll = new Hi.BLL.BD_TemplateAttribute().GetList("", "isnull(dr,0)=0 and compid=" + this.CompID + " and templateid=" + model.ID, "", Tran);
                            if (ll.Count > 0)
                            {
                                foreach (Hi.Model.BD_TemplateAttribute item in ll)
                                {
                                    Hi.Model.BD_TemplateAttribute model2 = new Hi.BLL.BD_TemplateAttribute().GetModel(item.ID);
                                    model2.CompID     = this.CompID;
                                    model2.modifyuser = this.UserID;
                                    model2.ts         = DateTime.Now;
                                    model2.dr         = 1;
                                    new Hi.BLL.BD_TemplateAttribute().Update(model2, Tran);
                                }
                            }
                        }
                    }
                }
            }
            Tran.Commit();
        }
        catch (Exception ex)
        {
            if (Tran != null)
            {
                if (Tran.Connection != null)
                {
                    Tran.Rollback();
                }
            }
            JScript.AlertMethod(this, "删除失败了", JScript.IconOption.错误);
            return;
        }
        finally
        {
            DBUtility.SqlHelper.ConnectionClose();
            Bind();
        }
    }