更新日志:
1、完善 HQL 數據查詢(增加流式查詢)功能,支持對指定字段進行查詢。
例如:讀取文章表的標題與發布日期字段列,並按發布日期進行降序排列(程序自行轉換為對應實體)。
第一種:手寫配置
var queryBuilder =
new HQLEntityQueryBuilder(
"
ArticleEntity
")
.SetSelects( " Title,Pubdate ")
.SetOrders( " Pubdate ").SetOrderby(DataOrderby.Desc);
.SetSelects( " Title,Pubdate ")
.SetOrders( " Pubdate ").SetOrderby(DataOrderby.Desc);
第二種:Lambda 表達式配置
var queryBuilder =
new HQLEntityQueryBuilder<ArticleEntity>()
.SetSelect(a => a.Title).SetSelect(a => a.Pubdate)
.SetOrder(a => a.Pubdate).SetOrderby(DataOrderby.Desc);
.SetSelect(a => a.Title).SetSelect(a => a.Pubdate)
.SetOrder(a => a.Pubdate).SetOrderby(DataOrderby.Desc);
執行查詢,並輸出列表
//
輸出列表
WriteList(ArticleBll.TopList( 6, queryBuilder));
WriteList(ArticleBll.TopList( 6, queryBuilder));
運行效果
分頁數據效果
2、支持多表關聯查詢
例如:讀取文章表的標題、序號與文章統計表的瀏覽次數字段列,並按瀏覽次數進行降序排列。
var queryBuilder =
new HQLEntityQueryBuilder<ArticleEntity>()
.SetSelects( " Title,Articleid,View.Count ")
.SetOrders( " View.Count ").SetOrderby(DataOrderby.Desc);
.SetSelects( " Title,Articleid,View.Count ")
.SetOrders( " View.Count ").SetOrderby(DataOrderby.Desc);
執行查詢,並輸出列表
//
獲取前2條數據
var list2 = ArticleBll.TopList( 2, queryBuilder);
// 獨立輸出
list2.TryEach((i2, li2) =>
{
if (i2 == list2.Count - 1)
Response.TestParagraphLine( " 標題 / 編號 / 人氣 ", li2.Title + " / " + li2.Articleid + " / " + li2.View.Count);
else
Response.TestLine( " 標題 / 編號 / 人氣 ", li2.Title + " / " + li2.Articleid + " / " + li2.View.Count);
});
var list2 = ArticleBll.TopList( 2, queryBuilder);
// 獨立輸出
list2.TryEach((i2, li2) =>
{
if (i2 == list2.Count - 1)
Response.TestParagraphLine( " 標題 / 編號 / 人氣 ", li2.Title + " / " + li2.Articleid + " / " + li2.View.Count);
else
Response.TestLine( " 標題 / 編號 / 人氣 ", li2.Title + " / " + li2.Articleid + " / " + li2.View.Count);
});
運行效果
3、前台呈現(結合 jQuery、jQuery-UI 實現異步讀取,異步分頁等效果;瀏覽器為IE9)
<div>
<!-- UL/LI -->
<ul id= " first_test " class= " list ">
<li><h3 style= " display:inline; ">這是標題</h3><span style= " margin-left:10px; ">這是時間</span></li>
</ul>
<script type= " text/javascript ">
function firstRenderListTest(i, entity) {
var demo = ' <li> ';
demo += ' <h3 style="display:inline;"> ' + entity.Title + ' </h3> ';
demo += ' <span style="margin-left:10px;"> ' + entity.Pubdate + ' </span> ';
demo += ' </li> ';
return demo;
};
var selects = " Title,Pubdate ";
var orders = " Pubdate ";
$( " #first_test ").dataList( " ArticleEntity ",
{ size: 6, selects: selects, orders: orders /* ,orderby: "desc/asc"(默認為倒序) */ },
firstRenderListTest);
</script>
</div>
<!-- UL/LI -->
<ul id= " first_test " class= " list ">
<li><h3 style= " display:inline; ">這是標題</h3><span style= " margin-left:10px; ">這是時間</span></li>
</ul>
<script type= " text/javascript ">
function firstRenderListTest(i, entity) {
var demo = ' <li> ';
demo += ' <h3 style="display:inline;"> ' + entity.Title + ' </h3> ';
demo += ' <span style="margin-left:10px;"> ' + entity.Pubdate + ' </span> ';
demo += ' </li> ';
return demo;
};
var selects = " Title,Pubdate ";
var orders = " Pubdate ";
$( " #first_test ").dataList( " ArticleEntity ",
{ size: 6, selects: selects, orders: orders /* ,orderby: "desc/asc"(默認為倒序) */ },
firstRenderListTest);
</script>
</div>
頁面預覽效果
異步分頁
<div id=
"
tabs-1
">
<ul id= " four_test " class= " list ">
<li><h3 style= " display:inline; ">這是標題</h3><span style= " margin-left:10px; ">這是時間</span></li>
</ul>
<div id= " four_paging ">
Loading...
</div>
<script type= " text/javascript ">
function fourRenderListTest(i, entity) {
var demo = ' <li> ';
demo += ' <h3 style="display:inline;"> ' + entity.Title + ' </h3> ';
demo += ' <span style="margin-left:10px;"> ' + entity.Pubdate + ' </span> ';
demo += ' </li> ';
return demo;
};
function fourPagingList(index) {
var entityName = " ArticleEntity ";
var selects = " Title,Pubdate ";
// var wheres = [{ Key: "Articleid", Value: "1", Type: "int", Compare: "Equals"}];
var orders = " Pubdate ";
var options = {
size: 6, index: index, selects: selects, orders: orders, paging: " true " // , wheres: wheres
};
// 數據列表
$( " #four_test ").dataList(entityName, options, fourRenderListTest);
// 分頁
$( " #four_paging ").paging(entityName, options, function (i) {
return " javascript:fourPagingList( " + i + " ); ";
});
};
fourPagingList( 1);
</script>
</div>
<ul id= " four_test " class= " list ">
<li><h3 style= " display:inline; ">這是標題</h3><span style= " margin-left:10px; ">這是時間</span></li>
</ul>
<div id= " four_paging ">
Loading...
</div>
<script type= " text/javascript ">
function fourRenderListTest(i, entity) {
var demo = ' <li> ';
demo += ' <h3 style="display:inline;"> ' + entity.Title + ' </h3> ';
demo += ' <span style="margin-left:10px;"> ' + entity.Pubdate + ' </span> ';
demo += ' </li> ';
return demo;
};
function fourPagingList(index) {
var entityName = " ArticleEntity ";
var selects = " Title,Pubdate ";
// var wheres = [{ Key: "Articleid", Value: "1", Type: "int", Compare: "Equals"}];
var orders = " Pubdate ";
var options = {
size: 6, index: index, selects: selects, orders: orders, paging: " true " // , wheres: wheres
};
// 數據列表
$( " #four_test ").dataList(entityName, options, fourRenderListTest);
// 分頁
$( " #four_paging ").paging(entityName, options, function (i) {
return " javascript:fourPagingList( " + i + " ); ";
});
};
fourPagingList( 1);
</script>
</div>
頁面預覽效果
第二頁異步加載效果
異步加載完成效果
多表關聯查詢
<div id=
"
tabs-2
">
<dl id= " five_test " class= " list ">
<dd><h3 style= " display:inline; ">這是標題</h3><span style= " margin-left:10px; ">這是瀏覽次數</span></dd>
</dl>
<script type= " text/javascript ">
function fiveRenderListTest(i, entity) {
var demo = ' <li> ';
demo += ' <h3 style="display:inline;"> ' + entity.Title + ' </h3> ';
demo += ' <span style="margin-left:10px;"> ' + entity.View.Count + ' </span> ';
demo += ' </li> ';
return demo;
};
var selects = " Title,View.Count ";
var orders = " View.Count ";
$( " #five_test ").dataList( " ArticleEntity ",
{ size: 2, selects: selects, orders: orders },
fiveRenderListTest);
</script>
</div>
<dl id= " five_test " class= " list ">
<dd><h3 style= " display:inline; ">這是標題</h3><span style= " margin-left:10px; ">這是瀏覽次數</span></dd>
</dl>
<script type= " text/javascript ">
function fiveRenderListTest(i, entity) {
var demo = ' <li> ';
demo += ' <h3 style="display:inline;"> ' + entity.Title + ' </h3> ';
demo += ' <span style="margin-left:10px;"> ' + entity.View.Count + ' </span> ';
demo += ' </li> ';
return demo;
};
var selects = " Title,View.Count ";
var orders = " View.Count ";
$( " #five_test ").dataList( " ArticleEntity ",
{ size: 2, selects: selects, orders: orders },
fiveRenderListTest);
</script>
</div>
頁面預覽效果
瀏覽器兼容性測試(Google Chrome 17.0.963.78)
更換主題效果
Librame Utility 開源項目組(http://librame.codeplex.com/)