protected void bt_In_Click(object sender, EventArgs e)
    {
        Save();
        foreach (GridViewRow row in gv_NotInList.Rows)
        {
            CheckBox cb_check = (CheckBox)row.FindControl("cb_Check");
            if (cb_check.Checked)
            {
                ORD_ApplyPublishBLL _bll;
                if ((int)ViewState["ID"] != 0)
                    _bll = new ORD_ApplyPublishBLL((int)ViewState["ID"]);
                else
                    return;

                ORD_ApplyPublishDetail pd = new ORD_ApplyPublishDetail();
                pd.ID = (int)ViewState["ID"];
                pd.Product = int.Parse(gv_NotInList.DataKeys[row.RowIndex]["ID"].ToString());
                pd.Price = new PDT_ProductBLL(pd.Product).Model.FactoryPrice;
                _bll.AddDetail(pd);
            }
        }
        Response.Redirect("PublishDetail.aspx?ID=" + ViewState["ID"].ToString());
    }
    private bool Save()
    {
        ORD_ApplyPublishBLL _bll;
        if ((int)ViewState["ID"] != 0)
            _bll = new ORD_ApplyPublishBLL((int)ViewState["ID"]);
        else
            _bll = new ORD_ApplyPublishBLL();

        pl_ApplyPublish.GetData(_bll.Model);

        #region 判断有效性
        if (_bll.Model.Type == 2)
        {
            if (_bll.Model["ProductBrand"] == "0")
            {
                MessageBox.Show(this, "请选择【品牌】!");
                return false;
            }

            if (_bll.Model["GiftClassify"] == "0")
            {
                MessageBox.Show(this, "请选择【赠品费用类别】!");
                return false;
            }
        }
        #endregion

        #region 组织主题
        if (_bll.Model.Topic == "")
        {
            DropDownList ddl_Type = (DropDownList)pl_ApplyPublish.FindControl("ORD_ApplyPublish_Type");
            if (ddl_Type != null) _bll.Model.Topic += ddl_Type.SelectedItem.Text + " ";

            DropDownList ddl_AccountMonth = (DropDownList)pl_ApplyPublish.FindControl("ORD_ApplyPublish_AccountMonth");
            if (ddl_AccountMonth != null) _bll.Model.Topic += ddl_AccountMonth.SelectedItem.Text.Replace('-', '年') + "月 ";

            DropDownList ddl_ProductBrand = (DropDownList)pl_ApplyPublish.FindControl("ORD_ApplyPublish_ProductBrand");
            if (ddl_ProductBrand != null) _bll.Model.Topic += ddl_ProductBrand.SelectedItem.Text + " ";

            DropDownList ddl_GiftClassify = (DropDownList)pl_ApplyPublish.FindControl("ORD_ApplyPublish_GiftClassify");
            if (ddl_GiftClassify != null) _bll.Model.Topic += ddl_GiftClassify.SelectedItem.Text + " ";
        }
        #endregion

        if ((int)ViewState["ID"] != 0)
        {
            if (_bll.Model.Type == 2 && _bll.Model.FeeType == 0)
            {
                //赠品所属费用类型
                _bll.Model.FeeType = ConfigHelper.GetConfigInt("GiftFeeType");
            }
            _bll.Model.UpdateStaff = int.Parse(Session["UserID"].ToString());
            _bll.Update();
        }
        else
        {
            #region 判断相同品牌的申请当月是否已存在
            string condition = string.Format(@"AccountMonth={0} AND Type={1} AND
                ToOrganizeCity={2} AND
                MCS_SYS.dbo.UF_Spilt2('MCS_Logistics.dbo.ORD_ApplyPublish',ExtPropertys,'ProductBrand')='{3}' AND
                MCS_SYS.dbo.UF_Spilt2('MCS_Logistics.dbo.ORD_ApplyPublish',ExtPropertys,'GiftClassify')='{4}' ",
                _bll.Model.AccountMonth, _bll.Model.Type, _bll.Model.ToOrganizeCity, _bll.Model["ProductBrand"], _bll.Model["GiftClassify"]);

            if (ORD_ApplyPublishBLL.GetModelList(condition).Count > 0)
            {
                MessageBox.Show(this, "对不起,相同品牌相同类别的申请目录已发布了,请勿重复发布!");
                return false;
            }
            #endregion

            _bll.Model.State = 1;
            _bll.Model.ApproveFlag = 2;
            _bll.Model.InsertStaff = (int)Session["UserID"];
            _bll.Add();
            ViewState["ID"] = _bll.Model.ID;
        }

        #region 修改明细
        foreach (GridViewRow row in gv_List.Rows)
        {
            ORD_ApplyPublishDetail item = new ORD_ApplyPublishDetail();
            item.PublishID = _bll.Model.ID;
            item.ID = int.Parse(gv_List.DataKeys[row.RowIndex]["ID"].ToString());
            item.Product = int.Parse(gv_List.DataKeys[row.RowIndex]["Product"].ToString());

            PDT_Product p = new PDT_ProductBLL(item.Product).Model;
            item.Price = p.FactoryPrice;

            if (row.FindControl("tbx_AvailableQuantity_T") != null)
                item.AvailableQuantity = int.Parse(((TextBox)row.FindControl("tbx_AvailableQuantity_T")).Text) * p.ConvertFactor;

            if (row.FindControl("tbx_MinQuantity_T") != null)
                item.MinQuantity = int.Parse(((TextBox)row.FindControl("tbx_MinQuantity_T")).Text) * p.ConvertFactor;

            if (row.FindControl("tbx_MaxQuantity_T") != null)
                item.MaxQuantity = int.Parse(((TextBox)row.FindControl("tbx_MaxQuantity_T")).Text) * p.ConvertFactor;

            if (row.FindControl("tbx_Remark") != null)
                item.Remark = ((TextBox)row.FindControl("tbx_Remark")).Text;

            if (row.FindControl("tbx_GiveLevel") != null)
                item["GiveLevel"] = ((TextBox)row.FindControl("tbx_GiveLevel")).Text;

            if (item.MaxQuantity > 0 && item.MinQuantity > item.MaxQuantity)
            {
                MessageBox.Show(this, "产品:" + p.FullName + "的【单次最小请购数量】不能大于【单次最大请购数量】!");
                return false;
            }

            if (item.MaxQuantity > 0 && item.AvailableQuantity > 0 && item.MaxQuantity > item.AvailableQuantity)
            {
                MessageBox.Show(this, "产品:" + p.FullName + "的【单次最大请购数量】不能大于【可供请购数量】!");
                return false;
            }
            _bll.UpdateDetail(item);
        }

        #endregion

        return true;
    }