private void btnOk_Click(object sender, EventArgs e)
        {
            try
              {
            //	---	Check input data
            bool isValidated = CheckData();
            if (!isValidated)
            {
              DialogResult = DialogResult.None;
              return;
            }

            if (m_CurrentDetail == null)
            {
              // check existing question:
              bool existID = false;
              bool existOrder = false;
              string detailId = txtID.Text;
              int order = Convert.ToInt32(txtOrder.Text);
              int pageIndex = Convert.ToInt32(Convert.ToInt32(cmbPage.SelectedValue));
              foreach (TemplateDetail d in m_ExistingDetails.All)
              {
            if (d.ID.Equals(detailId)) existID = true;
            if ((d.PageIndex == pageIndex) && (d.Order == order))
            {
              existOrder = true;
            }
              }

              if (existID)
              {
            MessageBox.Show("A megadott azonosítóval már létezik kérdés.", "NDI HelpDesk Adminisztrátor",
                            MessageBoxButtons.OK, MessageBoxIcon.Warning);
            DialogResult = DialogResult.None;
            txtID.Focus();
            return;
              }

              if (existOrder)
              {
            MessageBox.Show("A megadott lapon belüli sorszámmal már létezik kérdés.", "NDI HelpDesk Adminisztrátor",
                            MessageBoxButtons.OK, MessageBoxIcon.Warning);
            DialogResult = DialogResult.None;
            txtOrder.Focus();
            return;
              }
              m_CurrentDetail = new TemplateDetail(detailId, m_TemplateID);
            }

            #region Inaktív oldalhoz nem lehet aktív kérdést beszúrni ...

            string hash = m_TemplateID.ToString() + "<#>" + cmbPage.SelectedValue.ToString();

            TemplatePage selectedPage = (TemplatePage) m_Pages[hash];

            if ((cbxActivate.Checked == true) && (selectedPage.IsActive == false))
            {
              //figyelmeztetés
              DialogResult msgResult =
            MessageBox.Show(
              "A lap amelyhez a kérdés tartozik jelenleg nem aktív ezért nem adható hozzá aktív kérdés. \n Aktíváljuk a lapot?",
              "NDI HelpDesk Adminisztrátor",
              MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);

              if (msgResult == DialogResult.Cancel)
              {
            DialogResult = DialogResult.None;
            return;
              }
              else
              {
            DialogResult = msgResult;
              }
            }

            #endregion

            m_CurrentDetail.Question = txtQuestion.Text;
            m_CurrentDetail.QuestionDataType = (QuestionDataType) cmbDataType.SelectedValue;
            m_CurrentDetail.QuestionLayout = (QuestionLayout) cmbLayout.SelectedValue;
            m_CurrentDetail.Description = txtDescription.Text;
            m_CurrentDetail.IsActive = cbxActivate.Checked;
            m_CurrentDetail.IsFilterCondition = cbxIsFilterCondition.Checked;
            m_CurrentDetail.PageIndex = Convert.ToInt32(cmbPage.SelectedValue);
            m_CurrentDetail.Order = Convert.ToInt32(txtOrder.Text);

            // validation constraints:
            QuestionConstraint constr = new QuestionConstraint();
            if (txtMaxLength.Text.Length > 0)
            {
              constr.MaxLength = Convert.ToInt32(txtMaxLength.Text);
            }
            constr.Mandatory = cbxMandatory.Checked;
            constr.RangeFrom = txtFrom.Text;
            constr.RangeTo = txtTo.Text;
            constr.Validator = txtRegExp.Text;
            constr.ExpectedFormat = txtExpectedFormat.Text;
            m_CurrentDetail.QuestionConstraint = constr;

            // ListItems
            QuestionListItems list = new QuestionListItems();
            list.ControlRows = Convert.ToInt32(txtControlHeight.Text);
            list.Width = Convert.ToInt32(txtControlWidth.Text);
            if (rbtOrderByItemIndex.Checked)
            {
              list.ItemOrder = ListItemOrder.ByItemIndex;
            }
            else
            {
              list.ItemOrder = ListItemOrder.ByItemName;
            }
            int i = 0;
            foreach (ListViewItem lvItem in lvDetailListItems.Items)
            {
              QuestionListItem qli = new QuestionListItem();
              qli.ItemName = lvItem.Text;
              qli.Selected = lvItem.Selected;
              qli.ItemIndex = i;
              list.Add(qli);
              i += 1;
            }
            m_CurrentDetail.QuestionItemList = list;
              }
              catch (Exception ex)
              {
            //	---	Log exception
            ExceptionManager.Publish(ex);
            //	---	Display Exception
            ErrorHandler.DisplayError("Hiba történt a kérdés mentése során.", ex);
            //	---	Handle dialogresult
            DialogResult = DialogResult.None;
              }
        }
Пример #2
0
 // -------------------------------------------------------------------------------------
 /// <summary>
 /// Validate Answer value and fill ValidationSummary property if validation failed
 /// </summary>
 // -------------------------------------------------------------------------------------
 public bool Validate()
 {
     var constraint = new QuestionConstraint(m_Constraint);
       bool isValid = constraint.ValidateValue(m_Answer, QuestionDataType);
       m_ValidationSummary = constraint.ValidationError;
       return isValid;
 }