public static Common.DB.ResultList GetList(Common.DB.NVCollection queryParams)
{
//string pageString = queryParams["page"] as string ?? "1";
//string psString = queryParams["pagesize"] as string ?? string.Empty;
//string cidString = queryParams["cid"] as string ?? string.Empty;
string sort = queryParams["sort"] as string ?? string.Empty;
string cate = queryParams["cate"] as string ?? string.Empty;
string type = queryParams["type"] as string ?? string.Empty;
string ch = queryParams["ch"] as string ?? string.Empty;
string kind = queryParams["kind"] as string ?? string.Empty;
string andwhere = "1=1";
string rootKey = null;
switch (type)
{
case "appsoft":
rootKey = "iphones";
break;
case "appgame":
rootKey = "iphoneg";
break;
case "azsoft":
rootKey = "soft";
break;
case "azgame":
rootKey = "game";
break;
}
var pnvc = new Common.DB.NVCollection();
if (rootKey != null)
{
var pcate = DBCache.SoftCategoryCache.Get(rootKey);
if (pcate != null)
{
andwhere += " and charIndex(@path,categoryPath)>0 ";
pnvc["path"] = "/" +
pcate.ID + "/";
}
}
if (ch == "az")
{
andwhere += " and (charIndex(@path1,categoryPath)>0 or charIndex(@path2,categoryPath)>0)";
pnvc["path1"] = "/" + DBCache.SoftCategoryCache.Get("game").ID + "/";
pnvc["path2"] = "/" + DBCache.SoftCategoryCache.Get("soft").ID + "/";
}
else if (ch == "app")
{
andwhere += " and (charIndex(@path1,categoryPath)>0 or charIndex(@path2,categoryPath)>0)";
pnvc["path1"] = "/" + DBCache.SoftCategoryCache.Get("appgame").ID + "/";
pnvc["path2"] = "/" + DBCache.SoftCategoryCache.Get("appsoft").ID + "/";
}
if (!string.IsNullOrEmpty(cate) && !string.IsNullOrEmpty(rootKey))
{
var cateEnt = DBCache.SoftCategoryCache.Get(rootKey, cate);
if (cateEnt != null)
{
andwhere += " and categoryid=@cid ";
pnvc["cid"] =
cateEnt.ID;
}
}
int cid = (queryParams["cid"] as int?) ?? 0;
if (cid > 0)
{
var cateEnt = DBCache.SoftCategoryCache.Get(cid);
if (cateEnt != null)
{
andwhere += " and categoryid=@cid ";
pnvc["cid"] =
cateEnt.ID;
}
}
string orderby = " id desc";
switch (sort)
{
case "new":
orderby = " id desc";
break;
case "hot":
orderby = " viewTimes desc,id desc";
break;
case "rank":
orderby = " downWeekTimes desc,id desc";
break;
default:
break;
}
switch (kind)
{
case "number":
andwhere += " and number>0";
orderby = " number desc,id desc ";
break;
case "hprec":
andwhere += " and recommend=1 and homepage=1 and number=0 ";
orderby = " viewtimes desc,id desc ";
break;
case "recnothp":
andwhere += " and recommend=1 and homepage=0 and number=0 ";
orderby = " viewtimes desc,id desc ";
break;
case "rec":
andwhere += " and recommend=1 ";
break;
case "all":
break;
case "normal":
default:
andwhere += " and recommend=0 and homepage=0 and number=0 ";
//orderby = " id desc ";
break;
}
int page = (queryParams["page"] as int?) ?? 1;
if (page <= 0)
{
page = 1;
}
int pagesize = (queryParams["pagesize"] as int?) ?? 10;
if (pagesize <= 0)
{
pagesize = 10;
}
Common.DB.ResultList result = new Common.DB.ResultList(pagesize);
var dbh = Common.DB.Factory.Default;
//List<Common.DB.NVCollection> list = new List<Common.DB.NVCollection>(pagesize);
var query = Common.DB.Factory.DefaultPagerQuery;
query.AbsolutePage = page;
query.Fields = "id,name,version,viewtimes,categoryid";
query.PageSize = pagesize;
query.Sort = orderby;
query.Table = "soft";
query.Where = andwhere;
string csql = query.GetCountQueryString();
string qsql = query.GetQueryString();
int rc = dbh.ExecuteScalar<int>(csql, pnvc);
var ls = dbh.GetDataList(qsql, pnvc);
int pc = Convert.ToInt32(Math.Ceiling((decimal)rc / (decimal)pagesize));
result.Page = page;
result.PageCount = pc;
result.RecordCount = rc;
result.PageSize = pagesize;
for (int i = 0; i < ls.Count; i++)
{
var o = ls[i];
var ent = new Common.DB.NVCollection();
var entcate = DBCache.SoftCategoryCache.Get((int)o["categoryid"]);
ent["id"] = o["id"];
ent["name"] = o["name"];
ent["version"] = o["version"];
ent["cid"] = o["categoryid"];
ent["cpath"] = Services.PathService.GetListPath(entcate);
ent["cname"] =
entcate.Name;
ent["path"] = Services.PathService.GetPath(entcate, (int)o["id"]);
ent["dtimes"] = o["viewtimes"];
result.Add(ent);
}
return result;
}