public Filter(string colName, object Value, ComparisonOperators cop) { if (SqlFactory.GetColType(Value.GetType()) == 1) { Expression = System.String.Format(" {0} {1} '{2}' ", colName, cops.getcopstr(cop), Value); } else { Expression = System.String.Format(" {0} {1} {2} ", colName, cops.getcopstr(cop), Value); } }
public static string CreateSqlToUpdate(IHashEntity entity) { Hashtable htalbe = entity.PropertySet; if (htalbe[entity.PKeyName] == null) { throw new Exception("实体没有主键不能用此方法更新"); } SqlFactory sql = new SqlFactory(entity.TableName, SqlType.UPDATE); foreach (string colName in entity.ColNames) { if (colName != entity.PKeyName && htalbe[colName] != System.DBNull.Value && htalbe[colName] != null) { switch (SqlFactory.GetColType(htalbe[colName].GetType())) { case 1: sql.AppendQuote(colName, htalbe[colName]); break; case 2: sql.Append(colName, htalbe[colName]); break; default: sql.Append(colName, htalbe[colName]); break; } } } switch (SqlFactory.GetColType(htalbe[entity.PKeyName].GetType())) { case 1: sql.AppendWhereQuote(entity.PKeyName, htalbe[entity.PKeyName]); break; case 2: sql.AppendWhere(entity.PKeyName, htalbe[entity.PKeyName]); break; default: sql.AppendWhere(entity.PKeyName, htalbe[entity.PKeyName]); break; } return(sql.CreateSQL()); }
public void Delete(IHashEntity entity) { string sql; switch (SqlFactory.GetColType(entity.PropertySet[entity.PKeyName].GetType())) { case 1: sql = "DELETE * FROM [{0}] WHERE {1} = '{2}'"; break; case 2: sql = "DELETE * FROM [{0}] WHERE {1} = {2}"; break; default: sql = "DELETE * FROM [{0}] WHERE {1} = '{2}'"; break; } ExecuteNonQuery(string.Format(sql, entity.TableName, entity.PKeyName, entity.PropertySet[entity.PKeyName])); }
public void Update(IHashEntity entity, IFilter filter) { Hashtable htalbe = entity.PropertySet; StringBuilder strSql = new StringBuilder(); strSql.AppendFormat("UPDATE {0} SET ", entity.TableName); foreach (string colName in entity.ColNames) { if (colName != entity.PKeyName && htalbe[colName] != System.DBNull.Value && htalbe[colName] != null) { switch (SqlFactory.GetColType(htalbe[colName].GetType())) { case 1: strSql.AppendFormat("{0}='{1}',", colName, htalbe[colName]); break; case 2: strSql.AppendFormat("{0}={1},", colName, htalbe[colName]); break; default: strSql.AppendFormat("{0}='{1}',", colName, htalbe[colName]); break; } } } strSql.Remove(strSql.Length - 1, 1); if (filter != null) { strSql.AppendFormat(" where {0}", filter.GetExpression()); } ExecuteNonQuery(strSql.ToString()); }
public void SelectToHash <TEntity>(IFilter filter, params string[] orderbys) where TEntity : new() { string sql = SqlFactory.CreateSqlToSelect <TEntity>(filter, orderbys); _HashTable = TableToHash(ExecuteWithQuery(sql)); }
public IList <TEntity> Select <TEntity>(IFilter filter, params string [] orderbys) where TEntity : new() { string sql = SqlFactory.CreateSqlToSelect <TEntity>(filter, orderbys); return(Select <TEntity>(sql)); }
public void Update(IHashEntity entity) { string sql = SqlFactory.CreateSqlToUpdate(entity); ExecuteNonQuery(sql); }