123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Configuration;
- using System.Data;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Net.Http;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Xml;
- namespace wadoClient
- {
- public partial class Form1 : Form
- {
- string wado = String.Empty;
- string wadoRS = String.Empty;
- string wadoURI = String.Empty;
- string tmpPath = System.Environment.CurrentDirectory + "\\temp";
- public Form1()
- {
- InitializeComponent();
- string wado = ConfigurationManager.AppSettings["wado"];
- string user = ConfigurationManager.AppSettings["User"];
- string pwd = ConfigurationManager.AppSettings["Password"];
- wado = wado + "User=" + user + "&Password=" + pwd;
- wadoRS = wado + "&requestType=Query&accessionNumber=";
- wadoURI = wado + "&requestType=WADO&contentType=application%2Fdicom&objectUID=";
- textBox2.Text = wado;
- Console.WriteLine(wado);
- if (Directory.Exists(tmpPath) == false)
- {
- Directory.CreateDirectory(tmpPath);
- }
- }
- private void btnQuery_Click(object sender, EventArgs e)
- {
- string accessionNumber = textBox1.Text;
- textBox2.Text = wadoRS + textBox1.Text;
- if (textBox5.Text.Length>0)
- {
- textBox2.Text = wadoRS + textBox1.Text + "&patientid=" + textBox5.Text;
- }
- string studyinfo = HttpRequestHelper.HttpGetRequest(textBox2.Text);
- this.richTextBox1.Text = studyinfo;
- if (studyinfo.Length>0)
- {
- XmlDocument xml = new XmlDocument();
- xml.LoadXml(studyinfo);
- xml.Save(tmpPath + "\\" + accessionNumber + ".xml");
- MessageBox.Show(xml.InnerXml);
- XmlNodeList dataset = xml.SelectNodes("//dataset");
- XmlNodeList topM = dataset[0].SelectNodes("//objectUID");
- //MessageBox.Show(topM.Count.ToString());
- if (topM.Count>0)
- {
- string studyPath = tmpPath + "\\" + accessionNumber;
- if (Directory.Exists(studyPath) == false)
- {
- Directory.CreateDirectory(studyPath);
- } else
- {
- DeleteFolder(studyPath);
- }
- foreach (XmlElement element in topM)
- {
- if (element.InnerText.Length>0)
- {
- //MessageBox.Show(element.InnerText);
- HttpDldFile df = new HttpDldFile();
- textBox3.Text = wadoURI + element.InnerText;
- this.richTextBox2.AppendText(textBox3.Text);
- textBox4.Text = studyPath + "\\" + element.InnerText + ".dcm";
- // df.Download(wadoURI + element.InnerText, studyPath + "\\" + element.InnerText + ".dcm");
- }
- }
- }
- }
-
- }
- private void btnDownload_Click(object sender, EventArgs e)
- {
- HttpDldFile df = new HttpDldFile();
- df.Download(textBox3.Text, textBox4.Text);
- }
- /// <summary>
- /// 清空文件夹
- /// </summary>
- /// <param name="dir"></param>
- private void DeleteFolder(string dir)
- {
- foreach (string d in Directory.GetFileSystemEntries(dir))
- {
- if (File.Exists(d))
- {
- try
- {
- FileInfo fi = new FileInfo(d);
- if (fi.Attributes.ToString().IndexOf("ReadOnly") != -1)
- fi.Attributes = FileAttributes.Normal;
- File.Delete(d);//直接删除其中的文件
- }
- catch
- {
- }
- }
- else
- {
- try
- {
- DirectoryInfo d1 = new DirectoryInfo(d);
- if (d1.GetFiles().Length != 0)
- {
- DeleteFolder(d1.FullName);////递归删除子文件夹
- }
- Directory.Delete(d);
- }
- catch
- {
- }
- }
- }
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- }
- }
- }
|