/// <summary> /// 生成@xxxx参数 /// </summary> /// <param name="tableFilter"></param> /// <param name="parameters"></param> /// <returns></returns> public string ParseTableDBParam(TableFilter tableFilter, DBParamCollection parameters) { string result = string.Empty; foreach (var child in tableFilter.ChildFilters) { foreach (var value in child.FilterValue.ConvertTostring().Split(',')) { var param = new DBParam(child.FilterName, value); parameters.Add(param); result += param.ParamName + ","; } } return(result.TrimEnd(',')); }
/// <summary> /// insert 生成values()参数,与列名 /// </summary> /// <param name="tableFilter"></param> /// <param name="parameters"></param> /// <returns></returns> public string ParseTableColumns(TableFilter tableFilter, DBParamCollection parameters, out string columns) { string result = string.Empty; columns = string.Empty; foreach (var child in tableFilter.ChildFilters) { if (child.FilterValue.IsNullOrEmpty()) { continue; } foreach (var value in child.FilterValue.ConvertTostring().Split(',')) { var param = new DBParam(child.FilterName, value); columns += child.FilterName + ","; parameters.Add(param); result += param.ParamName + ","; } } columns = columns.TrimEnd(','); return(result.TrimEnd(',')); }
public string ParseTableFilter(TableFilter tableFilter, DBParamCollection parameters) { if (null == tableFilter) { return("1=1"); } string result = string.Empty; if (tableFilter.IsContainer) { #region 遍历加载子条件 foreach (var child in tableFilter.ChildFilters) { child.MainTable = tableFilter.MainTable; var filterString = ParseTableFilter(child, parameters); if (string.IsNullOrWhiteSpace(filterString)) { continue; } if (!string.IsNullOrEmpty(result)) { result += tableFilter.And ? " AND " : " OR "; } result += filterString; } if (!string.IsNullOrEmpty(result)) { result = string.Format("{0}({1})", tableFilter.Not ? "NOT" : string.Empty, result); } else { result = "1=1"; } #endregion 遍历加载子条件 } else { if (tableFilter.FilterValue.IsNullOrEmpty() && tableFilter.OperateMode != EOperateMode.IsNull & tableFilter.OperateMode != EOperateMode.IsNotNull) { return(result); } if (tableFilter.OperateMode == EOperateMode.In) { string parmsString = string.Empty; foreach (var value in tableFilter.FilterValue.ConvertTostring().Split(',')) { var param = new DBParam(tableFilter.FilterName, value); parameters.Add(param); parmsString += param.ParamName + ","; } result = string.Format("{0}{1} IN ({2})", tableFilter.FilterName, (tableFilter.Not ? " NOT" : string.Empty), parmsString.TrimEnd(',')); } else { var paramValue = string.Empty; if (tableFilter.OperateMode == EOperateMode.LikeLeft) { paramValue = $"{tableFilter.FilterValue}%"; } else if (tableFilter.OperateMode == EOperateMode.LikeRight) { paramValue = $"%{tableFilter.FilterValue}"; } else if (tableFilter.OperateMode == EOperateMode.LikeRight) { paramValue = $"%{tableFilter.FilterValue}%"; } var param = new DBParam(tableFilter.FilterName, paramValue.IsNullOrEmpty() ? tableFilter.FilterValue : paramValue); if (tableFilter.OperateMode != EOperateMode.IsNull && tableFilter.OperateMode != EOperateMode.IsNotNull) { parameters.Add(param); } result = tableFilter.FilterName + GetOperateFilter(tableFilter.OperateMode, param.ParamName, parameters.GetStringPlus); if (tableFilter.Not) { result = "NOT(" + result + ")"; } } } return(result); }