public SearchReturn Expand(String searchText, String includeTypes, int offset, int numResults, DictionaryType dictionary, Language language) { log.DebugFormat("Enter searchText( {0}, {1}, {2}, {3}, {4}, {5} ).", searchText, includeTypes, offset, numResults, dictionary, language); SearchReturn ret; try { InputValidator.ValidateExpand(dictionary, language); DictionaryManager mgr = new DictionaryManager(); ret = mgr.Expand(searchText, includeTypes, offset, numResults, dictionary, language, API_VERSION); log.DebugFormat("Returning {0} results.", ret.Result.Count()); } // If there was a problem with the inputs for this request, fail with // an HTTP status message and an explanation. catch (DictionaryValidationException ex) { WebOperationContext ctx = WebOperationContext.Current; ctx.OutgoingResponse.SetStatusAsNotFound(ex.Message); ret = new SearchReturn() { Meta = new SearchReturnMeta() { Messages = new string[] { ex.Message } } }; } return(ret); }
/// <summary> /// Common code for building the results data structure from Search and Expand. /// </summary> /// <param name="results"></param> /// <returns></returns> private SearchReturn BuildSearchResultsStructure(SearchResults results, Language language, AudienceType audience, int offset) { List <String> messages = new List <string>(); int resultCount = results.MatchCount; // Report the count in a human-readable format. String message = String.Format("Found {0} results.", resultCount); log.Debug(message); messages.Add(message); // Retrieve results. We already know the number of results, so let's preset the // list to the size we know we're going to need. (Use the number of rows in the results // since MatchCount/resultCount is conceivably much larger than we need and might even be int.MaxValue.) List <DictionarySearchResultEntry> foundTerms = new List <DictionarySearchResultEntry>(results.Data.Rows.Count); foreach (DataRow row in results.Data.Rows) { try { int id = row.Field <int>("termID"); string matchName = row.Field <string>("TermName"); string detail = row.Field <string>("object"); detail = RewriteMediaFileLocations(detail); foundTerms.Add(new DictionarySearchResultEntry(id, matchName, detail)); } catch (Exception ex) { log.Debug("Error retrieving search results.", ex); } } // Populate return metadata structure SearchReturnMeta meta = new SearchReturnMeta() { Language = language.ToString(), Audience = audience.ToString(), Offset = offset, ResultCount = resultCount, Messages = messages.ToArray() }; // Combine meta and results to create the final return object. SearchReturn srchReturn = new SearchReturn() { Result = foundTerms.ToArray(), Meta = meta }; return(srchReturn); }
public SearchReturn SearchThruProducts(string term, string[] searchCategories) { using (var db = new SqlConnection(_connectionString)) { var searchResults = new SearchReturn(); var sql = @"SELECT p.*, FORMAT (p.Price / 100.00, 'C') as MoneyPrice ,u.BusinessName, c.Name as CategoryName, t.Type as TypeName FROM [Product] p JOIN [User] u on p.SellerId = u.Id JOIN [Category] c on p.CategoryId = c.Id JOIN [ProductType] t on p.TypeId = t.Id"; var whereStatement = ""; var regex = "%"; if (searchCategories.Length != 0) { whereStatement = @" WHERE p.categoryId in @searchCategories"; } if (term != null) { char[] charArr = term.ToCharArray(); foreach (char ch in charArr) { regex += "[" + ch + "]"; } regex += "%"; if (searchCategories.Length == 0) { whereStatement = " WHERE ([Title] LIKE @regex OR [BusinessName] LIKE @regex)"; } else { whereStatement = @" WHERE ([Title] LIKE @regex OR [BusinessName] LIKE @regex) AND p.categoryId in @searchCategories"; } } sql += whereStatement; var parameters = new { regex, searchCategories }; var productsSearched = db.Query <Product>(sql, parameters); var categoryTotalResults = _categoryRepo.GetProductsInCategories(regex); searchResults.Products = productsSearched; searchResults.TotalProducts = productsSearched.Count(); searchResults.TotalForEachCategory = categoryTotalResults; return(searchResults); } }
// For search demonstration purposes only. public HomeSeerAPI.SearchReturn[] Search(string SearchString, bool RegEx) { System.Collections.Generic.List <SearchReturn> colRET = new System.Collections.Generic.List <SearchReturn>(); SearchReturn RET; //So let's pretend we searched through all of the plug-in resources (triggers, actions, web pages, perhaps zone names, songs, etc.) // and found a few matches.... // The matches can be returned as just the string value...: RET = new SearchReturn(); colRET.Add(RET); return(colRET.ToArray()); }
public HomeSeerAPI.SearchReturn[] Search(string SearchString, bool RegEx)//TODO add search { // Not yet implemented in the Sample // // Normally we would do a search on plug-in actions, triggers, devices, etc. for the string provided, using // the string as a regular expression if RegEx is True. // List <SearchReturn> colRET = new List <SearchReturn>(); SearchReturn RET; //So let's pretend we searched through all of the plug-in resources (triggers, actions, web pages, perhaps zone names, songs, etc.) // and found a few matches.... // The matches can be returned as just the string value...: RET = new SearchReturn(); RET.RType = eSearchReturn.r_String_Other; RET.RDescription = "Found in the zone description for zone 4"; RET.RValue = Zone[4]; colRET.Add(RET); // The matches can be returned as a URL: RET = new SearchReturn(); RET.RType = eSearchReturn.r_URL; RET.RValue = Util.IFACE_NAME + Util.Instance; // Could have put something such as /DeviceUtility?ref=12345&edit=1 to take them directly to the device properties of a device. colRET.Add(RET); // The matches can be returned as an Object: // This will be VERY infrequently used as it is restricted to object types that can go through the HomeSeer-Plugin interface. // Normal data type objects (Date, String, Integer, Enum, etc.) can go through, but very few complex objects such as the // HomeSeer DeviceClass will make it through the interface unscathed. RET = new SearchReturn(); RET.RType = eSearchReturn.r_Object; RET.RDescription = "Found in a device."; RET.RValue = Util.hs.DeviceName(OneOfMyDevices.get_Ref(Util.hs)); //Returning a string in the RValue is optional since this is an object type return RET.RObject = OneOfMyDevices; colRET.Add(RET); return(colRET.ToArray()); }
public ActionResult SearchResultReturn(SearchReturn SearchReturn) { SearchResultOneWay result = new SearchResultOneWay(); result.cb = new List <ChuyenBay>(); DateTime dt = DateTime.ParseExact(SearchReturn.ReturnDate, "dd/MM/yyyy", CultureInfo.InvariantCulture); //người lớn và trẻ em thì cho ngồi ghế còn trẻ sơ sinh thì người lớn bế int soluonghanhkhach = SearchReturn.adultNo + SearchReturn.childNo; List <ChuyenBay> temp = new List <ChuyenBay>(); result.cb = new F_DanhSachChuyenBay().DS_ChuyenBay.Where(x => x.DiemDi == SearchReturn.arvAirport && x.DiemDen == SearchReturn.depAirport && x.Ngay == dt).ToList(); //kiểm tra thử còn chỗ không trên các chuyến bay với ngày đã chọn foreach (ChuyenBay item in temp) { int a = new AirLineDbContext().KhachHang_ChuyenBay.Where(x => x.MaChuyenBay == item.MaChuyenBay && x.NgayBay == item.Ngay).ToList().Count(); if (item.SoCho - a >= soluonghanhkhach) { result.cb.Add(item); } } result.departAirport = SearchReturn.arvAirport; result.arrivedAirport = SearchReturn.depAirport; result.date = null; result.rtndate = SearchReturn.ReturnDate; result.adultNo = SearchReturn.adultNo; result.childNo = SearchReturn.childNo; result.infantNo = SearchReturn.infantNo; ViewBag.MaChuyenBayLuotDi = SearchReturn.MaChuyenBayLuotDi; var session1 = (UserLogin)Session[CommonSession.USER_SESSION]; if (session1 != null) { TempData["layout"] = "logged in"; } return(View(result)); }
public IHttpActionResult SearchPost(SearchData sd) { int perpage = 20; List <SearchReturn> srd = new List <SearchReturn>(); using (var db = new oucfreetalkEntities()) { //查询主题 var search_post = (from it in db.posts join it2 in db.students on it.owner equals it2.id where it.state == true && (it.title.Contains(sd.searchtext) || it.contenttext.Contains(sd.searchtext)) select new { it.title, it.contenttext, it.id, it.updatetime, it2.nikename, stuid = it2.id }).ToList(); for (int i = 0; i < search_post.Count; i++) { SearchReturn srtemp = new SearchReturn(); srtemp.srtype = 2; //类型2帖子 srtemp.postid = search_post[i].id.ToString(); //帖子id srtemp.postname = search_post[i].title.ToString(); //贴子标题 srtemp.createtime = search_post[i].updatetime; //帖子最后更新时间 srtemp.stuid = search_post[i].stuid; srtemp.nikename = search_post[i].nikename; srtemp.replytext = search_post[i].contenttext; srd.Add(srtemp); } //搜索楼层 var search_post_s = (from it in db.postc join it2 in db.posts on it.ownpost equals it2.id join it3 in db.students on it.owner equals it3.id where it.state == true && it.body.Contains(sd.searchtext) select new { it.body, it.id, it.createtime, postname = it2.title, postid = it2.id, nikename = it3.nikename, stuid = it3.id }).ToList(); for (int i = 0; i < search_post_s.Count; i++) { SearchReturn srtemp = new SearchReturn(); srtemp.srtype = 3; srtemp.postid = search_post_s[i].postid.ToString(); srtemp.stuid = search_post_s[i].stuid; srtemp.nikename = search_post_s[i].nikename; srtemp.replytext = search_post_s[i].body; srtemp.commentsid = search_post_s[i].id.ToString(); srtemp.postname = search_post_s[i].postname; srtemp.createtime = search_post_s[i].createtime; srd.Add(srtemp); } var dd = (from it in db.students where it.nikename == sd.searchtext select it).ToList(); srd.OrderByDescending(a => a.createtime); for (int i = 0; i < dd.Count; i++) { SearchReturn srtemp = new SearchReturn(); srtemp.srtype = 1; srtemp.ico = dd[i].pic; srtemp.nikename = dd[i].nikename; srtemp.stuid = dd[i].id; srd.Insert(0, srtemp); } //计算页数 int allcount = srd.Count; int allpage = allcount / perpage; if (allcount % perpage != 0) { allpage++; } var search = srd.Skip((sd.index - 1) * perpage).Take(perpage); return(Ok(new { search, allpage })); } }
public HomeSeerAPI.SearchReturn[] Search(string SearchString, bool RegEx) { SearchReturn[] result = new SearchReturn[0]; return(result); }
private string SearchReturnConditionReturn(SearchReturn returnData) { string ConditionReturn = ""; if (returnData.txtreturnedID != null) { ConditionReturn += " AND PropertyReturn.ReturnID = @txtreturnedID "; } if (returnData.txtreturnedDateStart != null && returnData.txtreturnedDateeEnd != null) { ConditionReturn += " AND PropertyReturn.ReturnDate BETWEEN @txtreturnedDateStart AND @txtreturnedDateeEnd "; } if (returnData.txtgetgoodsBy != null) { ConditionReturn += " AND StaffDatabase.StaffName like @txtgetgoodsBy "; } if (returnData.txtrestationeryID != null) { ConditionReturn += " AND PropertyReturn.PropertyID = @txtrestationeryID "; } if (returnData.txtrestationeryName != null) { ConditionReturn += " AND PropertyDatabase.PropertyName like @txtrestationeryName "; } StaffDataBase sDB = new StaffDataBase(); List<string> UserFile = sDB.getStaffDataName(HttpContext.Current.User.Identity.Name); if (int.Parse(_StaffhaveRoles[4]) == 0 && UserFile[1].Length > 0) { ConditionReturn += " AND PropertyReturn.Unit =" + UserFile[2] + " "; } return ConditionReturn; }
public string[] SearchReturnCount(SearchReturn returnData) { string[] returnValue = new string[2]; returnValue[0] = "0"; returnValue[1] = "0"; DataBase Base = new DataBase(); string ConditionReturn = this.SearchReturnConditionReturn(returnData); using (SqlConnection Sqlconn = new SqlConnection(Base.GetConnString())) { try { StaffDataBase sDB = new StaffDataBase(); List<string> CreateFileName = sDB.getStaffDataName(HttpContext.Current.User.Identity.Name); Sqlconn.Open(); string sql = "SELECT COUNT(*) FROM PropertyReturn " + "INNER JOIN PropertyDatabase ON PropertyReturn.PropertyID=PropertyDatabase.PropertyID AND PropertyDatabase.isDeleted=0 " + "INNER JOIN StaffDatabase ON PropertyReturn.OutputTransactor=StaffDatabase.StaffID AND StaffDatabase.isDeleted=0 " + "WHERE PropertyReturn.isDeleted=0 " + ConditionReturn; SqlCommand cmd = new SqlCommand(sql, Sqlconn); cmd.Parameters.Add("@txtreturnedID", SqlDbType.Int).Value = Chk.CheckStringtoIntFunction(returnData.txtreturnedID); cmd.Parameters.Add("@txtreturnedDateStart", SqlDbType.Date).Value = Chk.CheckStringtoDateFunction(returnData.txtreturnedDateStart); cmd.Parameters.Add("@txtreturnedDateeEnd", SqlDbType.Date).Value = Chk.CheckStringtoDateFunction(returnData.txtreturnedDateeEnd); cmd.Parameters.Add("@txtgetgoodsBy", SqlDbType.NVarChar).Value = "%" + Chk.CheckStringFunction(returnData.txtgetgoodsBy) + "%"; cmd.Parameters.Add("@txtrestationeryID", SqlDbType.Int).Value = Chk.CheckStringtoIntFunction(returnData.txtrestationeryID); cmd.Parameters.Add("@txtrestationeryName", SqlDbType.NVarChar).Value = "%" + Chk.CheckStringFunction(returnData.txtrestationeryName) + "%"; returnValue[0] = cmd.ExecuteScalar().ToString(); Sqlconn.Close(); } catch (Exception e) { returnValue[0] = "-1"; returnValue[1] = e.Message.ToString(); } } return returnValue; }
public List<CreateReturn> SearchReturn(int indexpage, SearchReturn returnData) { List<CreateReturn> returnValue = new List<CreateReturn>(); DataBase Base = new DataBase(); string ConditionReturn = this.SearchReturnConditionReturn(returnData); using (SqlConnection Sqlconn = new SqlConnection(Base.GetConnString())) { try { StaffDataBase sDB = new StaffDataBase(); List<string> CreateFileName = sDB.getStaffDataName(HttpContext.Current.User.Identity.Name); Sqlconn.Open(); string sql = "SELECT * FROM (SELECT ROW_NUMBER() OVER (ORDER BY PropertyReturn.ReturnDate DESC, PropertyReturn.ID DESC) " + "AS RowNum, PropertyReturn.*,PropertyDatabase.PropertyName,PropertyDatabase.ItemUnit,StaffDatabase.StaffName AS receiveByName FROM PropertyReturn " + "INNER JOIN PropertyDatabase ON PropertyReturn.PropertyID=PropertyDatabase.PropertyID AND PropertyDatabase.isDeleted=0 " + "INNER JOIN StaffDatabase ON PropertyReturn.OutputTransactor=StaffDatabase.StaffID AND StaffDatabase.isDeleted=0 " + "WHERE PropertyReturn.isDeleted=0 " + ConditionReturn + " ) " + "AS NewTable " + "WHERE RowNum >= (@indexpage-" + PageMinNumFunction() + ") AND RowNum <= (@indexpage)"; SqlCommand cmd = new SqlCommand(sql, Sqlconn); cmd.Parameters.Add("@indexpage", SqlDbType.Int).Value = indexpage; cmd.Parameters.Add("@txtreturnedID", SqlDbType.Int).Value = Chk.CheckStringtoIntFunction(returnData.txtreturnedID); cmd.Parameters.Add("@txtreturnedDateStart", SqlDbType.Date).Value = Chk.CheckStringtoDateFunction(returnData.txtreturnedDateStart); cmd.Parameters.Add("@txtreturnedDateeEnd", SqlDbType.Date).Value = Chk.CheckStringtoDateFunction(returnData.txtreturnedDateeEnd); cmd.Parameters.Add("@txtgetgoodsBy", SqlDbType.NVarChar).Value = "%" + Chk.CheckStringFunction(returnData.txtgetgoodsBy) + "%"; cmd.Parameters.Add("@txtrestationeryID", SqlDbType.Int).Value = Chk.CheckStringtoIntFunction(returnData.txtrestationeryID); cmd.Parameters.Add("@txtrestationeryName", SqlDbType.NVarChar).Value = "%" + Chk.CheckStringFunction(returnData.txtrestationeryName) + "%"; SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { CreateReturn addValue = new CreateReturn(); addValue.rID = dr["ID"].ToString(); addValue.returnedID = dr["ReturnID"].ToString(); addValue.returnedDate = DateTime.Parse(dr["ReturnDate"].ToString()).ToString("yyyy-MM-dd"); addValue.getgoodsDate = DateTime.Parse(dr["OutputDate"].ToString()).ToString("yyyy-MM-dd"); addValue.getgoodsByID = dr["OutputTransactor"].ToString(); addValue.getgoodsByName = dr["receiveByName"].ToString(); addValue.restationeryID = dr["PropertyID"].ToString(); addValue.Unit = dr["Unit"].ToString(); addValue.returnedQuantity = dr["Quantity"].ToString(); addValue.returnedReason = dr["Reason"].ToString(); addValue.restationeryName = dr["PropertyName"].ToString(); addValue.restationeryUnit = dr["ItemUnit"].ToString(); returnValue.Add(addValue); } dr.Close(); Sqlconn.Close(); } catch (Exception e) { CreateReturn addValue = new CreateReturn(); addValue.checkNo = "-1"; addValue.errorMsg = e.Message.ToString(); returnValue.Add(addValue); } } return returnValue; }
public string[] SearchReturnDataCount(SearchReturn returnData) { OtherDataBase sDB = new OtherDataBase(); if (int.Parse(sDB._StaffhaveRoles[3]) == 1) { return sDB.SearchReturnCount(returnData); } else { return new string[2] { _noRole, _errorMsg }; } }
public List<CreateReturn> SearchReturnData(int index, SearchReturn returnData) { OtherDataBase sDB = new OtherDataBase(); return sDB.SearchReturn(index, returnData); }