Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.38 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.IO;
  11. using Microsoft.WindowsAPICodePack.Dialogs;
  12. using System.Xml;
  13. using System.Xml.Serialization;
  14. using ps9 = PlanSwift9;
  15. namespace WindowsFormsApplication1
  16. {
  17.  
  18. public partial class mAllInOne : Form
  19. {
  20.  
  21. public mAllInOne()
  22. {
  23.  
  24. InitializeComponent();
  25. var test =
  26.  
  27. }
  28.  
  29.  
  30.  
  31. class TGlobal
  32. {
  33. public static pswift.IPlanSwift ps;
  34. public static List<string> tlst;
  35. }
  36. private void mBrowse_Click(object sender, EventArgs e)
  37. {
  38. int size = -1;
  39. CommonOpenFileDialog openFileDialog1 = new CommonOpenFileDialog();
  40. //Show the Dialog and get Result
  41. openFileDialog1.IsFolderPicker = true;
  42. CommonFileDialogResult result = openFileDialog1.ShowDialog();
  43. if (result == CommonFileDialogResult.Ok) //Test Result.
  44. {
  45. string file = openFileDialog1.FileName;
  46. using System;
  47. using System.Collections.Generic;
  48. using System.ComponentModel;
  49. using System.Data;
  50. using System.Drawing;
  51. using System.Linq;
  52. using System.Text;
  53. using System.Threading.Tasks;
  54. using System.Windows.Forms;
  55. using System.IO;
  56. using Microsoft.WindowsAPICodePack.Dialogs;
  57. using System.Xml;
  58. using System.Xml.Serialization;
  59. using ps9 = PlanSwift9;
  60. namespace WindowsFormsApplication1
  61. {
  62.  
  63. public partial class mAllInOne : Form
  64. {
  65.  
  66. public mAllInOne()
  67. {
  68.  
  69. InitializeComponent();
  70. var test =
  71.  
  72. }
  73.  
  74.  
  75.  
  76. class TGlobal
  77. {
  78. public static pswift.IPlanSwift ps;
  79. public static List<string> tlst;
  80. }
  81. private void mBrowse_Click(object sender, EventArgs e)
  82. {
  83. int size = -1;
  84. CommonOpenFileDialog openFileDialog1 = new CommonOpenFileDialog();
  85. //Show the Dialog and get Result
  86. openFileDialog1.IsFolderPicker = true;
  87. CommonFileDialogResult result = openFileDialog1.ShowDialog();
  88. if (result == CommonFileDialogResult.Ok) //Test Result.
  89. {
  90. string file = openFileDialog1.FileName;
  91. try
  92. {
  93. //Data Structure to hold names of Folders to be examined for files
  94. Stack<string> dirs = new Stack<string>(20);
  95. if (Directory.Exists(file))
  96. {
  97. // throw new ArgumentException();
  98. }
  99. dirs.Push(file);
  100. while (dirs.Count > 0)
  101. {
  102. string currentDir = dirs.Pop();
  103. string[] subDirs;
  104. try
  105. {
  106. subDirs = Directory.GetDirectories(currentDir);
  107. }
  108. // An UnauthorizedAccessException exception will be thrown if we do not have
  109. // discovery permission on a folder or file. It may or may not be acceptable
  110. // to ignore the exception and continue enumerating the remaining files and
  111. // folders. It is also possible (but unlikely) that a DirectoryNotFound exception
  112. // will be raised. This will happen if currentDir has been deleted by
  113. // another application or thread after our call to Directory.Exists. The
  114. // choice of which exceptions to catch depends entirely on the specific task
  115. // you are intending to perform and also on how much you know with certainty
  116. // about the systems on which this code will run.
  117.  
  118. catch (UnauthorizedAccessException er)
  119. {
  120. MessageBox.Show((er.Message), "ERROR", MessageBoxButtons.OK,
  121. MessageBoxIcon.Error,
  122. MessageBoxDefaultButton.Button1);
  123. continue;
  124. }
  125. catch (DirectoryNotFoundException er)
  126. {
  127. MessageBox.Show((er.Message), "ERROR", MessageBoxButtons.OK,
  128. MessageBoxIcon.Error,
  129. MessageBoxDefaultButton.Button1);
  130. continue;
  131. }
  132. string[] Files = null;
  133. try
  134. {
  135.  
  136. Files = Directory.GetFiles(currentDir,"Data.xml");
  137. }
  138.  
  139. catch (UnauthorizedAccessException er)
  140. {
  141. MessageBox.Show((er.Message), "ERROR", MessageBoxButtons.OK,
  142. MessageBoxIcon.Error,
  143. MessageBoxDefaultButton.Button1);
  144. continue;
  145. }
  146. catch (DirectoryNotFoundException er)
  147. {
  148. MessageBox.Show((er.Message), "ERROR", MessageBoxButtons.OK,
  149. MessageBoxIcon.Error,
  150. MessageBoxDefaultButton.Button1);
  151. continue;
  152. }
  153. // Perform the required action on each file here.
  154. // Modify this block to perform your required task.
  155. foreach (string fileXML in Files)
  156. {
  157. try
  158. {
  159. //Here is where I read the XML Files
  160. XmlDocument doc = new XmlDocument();
  161. TGlobal.ps = new ps9.PlanSwift();
  162. string jobPath = TGlobal.ps.Root().FullPath() + file;
  163. ps9.IItem takeoff = TGlobal.ps.GetItem(jobPath);
  164. doc.Load(fileXML);
  165. string elem = doc.DocumentElement.InnerText;
  166. MessageBox.Show(elem);
  167. mItemList.Items.Add(elem);
  168. }
  169. catch (FileNotFoundException er)
  170. {
  171. MessageBox.Show((er.Message), "ERROR", MessageBoxButtons.OK,
  172. MessageBoxIcon.Error,
  173. MessageBoxDefaultButton.Button1);
  174. continue;
  175. }
  176.  
  177. }
  178. //Push subdirectories onto the stack for Traversal.
  179. //This could also be done before handing the files.
  180. foreach (string str in subDirs)
  181. dirs.Push(str);
  182. }
  183.  
  184. }
  185.  
  186. catch (IOException)
  187. {
  188.  
  189. }
  190. }
  191.  
  192. }
  193.  
  194. private void panel1_Paint(object sender, PaintEventArgs e)
  195. {
  196.  
  197. }
  198.  
  199. private void panel2_Paint(object sender, PaintEventArgs e)
  200. {
  201.  
  202. }
  203.  
  204. private void mBrowse2_Click(object sender, EventArgs e)
  205. {
  206.  
  207. }
  208.  
  209. private void progressBar3_Click(object sender, EventArgs e)
  210. {
  211.  
  212. }
  213.  
  214. private void mAllInOne_Load(object sender, EventArgs e)
  215. {
  216.  
  217. }
  218.  
  219. private void button2_Click(object sender, EventArgs e)
  220. {
  221.  
  222. }
  223.  
  224. }
  225.  
  226. }
  227.  
  228.  
  229.  
  230. catch (IOException)
  231. {
  232.  
  233. }
  234. }
  235.  
  236. }
  237.  
  238. private void panel1_Paint(object sender, PaintEventArgs e)
  239. {
  240.  
  241. }
  242.  
  243. private void panel2_Paint(object sender, PaintEventArgs e)
  244. {
  245.  
  246. }
  247.  
  248. private void mBrowse2_Click(object sender, EventArgs e)
  249. {
  250.  
  251. }
  252.  
  253. private void progressBar3_Click(object sender, EventArgs e)
  254. {
  255.  
  256. }
  257.  
  258. private void mAllInOne_Load(object sender, EventArgs e)
  259. {
  260.  
  261. }
  262.  
  263. private void button2_Click(object sender, EventArgs e)
  264. {
  265.  
  266. }
  267.  
  268. }
  269.  
  270. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement