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); } /// /// 清空文件夹 /// /// 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) { } } }