/// <summary>
 /// 根据ID得到运送方式的名字
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 protected string GetDeliverById(int id)
 {
     ShowShop.BLL.Product.Deliver bll = new ShowShop.BLL.Product.Deliver();
     ShowShop.Model.Product.Deliver model = bll.GetModelByID(id);
     if (model != null)
     {
         return model.Name.ToString();
     }
     else
     {
         return "无该运送方式名称";
     }
 }
 /// <summary>
 /// 列表
 /// </summary>
 /// <returns></returns>
 protected string GetList()
 {
     ChangeHope.WebPage.Table table = new ChangeHope.WebPage.Table();
     ShowShop.BLL.Product.Deliver bll = new ShowShop.BLL.Product.Deliver();
     ChangeHope.DataBase.DataByPage dataPage = bll.GetList();
     //第一步先添加表头
     table.AddHeadCol("", "序号");
     table.AddHeadCol("", "名称");
     table.AddHeadCol("", "是否使用");
     table.AddHeadCol("", "优先级");
     table.AddHeadCol("", "起点价格(元/千克)");
     table.AddHeadCol("", "起点重量(单位:千克)");
     table.AddHeadCol("", "会员类型");
     table.AddHeadCol("", "操作");
     table.AddRow();
     //添加表的内容
     if (dataPage.DataReader != null)
     {
         int curpage = ChangeHope.WebPage.PageRequest.GetInt("pageindex");
         if (curpage < 0)
         {
             curpage = 1;
         }
         int count = 0;
         while (dataPage.DataReader.Read())
         {
             count++;
             string No = (15 * (curpage - 1) + count).ToString();
             table.AddCol(No);
             table.AddCol(dataPage.DataReader["name"].ToString());
             table.AddCol(string.Format("<img src='../images/{0}.gif' style=\"cursor:pointer;\" onclick='SetIsUser({1})' alt='点击改变状态'/>", dataPage.DataReader["isused"].ToString(), dataPage.DataReader["id"].ToString()));
             table.AddCol(string.Format("<input id='txtSort{0}' value='{1}' size='5' onblur='SetSort({0})'/>", dataPage.DataReader["id"].ToString(), dataPage.DataReader["sort"].ToString()));
             table.AddCol(dataPage.DataReader["inceptprice"].ToString());
             table.AddCol(dataPage.DataReader["inceptweight"].ToString());
             table.AddCol(dataPage.DataReader["putouttyid"].ToString()=="1"?"普通会员":"管理员");
             table.AddCol(string.Format("<a href=deliver_edite.aspx?id={0}>编辑</a> <a href='javascript:void(0)' onclick='Del({0})'>删除</a>", dataPage.DataReader["id"].ToString()));
             table.AddRow();
         }
     }
     string view = table.GetTable() + dataPage.PageToolBar;
     dataPage.Dispose();
     dataPage = null;
     return view;
 }
 protected void lbtnSave_Click(object sender, EventArgs e)
 {
     //try
     //{
         ShowShop.BLL.Product.Deliver bll = new ShowShop.BLL.Product.Deliver();
         ShowShop.Model.Product.Deliver model = new ShowShop.Model.Product.Deliver();
         if (!ChangeHope.Common.ValidateHelper.IsMoney(txtInceptPrice.Text) || !ChangeHope.Common.ValidateHelper.IsNumber(txtInceptWeight.Text) || !ChangeHope.Common.ValidateHelper.IsMoney(txtAddPricelAdder.Text) || !ChangeHope.Common.ValidateHelper.IsMoney(txtAddWeightlAdder.Text) || !ChangeHope.Common.ValidateHelper.IsNumber(txtBoundU1.Text) || !ChangeHope.Common.ValidateHelper.IsNumber(txtBoundD1.Text) || !ChangeHope.Common.ValidateHelper.IsMoney(txtBoundP1.Text))
         {
             this.ltlMsg.Text = "操作失败,请输入正确的价格或者数字";
             this.pnlMsg.Visible = true;
             this.pnlMsg.CssClass = "actionErr";
             return;
         }
         if (float.Parse(txtInceptPrice.Text) <= 0 || float.Parse(txtInceptWeight.Text) <= 0 || float.Parse(txtAddPricelAdder.Text) <= 0 || float.Parse(txtAddWeightlAdder.Text) <= 0 || float.Parse(txtBoundU1.Text) <= 0 || float.Parse(txtBoundD1.Text) <= 0 || float.Parse(txtBoundP1.Text)<=0 )
         {
             this.ltlMsg.Text = "操作失败,价格与重量数不能小于或者等于0";
             this.pnlMsg.Visible = true;
             this.pnlMsg.CssClass = "actionErr";
             return;
         }
         model.Name = this.txtName.Text.Trim();
         model.InceptPrice = Convert.ToDecimal(this.txtInceptPrice.Text.Trim());
         model.InceptWeight = Convert.ToDecimal(this.txtInceptWeight.Text.Trim());
         model.ArrivePay = Convert.ToInt32(this.rblArrivePay.SelectedValue);
         model.Description = this.txtDescription.Text.Trim();
         model.AddPriceLadder = Convert.ToDecimal(this.txtAddPricelAdder.Text.Trim());
         model.AddWeightLadder = Convert.ToDecimal(this.txtAddWeightlAdder.Text.Trim());
         model.BoundPrice = GetBoundPrice();
         model.IsSpecial = Convert.ToInt32(this.rblIsSpecial.SelectedValue);
         model.IsUsed = Convert.ToInt32(this.rblisused.SelectedValue);
         model.Sort = Convert.ToInt32(this.txtSort.Text.Trim());
         if (ViewState["ID"] != null)//更新
         {
             model.ID = Convert.ToInt32(ViewState["ID"].ToString());
             model.PutoutId = Convert.ToInt32(ViewState["PutoutID"]);
             model.PutouttyId = Convert.ToInt32(ViewState["PutoutTyID"]);
             bll.Amend(model);
         }
         else//添加
         {
             ShowShop.Model.Admin.AdminInfo adminModel = (ShowShop.Model.Admin.AdminInfo)ShowShop.Common.AdministrorManager.Get();
             //管理员ID
             model.PutoutId = adminModel.AdminId;
             model.PutouttyId = 0;
             bll.Add(model);
         }
         this.ltlMsg.Text = "操作成功,已保存该信息";
         this.pnlMsg.Visible = true;
         this.pnlMsg.CssClass = "actionOk";
     //}
     //catch
     //{
     //    this.ltlMsg.Text = "操作失败,请查看数据格式是否符合要求";
     //    this.pnlMsg.Visible = true;
     //    this.pnlMsg.CssClass = "actionErr";
     //}
 }
        /// <summary>
        /// 显示编辑信息
        /// </summary>
        /// <param name="id"></param>
        protected void BandInfo(int id)
        {
            ShowShop.BLL.Product.Deliver bll = new ShowShop.BLL.Product.Deliver();
            ShowShop.Model.Product.Deliver model = bll.GetModelByID(id);
            this.txtName.Text = model.Name;
            this.txtInceptPrice.Text = model.InceptPrice.ToString();
            this.txtInceptWeight.Text = model.InceptWeight.ToString();
            this.rblArrivePay.SelectedValue = model.ArrivePay.ToString();
            this.txtDescription.Text = model.Description;
            this.txtAddPricelAdder.Text = model.AddPriceLadder.ToString();
            this.txtAddWeightlAdder.Text = model.AddWeightLadder.ToString();
            this.rblIsSpecial.SelectedValue = model.IsSpecial.ToString();
            this.rblisused.SelectedValue = model.IsUsed.ToString();
            this.txtSort.Text = model.Sort.ToString();
            string[] str = model.BoundPrice.Split('|');
            for (int i = 0; i < str.Length; i++)
            {
                if (i == 0)
                {
                    string[] arr0 = str[i].Split(',');
                    for (int j = 0; j < arr0.Length; j++)
                    {
                        this.txtBoundU1.Text = arr0[0];
                        this.txtBoundD1.Text = arr0[1];
                        this.txtBoundP1.Text = arr0[2];
                    }
                }
                else if(i==1)
                {
                    string[] arr1 = str[i].Split(',');
                    for (int j = 0; j < arr1.Length; j++)
                    {
                        this.txtBoundU2.Text = arr1[0];
                        this.txtBoundD2.Text = arr1[1];
                        this.txtBoundP2.Text = arr1[2];
                    }
                }
                else if (i == 2)
                {
                    string[] arr2 = str[i].Split(',');
                    for (int j = 0; j < arr2.Length; j++)
                    {
                        this.txtBoundU3.Text = arr2[0];
                        this.txtBoundD3.Text = arr2[1];
                        this.txtBoundP3.Text = arr2[2];
                    }
                }
                else if (i == 3)
                {
                    string[] arr3 = str[i].Split(',');
                    for (int j = 0; j < arr3.Length; j++)
                    {
                        this.txtBoundU4.Text = arr3[0];
                        this.txtBoundD4.Text = arr3[1];
                        this.txtBoundP4.Text = arr3[2];
                    }
                }
            }

            ViewState["ID"] = model.ID.ToString();
            ViewState["PutoutID"] = model.PutoutId.ToString();
            ViewState["PutoutTyID"] = model.PutouttyId.ToString();
        }
 /// <summary>
 /// 调整是否使用
 /// </summary>
 /// <param name="id"></param>
 private void SetUse(int id)
 {
     ShowShop.BLL.Product.Deliver bll = new ShowShop.BLL.Product.Deliver();
     ShowShop.Model.Product.Deliver model = bll.GetModelByID(id);
     if (model.IsUsed == 0)
     {
         bll.Amend(id, "isused", 1);
         Response.Write("ok");
     }
     else
     {
         bll.Amend(id, "isused", 0);
         Response.Write("ok");
     }
 }
 /// <summary>
 /// 修改优先级
 /// </summary>
 /// <param name="id"></param>
 /// <param name="sort"></param>
 private void SetSort(int id, int sort)
 {
     ShowShop.BLL.Product.Deliver bll = new ShowShop.BLL.Product.Deliver();
     bll.Amend(id, "sort", sort);
     Response.Write("ok");
 }
 /// <summary>
 /// 删除
 /// </summary>
 /// <param name="id"></param>
 private void Del(string id)
 {
     ShowShop.BLL.Product.Deliver bll = new ShowShop.BLL.Product.Deliver();
         bll.Delete(id);
         Response.Write("ok");
 }
 protected void DeliverBind()
 {
     ShowShop.BLL.Product.Deliver bll = new ShowShop.BLL.Product.Deliver();
     List<ShowShop.Model.Product.Deliver> list = bll.GetAll();
     this.ddlDeliver.DataSource = list;
     this.ddlDeliver.DataTextField = "Name";
     this.ddlDeliver.DataValueField = "ID";
     this.ddlDeliver.DataBind();
 }