/// <summary> /// 分解操作符为In的过滤参数,返回组合好的过滤条件表达式 /// </summary> /// <param name="para"></param> private static string GenerateConditionFromInParameter(FilterParameter para) { string formatString = " {0} {1} {2}"; StringBuilder expressions = new StringBuilder(); // 先用','作为分隔符,拆分出独立的条件 string[] separator1 = new string[] { "," }; string[] separator2 = new string[] { "~" }; string[] values = para.ParameterValue.ToString().Split(separator1, StringSplitOptions.None); string[] rangs; StringBuilder inValues = new StringBuilder(); // 保存In条件的单个值 foreach (string condition in values) { if (condition.Contains("~")) // 范围型转换为">=" 和 "<="两个条件 { if (expressions.Length > 0) { expressions.Append(" OR "); } rangs = condition.Split(separator2, StringSplitOptions.None); expressions.AppendFormat(CultureInfo.CurrentCulture , " ({0} >= {1} AND {0} <= {2})" , para.FieldName , rangs[0], rangs[1]); } else if (condition.Contains("%")) // 含有"%"的转换为"like"条件 { if (expressions.Length > 0) { expressions.Append(" OR "); } expressions.Append(String.Format(CultureInfo.CurrentCulture , formatString , para.FieldName , CommonOperation.GetOperatorSign(CompareOperator.Like) , condition)); } else //其它的单个值保存下来作为In条件的值,最后统一加 { if (inValues.Length > 0) { inValues.Append(','); } inValues.Append(condition); } } if (inValues.Length > 0) { if (expressions.Length > 0) { expressions.Append(" OR "); } expressions.Append(String.Format(CultureInfo.CurrentCulture , "{0} in ({1})" , para.FieldName , inValues.ToString())); } return("(" + expressions.ToString() + ")"); }
private void SetParameter(string parameterName, FilterParameter value) { //this.OnChange(); int num1 = this.IndexOf(parameterName); if (num1 < 0) { throw new ArgumentOutOfRangeException(MessageStringManager.GetString("ParameterOutOfRange")); } this.Replace(num1, value); }
/// <summary> /// Clone /// </summary> /// <returns></returns> public FilterParameter Clone() { FilterParameter cln = new FilterParameter(); cln.FieldName = this.FieldName; cln.Caption = this.Caption; cln.AllowUserEdit = this.AllowUserEdit; cln.DataCatalog = this.DataCatalog; cln.Description = this.Description; cln.Enabled = this.Enabled; cln.Operator = this.Operator; //cln.ParameterValue = this.ParameterValue; cln.Value = this.Value; cln.IsString = this.IsString; return(cln); }
/// <summary> /// 确定两个FilterParameter对象是否相同 /// </summary> /// <param name="obj"></param> /// <returns></returns> public override bool Equals(Object obj) { // If parameter is null, or cannot be cast to FilterParameter, // return false. if (obj == null) { return(false); } FilterParameter p = obj as FilterParameter; if ((object)p == null) { return(false); } // Return true if the fields match: return((FieldName == p.FieldName) && (Caption == p.Caption) && (IsString == p.IsString) && (Operator == p.Operator)); }
/// <summary> /// 查找指定参数对象在List中的位置 /// </summary> /// <param name="value"></param> /// <returns></returns> public int IndexOf(object value) { if (value != null) { ValidateType(value); List <FilterParameter> list1 = this.InnerList; FilterParameter temp = (FilterParameter)value; if (list1 != null) { for (int num1 = 0; num1 < list1.Count; num1++) { if (temp == list1[num1]) { return(num1); } } } } return(-1); }
/// <summary> /// 查找指定参数对象在List中的位置 /// </summary> /// <param name="value"></param> /// <returns></returns> public int IndexOf(FilterParameter value) { return(this.IndexOf(value)); }
/// <summary> /// 检查参数列表是否包含指定的参数 /// </summary> /// <param name="value"></param> /// <returns></returns> public bool Contains(FilterParameter value) { return(-1 != this.IndexOf(value)); }
/// <summary> /// 向参数列表添加参数 /// </summary> /// <param name="value"></param> /// <returns></returns> public FilterParameter Add(FilterParameter value) { this.Add((object)value.Clone()); return(value); }
private void SetParameter(int index, FilterParameter value) { //this.OnChange(); this.RangeCheck(index); this.Replace(index, value); }