public Form[] getForms() { List <Form> forms = new List <Form>(); string sql = "SELECT * FROM forms ORDER BY title"; SQLiteCommand command = new SQLiteCommand(sql, connection); SQLiteDataReader reader = command.ExecuteReader(); while (reader.Read()) { string s = reader["fields"].ToString(); forms.Add(new Form() { Id = Convert.ToInt32(reader["id"]), Title = reader["title"].ToString(), Template_html = File.ReadAllText(LocalPath.getTemplatePath() + reader["template_html"].ToString()), Template = reader["template"].ToString(), Fields = JsonConvert.DeserializeObject <Field[]>(reader["fields"].ToString()), Active = reader["visible"].ToString() == "1", Type = Convert.ToInt32(reader["type"]) }); } return(forms.ToArray()); }
private Database() { connection = new SQLiteConnection("Data Source=" + LocalPath.getDatabasePath() + "formsDB" + ".s3db;Version=3;"); connection.Open(); if (getForms().Length == 0) { foreach (Form f in TestData.getForms()) { insertForm(f); } } }