public bool Contains(QueryPart part) { if (part == QueryPart.QuerySubject && _sv != null) return true; if (part == QueryPart.QueryPredicate && _pv!= null) return true; if (part == QueryPart.QueryObject && _ov != null) return true; return false; }
public void AppendToQuery(Query query, bool isFirst) { var parts = QueryPart.Split('?'); if (parts.Length - 1 != Values.Length) { throw new InvalidOperationException($"You do not have a matching amount of parameters {QueryPart}, " + string.Join(", ", Values.Select(p => p?.ToString() ?? "null"))); } for (int i = 0; i < parts.Length - 1; i++) { query.Builder.Append(parts[i]); query.AppendParameter(Values[i]); } query.Builder.Append(parts[^ 1]);
protected override DriverResult Display(ActivityStreamPart part, string displayType, dynamic shapeHelper) { if (this.services.WorkContext.CurrentUser == null) { return(null); } // retrieving paging parameters var queryString = this.services.WorkContext.HttpContext.Request.QueryString; var settings = part.TypePartDefinition.Settings.GetModel <ActivityStreamPartSettings>(); var pageKey = "page"; var page = 0; int pageSize = settings.PageSize != default(int) ? settings.PageSize : 20; // don't try to page if not necessary if (queryString.AllKeys.Contains(pageKey)) { int.TryParse(queryString[pageKey], out page); } int count = 0; List <ActivityStreamRecord> items = new List <ActivityStreamRecord>(); QueryPart queryPart = part.QueryId.HasValue ? this.services.ContentManager.Get <QueryPart>(part.QueryId.Value) : null; if (queryPart != null) { var queries = projectionManagerWithDynamicSort.GetContentQueries(queryPart.Record, null, part.ContentItem).ToArray(); count += this.activityStreamService.ActivityStreamRestrictedByGivenQueryCount(queries); items.AddRange(this.activityStreamService.ActivityStreamRestrictedByGivenQuery(queries, page == 0 ? page : page - 1, pageSize)); items = items.OrderByDescending(c => c.Id).Take(pageSize).ToList(); } else { count = this.activityStreamService.ActivityStreamVisibleByCurrentUserCount(); items = this.activityStreamService.ActivityStreamVisibleByCurrentUser(page == 0 ? page : page - 1, pageSize).ToList(); } var model = this.activityStreamService.CreateModel(items, count, page, pageSize); return(this.ContentShape("Parts_DashboardActivityStream", () => shapeHelper.Parts_DashboardActivityStream(Model: model))); }
private static void FilterStaffProfileQuery(QueryPart staffProfileQuery) { var filterDictionary = new Dictionary <string, string>(); filterDictionary.Add("ContentTypes", "StaffProfile"); filterDictionary.Add("Description", "Staff Profiles"); var state = FormParametersHelper.ToString(filterDictionary); staffProfileQuery.FilterGroups[0].Filters.Add(new FilterRecord { Category = "Content", Description = "Staff Profiles", Position = 0, State = state, Type = "ContentTypes" }); }
public void Analyze(IEnumerable <Token> query, IList <IDictionary <QueryPart, IEnumerable <Token> > > result, IDictionary <QueryPart, IEnumerable <Token> > currParts = null) { currParts = currParts ?? new Dictionary <QueryPart, IEnumerable <Token> > { { QueryPart.SELECT, GetSelect(query) }, { QueryPart.FROM, GetFrom(query) }, { QueryPart.WHERE, GetWhere(query) } }; var analyzer = new BaseAnalyzer(); var keys = new QueryPart[currParts.Count]; currParts.Keys.CopyTo(keys, 0); foreach (var key in keys) { analyzer.StrategyType = key; analyzer.Analyze(currParts[key], result, currParts); } result.Add(currParts); }
protected override QueryPart QueryPartHook(QueryPart part) { if (part is QueryPart_Property) { QueryPart_Property prop_part = (QueryPart_Property)part; if (prop_part.Key == "inuri") // special case { QueryPart_Property new_part = new QueryPart_Property(); new_part.Logic = prop_part.Logic; new_part.Key = "beagle:inuri"; new_part.Type = PropertyType.Text; new_part.Value = prop_part.Value; return(new_part); } } return(part); }
public LayoutRecord AddLayout(string layoutState, string itemDisplayType, QueryPart queryPart) { // create layout LayoutRecord layout = new LayoutRecord { Type = "Shape", Category = "Html", QueryPartRecord = queryPart.Record, DisplayType = itemDisplayType, Display = 0, State = layoutState }; this.layoutRepository.Create(layout); this.layoutRepository.Flush(); this.filterRepository.Flush(); return(layout); }
public static IEnumerable <Token> SplitOnUnion(QueryPart part, IEnumerable <Token> tokens, IList <IDictionary <QueryPart, IEnumerable <Token> > > result, IDictionary <QueryPart, IEnumerable <Token> > currParts) { var tokenArray = tokens.ToArray(); var resultTokens = new List <Token>(); var analyzer = new BaseAnalyzer(); for (var i = 0; i < tokenArray.Length; i++) { var token = tokenArray[i]; if (token.Type.GetType() == SQLTokenTypeEnum.KEYWORD && token.Text.Equals("or", StringComparison.OrdinalIgnoreCase)) { var additionalArray = new Token[resultTokens.Count]; resultTokens.CopyTo(additionalArray); var newTokens = additionalArray .Reverse() .SkipWhile(t => !t.Text.Equals("or", StringComparison.OrdinalIgnoreCase) && !t.Text.Equals("and", StringComparison.OrdinalIgnoreCase) && !t.Text.Equals("on", StringComparison.OrdinalIgnoreCase)) .Reverse() .ToList(); newTokens.AddRange(tokenArray.Skip(i + 1)); var newParts = new Dictionary <QueryPart, IEnumerable <Token> >(currParts); newParts[part] = newTokens; analyzer.StrategyType = QueryPart.QUERY; analyzer.Analyze(newTokens, result, newParts); i = tokenArray.Skip(i + 1) .SkipWhile(t => !t.Text.Equals("or", StringComparison.OrdinalIgnoreCase) || !t.Text.Equals("and", StringComparison.OrdinalIgnoreCase) || !t.Text.Equals("on", StringComparison.OrdinalIgnoreCase)) .Select((t, index) => index).FirstOrDefault(); if (i == 0) { break; } } else { resultTokens.Add(token); } } return(resultTokens); }
// Returns: // 1 if it is a match // 0 if it doesn't apply // -1 if it doesn't match private int MatchesMetadata(QueryPart abstract_part) { int is_match = 0; if (abstract_part is QueryPart_Text) { QueryPart_Text part; part = (QueryPart_Text)abstract_part; if (part.SearchTextProperties && part.Text == base_name) { is_match = 1; } } else if (abstract_part is QueryPart_Property) { QueryPart_Property part; part = (QueryPart_Property)abstract_part; if (part.Key == "beagle:MimeType") { is_match = (part.Value == this.MimeType) ? 1 : -1; } else if (part.Key == "beagle:Filename") { is_match = (part.Value == base_name) ? 1 : -1; } else if (part.Key == "beagle:ExactFilename") { is_match = (part.Value == Name) ? 1 : -1; } } else if (abstract_part is QueryPart_DateRange) { QueryPart_DateRange part; part = (QueryPart_DateRange)abstract_part; is_match = (part.StartDate <= Timestamp && Timestamp <= part.EndDate) ? 1 : -1; } return(is_match); }
private void CreateStaffProfileProjection(QueryPart staffProfileQuery) { var projection = _contentManager.Create <ProjectionPart>("ProjectionPage", t => { t.Record.QueryPartRecord = staffProfileQuery.Record; }); projection.As <TitlePart>().Record.Title = "Staff Directory"; projection.As <MenuPart>().Record.MenuText = "Staff Directory"; projection.As <MenuPart>().Record.MenuPosition = "1"; var mainMenu = _menuService.GetMenu("Main Menu"); if (mainMenu != null) { projection.As <MenuPart>().Record.MenuId = _menuService.GetMenu("Main Menu").Id; } projection.As <AutoroutePart>().Record.DisplayAlias = "staff-directory"; projection.As <CommonPart>().Record.OwnerId = _membershipService.GetUser("admin").Id; //publish the staff directory projection _contentManager.Publish(projection.ContentItem); }
override protected bool MatchesQueryPart(QueryPart abstract_part) { if (abstract_part is QueryPart_Text) { QueryPart_Text part; part = (QueryPart_Text)abstract_part; if (part.SearchFullText) { foreach (string str in body) { if (part.Text == str) { return(true); } } } } return(false); }
public int PartsCount(QueryPart parts) { if ((parts & QueryPart.Select) > 0) { return(SelectPart.Count); } if ((parts & QueryPart.From) > 0) { return(FromPart.Count); } if ((parts & QueryPart.Where) > 0) { return(WherePart == null ? 0 : 1); } if ((parts & QueryPart.GroupBy) > 0) { return(GroupPart.Count); } if ((parts & QueryPart.OrderBy) > 0) { return(OrderPart.Count); } if ((parts & QueryPart.Skip) > 0) { return(Skip.Value); } if ((parts & QueryPart.Take) > 0) { return(Take.Value); } return(0); }
public QueryPart CreateProjectActivityStreamQuery() { var query = this.GetQuery(QueryNames.ProjectActivityStreamQueryName); if (query != null) { return(query.As <QueryPart>()); } query = this.contentManager.Create("Query"); query.As <TitlePart>().Title = QueryNames.ProjectActivityStreamQueryName; this.contentManager.Publish(query); QueryPart queryPart = query.As <QueryPart>(); var attachToProjectFilterGroup = queryPart.Record.FilterGroups.FirstOrDefault(); // AttachToProject string state = string.Format(CultureInfo.InvariantCulture, "<Form><Description></Description><Project_Id>{0}</Project_Id></Form>", "{AttachToProject.ProjectId}"); FilterRecord attachToProjectFilterRecord = this.CreateFilter(AttachToProjectFilter.CategoryName, AttachToProjectFilter.IdFilterType, state, attachToProjectFilterGroup); this.filterRepository.Flush(); var projectFilterGroup = new FilterGroupRecord { QueryPartRecord = queryPart.Record }; queryPart.Record.FilterGroups.Add(projectFilterGroup); this.filterGroupRepository.Create(projectFilterGroup); // project ContentType filter this.CreateContentTypeFilter(ContentTypes.ProjectContentType, projectFilterGroup); state = string.Format(CultureInfo.InvariantCulture, "<Form><Description></Description><Project_Id>{0}</Project_Id></Form>", "{Project.ProjectId}"); this.CreateFilter(ProjectFilter.CategoryName, ProjectFilter.IdFilterType, state, projectFilterGroup); this.filterGroupRepository.Flush(); this.filterRepository.Flush(); return(queryPart); }
private static void SortStaffProfileQuery(QueryPart staffProfileQuery) { var sortDictionary = new Dictionary <string, string>(); sortDictionary.Add("Description", "Staff Group"); sortDictionary.Add("Sort", "false"); //sort by name var profileNameCriteria = staffProfileQuery.SortCriteria.FirstOrDefault(); if (profileNameCriteria == null) { profileNameCriteria = new SortCriterionRecord { Category = "TitlePartRecord", Type = "Title", Description = "Profile Name", Position = 1 }; } profileNameCriteria.State = FormParametersHelper.ToString(sortDictionary); staffProfileQuery.SortCriteria.Add(profileNameCriteria); }
public void SetQueryPart(QueryPart part) { _visitor.SetQueryPart(part); }
// Returns an ICollection of QueryPart objects. static public ICollection Parse(string query_string) { Match m = query_string_regex.Match(query_string); ArrayList parts; parts = new ArrayList(); ArrayList or_list = null; while (m.Success) { QueryPart query_part = MatchToQueryPart(m); if (or_list != null) { or_list.Add(query_part); query_part = null; } Match next = m.NextMatch(); // Trap the OR operator // If the next match is an or, start an or_list // (if we don't have one already) and skip // ahead to the next part. if (next.Success && (next.Groups ["key"].ToString() == "") && (next.Groups ["midquote1"].ToString().ToUpper() == "OR")) { if (or_list == null) { or_list = new ArrayList(); or_list.Add(query_part); } m = next.NextMatch(); continue; } // If we have a non-empty or-list going, // Create the appropriate QueryPart and add it // to the list. if (or_list != null) { QueryPart_Or or_part = new QueryPart_Or(); or_part.Logic = QueryPartLogic.Required; foreach (QueryPart sub_part in or_list) { or_part.Add(sub_part); } parts.Add(or_part); or_list = null; } // Add the next text part if (query_part != null) { parts.Add(query_part); } m = next; } // If we ended with an or_parts list, do the right thing. if (or_list != null) { QueryPart_Or or_part = new QueryPart_Or(); or_part.Logic = QueryPartLogic.Required; foreach (QueryPart sub_part in or_list) { or_part.Add(sub_part); } } return(parts); }
public AdminEditViewModel GetQueryViewModel(QueryPart query) { var viewModel = new AdminEditViewModel { Id = query.Id, Name = query.Name }; #region Load Filters var filterGroupEntries = new List<FilterGroupEntry>(); foreach (var group in query.FilterGroups) { var filterEntries = group.Filters .Select(filter => new FilterEntry { Category = filter.Category, Type = filter.Type, FilterRecordId = filter.Id, DisplayText = filter.Description }).ToList(); filterGroupEntries.Add(new FilterGroupEntry {Id = group.Id, Filters = filterEntries}); } viewModel.FilterGroups = filterGroupEntries; #endregion #region Load Sort criterias var sortCriterionEntries = new List<SortCriterionEntry>(); var allSortCriteria = _projectionManager.DescribeSortCriteria() .SelectMany(x => x.Descriptors).ToList(); foreach (var sortCriterion in query.SortCriteria.OrderBy(s => s.Position)) { var category = sortCriterion.Category; var type = sortCriterion.Type; var f = allSortCriteria.FirstOrDefault(x => category == x.Category && type == x.Type); if (f != null) { sortCriterionEntries.Add( new SortCriterionEntry { Category = f.Category, Type = f.Type, SortCriterionRecordId = sortCriterion.Id, DisplayText = String.IsNullOrWhiteSpace(sortCriterion.Description) ? f.Display(new SortCriterionContext {State = FormParametersHelper.ToDynamic(sortCriterion.State)}).Text : sortCriterion.Description }); } } viewModel.SortCriteria = sortCriterionEntries; #endregion #region Load Layouts var layoutEntries = new List<LayoutEntry>(); var allLayouts = _projectionManager.DescribeLayouts().SelectMany(x => x.Descriptors).ToList(); foreach (var layout in query.Layouts) { var category = layout.Category; var type = layout.Type; var f = allLayouts.FirstOrDefault(x => category == x.Category && type == x.Type); if (f != null) { layoutEntries.Add( new LayoutEntry { Category = f.Category, Type = f.Type, LayoutRecordId = layout.Id, DisplayText = String.IsNullOrWhiteSpace(layout.Description) ? f.Display(new LayoutContext {State = FormParametersHelper.ToDynamic(layout.State)}).Text : layout.Description }); } } viewModel.Layouts = layoutEntries; #endregion return viewModel; }
public bool IsParameter(QueryPart part) { if (part == QueryPart.QuerySubject && _sv != null && _sv.Value.StartsWith("?")) return true; if (part == QueryPart.QueryPredicate && _pv != null && _pv.Value.StartsWith("?")) return true; if (part == QueryPart.QueryObject && _ov != null && _ov.Value.StartsWith("?")) return true; return false; }
protected override QueryPart QueryPartHook (QueryPart part) { if (part is QueryPart_Property) { QueryPart_Property prop_part = (QueryPart_Property) part; if (prop_part.Key == "inuri") { // special case QueryPart_Property new_part = new QueryPart_Property (); new_part.Logic = prop_part.Logic; new_part.Key = "beagrep:inuri"; new_part.Type = PropertyType.Text; new_part.Value = prop_part.Value; return new_part; } } return part; }
static void AddSearchTermInfo (QueryPart part, SearchTermResponse response, StringBuilder sb) { if (part.Logic == QueryPartLogic.Prohibited) return; if (part is QueryPart_Or) { ICollection sub_parts; sub_parts = ((QueryPart_Or) part).SubParts; foreach (QueryPart qp in sub_parts) AddSearchTermInfo (qp, response, sb); return; } if (! (part is QueryPart_Text)) return; QueryPart_Text tp; tp = (QueryPart_Text) part; string [] split; split = tp.Text.Split (' '); // First, remove stop words for (int i = 0; i < split.Length; ++i) if (LuceneCommon.IsStopWord (split [i])) split [i] = null; // Assemble the phrase minus stop words sb.Length = 0; for (int i = 0; i < split.Length; ++i) { if (split [i] == null) continue; if (sb.Length > 0) sb.Append (' '); sb.Append (split [i]); } response.ExactText.Add (sb.ToString ()); // Now assemble a stemmed version sb.Length = 0; // clear the previous value for (int i = 0; i < split.Length; ++i) { if (split [i] == null) continue; if (sb.Length > 0) sb.Append (' '); sb.Append (LuceneCommon.Stem (split [i].ToLower ())); } response.StemmedText.Add (sb.ToString ()); }
/// <summary> 保存配件信息 /// </summary> /// <param name="partArr">配件信息</param> /// <returns>True OR False</returns> private static bool SavePart(QueryPart.part[] partArr) { string nowTicks = Common.LocalDateTimeToUtcLong(GlobalStaticObj_Server.Instance.CurrentDateTime).ToString(); List<SysSQLString> list = new List<SysSQLString>(); foreach (QueryPart.part item in partArr) { #region 配件信息 SysSQLString sysSQLString = new SysSQLString(); sysSQLString.cmdType = CommandType.Text; sysSQLString.Param = new Dictionary<string, string>(); StringBuilder strSql = new StringBuilder(); bool isContactExist = DBHelper.IsExist("判断配件信息是否存在", GlobalStaticObj_Server.DbPrefix + GlobalStaticObj_Server.Instance.MainAccCode, "tb_parts", "car_parts_code='" + item.car_parts_code + "'"); if (isContactExist) { #region 更新语句 strSql.Append(" update tb_parts set "); strSql.Append(" parts_name = @parts_name , "); strSql.Append(" sales_unit_code = @sales_unit_code , "); strSql.Append(" sales_unit_name = @sales_unit_name , "); strSql.Append(" model = @model , "); strSql.Append(" status = @status , "); strSql.Append(" retail = @retail , "); strSql.Append(" price3a = @price3a , "); strSql.Append(" price2a = @price2a , "); strSql.Append(" base_unit_code = @base_unit_code , "); strSql.Append(" base_unit_name = @base_unit_name , "); strSql.Append(" sales_unit_quantity = @sales_unit_quantity , "); strSql.Append(" base_unit_quantity = @base_unit_quantity , "); strSql.Append(" enable_flag = @enable_flag "); strSql.Append(" data_source = @data_source "); strSql.Append(" update_time = @update_time "); strSql.Append(" update_by = @update_by "); strSql.Append(" where car_parts_code=@car_parts_code; "); #endregion } else { #region 插入语句 strSql.Append(" insert into tb_parts("); strSql.Append("parts_id,car_parts_code,parts_name,sales_unit_code,data_source,sales_unit_name,model,retail,price3a,price2a,status,enable_flag,base_unit_code,base_unit_name,sales_unit_quantity,base_unit_quantity,create_by,create_time,update_by,update_time"); strSql.Append(") values ("); strSql.Append("@parts_id,@car_parts_code,@parts_name,@sales_unit_code,@data_source,@sales_unit_name,@model,@retail,@price3a,@price2a,@status,@enable_flag,@base_unit_code,@base_unit_name,@sales_unit_quantity,@base_unit_quantity,@create_by,@create_time,@update_by,@update_time"); strSql.Append("); "); #endregion sysSQLString.Param.Add("parts_id", Guid.NewGuid().ToString()); sysSQLString.Param.Add("create_by", GlobalStaticObj_Server.Instance.UserID); sysSQLString.Param.Add("create_time", nowTicks); } #region 参数项 9 sysSQLString.sqlString = strSql.ToString(); sysSQLString.Param.Add("parts_name", item.parts_name); sysSQLString.Param.Add("sales_unit_code", item.unit_code); sysSQLString.Param.Add("sales_unit_name", item.unit_name); sysSQLString.Param.Add("model", item.model); sysSQLString.Param.Add("status", item.status); sysSQLString.Param.Add("retail", item.retail); sysSQLString.Param.Add("price3a", WebServUtil.GetEncFieldValue(item.price3a));//加密 sysSQLString.Param.Add("price2a", WebServUtil.GetEncFieldValue(item.price2a));//加密 sysSQLString.Param.Add("base_unit_code", item.basic_unit_code); sysSQLString.Param.Add("base_unit_name", item.basic_unit_name); sysSQLString.Param.Add("sales_unit_quantity", item.unit_name_quantity); sysSQLString.Param.Add("base_unit_quantity", item.basic_unit_quantity); sysSQLString.Param.Add("enable_flag", ((int)DataSources.EnumEnableFlag.USING).ToString()); sysSQLString.Param.Add("data_source", ((int)DataSources.EnumDataSources.YUTONG).ToString()); sysSQLString.Param.Add("update_by", GlobalStaticObj_Server.Instance.UserID); sysSQLString.Param.Add("update_time", nowTicks); sysSQLString.Param.Add("car_parts_code", item.car_parts_code); #endregion list.Add(sysSQLString); #endregion } bool flag = DBHelper.BatchExeSQLStringMultiByTrans("宇通:同步车型", GlobalStaticObj_Server.DbPrefix + GlobalStaticObj_Server.Instance.MainAccCode, list); if (!flag) { return false; } list = new List<SysSQLString>(); foreach (QueryPart.part item in partArr) { string car_parts_code = item.car_parts_code; #region 替代配件 foreach (QueryPart.replaceDetail itemReplace in item.partReplace) { SysSQLString sysSQLString0 = new SysSQLString(); sysSQLString0.cmdType = CommandType.Text; sysSQLString0.Param = new Dictionary<string, string>(); StringBuilder strSql0 = new StringBuilder(); string partid = DBHelper.GetSingleValue("获取配件id", "tb_parts", GlobalStaticObj_Server.DbPrefix + GlobalStaticObj_Server.Instance.MainAccCode, "parts_id", "car_parts_code='" + item.car_parts_code + "'", ""); string replacepartid = DBHelper.GetSingleValue("获取配件id", GlobalStaticObj_Server.DbPrefix + GlobalStaticObj_Server.Instance.MainAccCode, "tb_parts", "parts_id", "car_parts_code='" + itemReplace.repl_parts_code + "'", ""); bool isExist = DBHelper.IsExist("判断配件替代信息是否存在", GlobalStaticObj_Server.DbPrefix + GlobalStaticObj_Server.Instance.MainAccCode, "tb_parts_replace", "parts_id='" + partid + "' and repl_id='" + replacepartid + "'"); if (isExist) { #region 更新语句 strSql0.Append(" update tb_parts_replace set "); strSql0.Append(" repl_parts_code = @repl_parts_code , "); strSql0.Append(" repl_parts_status = @repl_parts_status , "); strSql0.Append(" repl_remark = @repl_remark , "); strSql0.Append(" change = @change "); strSql0.Append(" update_time = @update_time "); strSql0.Append(" update_by = @update_by "); strSql0.Append(" where parts_id='" + partid + "' and repl_id='" + replacepartid + "'"); #endregion } else { #region 插入语句 strSql0.Append(" insert into tb_parts_replace("); strSql0.Append("replace_id,parts_id,repl_id,repl_parts_code,repl_parts_status,repl_remark,change,create_by,create_time,update_by,update_time"); strSql0.Append(") values ("); strSql0.Append("@replace_id,@parts_id,@repl_id,@repl_parts_code,@repl_parts_status,@repl_remark,@change,@create_by,@create_time,@update_by,@update_time"); strSql0.Append("); "); #endregion sysSQLString0.Param.Add("replace_id", Guid.NewGuid().ToString()); sysSQLString0.Param.Add("create_by", GlobalStaticObj_Server.Instance.UserID); sysSQLString0.Param.Add("create_time", nowTicks); } #region sysSQLString0.sqlString = strSql0.ToString(); sysSQLString0.Param.Add("parts_id", partid); sysSQLString0.Param.Add("repl_id", replacepartid); sysSQLString0.Param.Add("repl_parts_code", itemReplace.repl_parts_code); sysSQLString0.Param.Add("repl_parts_status", itemReplace.repl_parts_status); sysSQLString0.Param.Add("repl_remark", itemReplace.repl_remark); sysSQLString0.Param.Add("change", itemReplace.change); sysSQLString0.Param.Add("update_by", GlobalStaticObj_Server.Instance.UserID); sysSQLString0.Param.Add("update_time", nowTicks); #endregion list.Add(sysSQLString0); } #endregion } flag = DBHelper.BatchExeSQLStringMultiByTrans("宇通:同步车型", GlobalStaticObj_Server.DbPrefix + GlobalStaticObj_Server.Instance.MainAccCode, list); return flag; }
public bool HasOnlyParts(QueryPart parts) { var result = true; var oppositeResult = true; if ((parts & QueryPart.Select) > 0) { result &= SelectPart.Count > 0; } else { oppositeResult &= SelectPart.Count > 0; } if ((parts & QueryPart.From) > 0) { result &= FromPart.Count > 0; } else { oppositeResult &= FromPart.Count > 0; } if ((parts & QueryPart.Where) > 0) { result &= WherePart == null; } else { oppositeResult &= WherePart == null; } if ((parts & QueryPart.GroupBy) > 0) { result &= GroupPart.Count > 0; } else { oppositeResult &= GroupPart.Count > 0; } if ((parts & QueryPart.OrderBy) > 0) { result &= OrderPart.Count > 0; } else { oppositeResult &= OrderPart.Count > 0; } if ((parts & QueryPart.Skip) > 0) { result &= Skip.HasValue; } else { oppositeResult &= Skip.HasValue; } if ((parts & QueryPart.Take) > 0) { result &= Take.HasValue; } else { oppositeResult &= Take.HasValue; } return result && !oppositeResult; }
string ProcessAndEncodeRawInputUrl(string Input) { string Path = ""; string Query = ""; string HashPart = ""; if (Input.Contains("#")) { string[] InputPartsAtHash = Input.Split(new char[] { '#' }, 2); { if (InputPartsAtHash.Length == 2) { Input = InputPartsAtHash[0]; HashPart = InputPartsAtHash[1]; } } } if (Input.Contains("?")) { string[] InputParts = Input.Split(new char[] { '?' }, 2); if (InputParts.Length == 2) { Path = InputParts[0]; Query = InputParts[1]; } else { Path = Input; } } else { Path = Input; } Path = Path.Replace("%2f", "/").Replace("%2F", "/"); StringBuilder SB = new StringBuilder(); SB.Append(Path); if (Query.Length > 0 || Input.EndsWith("?")) { SB.Append("?"); } string[] QueryParts = Query.Split(new char[] { '&' }, StringSplitOptions.RemoveEmptyEntries); foreach (string QueryPart in QueryParts) { string[] KV = QueryPart.Split(new char[] { '=' }, 2); string Key = ""; string Value = ""; if (KV.Length > 0) { Key = Tools.RelaxedUrlEncode(KV[0]); } if (KV.Length == 2) { Value = Tools.RelaxedUrlEncode(KV[1]); } SB.Append(Key); if (Value.Length > 0 || QueryPart.EndsWith("=")) { SB.Append("="); } SB.Append(Value); SB.Append("&"); } string ProcessedInput = SB.ToString(); if (!Query.EndsWith("&")) { ProcessedInput = ProcessedInput.TrimEnd('&'); } return(Tools.UrlPathEncode(ProcessedInput)); }
private void LayoutStaffProfileQuery(QueryPart staffProfileQuery) { var layoutDictionary = new Dictionary<string, string>(); layoutDictionary.Add("QueryId", staffProfileQuery.Id.ToString()); layoutDictionary.Add("Category", "Html"); layoutDictionary.Add("Type", "List"); layoutDictionary.Add("Description", "List"); layoutDictionary.Add("Display", "0"); layoutDictionary.Add("DisplayType", "Summary"); LayoutRecord layout = staffProfileQuery.Layouts.FirstOrDefault(); if (layout == null) { layout = new LayoutRecord() { Category = "Html", Type = "List", Description = "List", Display = 0, DisplayType = "Summary", }; staffProfileQuery.Layouts.Add(layout); } layout.State = FormParametersHelper.ToString(layoutDictionary); }
private static void SortStaffProfileQuery(QueryPart staffProfileQuery) { var sortDictionary = new Dictionary<string, string>(); sortDictionary.Add("Description", "Staff Group"); sortDictionary.Add("Sort", "false"); //sort by name var profileNameCriteria = staffProfileQuery.SortCriteria.FirstOrDefault(); if (profileNameCriteria == null) { profileNameCriteria = new SortCriterionRecord { Category = "TitlePartRecord", Type = "Title", Description = "Profile Name", Position = 1 }; } profileNameCriteria.State = FormParametersHelper.ToString(sortDictionary); staffProfileQuery.SortCriteria.Add(profileNameCriteria); }
public bool HasOnlyParts(QueryPart parts) { var result = true; var oppositeResult = true; if ((parts & QueryPart.Select) > 0) { result &= SelectPart.Count > 0; } else { oppositeResult &= SelectPart.Count > 0; } if ((parts & QueryPart.From) > 0) { result &= FromPart.Count > 0; } else { oppositeResult &= FromPart.Count > 0; } if ((parts & QueryPart.Where) > 0) { result &= WherePart == null; } else { oppositeResult &= WherePart == null; } if ((parts & QueryPart.GroupBy) > 0) { result &= GroupPart.Count > 0; } else { oppositeResult &= GroupPart.Count > 0; } if ((parts & QueryPart.OrderBy) > 0) { result &= OrderPart.Count > 0; } else { oppositeResult &= OrderPart.Count > 0; } if ((parts & QueryPart.Skip) > 0) { result &= Skip.HasValue; } else { oppositeResult &= Skip.HasValue; } if ((parts & QueryPart.Take) > 0) { result &= Take.HasValue; } else { oppositeResult &= Take.HasValue; } return(result && !oppositeResult); }
private QueryPart ParseQuery(List <QueryPart> parts) { while (true) { // Check for NOT clauses bool runAgain; do { runAgain = false; var notPos = parts.FindIndex(p => p.QueryType == QueryType.Word && p.Word.Equals("NOT", StringComparison.InvariantCultureIgnoreCase)); if (notPos <= -1) { continue; } parts[notPos + 1].QueryType = QueryType.Not; parts.RemoveAt(notPos); runAgain = true; } while (runAgain); // Check for AND clauses var andPos = parts.FindIndex(p => p.QueryType == QueryType.Word && p.Word.Equals("AND", StringComparison.InvariantCultureIgnoreCase)); if (andPos > -1) { var andPart = new QueryPart { QueryType = QueryType.And, LeftPart = this.ParseQuery(parts.GetRange(0, andPos)), RightPart = this.ParseQuery(parts.GetRange(andPos + 1, parts.Count - (andPos + 1))) }; return(andPart); } // Check for OR clauses var orPos = parts.FindIndex(p => p.QueryType == QueryType.Word && p.Word.Equals("OR", StringComparison.InvariantCultureIgnoreCase)); if (orPos > -1) { var orPart = new QueryPart { QueryType = QueryType.Or, LeftPart = this.ParseQuery(parts.GetRange(0, orPos)), RightPart = this.ParseQuery(parts.GetRange(orPos + 1, parts.Count - (orPos + 1))) }; return(orPart); } // Check if there's only one entry if (parts.Count <= 1) { return(parts[0]); } // Run through the remaining parts var newParts = new List <QueryPart>(); QueryPart lastPart = null; foreach (var part in parts) { if (lastPart != null) { newParts.Add(new QueryPart { QueryType = QueryType.Word, Word = "AND" }); } lastPart = part; newParts.Add(part); } parts = newParts; } }
public void SetQueryPart(QueryPart part) { _queryPart = part; }
public int PartsCount(QueryPart parts) { if ((parts & QueryPart.Select) > 0) { return SelectPart.Count; } if ((parts & QueryPart.From) > 0) { return FromPart.Count; } if ((parts & QueryPart.Where) > 0) { return WherePart == null ? 0 : 1; } if ((parts & QueryPart.GroupBy) > 0) { return GroupPart.Count; } if ((parts & QueryPart.OrderBy) > 0) { return OrderPart.Count; } if ((parts & QueryPart.Skip) > 0) { return Skip.Value; } if ((parts & QueryPart.Take) > 0) { return Take.Value; } return 0; }
private void CreateStaffProfileProjection(QueryPart staffProfileQuery) { var projection = _contentManager.Create<ProjectionPart>("ProjectionPage", t => { t.Record.QueryPartRecord = staffProfileQuery.Record; }); projection.As<TitlePart>().Record.Title = "Staff Directory"; projection.As<MenuPart>().Record.MenuText = "Staff Directory"; projection.As<MenuPart>().Record.MenuPosition = "1"; var mainMenu = _menuService.GetMenu("Main Menu"); if(mainMenu != null) projection.As<MenuPart>().Record.MenuId = _menuService.GetMenu("Main Menu").Id; projection.As<AutoroutePart>().Record.DisplayAlias = "staff-directory"; projection.As<CommonPart>().Record.OwnerId = _membershipService.GetUser("admin").Id; //publish the staff directory projection _contentManager.Publish(projection.ContentItem); }
private void Validate() { FilterState = QueryPart.Validate(Context); }
/// <summary> /// 非批量保存配件信息 /// </summary> /// <param name="partArr">配件信息</param> /// <param name="updateCount">更新条数</param> /// <returns></returns> private static bool SavePartNotBatch(QueryPart.part[] partArr, ref int updateCount) { long nowTicks = Common.LocalDateTimeToUtcLong(GlobalStaticObj_Server.Instance.CurrentDateTime); int partIndex = 0;//列表索引 int partCount = 10000;//每批执行条数 int partSum = partArr.Count() / partCount + 1;//执行批数 //partSum = 0; bool flag = true;//执行结果 DateTime startDate = DateTime.Now; YuTongDic dic = new YuTongDic(); //配件 DataTable dtParts = DBHelper.GetTable("配件信息", GlobalStaticObj_Server.DbPrefix + GlobalStaticObj_Server.Instance.MainAccCode, "tb_parts", "car_parts_code,parts_id", string.Format("data_source='{0}'", (int)DataSources.EnumDataSources.YUTONG), null, null); Dictionary<string, string> dicParts = new Dictionary<string, string>(); foreach (DataRow dr in dtParts.Rows) { dicParts.Add(dr["car_parts_code"].ToString(), dr["parts_id"].ToString()); } //配件替代信息 DataTable dtReplace = DBHelper.GetTable("配件替代信息", GlobalStaticObj_Server.DbPrefix + GlobalStaticObj_Server.Instance.MainAccCode, "tb_parts_replace", "parts_id,repl_id", null, null, null); //Dictionary<string, string> dicReplace = new Dictionary<string, string>(); List<string> listReplace = new List<string>(); foreach (DataRow dr in dtReplace.Rows) { //dicReplace.Add(dr["repl_id"].ToString(), dr["parts_id"].ToString()); listReplace.Add(string.Format("{0},{1}", dr["repl_id"], dr["parts_id"])); } CodingRule comm = new CodingRule(DataSources.EnumProjectType.Parts); string partCode = string.Empty;//配件编码 #region 生成表列 //配件表 List<DataRow> listTbParts = new List<DataRow>(); DataTable dtTbParts = new DataTable(); dtTbParts.Columns.Add(new DataColumn("parts_id", typeof(string))); dtTbParts.Columns.Add(new DataColumn("ser_parts_code", typeof(string))); dtTbParts.Columns.Add(new DataColumn("car_parts_code", typeof(string))); dtTbParts.Columns.Add(new DataColumn("parts_name", typeof(string))); dtTbParts.Columns.Add(new DataColumn("sales_unit_code", typeof(string))); dtTbParts.Columns.Add(new DataColumn("data_source", typeof(string))); dtTbParts.Columns.Add(new DataColumn("default_unit", typeof(string))); dtTbParts.Columns.Add(new DataColumn("sales_unit_name", typeof(string))); dtTbParts.Columns.Add(new DataColumn("model", typeof(string))); dtTbParts.Columns.Add(new DataColumn("retail", typeof(decimal))); dtTbParts.Columns.Add(new DataColumn("price3a_back", typeof(string))); dtTbParts.Columns.Add(new DataColumn("price2a_back", typeof(string))); dtTbParts.Columns.Add(new DataColumn("status", typeof(string))); dtTbParts.Columns.Add(new DataColumn("enable_flag", typeof(string))); dtTbParts.Columns.Add("parts_type", typeof(string)); dtTbParts.Columns.Add(new DataColumn("base_unit_code", typeof(string))); dtTbParts.Columns.Add(new DataColumn("base_unit_name", typeof(string))); dtTbParts.Columns.Add(new DataColumn("sales_unit_quantity", typeof(int))); dtTbParts.Columns.Add(new DataColumn("base_unit_quantity", typeof(int))); dtTbParts.Columns.Add(new DataColumn("create_by", typeof(string))); dtTbParts.Columns.Add(new DataColumn("create_time", typeof(long))); //配件价格信息 DataTable dtTbPartsPrice = new DataTable(); List<DataRow> listTbPrice = new List<DataRow>(); dtTbPartsPrice.Columns.Add(new DataColumn("pp_id", typeof(string))); dtTbPartsPrice.Columns.Add(new DataColumn("parts_id", typeof(string))); dtTbPartsPrice.Columns.Add("is_stock", typeof(string)); dtTbPartsPrice.Columns.Add("is_purchase", typeof(string)); dtTbPartsPrice.Columns.Add("is_sale", typeof(string)); dtTbPartsPrice.Columns.Add(new DataColumn("unit", typeof(string))); dtTbPartsPrice.Columns.Add(new DataColumn("ref_out_price", typeof(decimal))); dtTbPartsPrice.Columns.Add(new DataColumn("out_price_two", typeof(decimal))); dtTbPartsPrice.Columns.Add(new DataColumn("out_price_three", typeof(decimal))); dtTbPartsPrice.Columns.Add("sort_index", typeof(string)); dtTbPartsPrice.Columns.Add(new DataColumn("enable_flag", typeof(string))); dtTbPartsPrice.Columns.Add(new DataColumn("create_by", typeof(string))); dtTbPartsPrice.Columns.Add(new DataColumn("create_time", typeof(long))); //替换配件表 DataTable dtTbReplace = new DataTable(); List<DataRow> listTbReplace = new List<DataRow>(); dtTbReplace.Columns.Add(new DataColumn("replace_id", typeof(string))); dtTbReplace.Columns.Add(new DataColumn("parts_id", typeof(string))); dtTbReplace.Columns.Add(new DataColumn("repl_id", typeof(string))); dtTbReplace.Columns.Add(new DataColumn("repl_parts_code", typeof(string))); dtTbReplace.Columns.Add(new DataColumn("repl_parts_status", typeof(string))); dtTbReplace.Columns.Add(new DataColumn("repl_remark", typeof(string))); dtTbReplace.Columns.Add(new DataColumn("change", typeof(string))); dtTbReplace.Columns.Add(new DataColumn("create_by", typeof(string))); dtTbReplace.Columns.Add(new DataColumn("create_time", typeof(long))); //单位设置 DataTable dtTbPartsSetup = new DataTable(); List<DataRow> listTbSetup = new List<DataRow>(); dtTbPartsSetup.Columns.Add(new DataColumn("set_id", typeof(string))); dtTbPartsSetup.Columns.Add(new DataColumn("parts_id", typeof(string))); dtTbPartsSetup.Columns.Add(new DataColumn("stock_unit", typeof(string))); dtTbPartsSetup.Columns.Add(new DataColumn("purchase_unit", typeof(string))); dtTbPartsSetup.Columns.Add(new DataColumn("sale_unit", typeof(string))); dtTbPartsSetup.Columns.Add(new DataColumn("stock_purchase", typeof(string))); dtTbPartsSetup.Columns.Add(new DataColumn("purchase_sale", typeof(string))); dtTbPartsSetup.Columns.Add(new DataColumn("create_by", typeof(string))); dtTbPartsSetup.Columns.Add(new DataColumn("create_time", typeof(long))); dtTbPartsSetup.Columns.Add(new DataColumn("enable_flag", typeof(string))); #endregion for (int i = 0; i < partSum; i++) { List<SysSQLString> list = new List<SysSQLString>(); dtTbParts.Rows.Clear(); dtTbReplace.Rows.Clear(); listTbParts.Clear(); listTbReplace.Clear(); listTbPrice.Clear(); listTbSetup.Clear(); for (int y = partIndex; y < partCount; y++) { int index = i * partCount + y; if (index >= partArr.Count()) { break; } #region 配件信息 QueryPart.part item = partArr[index]; string price3a = WebServUtil.GetEncField(item.price3a);//加密 string price2a = WebServUtil.GetEncField(item.price2a);//加密 string partType = dic.GetLocalDicID("part_type", item.part_type);//配件类型 string partsID = null; bool isAdd = false;//是否新增 if (dicParts.ContainsKey(item.car_parts_code)) { partsID = dicParts[item.car_parts_code]; } if (!string.IsNullOrEmpty(partsID)) { #region 更新语句 SysSQLString sysSQLString = new SysSQLString(); sysSQLString.cmdType = CommandType.Text; sysSQLString.Param = new Dictionary<string, string>(); StringBuilder strSql = new StringBuilder(); strSql.Append(" update tb_parts set "); strSql.AppendFormat(" parts_name = '{0}' , ", item.parts_name); strSql.AppendFormat(" sales_unit_code = '{0}' , ", item.unit_code); strSql.AppendFormat(" sales_unit_name = '{0}' , ", item.unit_name); strSql.AppendFormat(" model = '{0}' , ", item.model); strSql.AppendFormat(" status = '{0}' , ", item.status == "0" ? "1" : "0"); strSql.AppendFormat(" retail = '{0}' , ", item.retail); strSql.AppendFormat(" price3a = {0} , ", price3a); strSql.AppendFormat(" price2a = {0} , ", price2a); strSql.AppendFormat(" parts_type='{0}',", partType); strSql.AppendFormat(" base_unit_code = '{0}' , ", item.basic_unit_code); strSql.AppendFormat(" base_unit_name = '{0}' , ", item.basic_unit_name); if (!string.IsNullOrEmpty(item.unit_name_quantity)) { strSql.AppendFormat(" sales_unit_quantity = {0} , ", item.unit_name_quantity); } if (!string.IsNullOrEmpty(item.basic_unit_quantity)) { strSql.AppendFormat(" base_unit_quantity = {0} , ", item.basic_unit_quantity); } strSql.AppendFormat(" enable_flag = '{0}' ,", (int)DataSources.EnumEnableFlag.USING); strSql.AppendFormat(" data_source = '{0}' ,", (int)DataSources.EnumDataSources.YUTONG); strSql.AppendFormat(" update_time = {0} ,", nowTicks); strSql.AppendFormat(" update_by = '{0}' ", GlobalStaticObj_Server.Instance.UserID); strSql.AppendFormat(" where car_parts_code='{0}'; ", item.car_parts_code); sysSQLString.sqlString = strSql.ToString(); list.Add(sysSQLString); #endregion } else { isAdd = true; #region 插入语句 partsID = Guid.NewGuid().ToString(); //strSql.Append(" insert into tb_parts("); //strSql.Append("parts_id,car_parts_code,parts_name,sales_unit_code,data_source,sales_unit_name,model,retail,price3a,price2a,status,enable_flag,base_unit_code,base_unit_name,sales_unit_quantity,base_unit_quantity,create_by,create_time"); //strSql.Append(") values ("); //strSql.AppendFormat("'{0}',", partsID); //strSql.AppendFormat("'{0}',", item.car_parts_code); //strSql.AppendFormat("'{0}',", item.parts_name); //strSql.AppendFormat("'{0}',", item.unit_code); //strSql.AppendFormat("'{0}',", (int)DataSources.EnumDataSources.YUTONG); //strSql.AppendFormat("'{0}',", item.unit_name); //strSql.AppendFormat("'{0}',", item.model); //strSql.AppendFormat("'{0}',", item.retail); //strSql.AppendFormat("{0},", price3a); //strSql.AppendFormat("{0},", price2a); //strSql.AppendFormat("'{0}',", item.status); //strSql.AppendFormat("'{0}',", (int)DataSources.EnumEnableFlag.USING); //strSql.AppendFormat("'{0}',", item.basic_unit_code); //strSql.AppendFormat("'{0}',", item.basic_unit_name); //strSql.AppendFormat("'{0}',", item.unit_name_quantity); //strSql.AppendFormat("'{0}',", item.basic_unit_quantity); //strSql.AppendFormat("'{0}',", GlobalStaticObj_Server.Instance.ClientID); //strSql.AppendFormat("{0})", nowTicks); //DataRow dr = dtParts.NewRow(); //dr["parts_id"] = partsID; //dr["car_parts_code"] = item.car_parts_code; //dtParts.Rows.Add(dr); dicParts.Add(item.car_parts_code, partsID); partCode = comm.AddNewNo(); DataRow drParts = dtTbParts.NewRow(); drParts["parts_id"] = partsID; drParts["ser_parts_code"] = partCode; drParts["car_parts_code"] = item.car_parts_code; drParts["parts_name"] = item.parts_name; drParts["sales_unit_code"] = item.unit_code; drParts["data_source"] = ((int)DataSources.EnumDataSources.YUTONG).ToString(); drParts["default_unit"] = item.unit_name; drParts["sales_unit_name"] = item.unit_name; drParts["model"] = item.model; if (!string.IsNullOrEmpty(item.retail)) { drParts["retail"] = Convert.ToDecimal(item.retail); } drParts["price3a_back"] = item.price3a; drParts["price2a_back"] = item.price2a; drParts["parts_type"] = partType; drParts["status"] = item.status == "0" ? "1" : "0"; drParts["enable_flag"] = ((int)DataSources.EnumEnableFlag.USING).ToString(); drParts["base_unit_code"] = item.basic_unit_code; drParts["base_unit_name"] = item.basic_unit_name; if (!string.IsNullOrEmpty(item.unit_name_quantity)) { drParts["sales_unit_quantity"] = (int)Convert.ToDecimal(item.unit_name_quantity); } if (!string.IsNullOrEmpty(item.basic_unit_quantity)) { drParts["base_unit_quantity"] = (int)Convert.ToDecimal(item.basic_unit_quantity); } drParts["create_by"] = GlobalStaticObj_Server.Instance.UserID; drParts["create_time"] = nowTicks; listTbParts.Add(drParts); //dtTbParts.Rows.Add(drParts); #endregion } #endregion #region 替代配件 foreach (QueryPart.replaceDetail itemReplace in item.partReplace) { if (!dicParts.ContainsKey(item.car_parts_code) || dicParts.ContainsKey(itemReplace.repl_parts_code) || string.IsNullOrEmpty(itemReplace.repl_parts_code)) { continue; } string partid = dicParts[item.car_parts_code]; string replacepartid = dicParts[itemReplace.repl_parts_code]; if (listReplace.Contains(string.Format("{0},{1}", replacepartid, partid))) { #region 更新语句 SysSQLString sysSQLString0 = new SysSQLString(); sysSQLString0.cmdType = CommandType.Text; sysSQLString0.Param = new Dictionary<string, string>(); StringBuilder strSql0 = new StringBuilder(); strSql0.Append(" update tb_parts_replace set "); strSql0.AppendFormat(" repl_parts_code = '{0}' , ", itemReplace.repl_parts_code); strSql0.AppendFormat(" repl_parts_status = '{0}' , ", itemReplace.repl_parts_status); strSql0.AppendFormat(" repl_remark = '{0}' , ", itemReplace.repl_remark); strSql0.AppendFormat(" change = '{0}' ", itemReplace.change); strSql0.AppendFormat(" update_time = {0} ", nowTicks); strSql0.AppendFormat(" update_by = '{0}' ", GlobalStaticObj_Server.Instance.UserID); strSql0.AppendFormat(" where parts_id='{0}' and repl_id='{1}'", partid, replacepartid); list.Add(sysSQLString0); #endregion } else { #region 插入语句 replacepartid = Guid.NewGuid().ToString(); //strSql0.Append(" insert into tb_parts_replace("); //strSql0.Append("replace_id,parts_id,repl_id,repl_parts_code,repl_parts_status,repl_remark,change,create_by,create_time"); //strSql0.Append(") values ("); //strSql0.AppendFormat("'{0}',", replacepartid); //strSql0.AppendFormat("'{0}',", partid); //strSql0.AppendFormat("'{0}',", Guid.NewGuid()); //strSql0.AppendFormat("'{0}',", itemReplace.repl_parts_code); //strSql0.AppendFormat("'{0}',", itemReplace.repl_parts_status); //strSql0.AppendFormat("'{0}',", itemReplace.repl_remark); //strSql0.AppendFormat("'{0}',", itemReplace.change); //strSql0.AppendFormat("'{0}',", GlobalStaticObj_Server.Instance.ClientID); //strSql0.AppendFormat("{0})", nowTicks); //DataRow dr = dtReplace.NewRow(); //dr["parts_id"] = partid; //dr["repl_id"] = replacepartid; //dtReplace.Rows.Add(dr); listReplace.Add(string.Format("{0},{1}", replacepartid, partid)); DataRow drReplace = dtTbReplace.NewRow(); drReplace["replace_id"] = replacepartid; drReplace["parts_id"] = partid; drReplace["repl_id"] = Guid.NewGuid().ToString(); drReplace["repl_parts_code"] = itemReplace.repl_parts_code; drReplace["repl_parts_status"] = itemReplace.repl_parts_status; drReplace["repl_remark"] = itemReplace.repl_remark; drReplace["change"] = itemReplace.change; drReplace["create_by"] = GlobalStaticObj_Server.Instance.UserID; drReplace["create_time"] = nowTicks; //dtTbReplace.Rows.Add(drReplace); listTbReplace.Add(drReplace); #endregion } } #endregion #region 配件价格信息 if (!isAdd) { DataRow drPrice = dtTbPartsPrice.NewRow(); drPrice["pp_id"] = Guid.NewGuid().ToString(); drPrice["parts_id"] = partsID; drPrice["unit"] = item.unit_name; drPrice["is_stock"] = "0"; drPrice["is_purchase"] = "0"; drPrice["is_sale"] = "1"; if (!string.IsNullOrEmpty(item.retail)) { drPrice["ref_out_price"] = Convert.ToDecimal(item.retail);//参考售价 } if (!string.IsNullOrEmpty(item.price2a)) { drPrice["out_price_two"] = Convert.ToDecimal(item.price2a); } if (!string.IsNullOrEmpty(item.price3a)) { drPrice["out_price_three"] = Convert.ToDecimal(item.price3a); } drPrice["sort_index"] = "0"; drPrice["enable_flag"] = ((int)DataSources.EnumEnableFlag.USING).ToString(); drPrice["create_by"] = GlobalStaticObj_Server.Instance.UserID; drPrice["create_time"] = nowTicks; listTbPrice.Add(drPrice); } #endregion partArr[index] = null;//释放项 } //flag = DBHelper.BatchExeSQLStringMultiByTrans("宇通:同步配件", list); //flag = DBHelper.BatchExeSQLStringMultiByTrans("tb_parts", listTbParts); flag = DBHelper.SqlBulkByTransNoLogNoBackUp("同步配件", GlobalStaticObj_Server.Instance.MainAccCode, "tb_parts", listTbParts); if (!flag) { break; } #region 更新配件编码 List<SysSQLString> listUpCode = new List<SysSQLString>(); SysSQLString sqlCode = new SysSQLString(); sqlCode.cmdType = CommandType.Text; sqlCode.Param = new Dictionary<string, string>(); sqlCode.Param.Add("bill_code_rule_id", comm.ruleID); sqlCode.Param.Add("last_bill_no", partCode); sqlCode.sqlString = "update sys_bill_code_rule set last_bill_no=@last_bill_no where bill_code_rule_id=@bill_code_rule_id"; listUpCode.Add(sqlCode); flag = DBHelper.BatchExeSQLStrMultiByTransNoLogNoBackup("", GlobalStaticObj_Server.Instance.MainAccCode, listUpCode); if (!flag) { break; } #endregion //flag = DBHelper.BatchExeSQLStringMultiByTrans("tb_parts_replace", listTbReplace); flag = DBHelper.SqlBulkByTransNoLogNoBackUp("同步替换配件", GlobalStaticObj_Server.Instance.MainAccCode, "tb_parts_replace", listTbReplace); if (!flag) { break; } flag = DBHelper.SqlBulkByTransNoLogNoBackUp("同步价格信息", GlobalStaticObj_Server.Instance.MainAccCode, "tb_parts_price", listTbPrice); if (!flag) { break; } flag = DBHelper.SqlBulkByTransNoLogNoBackUp("同步单位设置", GlobalStaticObj_Server.Instance.MainAccCode, "tb_parts_setup", listTbSetup); if (list.Count > 0) { flag = DBHelper.BatchExeSQLStrMultiByTransNoLogNoBackup("更新配件信息", GlobalStaticObj_Server.Instance.MainAccCode, list); if (!flag) { break; } } } #region 加密价格 List<SysSQLString> listUp = new List<SysSQLString>(); SysSQLString sqlPrice = new SysSQLString(); sqlPrice.cmdType = CommandType.Text; string price3aEnc = WebServUtil.GetEncFieldByField("price3a_back"); string price2aEnc = WebServUtil.GetEncFieldByField("price2a_back"); sqlPrice.sqlString = string.Format("update tb_parts set price3a={0},price2a={1},price2a_back=null,price3a_back=null where price3a_back is not null or price2a_back is not null", price2aEnc, price2aEnc); sqlPrice.Param = new Dictionary<string, string>(); listUp.Add(sqlPrice); DBHelper.BatchExeSQLStrMultiByTransNoLogNoBackup("", GlobalStaticObj_Server.Instance.MainAccCode, listUp); #endregion SysConfig sysConfig = new SysConfig(); sysConfig.UpdateLastTime("PartLastTime"); updateCount += partArr.Count(); dtParts = null; dtReplace = null; dtTbParts = null; dtTbPartsPrice = null; dtTbPartsSetup = null; dtTbReplace = null; dic = null; DateTime endDate = DateTime.Now; TimeSpan span = endDate - startDate; return flag; }
public void SetQueryPart(QueryPart part) { CurrentQueryPart = part; }
// Should not change passed query part virtual protected QueryPart QueryPartHook(QueryPart part) { return(part); }
public void SetQueryPart(QueryPart part) { }
private static void CreateFilterGroup(PublishContentContext ctx, QueryPart part) { if (!part.FilterGroups.Any()) { part.FilterGroups.Add(new FilterGroupRecord()); } }
// Should not change passed query part virtual protected QueryPart QueryPartHook (QueryPart part) { return part; }
protected override QueryPart QueryPartHook(QueryPart part) { if (part is QueryPart_Uri) return RemapUriQueryPart ((QueryPart_Uri) part); if (part is QueryPart_Property) { QueryPart_Property prop_part = (QueryPart_Property) part; if (prop_part.Key == "inuri") // special case return RemapInUriQueryPart (prop_part); } return part; }
////////////////////////////////////////////////////////////// // // Code to determine a a file will match a particular query // private bool MatchesQueryPart(QueryPart abstract_part) { bool is_match; is_match = false; if (abstract_part is QueryPart_Text) { QueryPart_Text part; part = abstract_part as QueryPart_Text; if ((part.SearchTextProperties && Name == part.Text) || (part.SearchFullText && BodyContains(part.Text))) { is_match = true; } } else if (abstract_part is QueryPart_Or) { QueryPart_Or part; part = abstract_part as QueryPart_Or; foreach (QueryPart sub_part in part.SubParts) { if (MatchesQueryPart(sub_part)) { is_match = true; break; } } } else if (abstract_part is QueryPart_Property) { QueryPart_Property part; part = abstract_part as QueryPart_Property; if (part.Key == "beagle:MimeType") { if (part.Value == "inode/directory") { is_match = IsDirectory; } else if (part.Value == "text/plain") { is_match = IsFile; } else { is_match = false; } } else if (part.Key == "beagle:ExactFilename") { is_match = (Name == part.Value); } else { throw new Exception("Unsupported property " + part.Key); } } else if (abstract_part is QueryPart_DateRange) { QueryPart_DateRange part; part = abstract_part as QueryPart_DateRange; // FIXME: We assume that the query refers to the file timestamp. // Instead, we should explicitly check part.Key. is_match = (part.StartDate <= Mtime && Mtime <= part.EndDate); } else { throw new Exception("Unsupported part"); } if (abstract_part.Logic == QueryPartLogic.Prohibited) { is_match = !is_match; } return(is_match); }
static private QueryPart MatchToQueryPart(Match m) { // Looping over all Matches we have got: // m.Groups["pm"] plus or minus sign // m.Groups["key"] keyname // m.Groups["quote"] quoted string // m.Groups["midquote1"] + m.Groups["midquote2"] quoted midway string also represents unquoted string string query = m.ToString(); // Either quote is set or midquote1 and (optionally) midquote2 is set string text = m.Groups ["quote"].ToString() + m.Groups ["midquote1"].ToString() + m.Groups ["midquote2"].ToString(); string key = m.Groups ["key"].ToString(); bool IsProhibited = (m.Groups ["pm"].ToString() == "-"); // check for file extensions // if match starts with *. or . and only contains letters we assume it's a file extension if (extension_re.Match(text).Success || key.ToLower() == "ext" || key.ToLower() == "extension") { QueryPart_Property query_part = new QueryPart_Property(); query_part.Key = Property.FilenameExtensionPropKey; if (text.StartsWith("*.")) { query_part.Value = text.Substring(1).ToLower(); } else if (text.StartsWith(".")) { query_part.Value = text.ToLower(); } else { query_part.Value = "." + text.ToLower(); } query_part.Type = PropertyType.Keyword; query_part.Logic = (IsProhibited ? QueryPartLogic.Prohibited : QueryPartLogic.Required); Logger.Log.Debug("Extension query: {0}", query_part.Value); return(query_part); } if (key == String.Empty) { Logger.Log.Debug("Parsed query '{0}' as text_query", text); return(StringToQueryPart(text, IsProhibited)); } // FIXME: i18n-izing "date" if (key == "date") { try { QueryPart part = DateQueryToQueryPart(text); part.Logic = (IsProhibited ? QueryPartLogic.Prohibited : QueryPartLogic.Required); return(part); } catch (FormatException) { Log.Warn("Could not parse [{0}] as date query. Assuming text.", text); return(StringToQueryPart(text, IsProhibited)); } } // FIXME: i18n-izing "uri" if (key == "uri") { try { QueryPart_Uri part = new QueryPart_Uri(); part.Logic = (IsProhibited ? QueryPartLogic.Prohibited : QueryPartLogic.Required); part.Uri = UriFu.UserUritoEscapedUri(text); return(part); } catch (System.UriFormatException) { Log.Warn("Could not parse [{0}] as uri query. Assuming text.", text); return(StringToQueryPart(text, IsProhibited)); } } // Special case if (key == "inuri") { QueryPart_Property inuri_part = new QueryPart_Property(); inuri_part.Logic = (IsProhibited ? QueryPartLogic.Prohibited : QueryPartLogic.Required); inuri_part.Key = "inuri"; inuri_part.Value = text; inuri_part.Type = PropertyType.Keyword; Log.Debug("Handing special query 'inuri:{0}'", text); return(inuri_part); } // Non-keyword queries by directly using property names // Query of form property:namespace:name=value // which is translated to a non-keyword query // namespace:name=value int pos; if (key == "property" && ((pos = text.IndexOf('=')) != -1)) { QueryPart_Property part = new QueryPart_Property(); part.Key = text.Substring(0, pos); part.Value = text.Substring(pos + 1); part.Type = PropertyType.Text; part.Logic = (IsProhibited ? QueryPartLogic.Prohibited : QueryPartLogic.Required); Logger.Log.Debug("Parsed query '" + query + "' as prop query:key=" + part.Key + ", value=" + part.Value + " and property type=" + part.Type); return(part); } // keyword queries by directly using property names // Query of form keyword:namespace:name=value // which is translated to a keyword query // namespace:name=value if (key == "keyword" && ((pos = text.IndexOf('=')) != -1)) { QueryPart_Property part = new QueryPart_Property(); part.Key = text.Substring(0, pos); part.Value = text.Substring(pos + 1); part.Type = PropertyType.Keyword; part.Logic = (IsProhibited ? QueryPartLogic.Prohibited : QueryPartLogic.Required); Logger.Log.Debug("Parsed query '" + query + "' as prop query:key=" + part.Key + ", value=" + part.Value + " and property type=" + part.Type); return(part); } if ((pos = text.IndexOf('*')) >= 0) { QueryPart_Wildcard wild = new QueryPart_Wildcard(); wild.QueryString = text; wild.PropertyOnly = true; return(wild); } string[] prop_string = null; bool is_present; PropertyType[] prop_type; int num; is_present = PropertyKeywordFu.GetMapping(key, out num, out prop_string, out prop_type); // if key is not present in the mapping, assume the query is a text query // i.e. if token is foo:bar and there is no mappable property named foo, // assume "foo:bar" as text query // FIXME the analyzer changes the text query "foo:bar" to "foo bar" // which might not be the right thing to do if (!is_present) { Logger.Log.Warn("Could not find property, parsed query '{0}' as text_query", query); return(StringToQueryPart(query, IsProhibited)); } if (num == 1) { QueryPart_Property query_part_prop = new QueryPart_Property(); query_part_prop.Key = prop_string [0]; query_part_prop.Value = text; query_part_prop.Type = prop_type [0]; query_part_prop.Logic = (IsProhibited ? QueryPartLogic.Prohibited : QueryPartLogic.Required); Logger.Log.Debug("Parsed query '" + query + "' as prop query:key=" + query_part_prop.Key + ", value=" + query_part_prop.Value + " and property type=" + query_part_prop.Type); return(query_part_prop); } // Multiple property queries are mapped to this keyword query // Create an OR query from them // FIXME: Would anyone want an AND query ? QueryPart_Or query_part_or = new QueryPart_Or(); query_part_or.Logic = (IsProhibited ? QueryPartLogic.Prohibited : QueryPartLogic.Required); Logger.Log.Debug("Parsed query '{0}' as OR of {1} queries:", query, num); for (int i = 0; i < num; ++i) { QueryPart_Property query_part_prop = new QueryPart_Property(); query_part_prop.Key = prop_string [i]; query_part_prop.Value = text; query_part_prop.Type = prop_type [i]; query_part_prop.Logic = QueryPartLogic.Required; Log.Debug("\t:key={0}, value={1} and property type={2}", query_part_prop.Key, query_part_prop.Value, query_part_prop.Type); query_part_or.Add(query_part_prop); } return(query_part_or); }
override protected bool MatchesQueryPart(QueryPart part) { // The only thing that could match is the name, and we check // for that already in FileSystemObject.MatchesQuery. return(false); }
// search_subset_uris is a list of Uris that this search should be // limited to. static protected void QueryPartToQuery (QueryPart abstract_part, bool only_build_primary_query, ArrayList term_list, QueryPartHook query_part_hook, out LNS.Query primary_query, out LNS.Query secondary_query, out HitFilter hit_filter) { primary_query = null; secondary_query = null; // By default, we assume that our lucene queries will return exactly the // matching set of objects. We need to set the hit filter if further // refinement of the search results is required. (As in the case of // date range queries, for example.) We essentially have to do this // to make OR queries work correctly. hit_filter = true_hit_filter; // The exception is when dealing with a prohibited part. Just return // null for the hit filter in that case. This works since // prohibited parts are not allowed inside of OR queries. if (abstract_part.Logic == QueryPartLogic.Prohibited) hit_filter = null; if (abstract_part == null) return; // Run the backend hook first. // This gives a chance to modify create new queries based on // backend specific properties if (query_part_hook != null) abstract_part = query_part_hook (abstract_part); if (abstract_part == null) return; if (abstract_part is QueryPart_Text) { QueryPart_Text part = (QueryPart_Text) abstract_part; if (! (part.SearchFullText || part.SearchTextProperties)) return; LNS.BooleanQuery p_query = new LNS.BooleanQuery (); LNS.BooleanQuery s_query = new LNS.BooleanQuery (); bool added_subquery = false; if (part.SearchFullText) { LNS.Query subquery; subquery = StringToQuery ("Text", part.Text, term_list); if (subquery != null) { p_query.Add (subquery, LNS.BooleanClause.Occur.SHOULD); added_subquery = true; } // FIXME: HotText is ignored for now! // subquery = StringToQuery ("HotText", part.Text); // if (subquery != null) { // p_query.Add (subquery, LNS.BooleanClause.Occur.SHOULD); // added_subquery = true; // } } if (part.SearchTextProperties) { LNS.Query subquery; subquery = StringToQuery ("PropertyText", part.Text, term_list); if (subquery != null) { p_query.Add (subquery, LNS.BooleanClause.Occur.SHOULD); // Properties can live in either index if (! only_build_primary_query) s_query.Add (subquery.Clone () as LNS.Query, LNS.BooleanClause.Occur.SHOULD); added_subquery = true; } // The "added_subquery" check is to handle the situation where // a part of the text is a stop word. Normally, a search for // "hello world" would break down into this query: // // (Text:hello OR PropertyText:hello OR PropertyKeyword:hello) // AND (Text:world OR PropertText:world OR PropertyKeyword:world) // // This fails with stop words, though. Let's assume that "world" // is a stop word. You would end up with: // // (Text:hello OR PropertyText:hello OR PropertyKeyword:hello) // AND (PropertyKeyword:world) // // Which is not what we want. We'd want to match documents that // had only "hello" without also having a keyword "world". In // this case, don't create the PropertyKeyword part of the query, // since it would be included in the larger set if it weren't // required anyway. if (added_subquery) { Term term; term = new Term ("PropertyKeyword", part.Text.ToLower ()); // make sure text is lowercased // FIXME: terms are already added in term_list. But they may have been tokenized // The term here is non-tokenized version. Should this be added to term_list ? // term_list is used to calculate scores if (term_list != null) term_list.Add (term); subquery = new LNS.TermQuery (term); p_query.Add (subquery, LNS.BooleanClause.Occur.SHOULD); // Properties can live in either index if (! only_build_primary_query) s_query.Add (subquery.Clone () as LNS.Query, LNS.BooleanClause.Occur.SHOULD); } else { // Reset these so we return a null query p_query = null; s_query = null; } } primary_query = p_query; if (! only_build_primary_query) secondary_query = s_query; return; } if (abstract_part is QueryPart_Wildcard) { QueryPart_Wildcard part = (QueryPart_Wildcard) abstract_part; LNS.BooleanQuery p_query = new LNS.BooleanQuery (); LNS.BooleanQuery s_query = new LNS.BooleanQuery (); Term term; LNS.Query subquery; // Lower case the terms for searching string query_string_lower = part.QueryString.ToLower (); // Search text content if (! part.PropertyOnly) { term = new Term ("Text", query_string_lower); subquery = new LNS.WildcardQuery (term); p_query.Add (subquery, LNS.BooleanClause.Occur.SHOULD); term_list.Add (term); } // Search text properties term = new Term ("PropertyText", query_string_lower); subquery = new LNS.WildcardQuery (term); p_query.Add (subquery, LNS.BooleanClause.Occur.SHOULD); // Properties can live in either index if (! only_build_primary_query) s_query.Add (subquery.Clone () as LNS.Query, LNS.BooleanClause.Occur.SHOULD); term_list.Add (term); if (! part.PropertyOnly) { // Search property keywords term = new Term ("PropertyKeyword", query_string_lower); term_list.Add (term); subquery = new LNS.WildcardQuery (term); p_query.Add (subquery, LNS.BooleanClause.Occur.SHOULD); // Properties can live in either index if (! only_build_primary_query) s_query.Add (subquery.Clone () as LNS.Query, LNS.BooleanClause.Occur.SHOULD); } primary_query = p_query; if (! only_build_primary_query) secondary_query = s_query; return; } if (abstract_part is QueryPart_DateRange) { QueryPart_DateRange part = (QueryPart_DateRange) abstract_part; // FIXME: We don't handle prohibited queries with sub-date // accuracy. For example, if we say we prohibit matches // between 5 May 2007 at 2 PM and 8 May at 5 AM, we'll // miss any matches that happen between midnight and 2 PM // on 5 May 2007 and between midnight and 5 AM on 8 May. primary_query = GetDateRangeQuery (part, out hit_filter); // Date properties can live in either index if (! only_build_primary_query && primary_query != null) secondary_query = primary_query.Clone () as LNS.Query; return; } if (abstract_part is QueryPart_Or) { QueryPart_Or part = (QueryPart_Or) abstract_part; // Assemble a new BooleanQuery combining all of the sub-parts. LNS.BooleanQuery p_query; p_query = new LNS.BooleanQuery (); LNS.BooleanQuery s_query = null; if (! only_build_primary_query) s_query = new LNS.BooleanQuery (); primary_query = p_query; secondary_query = s_query; OrHitFilter or_hit_filter = null; foreach (QueryPart sub_part in part.SubParts) { LNS.Query p_subq, s_subq; HitFilter sub_hit_filter; // FIXME: This is (and must be) ignored // FIXME: Any subpart in an OR which has a hit filter won't work // correctly, because we can't tell which part of an OR we matched // against to filter correctly. This affects date range queries. QueryPartToQuery (sub_part, only_build_primary_query, term_list, query_part_hook, out p_subq, out s_subq, out sub_hit_filter); if (p_subq != null) p_query.Add (p_subq, LNS.BooleanClause.Occur.SHOULD); if (s_subq != null) s_query.Add (s_subq, LNS.BooleanClause.Occur.SHOULD); if (sub_hit_filter != null) { if (or_hit_filter == null) or_hit_filter = new OrHitFilter (); or_hit_filter.Add (sub_hit_filter); } } if (or_hit_filter != null) hit_filter = new HitFilter (or_hit_filter.HitFilter); return; } if (abstract_part is QueryPart_Uri) { QueryPart_Uri part = (QueryPart_Uri) abstract_part; // Do a term query on the Uri field. // This is probably less efficient that using a TermEnum; // but this is required for the query API where the uri query // can be part of a prohibited query or a boolean or query. Term term; term = new Term ("Uri", UriFu.UriToEscapedString (part.Uri)); if (term_list != null) term_list.Add (term); primary_query = new LNS.TermQuery (term); // Query only the primary index return; } if (abstract_part is QueryPart_Property) { QueryPart_Property part = (QueryPart_Property) abstract_part; string field_name; if (part.Key == QueryPart_Property.AllProperties) field_name = TypeToWildcardField (part.Type); else field_name = PropertyToFieldName (part.Type, part.Key); // Details of the conversion here depends on BeagrepAnalyzer::TokenStream if (part.Type == PropertyType.Text) primary_query = StringToQuery (field_name, part.Value, term_list); else { Term term; // FIXME: Handle date queries for other date fields if (part.Type == PropertyType.Internal || field_name.StartsWith ("prop:k:" + Property.PrivateNamespace)) term = new Term (field_name, part.Value); else term = new Term (field_name, part.Value.ToLower ()); if (term_list != null) term_list.Add (term); primary_query = new LNS.TermQuery (term); } // Properties can live in either index if (! only_build_primary_query && primary_query != null) secondary_query = primary_query.Clone () as LNS.Query; return; } throw new Exception ("Unhandled QueryPart type! " + abstract_part.ToString ()); }
//////////////////////////////////////////////////// abstract protected bool MatchesQueryPart(QueryPart part);
static void AddSearchTermInfo(QueryPart part, SearchTermResponse response, StringBuilder sb) { if (part.Logic == QueryPartLogic.Prohibited) { return; } if (part is QueryPart_Or) { ICollection sub_parts; sub_parts = ((QueryPart_Or)part).SubParts; foreach (QueryPart qp in sub_parts) { AddSearchTermInfo(qp, response, sb); } return; } if (!(part is QueryPart_Text)) { return; } QueryPart_Text tp; tp = (QueryPart_Text)part; string [] split; split = tp.Text.Split(' '); // First, remove stop words for (int i = 0; i < split.Length; ++i) { if (LuceneCommon.IsStopWord(split [i])) { split [i] = null; } } // Assemble the phrase minus stop words sb.Length = 0; for (int i = 0; i < split.Length; ++i) { if (split [i] == null) { continue; } if (sb.Length > 0) { sb.Append(' '); } sb.Append(split [i]); } response.ExactText.Add(sb.ToString()); // Now assemble a stemmed version sb.Length = 0; // clear the previous value for (int i = 0; i < split.Length; ++i) { if (split [i] == null) { continue; } if (sb.Length > 0) { sb.Append(' '); } sb.Append(LuceneCommon.Stem(split [i].ToLower())); } response.StemmedText.Add(sb.ToString()); }
/////////////////////////////////////////////////////////////////////// // All of the query parts than can possibly match a directory are handled // in FileSystemObject.MatchesQuery. override protected bool MatchesQueryPart(QueryPart abstract_part) { return(false); }
public TransitionBasedQueryPart(QueryPart tail, IBuilderTransition transition) : base(tail) { _transition = transition; }
private static void FilterStaffProfileQuery(QueryPart staffProfileQuery) { var filterDictionary = new Dictionary<string, string>(); filterDictionary.Add("ContentTypes", "StaffProfile"); filterDictionary.Add("Description", "Staff Profiles"); var state = FormParametersHelper.ToString(filterDictionary); staffProfileQuery.FilterGroups[0].Filters.Add(new FilterRecord { Category = "Content", Description = "Staff Profiles", Position = 0, State = state, Type = "ContentTypes" }); }