public static bool existObj(object obj) { List <string> prikey = new List <string>(), prival = new List <string>(); DBAttribute.GetDBPrimaryElement(obj.GetType(), obj, prikey, prival); return(exist(obj.GetType(), prikey, prival)); }
public static bool Delete(OracleConnection connection, object obj) { Type type = obj.GetType(); StringBuilder strSql = new StringBuilder(); try { strSql.Append(string.Format("delete from {0}", DBAttribute.GetDBTable(type))); } catch (ArgumentException e) { throw new ArgumentException(e.Message); // throw new ArgumentException("Invaild Argument!\n\n from Delete(OracleConnection connection, object obj) \n"); } List <string> propertyPrimaryKeyList = new List <string>(); List <string> propertyPrimaryValueList = new List <string>(); DBAttribute.GetDBPrimaryElement(type, obj, propertyPrimaryKeyList, propertyPrimaryValueList); if (!(propertyPrimaryKeyList.Any() && propertyPrimaryValueList.Any())) { throw new ArgumentException("Invaild Argument!\n\n from Delete(OracleConnection connection, object obj) \n"); } strSql.Append(string.Format(" where ")); for (int i = 0; i < propertyPrimaryKeyList.Count; ++i) { strSql.Append(string.Format(" {0}={1} AND", propertyPrimaryKeyList[i], propertyPrimaryValueList[i])); } strSql.Length -= 3; return(ExecuteSql(connection, strSql.ToString()) > 0); }
public static void Query(OracleConnection connection, object obj, List <string> needs, List <string> res) { StringBuilder StrSql = new StringBuilder(); //字符串拼接器 try { StrSql.Append(string.Format("select"));//DBAttribute.GetDBTable(obj.GetType())) for (int i = 0; i < needs.Count; i++) { if (i == 0) { StrSql.Append(string.Format(" {0}", needs[i])); } else { StrSql.Append(string.Format(",{0}", needs[i])); } } StrSql.Append(string.Format(" from {0}", GetDBTable(obj.GetType())));//DBAttribute.GetDBTable(obj.GetType())) List <string> propertyPrimaryKeyList = new List <string>(); List <string> propertyPrimaryValueList = new List <string>(); //DBAttribute.GetDBElement(obj.GetType(), obj, propertyPrimaryKeyList, propertyPrimaryValueList); DBAttribute.GetDBPrimaryElement(obj.GetType(), obj, propertyPrimaryKeyList, propertyPrimaryValueList); if (!(propertyPrimaryKeyList.Any() && propertyPrimaryValueList.Any())) { throw new ArgumentException("Invaild Argument!\n\n from Delete(OracleConnection connection, object obj) \n"); } StrSql.Append(string.Format(" where ")); for (int i = 0; i < propertyPrimaryKeyList.Count; ++i) { if (propertyPrimaryValueList[i] != null) { StrSql.Append(string.Format(" {0}={1} AND", propertyPrimaryKeyList[i], propertyPrimaryValueList[i])); } } StrSql.Length -= 3; //减去AND } catch (ArgumentException e) { throw new ArgumentException(e.Message); } OracleCommand cmd = new OracleCommand(); PrepareCommand(cmd, connection, null, StrSql.ToString(), null); OracleDataReader odr = null; odr = cmd.ExecuteReader(); //odr读取数据并存入res while (odr.Read()) { for (int i = 0; i < needs.Count; i++) { res.Add(odr[i].ToString()); } } }