abp(net core)+easyui+efcore實現倉儲管理系統——建立應用服務(五)html
abp(net core)+easyui+efcore實現倉儲管理系統——EasyUI前端頁面框架 (十八) 前端
十六、查詢組織信息算法
1. 在Visual Studio 2017的「解決方案資源管理器」中,右鍵單擊在領域層「ABP.TPLMS.Web.Mvc」項目中的Views\Orgs目錄。 找到Index.cshmtl文件,添加一個查詢條件相關代碼。以下圖。json
具體代碼以下:
瀏覽器
<div id="dg-button"> <form name="searchform" method="post" action="" id="searchform"> <label for="Name">組織名稱:</label> <input name="Name" id="Name" class="easyui-validatebox" data-options="width:200" /> <label for="Code">組織代碼:</label> <input name="Code" id="Code" class="easyui-validatebox" data-options="width:150" /> <label for="CustomCode">海關代碼:</label> <input name="CustomCode" id="CustomCode" class="easyui-validatebox" data-options="width:100" /> <a href="#" id="search" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="Search()">查詢</a> </form> </div>
2.在Visual Studio 2017的「解決方案資源管理器」中,右鍵單擊「ABP.TPLMS.Application」項目的 「Orgs」文件夾中,找到Paged OrgResultRequestDto.cs文件,添加查詢條件屬性。代碼以下。
框架
public class PagedOrgResultRequestDto : PagedResultRequestDto { public string Keyword { get; set; } public string OrgName { get; set; } public string OrgCode { get; set; } public string CustomCode { get; set; } } }
3. 在Visual Studio 2017的「解決方案資源管理器」中,右鍵單擊在領域層「ABP.TPLMS.Web.Mvc」項目中的Controller目錄。找到「OrgsController.cs」文件。以下圖。ide
具體代碼以下:
工具
[DontWrapResult] [HttpPost] public string List() { PagedOrgResultRequestDto paged = new PagedOrgResultRequestDto(); paged.MaxResultCount = MAX_COUNT; paged.OrgName = Request.Form["Name"].ToString(); paged.OrgCode = Request.Form["Code"].ToString(); paged.CustomCode = Request.Form["CustomCode"].ToString(); var userList = _orgAppService.GetAll(paged).GetAwaiter().GetResult().Items; int total = userList.Count; var json = JsonEasyUI(userList, total); return json; }
4. 在Visual Studio 2017的「解決方案資源管理器」中,找到領域層「ABP.TPLMS.Web.Mvc」項目中的wwwroot目錄下的view-resources\Orgs文件夾下,找到Index.js文件,在工具欄(toolbar)中添加查詢條件。以下圖畫框處。post
5.在Index.js文件添加一個查詢方法Search,代碼以下。學習
function Search() { var _$form = $('form[name=searchform]'); var params = _$form.serializeFormToObject(); $('#dgOrg').treegrid({ queryParams: params }); }
7.在瀏覽器中的地址欄中輸入「http://localhost:5000/」,而後輸入管理員用戶名進行登陸。
8.在主界面的菜單中,選擇「Business->組織管理」菜單項,瀏覽器中呈現一個貨物信息列表與四個按鈕。以下圖。
9. 接下來,咱們要實現根據查詢條件進行查詢的功能。在Visual Studio 2017的「解決方案資源管理器」中,右鍵單擊「ABP.TPLMS.Application」項目的 「Orgs」文件夾中,找到OrgAppService.cs文件。重寫CreateFilteredQuery方法。代碼以下。關於GetParentOrgs方法,在這裏要說明一點,這個方法的具體做用是找到咱們查詢到的組織信息的全部上級組織。這個方法經過遞歸算法來查找條件當前查詢條件的組織信息中的第一條的全部上級組織信息。若是這個方法有缺陷,能夠自行修正。若是不調用GetParentOrgs方法,會出現什麼結果,能夠自行試驗。
protected override IQueryable<Org> CreateFilteredQuery(PagedOrgResultRequestDto input) { var qry= base.CreateFilteredQuery(input) .Where(t=>t.Name.Contains(input.OrgName)) .Where(t => t.BizCode.Contains(input.OrgCode)) .Where(t => t.CustomCode.Contains(input.CustomCode)); List<Org> list = qry.ToList<Org>(); var qry1 = base.CreateFilteredQuery(input); List<Org> listParent = new List<Org>(); GetParentOrgs(listParent, list[0].ParentId, qry1); return qry.Union<Org>(listParent); } private void GetParentOrgs(List<Org> orgs, int ParentId, IQueryable<Org> listOrgs) { List<Org> liOrgs = listOrgs.Where(x => x.Id == ParentId).ToList(); if (liOrgs == null || liOrgs .Count <= 0) { return; } else { for (int i = 0; i < liOrgs.Count; i++) { var org = liOrgs[i]; if (!orgs.Contains(org)) { orgs.Add(org); } GetParentOrgs(orgs, org.ParentId, listOrgs); } } }
10. 重複上面的第六、七、8步。而後在「組織名稱」查詢條件中輸入「北」,而後點擊「查詢」按鈕,然而查詢出全部貨物代碼中有「北」的貨物信息。以下圖。
11.在「海關代碼」查詢條件中輸入「1111」,而後點擊「查詢」按鈕,然而查詢出全部「海關代碼」中有「1111」的相關組織信息。以下圖。
12.在「組織代碼」查詢條件中輸入「B」,而後點擊「查詢」按鈕,然而查詢出全部「組織代碼」中有「B」的相關組織信息。以下圖。