/// <summary> /// 查询条件的内容 /// </summary> /// <returns></returns> public override string ToString() { StringBuilder sb = new StringBuilder(); if (_op == LogicalOperator.Not) { sb.Append("NOT "); sb.Append("(" + _lhs.ToString() + ")"); } else { if (_lhs is LogicalExpression) { sb.Append("(" + _lhs.ToString() + ")"); } else { sb.Append(_lhs.ToString()); } sb.Append(LogicOperator == LogicalOperator.And ? " AND " : " OR "); if (_rhs is LogicalExpression) { sb.Append("(" + _rhs.ToString() + ")"); } else { sb.Append(_rhs.ToString()); } } return(sb.ToString()); }
/// <summary> /// ToString /// </summary> /// <param name="searchExpressions"></param> /// <returns></returns> public static string ToString(ISearchExpression searchExpressions) { if (searchExpressions == null) { return(string.Empty); } else { return(searchExpressions.ToString()); } }
protected void Button1_Click(object sender, EventArgs e) { string zid = id.Text.Trim().ToString(); //string weiTuoRen = weiTuoRen.SelectedValue.ToString(); string tiDanHao1 = tiDanHao.Text.Trim().ToString(); string xiangLiang1 = xiangLiang.Text.Trim().ToString(); string zongZhongLiang1 = zongZhongLiang.Text.Trim().ToString(); string daiBiaoXing1 = daiBiaoXing.Text.Trim().ToString(); string pinMing1 = pinMing.Text.Trim().ToString(); string state1 = state.SelectedValue.ToString(); string url = "Search.aspx?window=网页查询_客户委托情况_进口&se="; Session.RemoveAll(); ISearchExpression se = null; if (!string.IsNullOrEmpty(zid)) { se = AndIfNecessary(se, SearchExpression.Like("货代自编号", "%" + zid + "%")); Session["id"] = zid; } if (!string.IsNullOrEmpty(tiDanHao1)) { se = AndIfNecessary(se, SearchExpression.Like("提单号", "%" + tiDanHao1 + "%")); Session["tiDanHao"] = tiDanHao1; } if (!string.IsNullOrEmpty(xiangLiang1)) { se = AndIfNecessary(se, SearchExpression.Eq("箱量", xiangLiang1)); Session["xiangLiang"] = xiangLiang1; } if (!string.IsNullOrEmpty(zongZhongLiang1)) { se = AndIfNecessary(se, SearchExpression.Eq("总重量", zongZhongLiang1)); Session["zongZhongLiang"] = zongZhongLiang1; } if (!string.IsNullOrEmpty(daiBiaoXing1)) { se = AndIfNecessary(se, SearchExpression.Like("代表性箱号", "%" + daiBiaoXing1 + "%")); Session["daiBiaoXing"] = daiBiaoXing1; } if (!string.IsNullOrEmpty(pinMing1)) { se = AndIfNecessary(se, SearchExpression.Like("品名", "%" + pinMing1 + "%")); Session["pinMing"] = pinMing1; } if (!string.IsNullOrEmpty(state1)) { se = AndIfNecessary(se, SearchExpression.Eq("当前状态", state1)); //Session["state"] = state1; } if (!weiTuoTime1.Value.Trim().ToString().Equals("")) { se = AndIfNecessary(se, SearchExpression.Ge("委托时间", weiTuoTime1.Value.Trim().ToString())); } if (!weiTuoTime2.Value.Trim().ToString().Equals("")) { se = AndIfNecessary(se, SearchExpression.Le("委托时间", weiTuoTime2.Value.Trim().ToString())); } if (!daoGangTime1.Value.Trim().ToString().Equals("")) { se = AndIfNecessary(se, SearchExpression.Ge("到港时间", daoGangTime1.Value.Trim().ToString())); } if (!daoGangTime2.Value.Trim().ToString().Equals("")) { se = AndIfNecessary(se, SearchExpression.Le("到港时间", daoGangTime2.Value.Trim().ToString())); } if (!danZhengTime1.Value.Trim().ToString().Equals("")) { se = AndIfNecessary(se, SearchExpression.Ge("单证齐全时间", danZhengTime1.Value.Trim().ToString())); } if (!danZhengTime2.Value.Trim().ToString().Equals("")) { se = AndIfNecessary(se, SearchExpression.Le("单证齐全时间", danZhengTime2.Value.Trim().ToString())); } if (!jieGuanTime1.Value.Trim().ToString().Equals("")) { se = AndIfNecessary(se, SearchExpression.Ge("结关时间", jieGuanTime1.Value.Trim().ToString())); } if (!jieGuanTime2.Value.Trim().ToString().Equals("")) { se = AndIfNecessary(se, SearchExpression.Le("结关时间", jieGuanTime2.Value.Trim().ToString())); } if (se != null) { //exp = HttpUtility.UrlEncode(exp); string exp = se.ToString(); //exp = HttpUtility.UrlEncode(exp, System.Text.Encoding.GetEncoding("gb2312")); exp = Server.UrlEncode(exp); url += exp; } Response.Redirect(url); }
internal static string FillDbCommand(ISearchExpression se, DbParameterCollection dbParams, bool isHaving, ref int paramCnt, Dictionary <string, string> selectAsColumns) { if (se == null) { return(null); } if (se is QueryExpression) { return(null); } if (se is LogicalExpression) { LogicalExpression le = se as LogicalExpression; switch (le.LogicOperator) { case LogicalOperator.And: { string b1 = FillDbCommand(le.LeftHandSide, dbParams, isHaving, ref paramCnt, selectAsColumns); string b2 = FillDbCommand(le.RightHandSide, dbParams, isHaving, ref paramCnt, selectAsColumns); if (!string.IsNullOrEmpty(b1) && !string.IsNullOrEmpty(b2)) { return("(" + b1 + " AND " + b2 + ")"); } else if (!string.IsNullOrEmpty(b1) && string.IsNullOrEmpty(b2)) { return(b1); } else if (string.IsNullOrEmpty(b1) && !string.IsNullOrEmpty(b2)) { return(b2); } else { return(null); } } case LogicalOperator.Or: { string b1 = FillDbCommand(le.LeftHandSide, dbParams, isHaving, ref paramCnt, selectAsColumns); string b2 = FillDbCommand(le.RightHandSide, dbParams, isHaving, ref paramCnt, selectAsColumns); if (!string.IsNullOrEmpty(b1) && !string.IsNullOrEmpty(b2)) { return("(" + b1 + " OR " + b2 + ")"); } else if (!string.IsNullOrEmpty(b1) && string.IsNullOrEmpty(b2)) { return(b1); } else if (string.IsNullOrEmpty(b1) && !string.IsNullOrEmpty(b2)) { return(b2); } else { return(null); } } case LogicalOperator.Not: { string b1 = FillDbCommand(le.LeftHandSide, dbParams, isHaving, ref paramCnt, selectAsColumns); if (!string.IsNullOrEmpty(b1)) { return("(NOT " + b1 + ")"); } else { return(null); } } default: throw new ArgumentException("Invalid LogicalOperator!", "se"); } } else if (se is SimpleExpression) { SimpleExpression cse = se as SimpleExpression; if (cse.FullPropertyName.Contains(":")) { throw new ArgumentException("Not supported in Sql SearchManager with ':' pattern"); } bool isInHaving = IsInHaving(se, selectAsColumns); if ((isHaving && isInHaving) || (!isHaving && !isInHaving)) { string columnName = cse.FullPropertyName; if (isHaving) { columnName = selectAsColumns[columnName]; } //string paraName = "@" + GetParameterName(cmd, cse.FullPropertyName + cse.Operator.ToString()); string paraName = CreateParamName(cse, dbParams); IList arrayData = cse.Values as IList; if (arrayData != null) { paramCnt += arrayData.Count; } else { paramCnt++; } switch (cse.Operator) { case SimpleOperator.Eq: dbParams.Add(DbHelper.Instance.CreateParameter(paraName, cse.Values)); return(columnName + " = " + paraName); case SimpleOperator.NotEq: dbParams.Add(DbHelper.Instance.CreateParameter(paraName, cse.Values)); return(columnName + " <> " + paraName); case SimpleOperator.EqProperty: return(columnName + " = " + cse.Values); case SimpleOperator.NotEqProperty: return(columnName + " <> " + cse.Values); case SimpleOperator.Like: return(FillLikeCommand(dbParams, columnName, paraName, cse.Values, false, false)); case SimpleOperator.InG: { StringBuilder sb = new StringBuilder(); sb.Append(columnName + " IN ("); IList data = cse.Values as IList; System.Diagnostics.Debug.Assert(data != null, "SimpleOperator.InG's Values should be ArrayList!"); for (int i = 0; i < data.Count; ++i) { string paraNameI = paraName + i.ToString(); sb.Append(paraNameI); if (i != data.Count - 1) { sb.Append(","); } dbParams.Add(DbHelper.Instance.CreateParameter(paraNameI, data[i])); } sb.Append(')'); return(sb.ToString()); } case SimpleOperator.IsNotNull: return(columnName + " IS NOT NULL"); case SimpleOperator.IsNull: return(columnName + " IS NULL"); case SimpleOperator.Gt: dbParams.Add(DbHelper.Instance.CreateParameter(paraName, cse.Values)); return(columnName + " > " + paraName); case SimpleOperator.Lt: dbParams.Add(DbHelper.Instance.CreateParameter(paraName, cse.Values)); return(columnName + " > " + paraName); case SimpleOperator.Ge: dbParams.Add(DbHelper.Instance.CreateParameter(paraName, cse.Values)); return(columnName + " >= " + paraName); case SimpleOperator.Le: dbParams.Add(DbHelper.Instance.CreateParameter(paraName, cse.Values)); return(columnName + " <= " + paraName); case SimpleOperator.GInG: { StringBuilder sb = new StringBuilder(); IList data = cse.Values as IList; System.Diagnostics.Debug.Assert(data != null, "SimpleOperator.InG's Values should be ArrayList!"); //if (data.Count <= 1) //{ sb.Append("( "); sb.Append(FillLikeCommand(dbParams, columnName, paraName, data[0], false, false)); for (int i = 1; i < data.Count; ++i) { string paraNameI = paraName + i.ToString(); sb.Append(FillLikeCommand(dbParams, columnName, paraNameI, data[i], false, true)); } sb.Append(" )"); //} //else //{ // sb.Append(columnName + " IN ("); // for (int i = 0; i < data.Count; ++i) // { // string paraNameI = paraName + i.ToString(); // sb.Append(paraNameI); // if (i != data.Count - 1) // { // sb.Append(","); // } // dbParams.Add(DbHelper.Instance.CreateParameter(paraNameI, data[i])); // } // sb.Append(')'); //} return(sb.ToString()); } case SimpleOperator.Any: return(null); case SimpleOperator.Sql: { return(cse.FullPropertyName); } default: throw new NotSupportedException("Not supported SimpleOperator"); } } else { return(null); } } else { throw new NotSupportedException("Invalid SearchExpression of " + se.ToString()); } }
/// <summary> /// ToString /// </summary> /// <param name="searchExpressions"></param> /// <returns></returns> public static string ToString(ISearchExpression searchExpressions) { if (searchExpressions == null) { return string.Empty; } else { return searchExpressions.ToString(); } }
internal static string FillDbCommand(ISearchExpression se, DbParameterCollection dbParams, bool isHaving, ref int paramCnt, Dictionary<string, string> selectAsColumns) { if (se == null) return null; if (se is QueryExpression) return null; if (se is LogicalExpression) { LogicalExpression le = se as LogicalExpression; switch (le.LogicOperator) { case LogicalOperator.And: { string b1 = FillDbCommand(le.LeftHandSide, dbParams, isHaving, ref paramCnt, selectAsColumns); string b2 = FillDbCommand(le.RightHandSide, dbParams, isHaving, ref paramCnt, selectAsColumns); if (!string.IsNullOrEmpty(b1) && !string.IsNullOrEmpty(b2)) { return "(" + b1 + " AND " + b2 + ")"; } else if (!string.IsNullOrEmpty(b1) && string.IsNullOrEmpty(b2)) { return b1; } else if (string.IsNullOrEmpty(b1) && !string.IsNullOrEmpty(b2)) { return b2; } else { return null; } } case LogicalOperator.Or: { string b1 = FillDbCommand(le.LeftHandSide, dbParams, isHaving, ref paramCnt, selectAsColumns); string b2 = FillDbCommand(le.RightHandSide, dbParams, isHaving, ref paramCnt, selectAsColumns); if (!string.IsNullOrEmpty(b1) && !string.IsNullOrEmpty(b2)) { return "(" + b1 + " OR " + b2 + ")"; } else if (!string.IsNullOrEmpty(b1) && string.IsNullOrEmpty(b2)) { return b1; } else if (string.IsNullOrEmpty(b1) && !string.IsNullOrEmpty(b2)) { return b2; } else { return null; } } case LogicalOperator.Not: { string b1 = FillDbCommand(le.LeftHandSide, dbParams, isHaving, ref paramCnt, selectAsColumns); if (!string.IsNullOrEmpty(b1)) { return "(NOT " + b1 + ")"; } else { return null; } } default: throw new ArgumentException("Invalid LogicalOperator!", "se"); } } else if (se is SimpleExpression) { SimpleExpression cse = se as SimpleExpression; if (cse.FullPropertyName.Contains(":")) { throw new ArgumentException("Not supported in Sql SearchManager with ':' pattern"); } bool isInHaving = IsInHaving(se, selectAsColumns); if ((isHaving && isInHaving) || (!isHaving && !isInHaving)) { string columnName = cse.FullPropertyName; if (isHaving) { columnName = selectAsColumns[columnName]; } //string paraName = "@" + GetParameterName(cmd, cse.FullPropertyName + cse.Operator.ToString()); string paraName = CreateParamName(cse, dbParams); IList arrayData = cse.Values as IList; if (arrayData != null) { paramCnt += arrayData.Count; } else { paramCnt++; } switch (cse.Operator) { case SimpleOperator.Eq: dbParams.Add(DbHelper.Instance.CreateParameter(paraName, cse.Values)); return columnName + " = " + paraName; case SimpleOperator.NotEq: dbParams.Add(DbHelper.Instance.CreateParameter(paraName, cse.Values)); return columnName + " <> " + paraName; case SimpleOperator.EqProperty: return columnName + " = " + cse.Values; case SimpleOperator.NotEqProperty: return columnName + " <> " + cse.Values; case SimpleOperator.Like: return FillLikeCommand(dbParams, columnName, paraName, cse.Values, false, false); case SimpleOperator.InG: { StringBuilder sb = new StringBuilder(); sb.Append(columnName + " IN ("); IList data = cse.Values as IList; System.Diagnostics.Debug.Assert(data != null, "SimpleOperator.InG's Values should be ArrayList!"); for (int i = 0; i < data.Count; ++i) { string paraNameI = paraName + i.ToString(); sb.Append(paraNameI); if (i != data.Count - 1) { sb.Append(","); } dbParams.Add(DbHelper.Instance.CreateParameter(paraNameI, data[i])); } sb.Append(')'); return sb.ToString(); } case SimpleOperator.IsNotNull: return columnName + " IS NOT NULL"; case SimpleOperator.IsNull: return columnName + " IS NULL"; case SimpleOperator.Gt: dbParams.Add(DbHelper.Instance.CreateParameter(paraName, cse.Values)); return columnName + " > " + paraName; case SimpleOperator.Lt: dbParams.Add(DbHelper.Instance.CreateParameter(paraName, cse.Values)); return columnName + " > " + paraName; case SimpleOperator.Ge: dbParams.Add(DbHelper.Instance.CreateParameter(paraName, cse.Values)); return columnName + " >= " + paraName; case SimpleOperator.Le: dbParams.Add(DbHelper.Instance.CreateParameter(paraName, cse.Values)); return columnName + " <= " + paraName; case SimpleOperator.GInG: { StringBuilder sb = new StringBuilder(); IList data = cse.Values as IList; System.Diagnostics.Debug.Assert(data != null, "SimpleOperator.InG's Values should be ArrayList!"); //if (data.Count <= 1) //{ sb.Append("( "); sb.Append(FillLikeCommand(dbParams, columnName, paraName, data[0], false, false)); for (int i = 1; i < data.Count; ++i) { string paraNameI = paraName + i.ToString(); sb.Append(FillLikeCommand(dbParams, columnName, paraNameI, data[i], false, true)); } sb.Append(" )"); //} //else //{ // sb.Append(columnName + " IN ("); // for (int i = 0; i < data.Count; ++i) // { // string paraNameI = paraName + i.ToString(); // sb.Append(paraNameI); // if (i != data.Count - 1) // { // sb.Append(","); // } // dbParams.Add(DbHelper.Instance.CreateParameter(paraNameI, data[i])); // } // sb.Append(')'); //} return sb.ToString(); } case SimpleOperator.Any: return null; case SimpleOperator.Sql: { return cse.FullPropertyName; } default: throw new NotSupportedException("Not supported SimpleOperator"); } } else { return null; } } else { throw new NotSupportedException("Invalid SearchExpression of " + se.ToString()); } }