public object Execute(string connectionName = "CountyDatabase") { try { if (SqlTypeString == "INSERT" || SqlTypeString == "UPDATE" || SqlString == "DELETE") { return(Adocls.ExecuteSql(this, true, connectionName)); } else { return(Adocls.FetchDataTable(this, connectionName)); } } catch (Exception) { return(null); } }
///// <summary> ///// Uses the SQL Generator to dynamically create a SELECT statement based on ///// the properties of the model referenced and returns an array of the ///// referenced model populated from the API. ///// </summary> //public static IEnumerable<T> LoadModel<T>(SQLWhere OptionalWhere = null) //{ // Type t = typeof(T); // List<T> o = Activator.CreateInstance<List<T>>(); // string TableName = t.Name; // if (TableName.EndsWith("DROPDOWN")) // { // TableName = TableName.Remove(TableName.Length - 8, 8); // } // SQLGenerator Gen = new SQLGenerator(SQLGenerator.SqlTypes.Select, TableName); // if (OptionalWhere != null) // { // Gen.AddWhereParameter(OptionalWhere); // } // foreach (PropertyInfo propertyInfo in t.GetProperties()) // { // if (propertyInfo.CanRead && propertyInfo.CanWrite) // { // Gen.AddField(propertyInfo.Name); // } // } // DataTable dt = ADOCLS.FetchDataTable(Gen); // for (int j = 0; j < dt.Rows.Count; j++) // { // T newo = Activator.CreateInstance<T>(); // for (int i = 0; i < dt.Columns.Count; i++) // { // string name = dt.Columns[i].ColumnName; // PropertyInfo pi = t.GetProperty(name); // if (dt.Rows[j][i] != System.DBNull.Value) // { // if (pi != null && pi.CanWrite) // { // object val = dt.Rows[j][i]; // Type newT = val.GetType(); // if (pi.PropertyType.UnderlyingSystemType == typeof(bool)) // { // if (newT == typeof(bool)) // pi.SetValue(newo, val); // else if (newT == typeof(byte)) // pi.SetValue(newo, (byte)val == 1); // } // else // { // pi.SetValue(newo, val); // } // } // } // } // o.Add(newo); // } // return o; //} /// <summary> /// Uses the SQL Generator to dynamically create a INSERT statement based on /// the properties of the model referenced and returns a string result. /// </summary> /// <param name="model">The model used to generate the INSERT statement</param> public static string InsertModel <T>(T model, string connectionString = "CountyDatabase", SqlGenerator gen = null) { try { Type t = model.GetType(); string tableName = t.Name; if (tableName.ToUpper().EndsWith("MODEL")) { tableName = tableName.Remove(tableName.Length - 5, 5); } if (gen == null) { gen = new SqlGenerator(SqlGenerator.SqlTypes.Insert, tableName); gen.InsertFromModel(model); } return(Adocls.ExecuteSql(gen, false, connectionString).ToString()); } catch { return(""); } }