private int CheckIsNullOrEmpty(AUDIT_LOG_DB db) { int rslt = 0; foreach (PropertyInfo prop in db.GetType().GetProperties()) { var varprop = db.GetType().GetProperty(prop.Name); if (varprop.PropertyType.Name == "String") { rslt = string.IsNullOrEmpty(varprop.GetValue(db, null) as string) ? rslt : ++rslt; } if (varprop.PropertyType.Name == "OracleClob") { rslt = string.IsNullOrEmpty((varprop.GetValue(db, null) as OracleClob).Value) ? rslt : ++rslt; } if (varprop.PropertyType.IsGenericType && varprop.PropertyType.GetGenericTypeDefinition() == typeof(Nullable <>)) { var propertyType = varprop.PropertyType.GetGenericArguments()[0].UnderlyingSystemType; if (propertyType.Name == "OracleTimeStamp") { rslt = ((varprop.GetValue(db, null) as OracleTimeStamp?).HasValue) ? rslt : ++rslt; } } } //rslt = (mtdb.CREATEDATE.HasValue) ? rslt : rslt++; return(rslt); }
private string GetSqlQuery(AUDIT_LOG_DB db) { StringBuilder sql = new StringBuilder(); StringBuilder sbwhere = new StringBuilder(); string space = " "; string select = string.Empty; string where = string.Empty; string orderby = string.Empty; select = "SELECT * FROM AUDIT_LOG_DB"; if (CheckIsNullOrEmpty(db) == 0) { sql.Append(select); sql.Append(space); sql.Append(" ORDER BY NO"); } else { sbwhere.Append("WHERE"); sbwhere.Append(space); int icond = 0; foreach (PropertyInfo prop in db.GetType().GetProperties()) { var varprop = db.GetType().GetProperty(prop.Name); if (varprop.PropertyType.Name == "String") { string value = varprop.GetValue(db, null) as string; if (!string.IsNullOrEmpty(value)) { where = varprop.Name + " = '@'"; where = where.Replace("@", value); if (icond > 0) { sbwhere.Append(space); sbwhere.Append("AND"); sbwhere.Append(space); } sbwhere.Append(where); icond++; } } if (varprop.PropertyType.Name == "OracleClob") { string value = (varprop.GetValue(db, null) as OracleClob).Value; if (!string.IsNullOrEmpty(value)) { where = varprop.Name + " = '@'"; where = where.Replace("@", value); if (icond > 0) { sbwhere.Append(space); sbwhere.Append("AND"); sbwhere.Append(space); } sbwhere.Append(where); icond++; } } if (varprop.PropertyType.IsGenericType && varprop.PropertyType.GetGenericTypeDefinition() == typeof(Nullable <>)) { var propertyType = varprop.PropertyType.GetGenericArguments()[0].UnderlyingSystemType; if (propertyType.Name == "OracleTimeStamp") { OracleTimeStamp?value = varprop.GetValue(db, null) as OracleTimeStamp?; if (value.HasValue) { where = varprop.Name + " = '@'"; where = where.Replace("@", value.Value.ToString()); if (icond > 0) { sbwhere.Append(space); sbwhere.Append("AND"); sbwhere.Append(space); } sbwhere.Append(where); icond++; } } } // end foreach } where = "ROWNUM <= @"; where = where.Replace("@", 100.ToString()); if (icond > 0) { sbwhere.Append(space); sbwhere.Append("AND"); sbwhere.Append(space); } sbwhere.Append(where); orderby = "ORDER BY NO"; sql.Append(select); sql.Append(space); sql.Append(sbwhere.ToString()); sql.Append(space); sql.Append(orderby); } // end if return(sql.ToString()); }