using System; using System.Collections.Generic; using System.ComponentModel; using System.Configuration; using System.Data; using System.Diagnostics; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; using Dicom; using Dicom.Log; using Dicom.Network; namespace PacsView3D { public partial class MainFrm : Form { private static string StoragePath = @".\DICOM"; private static string calledAE = ""; public static MainFrm mainfrm; private string encryptComputer = string.Empty; private bool isRegist = false; public static string studyPath = string.Empty; private string accessionnumber = string.Empty; string[] args = null; //private WadoQueryFrm queryFrm = new WadoQueryFrm(); private QRFrm queryFrm = new QRFrm(); //public MainFrm(string[] args) //{ // InitializeComponent(); // inifrm(); // this.args = args; // if (args.Length > 0) // { // Console.WriteLine(string.Format("接收到了{0}个参数", args.Length)); // foreach (var item in args) // { // if (item.Contains("path=")) // { // studyPath = item.Replace("path=", ""); // Console.WriteLine("path:{0}", studyPath); // } // if (item.Contains("accessionnumber=")) // { // accessionnumber = item.Replace("accessionnumber=", ""); // if(accessionnumber != string.Empty) // { // studyPath = queryFrm.LoadStudy(accessionnumber); // } // Console.WriteLine("studyuid:{0}", accessionnumber); // } // } // } // if (studyPath.Length>0) // { // this.axD3DA1.LoadDir(studyPath); // } //} public MainFrm() { InitializeComponent(); Log4NetHelper.InitLog4Net(Application.StartupPath + "\\log4net.config"); mainfrm = this; OpenSCP(); inifrm(); Log4NetHelper.WriteLog("程序启动"); } private bool CheckRegist() { EncryptionHelper helper = new EncryptionHelper(); string md5key = helper.GetMD5String(encryptComputer); Console.WriteLine(md5key); return CheckRegistData(md5key); } private bool CheckRegistData(string key) { if (RegistFileHelper.ExistRegistInfofile() == false) { isRegist = false; return false; } else { string info = RegistFileHelper.ReadRegistFile(); var helper = new EncryptionHelper(EncryptionKeyEnum.KeyB); string registData = helper.DecryptString(info); if (key == registData) { isRegist = true; return true; } else { isRegist = false; return false; } } } public void inifrm() { string computer = ComputerInfo.GetComputerInfo(); encryptComputer = new EncryptionHelper().EncryptString(computer); if (CheckRegist() == true) { this.Text = "PacsView3D --已注册"; } else { this.Text = "PacsView3D --未注册:试用时间2019-5-30"; RegistFileHelper.WriteComputerInfoFile(encryptComputer); DateTime lastDay = Convert.ToDateTime("2019-5-30"); DateTime currentTime = System.DateTime.Now; if (currentTime > lastDay) { MessageBox.Show("版本试用已到期!"); System.Diagnostics.Process tt = System.Diagnostics.Process.GetProcessById(System.Diagnostics.Process.GetCurrentProcess().Id); tt.Kill(); } } axD3DA1.Initialize(); this.panel1.Height = Convert.ToInt32( Height * 0.92); this.box2.Top = box1.Top + box1.Height + 5; this.box3.Top = box2.Top + box2.Height + 5; this.box2d.Top = box3.Top + box3.Height + 5; this.box3d.Top = box2.Top; this.box2d.Left = box1.Left; this.box2.Left = box1.Left; this.box3.Left = box1.Left; this.box3d.Left = box1.Left; this.box2d.Visible = false; this.box3d.Visible = true; this.box3d.Top = box2d.Top; this.box3d.Left = box2d.Left; this.axD3DA1.Show3dView(); } private void btnload_Click(object sender, EventArgs e) { FolderBrowserDialog dialog = new FolderBrowserDialog(); dialog.Description = "请选择文件路径"; if (dialog.ShowDialog() == DialogResult.OK) { string fileoath = dialog.SelectedPath; this.axD3DA1.LoadDir(fileoath); } } public void LoadStudy (string path) { this.axD3DA1.Clear(); this.axD3DA1.LoadDir(path); this.axD3DA1.Show3dView(); } private void btn3D_Click(object sender, EventArgs e) { this.axD3DA1.Show3dView(); box2d.Visible = false; box3d.Visible = true; box3d.Top = box2d.Top; box3d.Left = box2d.Left; } private void btn2D_Click(object sender, EventArgs e) { this.axD3DA1.Show2DView(); box2d.Visible = true; box3d.Visible = false; } private void btmmpr_Click(object sender, EventArgs e) { this.axD3DA1.ShowMprView(); box2d.Visible = false; box3d.Visible = false; } private void btnve_Click(object sender, EventArgs e) { this.axD3DA1.ShowVeView(); box2d.Visible = false; box3d.Visible = false; } public void button1_Click(object sender, EventArgs e) { Button button = (Button)sender; if (button.Tag.ToString() == "1") { button.Tag = "0"; this.axD3DA1.ShowPatientPanel(Convert.ToInt16(0)); } else { this.axD3DA1.ShowPatientPanel(Convert.ToInt16(1)); } } private void comboBoxSeries_SelectedIndexChanged(object sender, EventArgs e) { this.axD3DA1.Function2D(Convert.ToInt16(comboBoxSeries.SelectedIndex + 1)); } private void comboBoxImage_SelectedIndexChanged(object sender, EventArgs e) { this.axD3DA1.Function2D(Convert.ToInt16(comboBoxImage.SelectedIndex + 6)); } private void btnrule_Click(object sender, EventArgs e) { Button button = (Button)sender; this.axD3DA1.SetAnnTool(Convert.ToInt16(button.Tag)); } private void Tools_Click(object sender, EventArgs e) { Button button = (Button)sender; this.axD3DA1.SetPublicTool(Convert.ToInt16(button.Tag)); } private void button6_Click(object sender, EventArgs e) { Button button = (Button)sender; this.axD3DA1.Function2D(Convert.ToInt16(button.Tag)); } private void btnPX_Click(object sender, EventArgs e) { this.axD3DA1.Function2D(Convert.ToInt16(17)); } private void btnInfo_Click(object sender, EventArgs e) { Button button = (Button)sender; if (button.Tag.ToString() == "1") { button.Tag = "0"; this.axD3DA1.ShowInformation(Convert.ToInt16(0)); } else { this.axD3DA1.ShowInformation(Convert.ToInt16(1)); } } private void btn3DTools_Click(object sender, EventArgs e) { Button button = (Button)sender; this.axD3DA1.Function3D(Convert.ToInt16(button.Tag)); } private void btnList_Click(object sender, EventArgs e) { queryFrm.ShowDialog(this); } private void btnclear_Click(object sender, EventArgs e) { this.axD3DA1.Clear(); } private void OpenSCP() { string port = ConfigurationManager.AppSettings["PORT"]; calledAE = ConfigurationManager.AppSettings["QRAETITLE"]; if (int.Parse(port)>0) { var server = DicomServer.Create(int.Parse(port)); Console.WriteLine("打开端口:" + port); } } private class CStoreSCP : DicomService, IDicomServiceProvider, IDicomCStoreProvider, IDicomCEchoProvider { private static readonly DicomTransferSyntax[] AcceptedTransferSyntaxes = new DicomTransferSyntax[] { DicomTransferSyntax.ExplicitVRLittleEndian, DicomTransferSyntax.ExplicitVRBigEndian, DicomTransferSyntax.ImplicitVRLittleEndian }; private static readonly DicomTransferSyntax[] AcceptedImageTransferSyntaxes = new DicomTransferSyntax[] { // Lossless DicomTransferSyntax.JPEGLSLossless, DicomTransferSyntax.JPEG2000Lossless, DicomTransferSyntax.JPEGProcess14SV1, DicomTransferSyntax.JPEGProcess14, DicomTransferSyntax.RLELossless, // Lossy DicomTransferSyntax.JPEGLSNearLossless, DicomTransferSyntax.JPEG2000Lossy, DicomTransferSyntax.JPEGProcess1, DicomTransferSyntax.JPEGProcess2_4, // Uncompressed DicomTransferSyntax.ExplicitVRLittleEndian, DicomTransferSyntax.ExplicitVRBigEndian, DicomTransferSyntax.ImplicitVRLittleEndian }; public CStoreSCP(INetworkStream stream, Encoding fallbackEncoding, Logger log) : base(stream, fallbackEncoding, log) { } public Task OnReceiveAssociationRequestAsync(DicomAssociation association) { Log4NetHelper.WriteLog("ReceiveAssociation.CalledAE:" + association.CalledAE); Log4NetHelper.WriteLog("ReceiveAssociation.CallingAE:" + association.CallingAE); //if (association.CalledAE != calledAE) //{ // return SendAssociationRejectAsync( // DicomRejectResult.Permanent, // DicomRejectSource.ServiceUser, // DicomRejectReason.CalledAENotRecognized); //} foreach (var pc in association.PresentationContexts) { if (pc.AbstractSyntax == DicomUID.Verification) pc.AcceptTransferSyntaxes(AcceptedTransferSyntaxes); else if (pc.AbstractSyntax.StorageCategory != DicomStorageCategory.None) pc.AcceptTransferSyntaxes(AcceptedImageTransferSyntaxes); } Console.WriteLine("协商会话成功,SCU的AET为:" + association.CallingAE); return SendAssociationAcceptAsync(association); } public Task OnReceiveAssociationReleaseRequestAsync() { Console.WriteLine("成功完成了一次会话请求!study路径为:" + studyPath); mainfrm.LoadStudy(studyPath); return SendAssociationReleaseResponseAsync(); } public void OnReceiveAbort(DicomAbortSource source, DicomAbortReason reason) { } public void OnConnectionClosed(Exception exception) { Console.WriteLine("连接关闭"); } public DicomCStoreResponse OnCStoreRequest(DicomCStoreRequest request) { var studyUid = request.Dataset.GetSingleValue(DicomTag.StudyInstanceUID); var instUid = request.SOPInstanceUID.UID; Console.WriteLine($"接收图像 {instUid}"); var path = Path.GetFullPath(StoragePath); studyPath = Path.Combine(path, studyUid); path = Path.Combine(path, studyUid); if (!Directory.Exists(path)) Directory.CreateDirectory(path); path = Path.Combine(path, instUid) + ".dcm"; request.File.Save(path); return new DicomCStoreResponse(request, DicomStatus.Success); } public void OnCStoreRequestException(string tempFileName, Exception e) { Console.WriteLine("接收产生异常!"); // let library handle logging and error response } public DicomCEchoResponse OnCEchoRequest(DicomCEchoRequest request) { Console.WriteLine("接收到ECHO请求!"); return new DicomCEchoResponse(request, DicomStatus.Success); } } } }