Inheritance: ODFFormControl
		/// <summary>
		/// Gets the form.
		/// </summary>
		/// <param name="formnode">The node of the form.</param>
		/// <returns></returns>
		private ODFForm CreateForm(XmlNode formnode)
		{
			ODFForm form = null;
			try
			{
				if (formnode.Name == "form:form")
				{
					if (this._debugMode)
						this.LogNode(formnode, "Log form node before");
						
					//Create a new ODFForm
					
					///////////TODO. Fix for child forms!
					form = new ODFForm(formnode.CloneNode(true), this._document);
						
					form.SuppressControlEvents();
					foreach(XmlNode nodeChild in form.Node.ChildNodes)
					{
						
						switch (nodeChild.Name)
						{
							case "form:form":	
								if (nodeChild.ParentNode==form.Node)
								{
									ODFForm frmchild = CreateForm(nodeChild);
									if (frmchild != null)
									{
										form.ChildForms.Add(frmchild);
									}
									form.Node.RemoveChild(nodeChild);
								}
								break;
							case "form:properties": break;
							
							case "form:button":
								if (nodeChild.ParentNode==form.Node) 
								{
									ODFButton button = new ODFButton(form, nodeChild);
									button.FixPropertyCollection();
									form.Controls.Add(button);
								}
								break;
							
							case "form:listbox":
								if (nodeChild.ParentNode==form.Node) 
								{
									ODFListBox listbox = new ODFListBox(form, nodeChild);
									listbox.FixPropertyCollection();
									listbox.FixOptionCollection();
									form.Controls.Add(listbox);
								}
								break;
							
							case "form:combobox":
								if (nodeChild.ParentNode==form.Node) 
								{
									ODFComboBox combobox = new ODFComboBox(form, nodeChild);
									combobox.FixPropertyCollection();
									combobox.FixItemCollection();
									form.Controls.Add(combobox);
								}
								break;

							case "form:textarea":
								if (nodeChild.ParentNode==form.Node) 
								{
									ODFTextArea text = new ODFTextArea(form, nodeChild);
									text.FixPropertyCollection();
									form.Controls.Add(text);
								}
								break;

							case "form:frame":
								if (nodeChild.ParentNode==form.Node) 
								{
									ODFFrame frm = new ODFFrame(form, nodeChild);
									frm.FixPropertyCollection();
									form.Controls.Add(frm);
								}
								break;

							case "form:file":
								if (nodeChild.ParentNode==form.Node) 
								{
									ODFFile file = new ODFFile(form, nodeChild);
									file.FixPropertyCollection();
									form.Controls.Add(file);
								}
								break;
							
							case "form:hidden":
								if (nodeChild.ParentNode==form.Node) 
								{
									ODFHidden hidden = new ODFHidden(form, nodeChild);
									hidden.FixPropertyCollection();
									form.Controls.Add(hidden);
								}
								break;

							case "form:checkbox":
								if (nodeChild.ParentNode==form.Node) 
								{
									ODFCheckBox cb = new ODFCheckBox(form, nodeChild);
									cb.FixPropertyCollection();
									form.Controls.Add(cb);
								}
								break;

							case "form:radio":
								if (nodeChild.ParentNode==form.Node) 
								{
									ODFRadioButton rb = new ODFRadioButton(form, nodeChild);
									rb.FixPropertyCollection();
									form.Controls.Add(rb);
								}
								break;

							case "form:formatted-text":
								if (nodeChild.ParentNode==form.Node) 
								{
									ODFFormattedText text = new ODFFormattedText(form, nodeChild);
									text.FixPropertyCollection();
									form.Controls.Add(text);
								}
								break;
							case "form:value-range":
								if (nodeChild.ParentNode==form.Node) 
								{
									ODFValueRange vr = new ODFValueRange(form, nodeChild);
									vr.FixPropertyCollection();
									form.Controls.Add(vr);
								}
								break;
							case "form:image":
								if (nodeChild.ParentNode==form.Node) 
								{
									ODFImage img = new ODFImage(form, nodeChild);
									img.FixPropertyCollection();
									form.Controls.Add(img);
								}
								break;
							case "form:image-frame":
								if (nodeChild.ParentNode==form.Node) 
								{
									ODFImageFrame imgf = new ODFImageFrame(form, nodeChild);
									imgf.FixPropertyCollection();
									form.Controls.Add(imgf);
								}
								break;
							case "form:grid":
								if (nodeChild.ParentNode==form.Node) 
								{
									ODFGrid gr = new ODFGrid(form, nodeChild);
									gr.FixPropertyCollection();
									gr.FixColumnCollection();
									form.Controls.Add(gr);
								}
								break;
							default: 
								if (nodeChild.ParentNode==form.Node) 
								{
									ODFGenericControl gc = new ODFGenericControl(form, nodeChild);
									gc.FixPropertyCollection();
									form.Controls.Add(gc);
								}
								break;
						}
					}
					form.RestoreControlEvents();
					form.FixPropertyCollection();
				//	formnode.RemoveAll();
				//	formnode.InnerText = "";
				}
			}
				

			catch(Exception ex)
			{
				throw new AODLException("Exception while processing a form:form node.", ex);
			}
			return form;
		}
