예제 #1
0
 public ActionResult AddForm(Form m_Form)
 {
     if (ModelState.IsValid)
     {
         int m_FormId = FormRepository.Create(m_Form);
         return RedirectToAction("OrderFormFields", "Form", new { id = m_FormId });
     }
     else
     {
         ViewBag.FormFields = FormFieldRepository.RetrieveAll();
         return View("AddForm", m_Form);
     }
 }
예제 #2
0
 public ActionResult EditForm(Form m_Form)
 {
     if (ModelState.IsValid)
     {
         FormRepository.Update(m_Form);
         return RedirectToAction("Index", "Form");
     }
     else
     {
         m_Form.MyFormFields = new List<int>();
         ViewBag.FormFields = FormFieldRepository.RetrieveAll();
         return View("EditForm", m_Form);
     }
 }
예제 #3
0
        public static int Create(Form m_Form)
        {
            SqlConnection conn = DB.DbConnect();
            conn.Open();

            string queryString = "INSERT INTO CMS_Forms(formName, submissionEmail, submission, fromEmail) VALUES(@formName, @submissionEmail, @success, @fromEmail)";
            SqlCommand insertForm = new SqlCommand(queryString, conn);
            insertForm.Parameters.AddWithValue("formName", m_Form.FormName);
            insertForm.Parameters.AddWithValue("submissionEmail", m_Form.SubmissionEmail);
            insertForm.Parameters.AddWithValue("success", m_Form.Success);
            insertForm.Parameters.AddWithValue("fromEmail", m_Form.FromEmail);
            insertForm.ExecuteNonQuery();

            queryString = "SELECT IDENT_CURRENT('CMS_Forms')";
            SqlCommand getPageId = new SqlCommand(queryString, conn);
            int m_FormId = (int)(decimal)getPageId.ExecuteScalar();

            conn.Close();

            foreach (int FormField in m_Form.MyFormFields)
            {
                int sortOrder = getSortOrder(m_FormId);

                conn.Open();

                queryString = "INSERT INTO CMS_FormToFormFields(formId, formFieldId, sortOrder) VALUES(@formId, @formFieldId, @sortOrder)";
                SqlCommand insertInfo = new SqlCommand(queryString, conn);
                insertInfo.Parameters.AddWithValue("formId", m_FormId);
                insertInfo.Parameters.AddWithValue("formFieldId", FormField);
                insertInfo.Parameters.AddWithValue("sortOrder", sortOrder);

                insertInfo.ExecuteNonQuery();

                conn.Close();
            }

            return m_FormId;
        }
예제 #4
0
 public ActionResult AddForm()
 {
     Form m_Form = new Form();
     ViewBag.FormFields = FormFieldRepository.RetrieveAll();
     return View("AddForm", m_Form);
 }
예제 #5
0
 public void Update(Form m_Form)
 {
     DBForm.Update(m_Form);
 }
예제 #6
0
 public int Create(Form m_Form)
 {
     int m_FormId = DBForm.Create(m_Form);
     return m_FormId;
 }
예제 #7
0
파일: DBForm.cs 프로젝트: jwiggint/CMS
        public static void Update(Form m_Form)
        {
            SqlConnection conn = DB.DbConnect();
            conn.Open();

            string queryString = "UPDATE CMS_Forms SET formName = @formName, submissionEmail = @submissionEmail WHERE id = @id";
            SqlCommand updateForm = new SqlCommand(queryString, conn);
            updateForm.Parameters.AddWithValue("formName", m_Form.FormName);
            updateForm.Parameters.AddWithValue("submissionEmail", m_Form.SubmissionEmail);
            updateForm.Parameters.AddWithValue("id", m_Form.Id);
            updateForm.ExecuteNonQuery();

            queryString = "DELETE FROM CMS_FormToFormFields WHERE formId = @formId";
            SqlCommand deleteBridge = new SqlCommand(queryString, conn);
            deleteBridge.Parameters.AddWithValue("formId", m_Form.Id);
            deleteBridge.ExecuteNonQuery();

            conn.Close();

            int sortOrder = 1;

            foreach (int FormField in m_Form.MyFormFields)
            {
                conn.Open();

                queryString = "INSERT INTO CMS_FormToFormFields(formId, formFieldId, sortOrder) VALUES(@formId, @formFieldId, @sortOrder)";
                SqlCommand insertInfo = new SqlCommand(queryString, conn);
                insertInfo.Parameters.AddWithValue("formId", m_Form.Id);
                insertInfo.Parameters.AddWithValue("formFieldId", FormField);
                insertInfo.Parameters.AddWithValue("sortOrder", sortOrder);

                insertInfo.ExecuteNonQuery();

                conn.Close();
                sortOrder++;
            }
        }
