public ActionResult Index(int page=1)
 {
     ViewBag.id = 4;
     List<NhomSanPham> nhomsp = null;
     List<HangSX> hangsx = null;
     String orderby = TextLibrary.ToString(front_timkiem_sanpham["front_orderby"]);
     Boolean desc = TextLibrary.ToBoolean(front_timkiem_sanpham["front_desc"]);
     if(!front_timkiem_sanpham["front_nhomsanpham_id"].Equals(""))
     {
         nhomsp = new List<NhomSanPham>();
         NhomSanPhamController ctr2 = new NhomSanPhamController(ctr._db);
         NhomSanPham tmp = ctr2.get_by_id(TextLibrary.ToInt(front_timkiem_sanpham["front_nhomsanpham_id"]));
         nhomsp = ctr2.get_tree2(tmp);
     }
     if(!front_timkiem_sanpham["front_hangsx_ten"].Equals(""))
     {
         hangsx = new List<HangSX>();
         HangSXController ctr3 = new HangSXController(ctr._db);
         hangsx=ctr3.timkiem("",TextLibrary.ToString(front_timkiem_sanpham["front_hangsx_ten"]),"1","id",false,0,-1);
     }
     //calculate offset
     if (TextLibrary.ToString(Request["front_current_page"]) != "") page = int.Parse(TextLibrary.ToString(Request["front_current_page"]));
     int max_item_per_page = TextLibrary.ToInt(this.front_timkiem_sanpham["front_max_item_per_page"]);
         int start_point = (page - 1) * max_item_per_page;
         if (start_point <= 0) start_point = 0;
     //get list
         List<SanPham> listnew = ctr.timkiem("", "", this.front_timkiem_sanpham["front_ten"], front_timkiem_sanpham["front_mota"],  TextLibrary.ToInt(front_timkiem_sanpham["front_gia_from"]),
             TextLibrary.ToInt(front_timkiem_sanpham["front_gia_to"]), hangsx, nhomsp , "1", orderby,desc, start_point, max_item_per_page);
         ViewBag.SanPham_List = listnew;
         ViewBag.front_timkiem_sanpham = this.front_timkiem_sanpham;
     //pagination
         int Current_Page = page;
      //   int Result_Count = listnew.Count;
         int Result_Count = ctr.timkiem_count(
             "",
             front_timkiem_sanpham["front_masp"],
             front_timkiem_sanpham["front_ten"],
             front_timkiem_sanpham["front_mota"],
             TextLibrary.ToInt(front_timkiem_sanpham["front_gia_from"]),
             TextLibrary.ToInt(front_timkiem_sanpham["front_gia_to"]), hangsx, nhomsp, "1");
         int Total_Page = (int)(Math.Ceiling((double)Result_Count / max_item_per_page));
         Boolean CanNextPage = Current_Page >= Total_Page ? false : true;
         Boolean CanPrevPage = Current_Page == 1 ? false : true;
         ViewBag.Result_Count = Result_Count;
         ViewBag.CanNextPage = CanNextPage;
         ViewBag.CanPrevPage = CanPrevPage;
         ViewBag.Current_Page = Current_Page;
         ViewBag.Total_page = Total_Page;
     return View();
 }
 public List<SanPham> timkiem_dequy(NhomSanPham root = null, String active = "", int start_point = 0, int count = -1)
 {
     List<SanPham> re = new List<SanPham>();
     NhomSanPhamController ctr=new NhomSanPhamController();
     List<NhomSanPham> list = ctr.get_tree2(root);
     re.AddRange(this.timkiem("","","","",0,0,null,list,active,"id",true,start_point,count));
     return re;
 }
        public ActionResult Index(int page = 1,int id_loaisp=0,int level_loaisp=0)
        {
            ViewBag.id = 2;
            NhomSanPhamController ctr2 = new NhomSanPhamController(ctr._db);
            List<NhomSanPham> loaisp_list = new List<NhomSanPham>();
            NhomSanPham2 loaisp = new NhomSanPham2();
            List<List<SanPham>> splist = new List<List<SanPham>>();
            if (id_loaisp == 0 || level_loaisp == 0 )
            {
                NhomSanPham tmp;
                if (id_loaisp != 0)
                {
                    tmp = ctr2.get_by_id(id_loaisp);
                    loaisp.Load_From(tmp);
                    loaisp.level = level_loaisp;
                    if (tmp.ds_nhomcon.Count == 0)
                    {
                        loaisp_list.Add(tmp);
                        splist.Add(ctr.timkiem("","","","",0,0,null,loaisp_list,"1","id",true,0,-1));
                    }
                    else
                    {
                        foreach (NhomSanPham item in tmp.ds_nhomcon)
                        {
                            loaisp_list.Add(item);
                            splist.Add(ctr.timkiem_dequy(item, "1", 0, 3));
                        }
                    }
                }
                else
                {
                    tmp = null; loaisp = null;
                    List<NhomSanPham2> loaisp_l = ctr2.get_tree(tmp, 0);
                    foreach (NhomSanPham2 item in loaisp_l)
                    {
                       // if ((loaisp != null && loaisp.id != item.id && item.level == 1) || (loaisp == null && item.level == 0))
                        if(item.level==0&&item.active==true)
                        {
                            NhomSanPham a = ctr2.get_by_id(item.id);
                            loaisp_list.Add(a);
                            splist.Add(ctr.timkiem_dequy(a, "1", 0, 3));
                        }

                    }

                }
                ViewBag.splist = splist;
                ViewBag.loaisp = loaisp;
                ViewBag.loaisp_list = loaisp_list;
            }
            else
            {
                String orderby = TextLibrary.ToString(front_sanpham["front_orderby"]);
                Boolean desc = TextLibrary.ToBoolean(front_sanpham["front_desc"]);
                NhomSanPham tmp = ctr2.get_by_id(id_loaisp);
                loaisp.Load_From(tmp);
                loaisp.level = level_loaisp;
                foreach(var item in ctr2.get_tree2(tmp))
                {
                    if (item.active == true)
                        loaisp_list.Add(item);
                }
                //calculate offset
                if (TextLibrary.ToString(Request["front_current_page"]) != "") page = int.Parse(TextLibrary.ToString(Request["front_current_page"]));
                int max_item_per_page = TextLibrary.ToInt(this.front_sanpham["front_max_item_per_page"]);
                int start_point = (page - 1) * max_item_per_page;
                if (start_point <= 0) start_point = 0;
                //get list
                List<SanPham> listnew = ctr.timkiem("", "", "", "", -1, -1, null, loaisp_list, "1", orderby, desc, start_point, max_item_per_page);
                ViewBag.SanPham_List = listnew;
                ViewBag.front_sanpham = this.front_sanpham;
                ViewBag.loaisp = loaisp;
                //pagination
                int Current_Page = page;
                //   int Result_Count = listnew.Count;
                int Result_Count = ctr.timkiem_count("", "", "", "", -1, -1, null, loaisp_list, "1");
                int Total_Page = (int)(Math.Ceiling((double)Result_Count / max_item_per_page));
                Boolean CanNextPage = Current_Page >= Total_Page ? false : true;
                Boolean CanPrevPage = Current_Page == 1 ? false : true;
                ViewBag.Result_Count = Result_Count;
                ViewBag.CanNextPage = CanNextPage;
                ViewBag.CanPrevPage = CanPrevPage;
                ViewBag.Current_Page = Current_Page;
                ViewBag.Total_page = Total_Page;
            }
            return View();
        }
        public ActionResult Index(int page=1)
        {
            //check
            if (!this._nhanvien_permission.Contains("sanpham_view"))
            {
                return this._fail_permission("sanpham_view");
            }
            SanPhamController ctr = new SanPhamController();
            NhomSanPhamController ctr_nhom = new NhomSanPhamController();
            HangSXController ctr_hangsx = new HangSXController();
            List<HangSX> hangsx_list = ctr_hangsx.timkiem(timkiem_sanpham["hangsx_id"]);
            NhomSanPham nhom_obj = ctr_nhom.get_by_id(TextLibrary.ToInt(timkiem_sanpham["nhomsanpham_id"]));
            List<NhomSanPham> nhomsanpham_list = ctr_nhom.get_tree2(nhom_obj);
            //pagination
                int max_item_per_page = TextLibrary.ToInt(this.timkiem_sanpham["max_item_per_page"]);
                Pagination pg = new Pagination();
                pg.set_current_page(page);
                pg.set_max_item_per_page(max_item_per_page);
                pg.set_total_item(
                    ctr.timkiem_count(
                        timkiem_sanpham["id"],
                        timkiem_sanpham["masp"],
                        timkiem_sanpham["ten"],
                        "",
                        TextLibrary.ToInt(timkiem_sanpham["gia_from"]),
                        TextLibrary.ToInt(timkiem_sanpham["gia_to"]),
                        hangsx_list, nhomsanpham_list, timkiem_sanpham["active"]
                        )
                    );
                pg.update();
            //Chọn danh sách nhân viên để hiển thị theo cookies tìm kiếm

            ViewBag.SanPham_List = ctr.timkiem(
                timkiem_sanpham["id"],
                timkiem_sanpham["masp"],
                timkiem_sanpham["ten"],
                "",
                TextLibrary.ToInt( timkiem_sanpham["gia_from"]),
                TextLibrary.ToInt(timkiem_sanpham["gia_to"]),
                hangsx_list, nhomsanpham_list, timkiem_sanpham["active"], timkiem_sanpham["order_by"], TextLibrary.ToBoolean(timkiem_sanpham["order_desc"]), pg.start_point, max_item_per_page
                );
            //set search cookies
            ViewBag.timkiem_sanpham = this.timkiem_sanpham;
            ViewBag.Title += " - Quản lý";
            ViewBag.pagination = pg;
            ViewBag.NhomSanPham2_List = ctr_nhom.timkiem();
            ViewBag.HangSX_List = ctr_hangsx.timkiem();
            return View();
        }