C#通用DAO实现(七)

第3013到最后一行的代码(终于完了)

/// <summary> /// 表示条件的枚举 /// </summary> public enum Op { /// <summary> /// 表示"大于" /// </summary> MoreThan = 0, /// <summary> /// 表示"大于等于" /// </summary> BeginWith = 1, /// <summary> /// 表示"小于" /// </summary> LessThan = 2, /// <summary> /// 表示"小于等于" /// </summary> EndWith = 3, /// <summary> /// 表示"等于" /// </summary> Same = 4, /// <summary> /// 模糊查询 /// </summary> Like = 5, /// <summary> /// 是否是 /// </summary> Is = 6, /// <summary> /// 不等于(<>) /// </summary> UnequalTo = 7 } /// <summary> /// 查询条件类 /// </summary> [Serializable] public class Connditon { private string name; /// <summary> /// 条件名 /// </summary> public string Name { get { return name; } set { name = value; } } private Op opType; /// <summary> /// 查询条件 /// </summary> public Op OpType { get { return opType; } set { opType = value; } } private object value; /// <summary> /// 条件值 /// </summary> public object Value { get { return this.value; } set { if (value is String) { //特殊符号处理 String _value = value as String; _value = _value.Replace("[", "[[]"); _value = _value.Replace("%", "[%]"); _value = _value.Replace("_", "[_]"); this.value = _value; } else { this.value = value; } } } public static string GetType(Op opType) { string TypeString = ""; switch (opType) { case Op.BeginWith: TypeString = ">="; break; case Op.EndWith: TypeString = "<="; break; case Op.LessThan: TypeString = "<"; break; case Op.Like: TypeString = "like"; break; case Op.MoreThan: TypeString = ">"; break; case Op.Same: TypeString = "="; break; case Op.Is: TypeString = "is"; break; case Op.UnequalTo: TypeString = "<>"; break; } return TypeString; } public override bool Equals(object obj) { return obj is Connditon ? this.name.ToLower().Equals((obj as Connditon).name.ToLower()) : false; } public override int GetHashCode() { return this.name.GetHashCode(); } } /// <summary> /// 连接类 /// </summary> public class Conn { private static string conStr = ConfigurationManager.ConnectionStrings["SqlServerConnectionString"].ToString(); public static DbConnection getConn() { return new SqlConnection(conStr); } } }

你可能感兴趣的:(C#通用DAO实现(七))