public FormResponses(responseFixed responseFixed)
        {
            InitializeComponent();
            this.responseFixed = responseFixed;

            // Pre-populate with true/false
            this.dataGridView1.Rows.Add(2);
            this.dataGridView1.Rows[0].Cells[0].Value = "true";
            this.dataGridView1.Rows[0].Cells[1].Value = "yes";
            this.dataGridView1.Rows[1].Cells[0].Value = "false";
            this.dataGridView1.Rows[1].Cells[1].Value = "no";
        }
        private void buttonNext_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(this.textBoxQID.Text)
                || string.IsNullOrWhiteSpace(this.textBoxQText.Text))
            {
                Mbox.ShowSimpleMsgBoxError("Required data missing!");
                return;
            }

            q = new question();
            q.id = this.textBoxQID.Text;
            questionText qt = new questionText();
            qt.Value = this.textBoxQText.Text;
            q.text = qt;

            // Responses
            response responses = new response();
            q.response = responses;

            if (this.radioButtonMCYes.Checked)
            {
                // MCQ: display response form
                responseFixed responseFixed = new responseFixed();
                responses.Item = responseFixed;
                FormResponses formResponses = new FormResponses(responseFixed);
                formResponses.ShowDialog();

                // TODO - handle cancel
            }
            else
            {
                // Not MCQ
                responseFree responseFree = new responseFree();
                responses.Item = responseFree;

                // Free - just text for now
                // later, configure type
                responseFree.format = responseFreeFormat.text;
            }

            // Finally, add to part
            //updateQuestionsPart(q);

            this.Close();
        }
        ///// <summary>
        ///// Generate a simple ID
        ///// </summary>
        ///// <returns></returns>
        //private string generateId()
        //{
        //    int i = this.answerID.Count;
        //    do
        //    {
        //        i++;
        //    } while (this.answerID.Contains("rpt" + i));
        //    return "rpt" + i;
        //}
        private void buttonNext_Click(object sender, EventArgs e)
        {
            int min = 1;
            int defautlVal = 2;
            int max = 4;
            int step = 1;

            //log.Info(".Text:" + answerID.Text);
            //log.Info(".SelectedText:" + answerID.SelectedText);

            //log.Info(".textBoxQuestionText:" + textBoxQuestionText.Text);

            if (//string.IsNullOrWhiteSpace(this.answerID.Text) ||
                 string.IsNullOrWhiteSpace(this.textBoxQuestionText.Text))
            {
                Mbox.ShowSimpleMsgBoxError("Required data missing!");
                DialogResult = DialogResult.None; // or use on closing event; see http://stackoverflow.com/questions/2499644/preventing-a-dialog-from-closing-in-the-buttons-click-event-handler
                return;
            }
            String repeatName = this.textBoxQuestionText.Text.Trim();

            try
            {
                string foo = repeatNameToIdMap[repeatName];

                Mbox.ShowSimpleMsgBoxError("You already have a repeat named '" + repeatName
                    + "' . Click the 're-use' tab to re-use it, or choose another name.");
                DialogResult = DialogResult.None;
                return;
            }
            catch (KeyNotFoundException knfe)
            {
                // Good
            }

            // Basic data validation
            try
            {
                min = int.Parse(this.textBoxMin.Text);
                defautlVal = int.Parse(this.textBoxDefault.Text);
                max = int.Parse(this.textBoxMax.Text);
                step = int.Parse(this.textBoxRangeStep.Text);
            } catch (Exception) {
                log.Warn("Repeat range val didn't parse to int properly");
            }
            if (min < 0) min = 0;
            if (min > 20) min = 20;
            if (max < min) max = min + 4;
            if (max > 30) max = 30;
            int av = (int)Math.Round((min + max) / 2.0);
            if (defautlVal < min || defautlVal > max)
                defautlVal = av;
            if (step > av) step = 1;

            TagData td;

            // Work out where to put this repeat
            // It will just go in /answers, unless it
            // has a repeat ancestor.
            // So look for one...
            Word.ContentControl repeatAncestor = null;
            Word.ContentControl currentCC = cc.ParentContentControl;
            while (repeatAncestor == null && currentCC != null)
            {
                if (currentCC.Tag.Contains("od:repeat"))
                {
                    repeatAncestor = currentCC;
                    break;
                }
                currentCC = currentCC.ParentContentControl;
            }

            // Generate a nice ID
            // .. first we need a list of existing IDs
            List<string> reserved = new List<string>();
            foreach (question qx in questionnaire.questions)
            {
                reserved.Add(qx.id);
            }
            ID = IdHelper.SuggestID(repeatName, reserved) + "_" + IdHelper.GenerateShortID(2);

            string xpath;
            if (repeatAncestor == null)
            {
                // create it in /answers
                Office.CustomXMLNode node = answersPart.SelectSingleNode("/oda:answers");
                //string xml = "<repeat qref=\"" + ID + "\" xmlns=\"http://opendope.org/answers\"><row/></repeat>";
                string xml = "<oda:repeat qref=\"" + ID + "\" xmlns:oda=\"http://opendope.org/answers\" ><oda:row/></oda:repeat>";

                node.AppendChildSubtree(xml);
                xpath = "/oda:answers/oda:repeat[@qref='" + ID + "']/oda:row"; // avoid trailing [1]

            } else
            {
                td = new TagData(repeatAncestor.Tag);
                string ancestorRepeatXPathID = td.getRepeatID();

                // Get the XPath, to find the question ID,
                // which is what we use to find the repeat answer.
                xpathsXpath xp = xppe.getXPathByID(ancestorRepeatXPathID);

                Office.CustomXMLNode node = answersPart.SelectSingleNode("//oda:repeat[@qref='" + xp.questionID + "']/oda:row");

                string parentXPath = NodeToXPath.getXPath(node);

                //string xml = "<repeat qref=\"" + ID + "\" xmlns=\"http://opendope.org/answers\"><row/></repeat>";
                string xml = "<oda:repeat qref=\"" + ID + "\"  xmlns:oda=\"http://opendope.org/answers\" ><oda:row/></oda:repeat>";

                node.AppendChildSubtree(xml);

                xpath = parentXPath + "/oda:repeat[@qref='" + ID + "']/oda:row"; // avoid trailing [1]
            }

            log.Info(answersPart.XML);

            // Question
            q = new question();
            //q.id = this.answerID.Text; // not SelectedText
            q.id = ID;
            q.text = repeatName;

            if (!string.IsNullOrWhiteSpace(this.textBoxHelp.Text))
            {
                q.help = this.textBoxHelp.Text;
            }
            if (!string.IsNullOrWhiteSpace(this.textBoxHint.Text))
            {
                q.hint = this.textBoxHint.Text;
            }

            if (this.isAppearanceCompact())
            {
                q.appearance = appearanceType.compact;
                q.appearanceSpecified = true;
            }
            else
            {
                q.appearanceSpecified = false;
            }

            questionnaire.questions.Add(q);

            // Bind to answer XPath
            xpathsXpath xpathEntry = xppe.setup("", answersPart.Id, xpath, null, false);
            xpathEntry.questionID = q.id;
            xpathEntry.dataBinding.prefixMappings = "xmlns:oda='http://opendope.org/answers'";
            xpathEntry.type = "nonNegativeInteger";
            xppe.save();

            // Repeat
            td = new TagData("");
            td.set("od:repeat", xppe.xpathId);
            cc.Tag = td.asQueryString();

            // At this point, answer should be present.  Sanity check!

            cc.Title = "REPEAT " + repeatName;
            cc.SetPlaceholderText(null, null, "Repeating content goes here.");

            //Not for wdContentControlRichText!
            //cc.XMLMapping.SetMapping(xpath, null, model.userParts[0]);

            // Responses
            response responses = q.response;
            if (responses == null)
            {
                responses = new response();
                q.response = responses;
            }

            // MCQ: display response form
            responseFixed responseFixed = new responseFixed();
            responses.Item = responseFixed;

            //for (int i = min; i<=max; i=i+step)
            //{
            //    responseFixedItem item = new OpenDoPEModel.responseFixedItem();

            //    item.value = ""+i;
            //    item.label = "" + i;

            //    responseFixed.item.Add(item);
            //}

            responseFixed.canSelectMany = false;

            // Finally, add to part
            updateQuestionsPart();

            this.Close();
        }
        public override void populateValues(responseFixed responses, string matchResponse)
        {
            this.comboBoxValues.Items.Clear();

            foreach (responseFixedItem item in responses.item)
            {
                int currentIndex = this.comboBoxValues.Items.Add(item);
                if (matchResponse != null && matchResponse.Contains(item.value))
                {
                    // Simple minded matching, will do for now.
                    // Saves us having an XPath parser.
                    this.comboBoxValues.SelectedIndex = currentIndex;
                }
            }
        }
 public FormResponses(responseFixed responseFixed)
 {
     InitializeComponent();
     this.controlQuestionResponsesFixed1.init(responseFixed);
 }
 public static bool LoadFromFile(string fileName, out responseFixed obj)
 {
     System.Exception exception = null;
     return LoadFromFile(fileName, out obj, out exception);
 }
 /// <summary>
 /// Deserializes workflow markup into an responseFixed object
 /// </summary>
 /// <param name="xml">string workflow markup to deserialize</param>
 /// <param name="obj">Output responseFixed object</param>
 /// <param name="exception">output Exception value if deserialize failed</param>
 /// <returns>true if this XmlSerializer can deserialize the object; otherwise, false</returns>
 public static bool Deserialize(string xml, out responseFixed obj, out System.Exception exception)
 {
     exception = null;
     obj = default(responseFixed);
     try
     {
         obj = Deserialize(xml);
         return true;
     }
     catch (System.Exception ex)
     {
         exception = ex;
         return false;
     }
 }
 /// <summary>
 /// Deserializes xml markup from file into an responseFixed object
 /// </summary>
 /// <param name="fileName">string xml file to load and deserialize</param>
 /// <param name="obj">Output responseFixed object</param>
 /// <param name="exception">output Exception value if deserialize failed</param>
 /// <returns>true if this XmlSerializer can deserialize the object; otherwise, false</returns>
 public static bool LoadFromFile(string fileName, out responseFixed obj, out System.Exception exception)
 {
     exception = null;
     obj = default(responseFixed);
     try
     {
         obj = LoadFromFile(fileName);
         return true;
     }
     catch (System.Exception ex)
     {
         exception = ex;
         return false;
     }
 }
 public static bool Deserialize(string xml, out responseFixed obj)
 {
     System.Exception exception = null;
     return Deserialize(xml, out obj, out exception);
 }
        public void populateControl(xpathsXpath xpathObj, question q, string defaultAnswer)
        {
            responseFixed =  q.response.Item as responseFixed;

            if (xpathObj.type.Equals("string"))
            {
                this.radioTypeText.Checked = true;

            }
            else if (xpathObj.type.Equals("decimal"))
            {
                this.radioTypeNumber.Checked = true;

            }
            else if (xpathObj.type.Equals("date"))
            {
                this.radioTypeDate.Checked = true;

            }
            else if (xpathObj.type.Equals("boolean"))
            {
                this.radioTypeBoolean.Checked = true;

            }
            //else if (xpathObj.type.Equals("duration"))
            //{
            //    this.radioTypeText.Checked = true;

            //}
            //else if (xpathObj.type.Equals("email"))
            //{
            //    this.radioTypeText.Checked = true;

            //}
            //else if (xpathObj.type.Equals("cardnumber"))
            //{
            //    this.radioTypeText.Checked = true;
            //}
            else
            {
                log.Error("XPath " + xpathObj.id + " has unknown value for datatype: '" + xpathObj.type);
            }

            // The possible responses
            int i = 0;
            this.dataGridView1.Rows.Add(responseFixed.item.Count);
            foreach (responseFixedItem rFI in responseFixed.item)
            {
                this.dataGridView1.Rows[i].Cells[0].Value = rFI.value;
                this.dataGridView1.Rows[i].Cells[1].Value = rFI.label;
                i++;
            }

            // How many responses can be checked?
            if (responseFixed.canSelectMany)
            {
                this.radioButtonYes.Checked = true;
            }
            else {
                this.radioButtonNo.Checked = true;
            }

            // Interview appearance
            if (q.appearance.Equals(appearanceType.compact)) {
                this.radioButtonAppearanceCompact.Checked = true;
            }
            else if (q.appearance.Equals(appearanceType.full)) {
                this.radioButtonAppearanceFull.Checked = true;
            }
            else if (q.appearance.Equals(appearanceType.minimal) ){
                this.radioButtonAppearanceMinimal.Checked = true;
            }

            // Default
            this.textBoxDefault.Text = defaultAnswer;
        }
        public void init(responseFixed responseFixed)
        {
            this.responseFixed = responseFixed;

            // Pre-populate with true/false
            this.dataGridView1.Rows.Add(2);
            this.dataGridView1.Rows[0].Cells[0].Value = "true"; // val
            this.dataGridView1.Rows[0].Cells[1].Value = "yes";  // label

            this.dataGridView1.Rows[1].Cells[0].Value = "false";
            this.dataGridView1.Rows[1].Cells[1].Value = "no";
        }
 public virtual void populateValues(responseFixed responses, string matchResponse)
 {
 }