public static void ExportToSoils(BaseController Controller) { SaveFileDialog Dialog = new SaveFileDialog(); Dialog.Filter = "Soils files (*.soils)|*.soils|All files (*.*)|*.*"; Dialog.Title = "Enter a .soils file to export to"; Dialog.DefaultExt = "soils"; if (Dialog.ShowDialog() == DialogResult.OK) { XmlDocument Doc = new XmlDocument(); if (!File.Exists(Dialog.FileName)) { Doc.AppendChild(XmlHelper.CreateNode(Doc, "soils", "")); } else { Doc.Load(Dialog.FileName); } foreach (string SelectedPath in Controller.SelectedPaths) { ApsimFile.Component Comp = Controller.ApsimData.Find(SelectedPath); XmlDocument NodeDoc = new XmlDocument(); NodeDoc.LoadXml(Comp.FullXML()); Doc.DocumentElement.AppendChild(Doc.ImportNode(NodeDoc.DocumentElement, true)); } XmlHelper.SetAttribute(Doc.DocumentElement, "version", ApsimFile.APSIMChangeTool.CurrentVersion.ToString()); Doc.Save(Dialog.FileName); MessageBox.Show("Soils have been successfully exported to '" + Dialog.FileName + "'. It is suggested that you rename soils within the new file to avoid confusion.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void TreeView_ItemDrag(object sender, System.Windows.Forms.ItemDragEventArgs e) { // ----------------------------------------------------------------- // User has initiated a drag on a node - the full xml of the node // is stored as the data associated with the drag event args. // ----------------------------------------------------------------- //If what is being dragged is not already in the controller as a selected item. if (Controller.SelectedPaths.IndexOf(GetPathFromNode((TreeNode)e.Item)) == -1) { SelectedNode = (TreeNode)e.Item; //add it to the base controller (by setting the selected node of the tree to the dragged item. This then fires the selection changed event for the tree which I think is handled by the base controller. This will add the dragged items to the base controller) } //Work out the xml of what you are dragging. string FullXML = ""; //used to store the xml of ALL the components that have been selected in the drag 'reset it to nothing, ready for recreation. //get the full xml of all the selected nodes that are getting dragged foreach (string SelectedPath in Controller.SelectedPaths) { ApsimFile.Component Comp = Controller.ApsimData.Find(SelectedPath); //get the component for this particular selected node (using it's path) FullXML = FullXML + Comp.FullXML(); //get the xml for the component and add it to the xml of previous selected nodes } PathsBeingDragged = Controller.SelectedPaths; //store the paths of ALL the nodes that are being dragged in a global variable, so it can be used by other drag events. //Raise the other DragDropEvents DoDragDrop(FullXML, DragDropEffects.Copy | DragDropEffects.Move | DragDropEffects.Link); //parameters: (Store xml of what you are dragging in "data" Drag Event Argument), (allowable types of left mouse drags [Drag Drop Effects are of type FlagsAttribute, which allow bitwise operators AND and OR]). }
// -------------------------------------------------------- // User is trying to initiate a drag - allow drag operation // -------------------------------------------------------- private void ListView_ItemDrag(object sender, System.Windows.Forms.ItemDragEventArgs e) { ApsimFile.Component Comp = Controller.ApsimData.Find(NodePath); ApsimFile.Component SelectedComp = Comp.Find(ListView.SelectedItems[0].Text); string DataString = SelectedComp.FullXML(); ListView.DoDragDrop(DataString, DragDropEffects.All); }
static public void ExportSelectedToFile(string FileName, BaseController Controller) { Cursor.Current = Cursors.WaitCursor; File.Delete(FileName); DataTable Table = new DataTable("SoilData"); int Row = 0; foreach (string SelectedPath in Controller.SelectedPaths) { ApsimFile.Component SoilComponent = Controller.ApsimData.Find(SelectedPath); XmlDocument Doc = new XmlDocument(); Doc.LoadXml(SoilComponent.FullXML()); CreateTableFromData(Doc.DocumentElement, Table, SelectedPath.Replace("/", "\\"), ref Row); } ExcelHelper.SendDataToSheet(FileName, "SoilData", Table); Cursor.Current = Cursors.Default; }
private static void CheckSoils(ApsimFile.Component Data, ref string ErrorMessage) { if (Data.Type.ToLower() == "soil") { Soil ThisSoil = Soil.Create(Data.FullXML()); string Errors = ThisSoil.Check(true); if (!string.IsNullOrEmpty(Errors)) { ErrorMessage += Environment.NewLine + Data.FullPath + Environment.NewLine + StringManip.IndentText(Errors, 6); } } else if (Data.Type.ToLower() == "folder") { foreach (ApsimFile.Component Child in Data.ChildNodes) { CheckSoils(Child, ref ErrorMessage); } } }