public static object ChangeValueForType(Type type, string text) { string typename = type.ToString().Replace("System.Nullable`1[", "").Replace("]", "").Replace("System.", "").ToLower(); switch (typename.ToLower()) { case "decimal": return(ToolFunction.ToDec(text)); case "int": case "int32": case "int64": case "long": return(ToolFunction.ToInt(text)); case "double": return(ToolFunction.ToDouble(text)); case "float": return(ToolFunction.ToFloat(text)); case "string": return(text.ToString()); case "bool": case "boolean": bool ret = false; if (text.ToString() == "是") { ret = true; } if (text.ToString() == "1") { ret = true; } if (text.ToString().ToLower() == "true") { ret = true; } if (text.ToString() == "否") { ret = false; } if (text.ToString() == "0") { ret = false; } if (text.ToString().ToLower() == "false") { ret = false; } return(ret); case "datetime": return(ToolFunction.ToDateTime(text)); default: return(text); } }
public bool CompareValue(string type, object rowValue, object filterValue, string conditionStr) { bool result = false; switch (type.ToLower()) { case "decimal": case "int": case "int32": case "int64": case "long": case "double": case "float": var s_d = ToolFunction.ToDec(rowValue); var t_d = ToolFunction.ToDec(filterValue); switch (conditionStr) { case "=": result = s_d == t_d; break; case ">": result = s_d > t_d; break; case "<": result = s_d < t_d; break; case ">=": result = s_d >= t_d; break; case "<=": result = s_d <= t_d; break; case "!=": result = s_d != t_d; break; } break; case "string": var s_s = rowValue.ToString(); var t_s = filterValue.ToString(); if (string.IsNullOrWhiteSpace(conditionStr)) { conditionStr = "like"; } switch (conditionStr) { case "like": result = s_s.ToLower().Contains(t_s.ToLower()); break; case "!like": result = !s_s.ToLower().Contains(t_s.ToLower()); break; case "=": result = s_s.ToLower() == t_s.ToLower(); break; } break; case "bool": case "boolean": bool s_b = false; if (rowValue.ToString() == "是") { s_b = true; } if (rowValue.ToString() == "1") { s_b = true; } if (rowValue.ToString().ToLower() == "true") { s_b = true; } if (rowValue.ToString() == "否") { s_b = false; } if (rowValue.ToString() == "0") { s_b = false; } if (rowValue.ToString().ToLower() == "false") { s_b = false; } //================================== var t_b = false; if (filterValue.ToString() == "是") { t_b = true; } if (filterValue.ToString() == "1") { t_b = true; } if (filterValue.ToString().ToLower() == "true") { t_b = true; } if (filterValue.ToString() == "否") { t_b = false; } if (filterValue.ToString() == "0") { t_b = false; } if (filterValue.ToString().ToLower() == "false") { t_b = false; } switch (conditionStr) { case "!=": result = s_b != t_b; break; case "=": result = s_b == t_b; break; } break; case "datetime": var s_dt = ToolFunction.ToDateTime(rowValue); var t_dt = ToolFunction.ToDateTime(filterValue); switch (conditionStr) { case "=": result = s_dt == t_dt; break; case ">": result = s_dt > t_dt; break; case ">=": result = s_dt >= t_dt; break; case "<=": result = s_dt <= t_dt; break; case "<": result = s_dt < t_dt; break; case "!=": result = s_dt != t_dt; break; } break; } return(result); }