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 static bool LoadFromFile(string fileName, out response obj) { System.Exception exception = null; return LoadFromFile(fileName, out obj, out exception); }
public question() { this.responseField = new response(); }
/// <summary> /// Deserializes xml markup from file into an response object /// </summary> /// <param name="fileName">string xml file to load and deserialize</param> /// <param name="obj">Output response 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 response obj, out System.Exception exception) { exception = null; obj = default(response); try { obj = LoadFromFile(fileName); return true; } catch (System.Exception ex) { exception = ex; return false; } }
public static bool Deserialize(string xml, out response obj) { System.Exception exception = null; return Deserialize(xml, out obj, out exception); }
/// <summary> /// Deserializes workflow markup into an response object /// </summary> /// <param name="xml">string workflow markup to deserialize</param> /// <param name="obj">Output response 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 response obj, out System.Exception exception) { exception = null; obj = default(response); try { obj = Deserialize(xml); return true; } catch (System.Exception ex) { exception = ex; return false; } }