using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; using DAVIVIENDA.SUGESE.Model; namespace DAVIVIENDA.SUGESE.Util { public static class Util { public static string GetExtReportFile(string format) { string _ext = "."; switch (format) { case Constante.CodigoTipoFormato.EXCEL: _ext = Constante.ExtRep.EXCEL; break; case Constante.CodigoTipoFormato.PDF: _ext = Constante.ExtRep.PDF; break; case Constante.CodigoTipoFormato.HTML: _ext = Constante.ExtRep.HTML; break; default: break; } return _ext; } //public static DataSet ToDataSet(this IEnumerable list) //{ // Type elementType = typeof(T); // DataSet ds = new DataSet(); // DataTable t = new DataTable(); // //add a column to table for each public property on T // foreach (var propInfo in elementType.GetProperties()) // { // t.Columns.Add(propInfo.Name, propInfo.PropertyType); // } // //go through each property on T and add each value to the table // foreach (T item in list) // { // DataRow row = t.NewRow(); // foreach (var propInfo in elementType.GetProperties()) // { // row[propInfo.Name] = propInfo.GetValue(item, null); // //t.Rows.Add(row); // } // } // ds.Tables.Add(t); // return ds; //} //public static DataSet ToDataSet(this IEnumerable list) //{ // var elementType = typeof(T); // var ds = new DataSet(); // var t = new DataTable(); // ds.Tables.Add(t); // if (elementType.IsValueType) // { // var colType = Nullable.GetUnderlyingType(elementType) ?? elementType; // t.Columns.Add(elementType.Name, colType); // } // else // { // //add a column to table for each public property on T // foreach (var propInfo in elementType.GetProperties()) // { // var colType = Nullable.GetUnderlyingType(propInfo.PropertyType) ?? propInfo.PropertyType; // t.Columns.Add(propInfo.Name, colType); // } // } // //go through each property on T and add each value to the table // foreach (var item in list) // { // var row = t.NewRow(); // if (elementType.IsValueType) // { // row[elementType.Name] = item; // } // else // { // foreach (var propInfo in elementType.GetProperties()) // { // row[propInfo.Name] = propInfo.GetValue(item, null) ?? DBNull.Value; // } // } // t.Rows.Add(row); // } // return ds; //} //public static DataTable ConvertToDataTable(IList list) where T : class //{ // try // { // DataTable table = CreateDataTable(); // Type objType = typeof(T); // PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(objType); // foreach (T item in list) // { // DataRow row = table.NewRow(); // foreach (PropertyDescriptor property in properties) // { // if (!CanUseType(property.PropertyType)) continue; // row[property.Name] = property.GetValue(item) ?? DBNull.Value; // } // table.Rows.Add(row); // } // return table; // } // catch (DataException) // { // return null; // } //} //private static DataTable CreateDataTable() where T : class //{ // Type objType = typeof(T); // DataTable table = new DataTable(objType.Name); // PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(objType); // foreach (PropertyDescriptor property in properties) // { // Type propertyType = property.PropertyType; // if (!CanUseType(propertyType)) continue; // //nullables must use underlying types // if (propertyType.IsGenericType && propertyType.GetGenericTypeDefinition() == typeof(Nullable<>)) // propertyType = Nullable.GetUnderlyingType(propertyType); // //enums also need special treatment // if (propertyType.IsEnum) // propertyType = Enum.GetUnderlyingType(propertyType); // table.Columns.Add(property.Name, propertyType); // } // return table; //} //private static bool CanUseType(Type propertyType) //{ // //only strings and value types // if (propertyType.IsArray) return false; // if (!propertyType.IsValueType && propertyType != typeof(string)) return false; // return true; //} } }