Exemplo n.º 2
0
		public void ODFHiddenAndFormActionTest()
		{
			//Create a new text document
			TextDocument document					= new TextDocument();
			document.New();
			
			// Create a main paragraph
			Paragraph p =new Paragraph(document);
			// Create a main form
			
			// Create the first form (Method = GET)
			ODFForm form1 = new ODFForm(document, "form1");
			form1.Method = Method.Get;
			form1.Href = "http://foo.foo";
			
			// Create all the controls for form1
			ODFFrame frm1 = new ODFFrame(form1, p.Content, "frm1", "5mm", "5mm", "11cm", "3cm");
			frm1.Label = "Form submission test (Method = GET, Hidden name = hid)";
			form1.Controls.Add (frm1);
			ODFButton butt1 = new ODFButton(form1, p.Content, "butt1", "2cm", "15mm", "8cm", "1cm");
			butt1.Label = "Submit to foo.foo!";
			butt1.ButtonType = ButtonType.Submit;
			butt1.Name = "butt1";
			form1.Controls.Add (butt1);
			ODFHidden hid1 = new ODFHidden(form1, p.Content, "hid1", "0cm", "0cm", "0cm", "0cm");
			hid1.Value = "hello!";
			hid1.Name = "hid1";
			form1.Controls.Add(hid1);

			// Create the second form (Method = POST)
			ODFForm form2 = new ODFForm(document, "form2");
			form2.Method = Method.Post;
			form2.Href = "http://foo.foo.2";
			ODFFrame frm2 = new ODFFrame(form2, p.Content, "frm2", "5mm", "45mm", "11cm", "3cm");
			frm2.Label = "Form submission test (Method = POST, Hidden name = hid)";
			form2.Controls.Add (frm2);
			
			// Create all the controls for form2
			ODFButton butt2 = new ODFButton(form2, p.Content, "butt2", "2cm", "55mm", "8cm", "1cm");
			butt2.Label = "Submit to foo.foo!";
			butt2.ButtonType = ButtonType.Submit;
			butt2.Name = "butt2";
			form2.Controls.Add (butt2);
			ODFHidden hid2 = new ODFHidden(form2, p.Content, "hid2", "0cm", "0cm", "0cm", "0cm");
			hid2.Value = "hello!";
			hid2.Name = "hid2";
			form2.Controls.Add (hid2);

			document.Forms.Add(form1);
			document.Forms.Add(form2);
			document.Content.Add(p);

			document.SaveTo(AARunMeFirstAndOnce.outPutFolder+"hidden_subm_test.odt");
			document.Load(AARunMeFirstAndOnce.outPutFolder+"hidden_subm_test.odt");
			document.SaveTo(AARunMeFirstAndOnce.outPutFolder+"hidden_subm_test2.odt");
		}