public SearchResult FindItemByContainFieldValue(object item, string fields, int pageSize, int pageNumber) { SearchResult val = null; string name = item.GetType().Name; string[] a = fields.Split(',').Select(x => x.Trim().ToUpper()).ToArray(); if (a.Length > 0 && m_listDataName.IndexOf(name) != -1) { string[] fd = item.GetType().GetProperties().Select(x => new { Name = x.Name, Char = (x.PropertyType.Name == "String" ? "\"" : string.Empty), Value = x.GetGetMethod().Invoke(item, null) }) .Where(x => a.Any(o => o == x.Name) && x.Value != null && x.Value.ToString() != string.Empty) .Select((x, k) => x.Name + " = @" + k.ToString()) .ToArray(); object[] vd = item.GetType().GetProperties().Where(x => a.Any(o => o == x.Name)).Select(x => x.GetGetMethod().Invoke(item, null)) .Where(x => x != null && x.ToString() != string.Empty) .ToArray(); DataFile db = GetDF(name); if (db != null && db.Opened) { val = db.SearchGetIDs(new SearchRequest(string.Join(" && ", fd), vd) { PageSize = pageSize, PageNumber = pageNumber }); } } return(val); }
public bool RemoveItem(object item, string fields) { string name = item.GetType().Name; string[] a = fields.Split(',').Select(x => x.Trim().ToUpper()).ToArray(); if (a.Length > 0 && m_listDataName.IndexOf(name) != -1) { string[] fd = item.GetType().GetProperties().Select(x => new { Name = x.Name, Char = (x.PropertyType.Name == "String" ? "\"" : string.Empty), Value = x.GetGetMethod().Invoke(item, null) }) .Where(x => a.Any(o => o == x.Name) && x.Value != null && x.Value.ToString() != string.Empty) .Select((x, k) => x.Name + " = @" + k.ToString()) .ToArray(); object[] vd = item.GetType().GetProperties().Where(x => a.Any(o => o == x.Name)).Select(x => x.GetGetMethod().Invoke(item, null)) .Where(x => x != null && x.ToString() != string.Empty) .ToArray(); DataFile db = GetDF(name); if (db != null && db.Opened) { SearchResult rs = db.SearchGetIDs(new SearchRequest(1, 1, string.Join(" && ", fd), vd)); if (rs.Status && rs.Total > 0) { return(db.RemoveBySearh(new SearchRequest(string.Join(" && ", fd), vd))); } } } return(false); }
public IndexDynamic FindItemFirstByContainFieldValue(object item, string fields) { object val = null; int index = -1; string name = item.GetType().Name; string[] a = fields.Split(',').Select(x => x.Trim().ToUpper()).ToArray(); if (a.Length > 0 && m_listDataName.IndexOf(name) != -1) { string[] fd = item.GetType().GetProperties().Select(x => new { Name = x.Name, Char = (x.PropertyType.Name == "String" ? "\"" : string.Empty), Value = x.GetGetMethod().Invoke(item, null) }) .Where(x => a.Any(o => o == x.Name) && x.Value != null && x.Value.ToString() != string.Empty) .Select((x, k) => x.Name + " = @" + k.ToString()) .ToArray(); object[] vd = item.GetType().GetProperties().Where(x => a.Any(o => o == x.Name)).Select(x => x.GetGetMethod().Invoke(item, null)) .Where(x => x != null && x.ToString() != string.Empty) .ToArray(); DataFile db = GetDF(name); if (db != null && db.Opened) { SearchResult rs = db.SearchGetIDs(new SearchRequest(1, 1, string.Join(" && ", fd), vd)); if (rs.Status && rs.Total > 0) { index = rs.IDs[0]; var li = (IList)rs.Message; if (li.Count > 0) { val = li[0]; } } } } return(new IndexDynamic(index, val)); }
public SearchResult Search(string dbName, SearchRequest sr) { SearchResult val = null; DataFile db = GetDF(dbName); if (db != null && db.Opened) { val = db.SearchGetIDs(sr); } return(val); }