using System;
using System.Web.UI.WebControls;
using TopWinCMS.BLL;
using TopWinCMS.Common;

namespace TopWinCMS.WebUI.Admin.Shop
{
    public partial class PriceChanges : System.Web.UI.Page
    {
        PriceChangesManage MyClassBLL = new PriceChangesManage();
        SQLModel s_model = new SQLModel();
        int ModelID ;
        protected void Page_Load(object sender, EventArgs e)
        {
            ModelID = int.Parse(Request.QueryString["ModelID"]);
            if (!IsPostBack)
            {

                BindList();
            }
        }
        private void BindList()
        {
            string strPath = string.Format("{0} → 订单管理 → <a href='PriceChanges.aspx?ModelID={1}'>订单价格修改记录</a>",
               ModelManage.GetModelName(ModelID),
               ModelID 
               );

            LB_Path.Text = strPath;

            GV_List.EmptyDataTemplate = TopWinCMS.WebFactory.PageBase.GetTemplate(this);
            s_model.Fields = "*";
            s_model.TableName = "TopWinCMS_PriceChanges";
            s_model.OrderField = "ID Desc";


            s_model.PageSize = 15;

            MyClassBLL.BindList(GV_List, PageNavigation1, s_model);

            if (GV_List.Rows.Count <= 0)
            {
                BT_DelSeletedID.Enabled = false;
            }
        }



        protected void GV_List_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            MyClassBLL.Delete(GV_List.DataKeys[e.RowIndex].Value.ToString(), UpdatePanel1);
            BindList();
        }

        protected void PageNavigation1_PageChanging(object src, TopWinCMS.WebControls.PageChangingEventArgs e)
        {
            s_model.PageNo = e.NewPageIndex;
            BindList();
        }

        protected void BT_DelSeletedID_Click(object sender, EventArgs e)
        {
            MyClassBLL.Delete(GetSelectedRow.IDs(GV_List), UpdatePanel1);
            BindList();
        }

        protected void GV_List_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                TableCell myTableCell = e.Row.Cells[GV_List.Columns.Count - 1];
                if (myTableCell.Controls.Count > 0)
                {
                    LinkButton btnDel = (LinkButton)myTableCell.Controls[0];

                    //if 
                    //{
                    btnDel.Attributes.Add("onclick", "return confirm('您确定要删除？');");
                    //}
                    //else
                    //{
                    //    btnDel.Attributes.Add("onclick", "alert('您没有删除权限？');return false");
                    //}

                }
            }
        }

        protected void BT_Search_Click(object sender, EventArgs e)
        {
            s_model.WHERE = "OderNum='" + MyString.SQL_ESC(TB_KeyWord.Text.Trim()) + "'";
            s_model.PageNo = 1;
            BindList();
        }
    }
}
