public bool AddJob(PrintJob job) { bool flag = false; if ((this.sendThread == null) || (this.sendThread.ThreadState == System.Threading.ThreadState.Stopped)) { this._jobList.InsertRange(0, this._errorJobList); } lock (_sycKey) { if ((this._jobList.Count + this._errorJobList.Count) < this.MaxPrintListSize) { this._jobList.Add(job); //TypedDataDesign.PrintQueueRow row = this._printTable.NewPrintQueueRow(); //row.ID = job.ID; //row.PrintCount = job.Copies; //row.Status = SR.ReadyToSend; //this._printTable.Rows.Add(row); flag = true; } } this.Start(); return(flag); }
public void Print(PrintJob job) { this.InternalPrint(job); }
private void PrintDicomFiles(string sMessage, int Rows, int Columns, string strPrintFileNames, PrintJob job) { string DcmPrintPath = System.Windows.Forms.Application.StartupPath + @"\PrintFiles\"; string lPrtFile = DcmPrintPath + sMessage + ".prt"; string lDicomPrnAppName = System.Windows.Forms.Application.StartupPath + @"\DcmPrnProtect.exe"; IniFiles prtini = new IniFiles(lPrtFile); prtini.WriteString("DCMPRNT", "AETITLE", job.Printer.AET); prtini.WriteString("DCMPRNT", "AETITLESCU", job.Printer.CalledAET); prtini.WriteString("DCMPRNT", "IPADDRESS", job.Printer.Host); //prtini.WriteString("DCMPRNT", "PORT", job.Printer.Port); prtini.WriteInteger("DCMPRNT", "PORT", job.Printer.Port); prtini.WriteString("DCMPRNT", "IMAGEDISFORMAT", string.Format("STANDARD\\{0},{1}", Columns, Rows)); if (job.FilmOrientation == FilmOrientation.Landscape) { prtini.WriteString("DCMPRNT", "FILMORE", "landscape"); } else { prtini.WriteString("DCMPRNT", "FILMORE", "portrait"); } prtini.WriteString("DCMPRNT", "FILMSIZE", job.FilmSize.ToString()); prtini.WriteString("DCMPRNT", "NUMBERCOPYS", "1"); prtini.WriteString("DCMPRNT", "FILES", strPrintFileNames); prtini.WriteString("DCMPRNT", "TEMPIMAGEPATH", DcmPrintPath); prtini.WriteString("DCMPRNT", "PATIENTID", "123"); //prtini.WriteString("DCMPRNT", "MediumType", cmbFilmType.Text); try { //Call Dicom Print Process ProcessStartInfo Info = new ProcessStartInfo(); Info.FileName = lDicomPrnAppName; Info.Arguments = sMessage; int WINDOW_HANDLER = FindWindow(null, @"胶片打印"); if (WINDOW_HANDLER == 0) { Process proc = Process.Start(Info); } else { SendMessage(WINDOW_HANDLER, WM_PRINTDICOM, Convert.ToInt32(sMessage), 0); } } catch (Exception ex) { //MessageBox.Show(ex.Message, ex.Source); } }
private void InternalPrint(PrintJob job) { BasicFilmSessionModuleIod basicFilmSessionModuleIod = new BasicFilmSessionModuleIod { NumberOfCopies = job.Copies, MediumType = job.MediumType, FilmDestination = job.FilmDestination }; BasicFilmBoxModuleIod basicFilmBoxModuleIod = new BasicFilmBoxModuleIod { //ImageDisplayFormat = @"STANDARD\1,1", ImageDisplayFormat = ImageDisplayFormat.Standard_1x1, FilmSizeId = job.FilmSize, Illumination = job.Illumination, FilmOrientation = job.FilmOrientation, ReflectedAmbientLight = job.ReflectedAmbientLight, MagnificationType = job.MagnificationType }; IList <ImageBoxPixelModuleIod> imageBoxPixelModuleIods = new List <ImageBoxPixelModuleIod>(); bool userCancelled = false; BackgroundTask task = new BackgroundTask(delegate(IBackgroundTaskContext context) { try { BackgroundTaskProgress progress; ushort num = 1; int percent = 0; new List <string>(); ImageBoxPixelModuleIod item = new ImageBoxPixelModuleIod { ImageBoxPosition = 1 }; BasicGrayscaleImageSequenceIod iod2 = new BasicGrayscaleImageSequenceIod { PhotometricInterpretation = job.MonochormeType }; Size size = this.CalcMaxSize(job.Format, job.Images); Bitmap image = new Bitmap(size.Width, size.Height); System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(image); foreach (PreviewTile tile in job.Images) { percent = (int)((((float)(num - 1)) / ((float)job.Images.Count)) * 80f); num = (ushort)(num + 1); progress = new BackgroundTaskProgress(percent, string.Format(SR.CreatingImageBuffer, num, job.Images.Count)); context.ReportProgress(progress); if (tile.ImageData != null) { Platform.Log(LogLevel.Error, "TITLE IMAGEDATA"); Bitmap printImagePixel = tile.GetPrintImagePixel(false); float x = tile.NormalizedRectangle.X * size.Width; float y = tile.NormalizedRectangle.Y * size.Height; float width = tile.NormalizedRectangle.Width * size.Width; float height = tile.NormalizedRectangle.Height * size.Height; g.DrawImage(printImagePixel, x, y, width, height); g.DrawRectangle(Pens.White, x, y, width, height); Rectangle destination = new Rectangle(((int)x) + 2, ((int)y) + 2, ((int)width) - 4, ((int)height) - 4); try { IconCreator.DrawTextOverlay(g, destination, tile.ImageData); } catch (Exception ex) { Platform.Log(LogLevel.Error, " exception: " + ex.ToString()); } printImagePixel.Dispose(); if (context.CancelRequested) { userCancelled = true; break; } } } //clear foreach (PreviewTile tile in job.Images) { ImageSop sop = ((IImageSopProvider)tile.ImageData).ImageSop; string strUID = sop.SopInstanceUid; //获取UID 的 accession try { if (Conn.isOracle()) { string sqlstr = string.Format(" update examrecord set filmprint='{0}' where id=(select AccessionNumber from images where SopInstanceUID='{1}') and modulename='RIS' ", "1", strUID); OracleCommand sqlCmd = new OracleCommand(); sqlCmd.Connection = GlobalData.MainConn.ChangeTypeOracle(); sqlCmd.CommandText = sqlstr; sqlCmd.ExecuteNonQuery(); sqlCmd.Dispose(); } else { string sqlstr = string.Format(" update examrecord set filmprint='{0}' where id=(select AccessionNumber from images where SopInstanceUID='{1}') and modulename='RIS' ", "1", strUID); SqlCommand sqlCmd = new SqlCommand(); sqlCmd.Connection = GlobalData.MainConn.ChangeType(); sqlCmd.CommandText = sqlstr; sqlCmd.ExecuteNonQuery(); sqlCmd.Dispose(); Platform.Log(LogLevel.Error, " sql is " + sqlstr); } } catch (Exception ex) { Platform.Log(LogLevel.Error, "exception is " + ex.ToString()); } //tile.Dispose(); tile.RemoveImage(); } job.Images.Clear(); g.Dispose(); //iod2.AddBitmap(image); Unlock(); RasterImage lRasterImage = null; RasterCodecs lRasterCodecs = new RasterCodecs(); lRasterImage = RasterImageConverter.ConvertFromImage(image, ConvertFromImageOptions.None); lRasterCodecs.Save(lRasterImage, System.Windows.Forms.Application.StartupPath + @"\print.jpg", RasterImageFormat.Tif, 8); string lDicomFile = "1" + DateTime.Now.ToString("HHmmss", DateTimeFormatInfo.InvariantInfo); lRasterCodecs.Save(lRasterImage, System.Windows.Forms.Application.StartupPath + @"\PrintFiles\" + lDicomFile, RasterImageFormat.DicomGray, 16); //image.Save("d:\\test.jpg"); image.Dispose(); lRasterImage.Dispose(); lRasterCodecs.Dispose(); //item.BasicGrayscaleImageSequenceList.Add(iod2); //imageBoxPixelModuleIods.Add(item); if (userCancelled) { Platform.Log(LogLevel.Info, SR.UserCancel); } else { progress = new BackgroundTaskProgress(80, SR.BeginSendImage); context.ReportProgress(progress); PrintDicomFiles(lDicomFile, 1, 1, lDicomFile, job); //BasicGrayscalePrintScu scu = new BasicGrayscalePrintScu(); //scu.Print(job.Printer.AET, job.Printer.CalledAET, job.Printer.Host, job.Printer.Port, basicFilmSessionModuleIod, basicFilmBoxModuleIod, imageBoxPixelModuleIods); //if (scu.ResultStatus == DicomState.Success) //{ // this.UpdateStudyPrintStatus(this.GetStudyInstanceUIDs(job.Images)); // PrintToolComponent.TilesComponent.ResetTiles(); //} //else //{ // this._component.ShowMessageBox(SR.FilmError); //} } } catch (OutOfMemoryException) { Platform.Log(LogLevel.Error, "内存不够"); BackgroundTaskProgress progress2 = new BackgroundTaskProgress(100, SR.OutOfMemory); context.ReportProgress(progress2); this._component.ShowMessageBox(SR.OutOfMemory); } catch (Exception exception) { Platform.Log(LogLevel.Error, exception.Message); BackgroundTaskProgress progress3 = new BackgroundTaskProgress(100, exception.Message); context.ReportProgress(progress3); this._component.ShowMessageBox(SR.PrinterError); } finally { context.Complete(null); } }, true); ProgressDialog.Show(task, this._window, true, ProgressBarStyle.Blocks); }
private bool GoPrint(PrintJob printJob, out int successSend) { successSend = 0; try { BasicFilmSessionModuleIod basicFilmSessionModuleIod = new BasicFilmSessionModuleIod { NumberOfCopies = printJob.Copies, MediumType = printJob.MediumType, FilmDestination = printJob.FilmDestination }; BasicFilmBoxModuleIod basicFilmBoxModuleIod = new BasicFilmBoxModuleIod { //ImageDisplayFormat = printJob.Format, FilmSizeId = printJob.FilmSize, Illumination = printJob.Illumination, FilmOrientation = printJob.FilmOrientation, ReflectedAmbientLight = printJob.ReflectedAmbientLight, MagnificationType = printJob.MagnificationType }; IList <ImageBoxPixelModuleIod> imageBoxPixelModuleIods = new List <ImageBoxPixelModuleIod>(); ushort num = 1; foreach (PreviewTile tile in printJob.Images) { this.ChangeSendStatus(printJob.ID, string.Format(SR.CreatingImageBuffer, num, printJob.Images.Count)); ImageBoxPixelModuleIod item = new ImageBoxPixelModuleIod { ImageBoxPosition = tile.Position }; BasicGrayscaleImageSequenceIod iod4 = new BasicGrayscaleImageSequenceIod { PhotometricInterpretation = printJob.MonochormeType }; Bitmap printImagePixel = tile.GetPrintImagePixel(true); iod4.AddBitmap(printImagePixel); printImagePixel.Dispose(); item.BasicGrayscaleImageSequenceList.Add(iod4); imageBoxPixelModuleIods.Add(item); } if (this.StopKey) { return(false); } this.ChangeSendStatus(printJob.ID, SR.BeginSendImage); try { for (int i = 0; i < printJob.Copies; i++) { BasicGrayscalePrintScu scu = new BasicGrayscalePrintScu(); this.ChangeSendStatus(printJob.ID, string.Format(SR.Sending, i.ToString(), printJob.Copies.ToString())); if (scu.Print(printJob.Printer.AET, printJob.Printer.CalledAET, printJob.Printer.Host, printJob.Printer.Port, basicFilmSessionModuleIod, basicFilmBoxModuleIod, imageBoxPixelModuleIods) == DicomState.Success) { successSend++; } } } catch (Exception exception) { Platform.Log(LogLevel.Error, exception); } } catch (Exception exception2) { Platform.Log(LogLevel.Error, exception2); } if (successSend == 0) { return(false); } return(true); }