/// <summary>
        /// 根据请购买申请单重新初始化购物车
        /// </summary>
        /// <param name="ApplyID"></param>
        /// <returns></returns>
        public static ORD_OrderCartBLL InitByOrderApply(int ApplyID)
        {
            ORD_OrderApplyBLL apply = new ORD_OrderApplyBLL(ApplyID);

            if (apply.Model == null)
            {
                return(null);
            }

            ORD_ApplyPublishBLL publish = new ORD_ApplyPublishBLL(apply.Model.PublishID);

            if (publish.Model == null)
            {
                return(null);
            }
            int addressid = 0;

            int.TryParse(apply.Model["AddressID"], out addressid);
            ORD_OrderCartBLL cart = new ORD_OrderCartBLL(apply.Model.PublishID, apply.Model.OrganizeCity, apply.Model.Client, apply.Model.AccountMonth, addressid);

            foreach (ORD_OrderApplyDetail item in apply.Items)
            {
                ORD_ApplyPublishDetail _m = publish.Items.FirstOrDefault(m => m.Product == item.Product);
                if (_m == null)
                {
                    continue;
                }

                ORD_OrderCart cartitem = new ORD_OrderCart();
                cartitem.ID                = _m.ID;
                cartitem.Product           = _m.Product;
                cartitem.MinQuantity       = _m.MinQuantity;
                cartitem.MaxQuantity       = _m.MaxQuantity;
                cartitem.Price             = item.Price;
                cartitem.AvailableQuantity = _m.AvailableQuantity;
                cartitem.SubmitQuantity    = ORD_OrderApplyBLL.GetSubmitQuantity(cart.Publish, cartitem.Product);

                cartitem.BookQuantity = item.BookQuantity;

                cart.Items.Add(cartitem);
            }

            return(cart);
        }
    protected void bt_Confirm_Click(object sender, ImageClickEventArgs e)
    {
        if (ddl_Publish.SelectedValue != "0")
        {
            int Client = 0;
            int.TryParse(select_Client.SelectValue, out Client);
            if (Client == 0)
            {
                MessageBox.Show(this, "请选择申请的客户!");
                return;
            }
            int Receiver = 0;
            int.TryParse(select_Receiver.SelectValue, out Receiver);
            if (Receiver == 0)
            {
                MessageBox.Show(this, "请选择收货客户!");
                return;
            }
            //if (ddl_Address.SelectedValue == "0")
            //{
            //    MessageBox.Show(this, "该客户没有对应ERP地址ID!");
            //    return;
            //}
            if (ORD_OrderApplyBLL.CheckClientCanApply(int.Parse(ddl_AccountMonth.SelectedValue), int.Parse(select_Client.SelectValue), int.Parse(ddl_Publish.SelectedValue)) <= 0)
            {
                MessageBox.Show(this, "该申请品项目录当月申请已达到可申请上限!");
                ddl_Publish.Focus();
                return;
            }
            int Publish = int.Parse(ddl_Publish.SelectedValue);
            int OrganizeCity = int.Parse(tr_OrganizeCity.SelectValue);
            int AccountMonth = int.Parse(ddl_AccountMonth.SelectedValue);

            Session["LogisticsOrderApplyDetail"] = new ORD_OrderCartBLL(Publish, OrganizeCity, Client, AccountMonth,0, Receiver, "");
            Response.Redirect("OrderApplyDetail1.aspx");

        }
        else
        {
            ddl_Publish.Focus();
            MessageBox.Show(this, "请正确选择要申请的发布目录!");
        }
    }
    protected void bt_Confirm_Click(object sender, ImageClickEventArgs e)
    {
        if (ddl_Publish.SelectedValue != "0")
        {
            int OrganizeCity = int.Parse(tr_OrganizeCity.SelectValue);
            int Publish = int.Parse(ddl_Publish.SelectedValue);
            int Client = 0;
            int.TryParse(select_Client.SelectValue, out Client);

            if (rbl_Type.SelectedValue == "1")
            {
                if (Client == 0)
                {
                    MessageBox.Show(this, "请选择申请的客户!");
                    return;
                }
                else
                {
                    OrganizeCity = new CM_ClientBLL(Client).Model.OrganizeCity;
                }
                if (rbl_IsSpecial.SelectedValue == "2" && ddl_OrderType.SelectedValue=="1")
                {
                    ORD_OrderApplyBLL bll = new ORD_OrderApplyBLL();
                    double DelayDays = Convert.ToDouble(System.Configuration.ConfigurationManager.AppSettings["OrderDelayDays"]);
                    IList<ORD_OrderApply> orderlist = bll._GetModelList(" Client=" + Client.ToString() + " AND MCS_SYS.dbo.UF_Spilt(ExtPropertys,'|',4)='1'  AND AccountMonth=" + ddl_AccountMonth.SelectedValue + " AND MCS_SYS.dbo.UF_Spilt(ExtPropertys,'|',5)=" + ddl_Brand.SelectedValue);
                    if (orderlist.Count >= 2)
                    {
                        MessageBox.Show(this, "对不起,非特殊订单只能申请两次。");
                        return;
                    }
                }
            }
            Session["LogisticsOrderApplyDetail"] = new ORD_OrderCartBLL(Publish, OrganizeCity,int.Parse(ddl_OrderType.SelectedValue),int.Parse(ddl_Brand.SelectedValue),int.Parse(rbl_IsSpecial.SelectedValue),Client);
            Response.Redirect("OrderApplyDetail1.aspx");

        }
        else
        {
            ddl_Publish.Focus();
            MessageBox.Show(this, "请正确选择要申请的产品目录!");
        }
    }
        /// <summary>
        /// 根据请购买申请单重新初始化购物车
        /// </summary>
        /// <param name="ApplyID"></param>
        /// <returns></returns>
        public static ORD_OrderCartBLL InitByOrderApply(int ApplyID)
        {
            ORD_OrderApplyBLL apply = new ORD_OrderApplyBLL(ApplyID);
            if (apply.Model == null) return null;

            ORD_ApplyPublishBLL publish = new ORD_ApplyPublishBLL(apply.Model.PublishID);
            if (publish.Model == null) return null;
            int addressid = 0;
            int.TryParse(apply.Model["AddressID"], out addressid);
            ORD_OrderCartBLL cart = new ORD_OrderCartBLL(apply.Model.PublishID, apply.Model.OrganizeCity, apply.Model.Client, apply.Model.AccountMonth, addressid);

            foreach (ORD_OrderApplyDetail item in apply.Items)
            {
                ORD_ApplyPublishDetail _m = publish.Items.FirstOrDefault(m => m.Product == item.Product);
                if (_m == null) continue;

                ORD_OrderCart cartitem = new ORD_OrderCart();
                cartitem.ID = _m.ID;
                cartitem.Product = _m.Product;
                cartitem.MinQuantity = _m.MinQuantity;
                cartitem.MaxQuantity = _m.MaxQuantity;
                cartitem.Price = item.Price;
                cartitem.AvailableQuantity = _m.AvailableQuantity;
                cartitem.SubmitQuantity = ORD_OrderApplyBLL.GetSubmitQuantity(cart.Publish, cartitem.Product);

                cartitem.BookQuantity = item.BookQuantity;

                cart.Items.Add(cartitem);
            }

            return cart;
        }