private Form ConvertSQLForm(SQLForm f) { // since all fields are stored in one table, we have to "arrange" them back by block number var result = new Form(f.FormName) { FormID = f.FormID, RequiresSignature = f.RequiresSignature, Description = f.Description }; foreach (var question in f.Questions) { result.Questions.Add(new Question(question.QuestionText, question.QuestionType, question.Units, question.DefaultValue, question.IsRequired, question.AcceptNotes)); } foreach (var field in f.Fields) { switch (field.BlockNumber) { case 1: result.Header.Add(field.Text, field.DefaultValue); break; case 2: result.Footer.Add(field.Text, field.DefaultValue); break; } } return(result); }
public void StoreForm(Form form) { m_store.BeginTransaction(); try { var entity = new SQLForm() { FormName = form.FormName, Description = form.Description, RequiresSignature = form.RequiresSignature }; foreach (var question in form.Questions) { entity.Questions.Add(new SQLQuestion() { QuestionText = question.QuestionText, QuestionType = question.QuestionType, Units = question.Units, DefaultValue = question.DefaultValue, IsRequired = question.IsRequired, AcceptNotes = question.AcceptNotes }); } foreach (var field in form.Header) { entity.Fields.Add(new SQLField() { Text = field.Text, DefaultValue = field.DefaultValue, BlockNumber = 1 }); } foreach (var field in form.Footer) { entity.Fields.Add(new SQLField() { Text = field.Text, DefaultValue = field.DefaultValue, BlockNumber = 2 }); } m_store.Insert(entity, true); m_store.Commit(); } catch (Exception ex) { m_store.Rollback(); if (Debugger.IsAttached) { Debugger.Break(); } throw ex; } }
internal void AddQuestionToForm(SQLQuestion question, SQLForm form, bool required, bool acceptNotes, object defaultValue) { var fq = new StoreFormQuestion() { FormID = form.FormID, QuestionID = question.QuestionID, IsRequired = required, AcceptNotes = acceptNotes, DefaultValue = defaultValue.ToString() }; m_store.Insert(fq); }
internal SQLForm CreateForm(string name, string description) { var form = new SQLForm() { FormName = name, Description = description }; // TODO: check for name duplication m_store.Insert(form); return(form); }