public override void PopulateData() { try { string searchTxt = txtSearch.Text.ToStr().ToLower().Trim(); string col = ddlColumns.Text.ToStr().Trim().ToLower(); if (searchTxt.Length < 3) { searchTxt = string.Empty; } if (AppVars.objPolicyConfiguration.EnablePOI.ToBool()) { string PostCode = string.Empty; string Address = string.Empty; if (col == "post code") { PostCode = txtSearch.Text.ToStr(); } else if (col == "address") { Address = txtSearch.Text.ToStr(); } using (TaxiDataContext db = new TaxiDataContext()) { var list = (from a in db.stp_GetRoadLevelAddress(PostCode, Address) select new { Id = a.Id, Address = a.Street, PostCode = a.PostCode, ZoneId = 0, Zone = "" }).ToList();; int cnt = list.Count; if (skip + pageSize > cnt && cnt - pageSize > 0) { skip = cnt - pageSize; } else if (cnt <= pageSize) { skip = 0; } //.Skip(skip).Take(pageSize).OrderBy(c => c.Address) var list2 = list.Skip(skip).Take(pageSize).OrderBy(c => c.Address).ToList(); AddressList = list2; } } else { var list1 = General.GetQueryable <Gen_Address>(null).Count(); if (this.IsFind) { // bool col_name = false; bool col_postCode = false; bool col_address = false; bool col_zone = false; if (col == "post code") { col_postCode = true; } else if (col == "address") { col_address = true; } else if (col == "zone") { col_zone = true; } int cnt = list1; if (skip + pageSize > cnt && cnt - pageSize > 0) { skip = cnt - pageSize; } else if (cnt <= pageSize) { skip = 0; } int findZoneId = 0; if (col_zone) { findZoneId = General.GetObject <Gen_Zone>(c => c.ZoneName.Contains(searchTxt) || c.ShortName.Contains(searchTxt)).DefaultIfEmpty().Id; } using (TaxiDataContext db = new TaxiDataContext()) { var list = (from a in db.GetTable <Gen_Address>() join b in db.GetTable <Gen_Zone>() on a.ZoneId equals b.Id into table2 from b in table2.DefaultIfEmpty() where (col_postCode && (a.PostalCode.ToUpper().Contains(searchTxt) || searchTxt == string.Empty) || (col_address && (a.AddressLine1 != null && a.AddressLine1.ToUpper().Contains(searchTxt) || searchTxt == string.Empty)) || (col_zone && findZoneId != 0 && (a.ZoneId != null && a.ZoneId == findZoneId || searchTxt == string.Empty)) ) select new { Id = a.EntityID, Address = a.AddressLine1, PostCode = a.PostalCode, ZoneId = a.ZoneId, Zone = a.ZoneId != null ? b.ZoneName : "" }).Skip(skip).Take(pageSize).OrderBy(c => c.Address).ToList(); AddressList = list; } HasError = false; } else { using (TaxiDataContext db = new TaxiDataContext()) { var list = (from a in db.GetTable <Gen_Address>() join b in db.GetTable <Gen_Zone>() on a.ZoneId equals b.Id into table2 from b in table2.DefaultIfEmpty() select new { Id = a.EntityID, Address = a.AddressLine1, PostCode = a.PostalCode, ZoneId = a.ZoneId, Zone = a.ZoneId != null ? b.ZoneName : "" }).Skip(skip).Take(pageSize).OrderBy(c => c.Address).ToList(); AddressList = list; } } } } catch (Exception ex) { HasError = true; } }