Form1.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Configuration;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.IO;
  8. using System.Linq;
  9. using System.Net.Http;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows.Forms;
  13. using System.Xml;
  14. namespace wadoClient
  15. {
  16. public partial class Form1 : Form
  17. {
  18. string wado = String.Empty;
  19. string wadoRS = String.Empty;
  20. string wadoURI = String.Empty;
  21. string tmpPath = System.Environment.CurrentDirectory + "\\temp";
  22. public Form1()
  23. {
  24. InitializeComponent();
  25. string wado = ConfigurationManager.AppSettings["wado"];
  26. string user = ConfigurationManager.AppSettings["User"];
  27. string pwd = ConfigurationManager.AppSettings["Password"];
  28. wado = wado + "User=" + user + "&Password=" + pwd;
  29. wadoRS = wado + "&requestType=Query&accessionNumber=";
  30. wadoURI = wado + "&requestType=WADO&contentType=application%2Fdicom&objectUID=";
  31. textBox2.Text = wado;
  32. Console.WriteLine(wado);
  33. if (Directory.Exists(tmpPath) == false)
  34. {
  35. Directory.CreateDirectory(tmpPath);
  36. }
  37. }
  38. private void btnQuery_Click(object sender, EventArgs e)
  39. {
  40. string accessionNumber = textBox1.Text;
  41. textBox2.Text = wadoRS + textBox1.Text;
  42. if (textBox5.Text.Length>0)
  43. {
  44. textBox2.Text = wadoRS + textBox1.Text + "&patientid=" + textBox5.Text;
  45. }
  46. string studyinfo = HttpRequestHelper.HttpGetRequest(textBox2.Text);
  47. this.richTextBox1.Text = studyinfo;
  48. if (studyinfo.Length>0)
  49. {
  50. XmlDocument xml = new XmlDocument();
  51. xml.LoadXml(studyinfo);
  52. xml.Save(tmpPath + "\\" + accessionNumber + ".xml");
  53. MessageBox.Show(xml.InnerXml);
  54. XmlNodeList dataset = xml.SelectNodes("//dataset");
  55. XmlNodeList topM = dataset[0].SelectNodes("//objectUID");
  56. //MessageBox.Show(topM.Count.ToString());
  57. if (topM.Count>0)
  58. {
  59. string studyPath = tmpPath + "\\" + accessionNumber;
  60. if (Directory.Exists(studyPath) == false)
  61. {
  62. Directory.CreateDirectory(studyPath);
  63. } else
  64. {
  65. DeleteFolder(studyPath);
  66. }
  67. foreach (XmlElement element in topM)
  68. {
  69. if (element.InnerText.Length>0)
  70. {
  71. //MessageBox.Show(element.InnerText);
  72. HttpDldFile df = new HttpDldFile();
  73. textBox3.Text = wadoURI + element.InnerText;
  74. this.richTextBox2.AppendText(textBox3.Text);
  75. textBox4.Text = studyPath + "\\" + element.InnerText + ".dcm";
  76. // df.Download(wadoURI + element.InnerText, studyPath + "\\" + element.InnerText + ".dcm");
  77. }
  78. }
  79. }
  80. }
  81. }
  82. private void btnDownload_Click(object sender, EventArgs e)
  83. {
  84. HttpDldFile df = new HttpDldFile();
  85. df.Download(textBox3.Text, textBox4.Text);
  86. }
  87. /// <summary>
  88. /// 清空文件夹
  89. /// </summary>
  90. /// <param name="dir"></param>
  91. private void DeleteFolder(string dir)
  92. {
  93. foreach (string d in Directory.GetFileSystemEntries(dir))
  94. {
  95. if (File.Exists(d))
  96. {
  97. try
  98. {
  99. FileInfo fi = new FileInfo(d);
  100. if (fi.Attributes.ToString().IndexOf("ReadOnly") != -1)
  101. fi.Attributes = FileAttributes.Normal;
  102. File.Delete(d);//直接删除其中的文件
  103. }
  104. catch
  105. {
  106. }
  107. }
  108. else
  109. {
  110. try
  111. {
  112. DirectoryInfo d1 = new DirectoryInfo(d);
  113. if (d1.GetFiles().Length != 0)
  114. {
  115. DeleteFolder(d1.FullName);////递归删除子文件夹
  116. }
  117. Directory.Delete(d);
  118. }
  119. catch
  120. {
  121. }
  122. }
  123. }
  124. }
  125. private void Form1_Load(object sender, EventArgs e)
  126. {
  127. }
  128. }
  129. }