using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Mall
{
   
    public partial class List : System.Web.UI.Page
    {

        public string str_daohang = string.Empty;
        public string html_str_newsmcview_left_his = string.Empty;
        public string str_html_left_class_list = string.Empty;
        public string str_html_left_allclass = string.Empty;
        public MODEL.MAD modelad = new MODEL.MAD();
        public System.Data.DataTable dt = new System.Data.DataTable();
        public string keyword = string.Empty;
        public string pagesize = "12";
        public string start = "0";
        public string endid = "0";
        public string fiter = "";
        public string countt = "0";//总条数
        public string page = "0";//当前页码
        public string id = string.Empty;
        public string action = string.Empty;
        public string pagecount = "0";
            
        protected void Page_Load(object sender, EventArgs e)
        {
             id = Request["id"] == null ? string.Empty : Request["id"].ToString();
             action = Request["action"] == null ? string.Empty : Request["action"].ToString();
            //取得当前id路径
            #region-------获得导航--------
            BLL.Models.MClassModels model_class = new BLL.Models.MClassModels();
            str_daohang = string.IsNullOrEmpty(id) == true ? "<A class=hp href='/'>首页</A>" : model_class.GetPathById(id);
            #endregion--------------------
            #region------左边导航上-------
            string lastview = Request.Cookies["lastview"] == null ? "" : Request.Cookies["lastview"].ToString();
            BLL.Models.ProductModels modelss_product = new BLL.Models.ProductModels();
            html_str_newsmcview_left_his = modelss_product.GetProductHisLeft(7, lastview);
            str_html_left_class_list = model_class.GetListClassInfo(id);
            str_html_left_allclass = model_class.GetListClassAll();
            #endregion------------------
            #region------头部广告处理---------
            string str_htm_topad = string.Empty;
            BLL.Models.MAdModels models_ad = new BLL.Models.MAdModels();
            
            modelad = models_ad.GetListAd();
            #endregion-----------------------
            #region------分页数据处理------

            page = Request["page"] == null ? "1" : Request["page"].ToString();
            keyword = Request["keyword"] == null ? string.Empty : Request["keyword"].ToString();
            BLL.Models.ProductModels pmodels = new BLL.Models.ProductModels();
            start = Convert.ToString(Convert.ToInt32(page) * Convert.ToInt32(pagesize) - Convert.ToInt32(pagesize));
            if (page == "1")
            {

                start = "0";
            }

            ///查询分类
            if (!string.IsNullOrEmpty(id))
            {

                fiter = fiter + " and classid in (" + model_class.GetIdList(id) + ") ";

            }
            if (!string.IsNullOrEmpty(keyword))
            {

                fiter = fiter + " and productname like '%" + keyword + "%' ";
            }
            //排序
            //排序
            string sorder = "";
            switch (action)
            {
                case "new":
                    sorder = "order by id desc";
                    break;
                case "hot":
                    sorder = "order by buycount desc,id desc";
                    break;
                case "tejia":
                    sorder = "order by price asc ,id desc";
                    break;
                default:
                    sorder = " order by id desc ";
                    break;
            }
            dt = pmodels.GetProductList(start, ref countt, sorder, fiter, pagesize);
            
            pagecount = Convert.ToInt32(countt) % Convert.ToInt32(pagesize) == 0 ? (Convert.ToInt32(countt) / Convert.ToInt32(pagesize)).ToString() : (Convert.ToInt32(countt) / Convert.ToInt32(pagesize)) < 1 ? "1" : (Convert.ToInt32(countt) / Convert.ToInt32(pagesize) + 1).ToString();

            #endregion----------------------
        }
    }
}