public static void SaveUserResponse(QuestionnaireForm_UserResponses resp)
        {
            using (var ctx = new BMIKidsEntities(ConnectionString))
            {
                try
                {
                    ctx.QuestionnaireForm_UserResponses.ApplyChanges(resp);
                    ctx.SaveChanges();

                }
                catch (Exception ex)
                {
                    LogUtility.WriteEntryEventLog("Poll_DataProvider_SavePoll", ex, EventLogEntryType.Information);
                    if (ex.InnerException != null)
                        throw ex.InnerException;
                    throw;
                }
            }
        }
Пример #2
0
        protected void SendBtn_Click(object sender, EventArgs e)
        {

            long userRandId = DateTime.Now.Ticks;

            foreach (GridViewRow QuestionRow in dgQuestions.Rows)
            {

                string idPrefix = QuestionRow.UniqueID + this.IdSeparator;

                HiddenField qHidden = QuestionRow.FindControl("hdQuestionId") as HiddenField;
                long questionId = Convert.ToInt64(qHidden.Value);


                QuestionnaireForm_Questions question = QuestionnaireForm_DataProvider.GetQuestion(questionId).FirstOrDefault();
                if (question.ItemsType == (int)ResponseItemsType.CheckBox)
                {
                    for (int j = 0; j < question.QuestionnaireForms_ResponseItems.Count; j++)
                    {
                        QuestionnaireForms_ResponseItems ritem = question.QuestionnaireForms_ResponseItems[j];
                        if (Page.Request.Form[idPrefix + ritem.ItemId] != null && Page.Request.Form[idPrefix + ritem.ItemId].ToLower() == "on")
                        {
                            ritem.ItemValue = ritem.ItemText;
                            if (ritem.HasInputText)
                            {
                                string itemTextBox = Page.Request.Form[idPrefix + "txt" + ritem.ItemId];
                                if (itemTextBox.Trim().Length > 0)
                                    ritem.ItemValue = itemTextBox.Trim();
                            }
                            QuestionnaireForm_UserResponses resp = new QuestionnaireForm_UserResponses
                            {
                                FormId = question.QuestionnaireForm.FormId,
                                QuestionId = questionId,
                                ItemId = ritem.ItemId,
                                ItemValue = ritem.ItemValue,
                                UserRandomId = userRandId
                            };
                            QuestionnaireForm_DataProvider.SaveUserResponse(resp);
                        }
                    }
                }
                else if (question.ItemsType == (int)ResponseItemsType.RadioButton)
                {
                    long selectedItemId = Convert.ToInt64(Page.Request.Form[idPrefix + "qroup" + questionId]);
                    //Page.Response.Write("<br> itemRadio : " + selectedItemId);
                    QuestionnaireForms_ResponseItems selectedItem = QuestionnaireForm_DataProvider.GetQuestionnaireForms_ResponseItem(selectedItemId).FirstOrDefault();
                    if (selectedItem != null)
                    {
                        selectedItem.ItemValue = selectedItem.ItemText;
                        if (selectedItem.HasInputText)
                        {
                            string itemTextBox = Page.Request.Form[idPrefix + "txt" + selectedItemId.ToString()];
                            if (itemTextBox.Trim().Length > 0)
                                selectedItem.ItemValue = itemTextBox.Trim();
                        }

                        QuestionnaireForm_UserResponses resp = new QuestionnaireForm_UserResponses
                        {
                            FormId = question.QuestionnaireForm.FormId,
                            QuestionId = questionId,
                            ItemId = selectedItem.ItemId,
                            ItemValue = selectedItem.ItemValue,
                            UserRandomId = userRandId
                        };
                        QuestionnaireForm_DataProvider.SaveUserResponse(resp);
                    }
                }
                else if (question.ItemsType ==(int) ResponseItemsType.InputText)
                {
                    for (int j = 0; j < question.QuestionnaireForm_UserResponses.Count; j++)
                    {
                        QuestionnaireForm_UserResponses ritem = question.QuestionnaireForm_UserResponses[j];
                        string itemTextBox = Page.Request.Form[idPrefix + ritem.ItemId];
                        ritem.ItemValue = itemTextBox;

                        QuestionnaireForm_UserResponses resp = new QuestionnaireForm_UserResponses
                        {
                            FormId = question.QuestionnaireForm.FormId,
                            QuestionId = questionId,
                            ItemId = ritem.Serial,
                            ItemValue = ritem.ItemValue,
                            UserRandomId = userRandId
                        };

                        QuestionnaireForm_DataProvider.SaveUserResponse(resp);
                    }
                }
            }

            lblMessage.Text = "پاسخ شما به فرم زير با موفقيت ثبت شد. از توجه شما متشكريم.";
            SendBtn.Visible = false;
            cancelBtn.Visible = false;
            //Page.Response.Redirect(Globals.UrlThnkEvalList);

            long formId = -1;
            if (UtilityMethod.GetRequestParameter( "frmId").IsInt64())
                formId = UtilityMethod.GetRequestParameter( "frmId").ToLong();
            HttpCookie cook = new HttpCookie(coockiPrefix + formId)
                {
                    Expires = DateTime.MaxValue,
                    Value = userRandId.ToString()
                };
            Response.Cookies.Add(cook);

        }