protected string GenSelectClauseForUSC(InternalBookmarkItem ibmItem, ref GenOsqlParamInfo paramInfo) { //1.Find USC bookmark in the list Conditions to get actual USC. //2.Build SQl string sqlClause = string.Empty; string itemName = BaseMarkupUtilities.GetOriginalBizName(ibmItem.Key, ibmItem.BizName); if (paramInfo.UscItems == null || paramInfo.UscItems.Count <= 0 || ibmItem.Key.EndsWith(BaseProntoMarkup.KeyEndIf)) { return(sqlClause); } USCItem uscItem = null; if (paramInfo.UscItems.Keys.Contains(itemName)) { uscItem = paramInfo.UscItems[itemName]; } // Dictionary <string, DSTreeView> lowerFields = new Dictionary <string, DSTreeView>(); foreach (string key in paramInfo.DomainInfo.Fields.Keys) { lowerFields.Add(key.ToLower(), paramInfo.DomainInfo.Fields[key]); } //Validate and Build SQl if (uscItem != null) { List <Token> lstTokens = new List <Token>(); string error = string.Empty; ExpressionProvider expressProvider = new ExpressionProvider(); expressProvider.DoTokenize(uscItem.SQLExpression, ref lstTokens, ref error); foreach (Token token in lstTokens) { string key = string.Empty; if (token.Name.Contains("[") && token.Name.Contains("]")) { key = token.Name.Substring(1, token.Name.Length - 2).ToLower(); if (lowerFields.ContainsKey(key)) { token.Name = lowerFields[key].TechName; if (paramInfo.DSRelationRow == null) { paramInfo.DSRelationRow = lowerFields[key].Relation.Clone(); } else { paramInfo.DSRelationRow.OrRow(lowerFields[key].Relation); } } } sqlClause += token.Name + " "; } } return(sqlClause.Trim()); }
private bool ProcessUSCTag(InternalBookmarkItem ibmItem, DSIconType dataTagType, string itemName, ref GenOsqlParamInfo paramInfo, ref Dictionary <string, bool> dataTagChecker) { if (dataTagType == DSIconType.USC) { GetTableIndexForUSC(ibmItem, ref paramInfo); USCItem usc = paramInfo.UscItems[itemName]; string orderFieldName = usc.BaseOnField; if (!string.IsNullOrWhiteSpace(orderFieldName) && !dataTagChecker.ContainsKey(orderFieldName)) { InternalBookmarkItem exist = (from c in paramInfo.IbmDomain.InternalBookmarkItems where (c.TableIndex == usc.TableIndex) && (string.Equals(c.ItemType, DSIconType.Field.ToString())) select c).FirstOrDefault(); //If existed one data field in selected tag, shouldnot include data field in udf if (exist == null || string.IsNullOrEmpty(exist.BizName)) { InternalBookmarkItem bm = AddUdfFields(orderFieldName, ref paramInfo); dataTagChecker.Add(BaseMarkupUtilities.GetOriginalBizName(bm.Key, bm.BizName), true); } else { dataTagChecker.Add(itemName, true); paramInfo.AddDataTags(ibmItem, true); } } return(true); } return(false); }
private Token SetDataTypeForField(OperandInfo token, USCItem variableInfo) { if ((null == token) || (null == variableInfo)) { return(token); } if (variableInfo.Type == DSIconType.Field) { token.Type = variableInfo.DataType; } return(token); }
/// <summary> /// Add new a User Specificed Condition. /// </summary> /// <param name="name"></param> /// <param name="value"></param> /// <param name="listFields"></param> /// <returns></returns> public USCItem CreateUscItem(string name, string value, Dictionary <string, USCItem> listFields, ref string errorMessage) { List <USCItem> returnFields = new List <USCItem>(); USCItem item = null; if (ValidateCondition(value, listFields, ref returnFields, ref errorMessage)) { item = new USCItem(name, value); if (returnFields != null && returnFields.Count > 0) { item.Fields = returnFields; } } return(item); }
private int GetTableIndexForUSC(InternalBookmarkItem ibmItem, ref GenOsqlParamInfo paramInfo) { if (paramInfo.UscItems == null || paramInfo.UscItems.Count <= 0) { return(-1); } string itemName = BaseMarkupUtilities.GetOriginalBizName(ibmItem.Key, ibmItem.BizName); USCItem item = paramInfo.UscItems[itemName]; int maxIndex = -1; if (item.Fields.Count > 0) { foreach (USCItem subField in item.Fields) { if (paramInfo.DomainInfo.Fields.Keys.Contains(subField.BusinessName)) { if (maxIndex < paramInfo.DomainInfo.Fields[subField.BusinessName].TableIndex) { maxIndex = paramInfo.DomainInfo.Fields[subField.BusinessName].TableIndex; item.BaseOnField = string.IsNullOrWhiteSpace(paramInfo.DomainInfo.Fields[subField.BusinessName].OrginalField) ? paramInfo.DomainInfo.Fields[subField.BusinessName].Text : paramInfo.DomainInfo.Fields[subField.BusinessName].OrginalField; } } } } ibmItem.TableIndex = maxIndex; item.TableIndex = maxIndex; //Update to Relation DSOnClause table = paramInfo.DomainInfo.DSDomainData.OnClauses.Items[maxIndex]; string tableName = table.Alias; if (!paramInfo.DomainInfo.Relations.MapInfos.ContainsKey(itemName)) { paramInfo.DomainInfo.Relations.MapInfos.Add(itemName, new Mapping(itemName, tableName, itemName)); } else { paramInfo.DomainInfo.Relations.MapInfos[itemName].TableName = tableName; } return(maxIndex); }
public bool ValidateFieldsInCondition(List <USCItem> listCondition, Dictionary <string, USCItem> listItems) { if (listCondition == null) { return(true); } else if (listItems == null) { return(false); } foreach (USCItem item in listCondition) { if (item.Fields != null && item.Fields.Count > 0) { foreach (USCItem subField in item.Fields) { if (listItems.ContainsKey(subField.BusinessName.ToLower())) { USCItem field = listItems[subField.BusinessName.ToLower()]; subField.BusinessName = field.BusinessName; subField.DataType = field.DataType; subField.Type = field.Type; item.IsValid = true; } else { item.IsValid = false; item.ErrorMessage += MessageUtils.Expand(Properties.Resources.ipm_M005, Properties.Resources.ipe_M005, subField.BusinessName); } } } } return(true); }