示例#1
0
        protected void btnCreateForm_Click(object sender, EventArgs e)
        {
            // get the list of post data
            List<string> list = new List<string>();

            foreach (string i in Request.Form) {
                list.Add(Request.Form[i]);
            }

            // get rid of viewstate and hidden input field values
            for (int i = 0; i < 2; i ++) list.RemoveAt(0);

            // create form object and set name and info field values
            form = cMain.newForm();
            form.Name = list[0].Trim();
            form.Info = list[1].Trim();

            // persist form
            if (form.persist()) {
                // get question names and question info field values
                for (int i = 2, until = list.Count - 1; i < until; i += 3) {
                    if (!form.addQuestion(list[i], list[i + 1], list[i + 2])) {
                        setErrorMessage("Error while saving Form!");
                        break;
                    }
                }
                // redirect
                Session["message"] = convertSuccessMessage();
                Response.Redirect("Create.aspx");
            }
            else
                setErrorMessage("Error while saving Form!");
        }
示例#2
0
        public static cForm getForm(string formID)
        {
            cForm form = new cForm();

            form.load(formID);
            return(form);
        }
示例#3
0
        // this method creates & returns a collection of questions for a special form
        internal bool loadFormQuestions(cForm form)
        {
            SqlCommand cmd = new SqlCommand("SELECT ID, FormID, Text, Info, Type FROM questions WHERE FormID = @fid ORDER BY ID", cMain.getConnection());

            cmd.Parameters.Add(new SqlParameter("fid", form.ID));
            SqlDataReader reader = cmd.ExecuteReader();

            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    cQuestion q = new cQuestion();
                    q.ID     = reader.GetString(0);
                    q.FormID = reader.GetString(1);
                    q.Text   = reader.GetString(2);
                    q.Info   = reader.GetString(3);
                    q.Type   = reader.GetString(4);

                    this.Add(q);
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#4
0
 // grab the GET parameter with form id and validate form id
 public void initFormSet()
 {
     try {
         if (Request.QueryString["form"].Length != 0) {
             form = cMain.getForm(Request.QueryString["form"]);
             if (form.ID.Length != 0) formset = true;
             else formset = false;
         }
         else formset = false;
     }
     catch { formset = false; }
 }
示例#5
0
        // this method creates & returns a collection of form entries for a special form
        internal bool loadFormEntries(cForm form)
        {
            SqlCommand cmd = new SqlCommand("SELECT ID, FormID FROM formEntries WHERE FormID = @feid ORDER BY ID", cMain.getConnection());

            cmd.Parameters.Add(new SqlParameter("feid", form.ID));
            SqlDataReader reader = cmd.ExecuteReader();

            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    cFormEntry fe = new cFormEntry();
                    fe.ID     = reader.GetString(0);
                    fe.FormID = reader.GetString(1);

                    this.Add(fe);
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#6
0
        // this function renders the form and it's questions
        public void renderForm(cForm form)
        {
            // get questions from form
            cQuestions questions = form.Questions;

            // render form name and info
            Response.Write("<h2>" + form.Name + "</h2><h5>" + form.Info + "</h5>");

            // render questions
            int j = 0;
            foreach(var i in questions) {
                Response.Write("<div class='form-view-question'>");
                Response.Write("<div class='question'>" + i.Text + "</div><div class='infotext'>" + i.Info + "</div>");
                switch (i.Type) {
                    case "text": Response.Write("<input type='text' id='q" + j + "' name='q" + j + "' maxlength='150' />");
                        break;
                    case "textarea": Response.Write("<textarea id='q" + j + "' name='q" + j + "' rows='2' cols='70' maxlength='255'></textarea>");
                        break;
                }
                Response.Write("</div>");
                j++;
            }
            Response.Write("<input type='hidden' name='insert' value='make' />");
            // render save entry submit button and back button
            Response.Write("<input type='submit' id='submitentry' name='submitentry' value='Save' class='button form-view-button' />&nbsp;<input type='button' class='button form-view-button' value='Cancel' onclick='window.location.href=&#39Create.aspx&#39' />");
        }
示例#7
0
 public static cForm getForm(string formID)
 {
     cForm form = new cForm();
     form.load(formID);
     return form;
 }