/// <summary> /// Gets all categories in database /// </summary> /// <returns>List of categories</returns> public override List<Field> FillFields() { List<Field> fields = new List<Field>(); string connString = ConfigurationManager.ConnectionStrings[connStringName].ConnectionString; string providerName = ConfigurationManager.ConnectionStrings[connStringName].ProviderName; DbProviderFactory provider = DbProviderFactories.GetFactory(providerName); using (DbConnection conn = provider.CreateConnection()) { conn.ConnectionString = connString; using (DbCommand cmd = conn.CreateCommand()) { string sqlQuery = "SELECT FieldID,FieldName,Description " + "FROM " + tablePrefix + "Fields "; cmd.CommandText = sqlQuery; cmd.CommandType = CommandType.Text; conn.Open(); using (DbDataReader rdr = cmd.ExecuteReader()) { if (rdr.HasRows) { while (rdr.Read()) { Field fld = new Field(); fld.FieldName = rdr.GetString(1); if (rdr.IsDBNull(2)) fld.Description = ""; else fld.Description = rdr.GetString(2); fld.Id = new Guid(rdr.GetGuid(0).ToString()); fields.Add(fld); fld.MarkOld(); } } } } } return fields; }
/// <summary> /// Returns a field /// </summary> /// <param name="id">Id of field to return</param> /// <returns></returns> public override Field SelectField(Guid id) { List<Field> fields = Field.Fields; Field field = new Field(); foreach (Field cat in fields) { if (cat.Id == id) field = cat; } field.MarkOld(); return field; }