using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TopWinCMS.BLL;
using System.Data;

namespace TopWinCMS.WebUI.Admin.Shop
{
    public partial class GoodsRank : System.Web.UI.Page
    {
        int ModelID;
        protected void Page_Load(object sender, EventArgs e)
        {
            ModelID = int.Parse(Request.QueryString["ModelID"]);
            if (!IsPostBack)
            {
                LB_Path.Text = string.Format("{0} → 销售 → <a href='GoodsRank.aspx?ModelID={1}'>销售统计/排行</a>", ModelManage.GetModelName(ModelID), ModelID);
                BindList(0);
            }
        }

        private void BindList(int Type)
        {
            GV_List.EmptyDataTemplate = TopWinCMS.WebFactory.PageBase.GetTemplate(this);
            new OrderListManage().Rank(GV_List, Type);
        }

        protected void DDL_Total_SelectedIndexChanged(object sender, EventArgs e)
        {
            BindList(int.Parse(DDL_Total.SelectedValue));

        }
        decimal sumX = 0;
        decimal sumY = 0;
        protected void GV_List_RowDataBound(object sender, GridViewRowEventArgs e)
        {

            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                DataRowView myrows = (DataRowView)e.Row.DataItem;
                sumX += decimal.Parse(myrows[2].ToString());
                sumY += decimal.Parse(myrows[3].ToString());
            }
            // 合计
            if (e.Row.RowType == DataControlRowType.Footer)
            {
                e.Row.Cells[2].Text = "合计";
                e.Row.Cells[2].HorizontalAlign = HorizontalAlign.Center;

                e.Row.Cells[3].Text = sumX.ToString();
                e.Row.Cells[3].HorizontalAlign = HorizontalAlign.Right;

                e.Row.Cells[4].Text = sumY.ToString("C");
                e.Row.Cells[4].HorizontalAlign = HorizontalAlign.Right;


            }
        }
    }
}