예제 #8
0
파일: DBForm.cs 프로젝트: jwiggint/CMS
        public static Form RetrieveOne(int id)
        {
            SqlConnection conn = DB.DbConnect();
            conn.Open();

            string queryString = "SELECT * FROM CMS_Forms WHERE id = @id AND pageWorkFlowState != 4";
            SqlCommand getForm = new SqlCommand(queryString, conn);
            getForm.Parameters.AddWithValue("id", id);
            SqlDataReader formReader = getForm.ExecuteReader();

            Form m_Form = new Form();

            if (formReader.Read())
            {
                SqlConnection conn2 = DB.DbConnect();
                conn2.Open();

                m_Form.Id = formReader.GetInt32(0);
                m_Form.FormName = formReader.GetString(1);
                m_Form.SubmissionEmail = formReader.GetString(2);
                m_Form.MyFormFields = new List<int>();

                queryString = "SELECT * FROM CMS_FormFields as ff, CMS_FormToFormFields as fff WHERE ff.id = fff.formFieldId AND fff.formId = @formId ORDER BY sortOrder ASC";
                SqlCommand getFormFields = new SqlCommand(queryString, conn2);
                getFormFields.Parameters.AddWithValue("formId", id);
                SqlDataReader formFieldsReader = getFormFields.ExecuteReader();

                while (formFieldsReader.Read())
                {
                    FormField temp = new FormField();
                    temp.Id = formFieldsReader.GetInt32(0);
                    temp.Label = formFieldsReader.GetString(1);
                    temp.FieldType = formFieldsReader.GetInt32(2);
                    temp.ParentId = formFieldsReader.GetInt32(3);
                    temp.IsRequired = formFieldsReader.GetInt32(10);
                    temp.Children = DBFormField.RetrieveChildren(temp.Id);

                    m_Form.MyFormFields.Add(temp.Id);
                    m_Form.FormFields.Add(temp);

                }

                conn2.Close();
            }

            conn.Close();

            return m_Form;
        }
예제 #9
0
파일: DBForm.cs 프로젝트: jwiggint/CMS
        public static List<Form> RetrieveAll()
        {
            SqlConnection conn = DB.DbConnect();
            conn.Open();

            string queryString = "SELECT * FROM CMS_Forms WHERE pageWorkFlowState != 4";
            SqlCommand getForm = new SqlCommand(queryString, conn);
            SqlDataReader formReader = getForm.ExecuteReader();

            List<Form> m_Forms = new List<Form>();

            while (formReader.Read())
            {
                SqlConnection conn2 = DB.DbConnect();
                conn2.Open();

                Form tempForm = new Form();
                tempForm.Id = formReader.GetInt32(0);
                tempForm.FormName = formReader.GetString(1);
                tempForm.SubmissionEmail = formReader.GetString(2);

                queryString = "SELECT * FROM CMS_FormFields as ff, CMS_FormToFormFields as fff WHERE ff.id = fff.formFieldId AND fff.formId = @formId";
                SqlCommand getFormFields = new SqlCommand(queryString, conn2);
                getFormFields.Parameters.AddWithValue("formId", tempForm.Id);
                SqlDataReader formFieldsReader = getFormFields.ExecuteReader();

                while (formFieldsReader.Read())
                {
                    FormField temp = new FormField();
                    temp.Id = formFieldsReader.GetInt32(0);
                    temp.Label = formFieldsReader.GetString(1);
                    temp.FieldType = formFieldsReader.GetInt32(2);
                    temp.ParentId = formFieldsReader.GetInt32(3);
                    temp.IsRequired = formFieldsReader.GetInt32(10);

                    tempForm.FormFields.Add(temp);
                }

                m_Forms.Add(tempForm);
                conn2.Close();
            }

            conn.Close();

            return m_Forms;
        }