protected override string InsertQuery(object model) { string query = QueryManager.GetInstance().GetQuery((Model)model, QueryType.Create); Type info = model.GetType(); PropertyInfo[] properties = info.GetProperties(); foreach (PropertyInfo prop in properties) { if (prop.Name != QueryManager.ID) { Type pt = prop.PropertyType; if (pt.FullName.ToLower() == QueryManager.SSTRING) { query += "'" + SanitaizeStrings.ToDb((string)prop.GetValue(model)) + "',"; } else if (pt.FullName.ToLower() == QueryManager.SDATE) { query += "'" + prop.GetValue(model).ToString().Replace("/", "-") + "',"; } else { query += prop.GetValue(model) + ","; } } } query = query.Substring(0, query.Length - 1) + ");"; return(query); }
protected override string UpdateQuery(object model) { string query = QueryManager.GetInstance().GetQuery((Model)model, QueryType.Update); Type info = model.GetType(); PropertyInfo[] properties = info.GetProperties(); Hashtable id = new Hashtable(); foreach (PropertyInfo prop in properties) { ///TODO Coger primary key del GetValues if (prop.Name != QueryManager.ID) { Type pt = prop.PropertyType; if (pt.FullName.ToLower() == QueryManager.SSTRING) { query += prop.Name + "=" + "'" + SanitaizeStrings.ToDb((string)prop.GetValue(model)) + "',"; } else if (pt.FullName.ToLower() == QueryManager.SDATE) { query += prop.Name + "=" + "'" + prop.GetValue(model) + "',"; } else { query += prop.Name + "=" + prop.GetValue(model) + ","; } } else { ///TODO Coger la primary key de GetValues id[QueryManager.ID] = prop.GetValue(model) + ""; } } ///TODO Coger primary keys del GetValues query = query.Substring(0, query.Length - 1) + " WHERE " + QueryManager.ID + " = " + id[QueryManager.ID] + ";"; return(query); }