private int CheckIsNullOrEmpty(VMTREFDB mtrefdb) { int rslt = 0; foreach (PropertyInfo prop in mtrefdb.GetType().GetProperties()) { var varprop = mtrefdb.GetType().GetProperty(prop.Name); if (varprop.PropertyType.Name == "String") { rslt = string.IsNullOrEmpty(varprop.GetValue(mtrefdb, null) as string) ? rslt : ++rslt; } if (varprop.PropertyType.Name == "Int32") { rslt = ((varprop.GetValue(mtrefdb, null) as int?).HasValue) ? rslt : ++rslt; } if (varprop.PropertyType.Name == "DateTime") { rslt = ((varprop.GetValue(mtrefdb, null) as DateTime?).HasValue) ? rslt : ++rslt; } if (varprop.PropertyType.IsGenericType && varprop.PropertyType.GetGenericTypeDefinition() == typeof(Nullable <>)) { var propertyType = varprop.PropertyType.GetGenericArguments()[0].UnderlyingSystemType; if (propertyType.Name == "DateTime") { DateTime?value = varprop.GetValue(mtrefdb, null) as DateTime?; rslt = (!value.HasValue) ? rslt : ++rslt; } if (propertyType.Name == "Int32") { int?value = varprop.GetValue(mtrefdb, null) as int?; rslt = (!value.HasValue) ? rslt : ++rslt; } if (propertyType.Name == "Decimal") { decimal?value = varprop.GetValue(mtrefdb, null) as decimal?; rslt = (!value.HasValue) ? rslt : ++rslt; } } } //rslt = (mtdb.CREATEDATE.HasValue) ? rslt : rslt++; return(rslt); }
private string GetSqlQuery(VMTREFDB mtrefdb) { StringBuilder sql = new StringBuilder(); StringBuilder sbwhere = new StringBuilder(); string space = " "; string select = string.Empty; string where = string.Empty; string orderby = string.Empty; select = @"SELECT /*+" + Constant.TSQL_HINT + @"*/ * FROM MT_REF"; if (CheckIsNullOrEmpty(mtrefdb) == 0) { sql.Append(select); sql.Append(space); //TO_DATE('2016/5/18 00:50:00','yyyy/MM/dd HH24:MI:SS') sql.Append("WHERE ROWNUM<=1000 AND NVL(PARTNER, ' ') != ' '"); } else { sbwhere.Append("WHERE"); sbwhere.Append(space); int icond = 0; foreach (PropertyInfo prop in mtrefdb.GetType().GetProperties()) { var varprop = mtrefdb.GetType().GetProperty(prop.Name); if (varprop.PropertyType.Name == "String") { string value = varprop.GetValue(mtrefdb, null) as string; if (!string.IsNullOrEmpty(value)) { string outstring = ConvertToStringArray(value, varprop.Name); where = varprop.Name + " IN (@)"; where = where.Replace("@", outstring); if (icond > 0) { sbwhere.Append(space); sbwhere.Append("AND"); sbwhere.Append(space); } sbwhere.Append(where); icond++; } } // end if } // end foreach //where = "ROWNUM <= @"; where = where.Replace("@", 100.ToString()); where = "1=1"; if (icond > 0) { sbwhere.Append(space); sbwhere.Append("AND"); sbwhere.Append(space); } sbwhere.Append(where); orderby = "ORDER BY 1 ASC"; sql.Append(select); sql.Append(space); sql.Append(sbwhere.ToString()); sql.Append(space); sql.Append(orderby); } // end if return(sql.ToString()); }