예제 #1
0
		private void menuForms_Click(object sender,System.EventArgs e) {
			string formName = ((MenuItem)sender).Text;
			bool copied = true;
			Document doc = null;
			try {
				doc=ImageStore.ImportForm(formName,GetCurrentCategory(),PatCur);
			}
			catch(Exception ex) {
				MessageBox.Show(ex.Message);
				copied=false;
			}
			if(copied) {
				FillDocList(false);
				SelectTreeNode(GetNodeById(MakeIdDoc(doc.DocNum)));
				FormDocInfo FormD=new FormDocInfo(PatCur,doc,GetCurrentFolderName(treeDocuments.SelectedNode));
				FormD.ShowDialog();//some of the fields might get changed, but not the filename
				if(FormD.DialogResult!=DialogResult.OK) {
					DeleteSelection(false,false);
				}
				else {
					FillDocList(true);//Refresh possible changes in the document due to FormD.
				}
			}
		}
예제 #2
0
		private void ToolBarInfo_Click() {
			ImageNodeId nodeId=(ImageNodeId)treeDocuments.SelectedNode.Tag;
			if(nodeId.NodeType==ImageNodeType.None) {
				return;
			}
			if(nodeId.NodeType==ImageNodeType.Mount) {
				FormMountEdit form=new FormMountEdit(MountSelected);
				form.ShowDialog();//Edits the MountSelected object directly and updates and changes to the database as well.
				FillDocList(true);//Refresh tree in case description for the mount changed.}
			}
			else if(nodeId.NodeType==ImageNodeType.Doc) {
				//The FormDocInfo object updates the DocSelected and stores the changes in the database as well.
				FormDocInfo formDocInfo2=new FormDocInfo(PatCur,DocSelected,GetCurrentFolderName(treeDocuments.SelectedNode));
				formDocInfo2.ShowDialog();
				if(formDocInfo2.DialogResult!=DialogResult.OK) {
					return;
				}
				FillDocList(true);
			}
		}
예제 #3
0
		private void ToolBarImport_Click() {
			if(EhrAmendmentCur!=null) {
				if(EhrAmendmentCur.FileName!=null && EhrAmendmentCur.FileName!="") {
					if(!MsgBox.Show(this,true,"This will delete your old file. Proceed?")) {
						return;
					}
				}
			}
			OpenFileDialog openFileDialog=new OpenFileDialog();
			openFileDialog.Multiselect=false;
			if(openFileDialog.ShowDialog()!=DialogResult.OK) {
				return;
			}
			string[] fileNames=openFileDialog.FileNames;
			if(fileNames.Length<1) {
				return;
			}
			ImageNodeId nodeId=new ImageNodeId();
			bool copied=true;
			if(ClaimPaymentNum!=0) {//eob
				EobAttach eob=null;
				for(int i=0;i<fileNames.Length;i++) {
					try {
						eob=ImageStore.ImportEobAttach(fileNames[i],ClaimPaymentNum);
					}
					catch(Exception ex) {
						MessageBox.Show(Lan.g(this,"Unable to copy file, May be in use: ")+ex.Message+": "+openFileDialog.FileName);
						copied = false;
					}
				}
				if(copied) {
					FillDocList(false);
				}
				if(eob!=null) {
					SelectTreeNode(GetNodeById(MakeIdEob(eob.EobAttachNum)));
				}
			}
			else if(EhrAmendmentCur!=null) {
				string amdFilename=EhrAmendmentCur.FileName;
				for(int i=0;i<fileNames.Length;i++) {
					try {
						EhrAmendmentCur=ImageStore.ImportAmdAttach(fileNames[i],EhrAmendmentCur);
						SelectTreeNode(null);
						ImageStore.CleanAmdAttach(amdFilename);
					}
					catch(Exception ex) {
						MessageBox.Show(Lan.g(this,"Unable to copy file, May be in use: ")+ex.Message+": "+openFileDialog.FileName);
						copied = false;
					}
				}
				if(copied) {
					FillDocList(false);
				}
				if(EhrAmendmentCur!=null) {
					SelectTreeNode(GetNodeById(MakeIdAmd(EhrAmendmentCur.EhrAmendmentNum)));
				}
			}
			else {//regular Images module
				Document doc=null;
				for(int i=0;i<fileNames.Length;i++) {
					try {
						doc=ImageStore.Import(fileNames[i],GetCurrentCategory(),PatCur);
					}
					catch(Exception ex) {
						MessageBox.Show(Lan.g(this,"Unable to copy file, May be in use: ")+ex.Message+": "+openFileDialog.FileName);
						copied = false;
					}
					if(copied) {
						FillDocList(false);
						SelectTreeNode(GetNodeById(MakeIdDoc(doc.DocNum)));
						FormDocInfo FormD=new FormDocInfo(PatCur,doc,GetCurrentFolderName(treeDocuments.SelectedNode));
						FormD.ShowDialog();//some of the fields might get changed, but not the filename
						if(FormD.DialogResult!=DialogResult.OK) {
							DeleteSelection(false,false);
						}
						else {
							nodeId=MakeIdDoc(doc.DocNum);
							DocSelected=doc.Copy();
						}
					}
				}
				//Reselect the last successfully added node when necessary.
				if(doc!=null && !MakeIdDoc(doc.DocNum).Equals(nodeId)) {
					SelectTreeNode(GetNodeById(MakeIdDoc(doc.DocNum)));
				}
				FillDocList(true);
			}
		}
예제 #4
0
		private void ToolBarPaste_Click() {
			IDataObject clipboard=Clipboard.GetDataObject();
			if(!clipboard.GetDataPresent(DataFormats.Bitmap)) {
				MessageBox.Show(Lan.g(this,"No bitmap present on clipboard"));
				return;
			}
			Bitmap bitmapPaste=(Bitmap)clipboard.GetData(DataFormats.Bitmap);
			Document doc;
			ImageNodeId nodeId=new ImageNodeId();
			if(treeDocuments.SelectedNode!=null && treeDocuments.SelectedNode.Tag!=null) {
				nodeId=(ImageNodeId)treeDocuments.SelectedNode.Tag;
			}
			Cursor=Cursors.WaitCursor;
			if(ClaimPaymentNum!=0) {
				EobAttach eob=null;
				try {
					eob=ImageStore.ImportEobAttach(bitmapPaste,ClaimPaymentNum);
				}
				catch {
					MessageBox.Show(Lan.g(this,"Error saving eob."));
					Cursor=Cursors.Default;
					return;
				}
				FillDocList(false);
				SelectTreeNode(GetNodeById(MakeIdEob(eob.EobAttachNum)));
			}
			else if(EhrAmendmentCur!=null) {
				EhrAmendment amd=null;
				try {
					amd=ImageStore.ImportAmdAttach(bitmapPaste,EhrAmendmentCur);
				}
				catch {
					MessageBox.Show(Lan.g(this,"Error saving amendment."));
					Cursor=Cursors.Default;
					return;
				}
				FillDocList(false);
				SelectTreeNode(GetNodeById(MakeIdAmd(amd.EhrAmendmentNum)));
			}
			else if(nodeId.NodeType==ImageNodeType.Mount && IdxSelectedInMount>=0) {//Pasting into the mount item of the currently selected mount.
				if(DocsInMount[IdxSelectedInMount]!=null) {
					if(!MsgBox.Show(this,MsgBoxButtons.YesNo,"Do you want to replace the existing item in this mount location?")) {
						this.Cursor=Cursors.Default;
						return;
					}
					DeleteSelection(false,true);
				}
				try {
					doc=ImageStore.ImportImageToMount(bitmapPaste,0,MountItemsForSelected[IdxSelectedInMount].MountItemNum,GetCurrentCategory(),PatCur);
					doc.WindowingMax=255;
					doc.WindowingMin=0;
					Documents.Update(doc);
				}
				catch {
					MessageBox.Show(Lan.g(this,"Error saving document."));
					Cursor=Cursors.Default;
					return;
				}
				DocsInMount[IdxSelectedInMount]=doc;
				ImagesCur[IdxSelectedInMount]=bitmapPaste;
			}
			else {//Paste the image as its own unique document.
				try {
					doc=ImageStore.Import(bitmapPaste,GetCurrentCategory(),ImageType.Photo,PatCur);
				}
				catch {
					MessageBox.Show(Lan.g(this,"Error saving document."));
					Cursor=Cursors.Default;
					return;
				}
				FillDocList(false);
				SelectTreeNode(GetNodeById(MakeIdDoc(doc.DocNum)));
				FormDocInfo formD=new FormDocInfo(PatCur,doc,GetCurrentFolderName(treeDocuments.SelectedNode));
				formD.ShowDialog();
				if(formD.DialogResult!=DialogResult.OK) {
					DeleteSelection(false,false);
				}
				else {
					FillDocList(true);
				}
			}
			InvalidateSettings(ImageSettingFlags.ALL,true);
			Cursor=Cursors.Default;
		}
예제 #5
0
		private void ToolBarScanMulti_Click() {
			if(EhrAmendmentCur!=null) {
				if(EhrAmendmentCur.FileName!=null && EhrAmendmentCur.FileName!="") {
					if(!MsgBox.Show(this,true,"This will delete your old file. Proceed?")) {
						return;
					}
				}
			}
			string tempFile=Path.GetTempFileName().Replace(".tmp",".pdf");
			try {
				xImageDeviceManager.Obfuscator.ActivateEZTwain();
			}
			catch {
				Cursor=Cursors.Default;
				MsgBox.Show(this,"EzTwain4.dll not found.  Please run the setup file in your images folder.");
				return;
			}
			if(ComputerPrefs.LocalComputer.ScanDocSelectSource) {
				if(!EZTwain.SelectImageSource(this.Handle)) {
					return;//User clicked cancel.
				}
			}
			//EZTwain.LogFile(7);//Writes at level 7 (very detailed) in the C:\eztwain.log text file. Useful for getting help from EZTwain support on their forum.
			EZTwain.SetHideUI(!ComputerPrefs.LocalComputer.ScanDocShowOptions);
			EZTwain.PDF_SetCompression((int)this.Handle,(int)ComputerPrefs.LocalComputer.ScanDocQuality);
			if(!EZTwain.OpenDefaultSource()) {//if it can't open the scanner successfully
				MsgBox.Show(this,"Default scanner could not be opened.  Check that the default scanner works from Windows Control Panel and from Windows Fax and Scan.");
				Cursor=Cursors.Default;
				return;
			}
			bool duplexEnabled=EZTwain.EnableDuplex(ComputerPrefs.LocalComputer.ScanDocDuplex);//This line seems to cause problems.
			if(ComputerPrefs.LocalComputer.ScanDocGrayscale) {
				EZTwain.SetPixelType(1);//8-bit grayscale
			}
			else {
				EZTwain.SetPixelType(2);//24-bit color
			}
			EZTwain.SetResolution(ComputerPrefs.LocalComputer.ScanDocResolution);
			EZTwain.AcquireMultipageFile(this.Handle,tempFile);//This is where the options dialog will come up if enabled. This will ignore and override the settings above.
			int errorCode=EZTwain.LastErrorCode();
			if(errorCode!=0) {
				string message="";
				if(errorCode==(int)EZTwainErrorCode.EZTEC_USER_CANCEL) {//19
					//message="\r\nScanning cancelled.";//do nothing
					return;
				}
				else if(errorCode==(int)EZTwainErrorCode.EZTEC_JPEG_DLL) {//22
					message="Missing dll\r\n\r\nRequired file EZJpeg.dll is missing.";
				}
				else if(errorCode==(int)EZTwainErrorCode.EZTEC_0_PAGES) {//38
					//message="\r\nScanning cancelled.";//do nothing
					return;
				}
				else if(errorCode==(int)EZTwainErrorCode.EZTEC_NO_PDF) {//43
					message="Missing dll\r\n\r\nRequired file EZPdf.dll is missing.";
				}
				else if(errorCode==(int)EZTwainErrorCode.EZTEC_DEVICE_PAPERJAM) {//76
					message="Paper jam\r\n\r\nPlease check the scanner document feeder and ensure there path is clear of any paper jams.";
				}
				else if(errorCode==(int)EZTwainErrorCode.EZTEC_DS_FAILURE) {//5
					message="Duplex failure\r\n\r\nDuplex mode without scanner options window failed. Try enabling the scanner options window or disabling duplex mode.";
				}
				else {
					message=errorCode+" "+((EZTwainErrorCode)errorCode).ToString();
				}
				MessageBox.Show(Lan.g(this,"Unable to scan. Please make sure you can scan using other software. Error: "+message));
				return;
			}
			ImageNodeId nodeId=new ImageNodeId();
			bool copied=true;
			if(ClaimPaymentNum!=0) {//eob
				EobAttach eob=null;
				try {
					eob=ImageStore.ImportEobAttach(tempFile,ClaimPaymentNum);
				}
				catch(Exception ex) {
					MessageBox.Show(Lan.g(this,"Unable to copy file, May be in use: ") + ex.Message + ": " + tempFile);
					copied = false;
				}
				if(copied) {
					FillDocList(false);
					SelectTreeNode(GetNodeById(MakeIdEob(eob.EobAttachNum)));
				}
				File.Delete(tempFile);
			}
			else if(EhrAmendmentCur!=null) {//amendment
				string fileNameOld=EhrAmendmentCur.FileName;
				try {
					ImageStore.ImportAmdAttach(tempFile,EhrAmendmentCur);
					SelectTreeNode(null);
					ImageStore.CleanAmdAttach(fileNameOld);
				}
				catch(Exception ex) {
					MessageBox.Show(Lan.g(this,"Unable to copy file, May be in use: ") + ex.Message + ": " + tempFile);
					copied = false;
				}
				if(copied) {
					FillDocList(false);
					SelectTreeNode(GetNodeById(MakeIdAmd(EhrAmendmentCur.EhrAmendmentNum)));
				}
				File.Delete(tempFile);
			}
			else {//regular Images module
				Document doc=null;
				try {
					doc=ImageStore.Import(tempFile,GetCurrentCategory(),PatCur);
				}
				catch(Exception ex) {
					MessageBox.Show(Lan.g(this,"Unable to copy file, May be in use: ") + ex.Message + ": " + tempFile);
					copied = false;
				}
				if(copied) {
					FillDocList(false);
					SelectTreeNode(GetNodeById(MakeIdDoc(doc.DocNum)));
					FormDocInfo FormD=new FormDocInfo(PatCur,doc,GetCurrentFolderName(treeDocuments.SelectedNode));
					FormD.ShowDialog();//some of the fields might get changed, but not the filename 
					if(FormD.DialogResult!=DialogResult.OK) {
						DeleteSelection(false,false);
					}
					else {
						nodeId=MakeIdDoc(doc.DocNum);
						DocSelected=doc.Copy();
					}
				}
				File.Delete(tempFile);
				//Reselect the last successfully added node when necessary. js This code seems to be copied from import multi.  Simplify it.
				if(doc!=null && !MakeIdDoc(doc.DocNum).Equals(nodeId)) {
					SelectTreeNode(GetNodeById(MakeIdDoc(doc.DocNum)));
				}
				FillDocList(true);
			}
		}
예제 #6
0
		///<summary>Valid values for scanType are "doc","xray",and "photo"</summary>
		private void ToolBarScan_Click(string scanType) {
			if(EhrAmendmentCur!=null) {
				if(EhrAmendmentCur.FileName!=null && EhrAmendmentCur.FileName!="") {
					if(!MsgBox.Show(this,true,"This will delete your old file. Proceed?")) {
						return;
					}
				}
			}
			Cursor=Cursors.WaitCursor;
			Bitmap bitmapScanned=null;
			IntPtr hdib=IntPtr.Zero;
			try {
				xImageDeviceManager.Obfuscator.ActivateEZTwain();
			}
			catch {
				Cursor=Cursors.Default;
				MsgBox.Show(this,"EzTwain4.dll not found.  Please run the setup file in your images folder.");
				return;
			}
			if(ComputerPrefs.LocalComputer.ScanDocSelectSource) {
				if(!EZTwain.SelectImageSource(this.Handle)) {//dialog to select source
					Cursor=Cursors.Default;
					return;//User clicked cancel.
				}
			}
			EZTwain.SetHideUI(!ComputerPrefs.LocalComputer.ScanDocShowOptions);
			if(!EZTwain.OpenDefaultSource()) {//if it can't open the scanner successfully
				Cursor=Cursors.Default;
				MsgBox.Show(this,"Default scanner could not be opened.  Check that the default scanner works from Windows Control Panel and from Windows Fax and Scan.");
				return;
			}
			EZTwain.SetResolution(ComputerPrefs.LocalComputer.ScanDocResolution);
			if(ComputerPrefs.LocalComputer.ScanDocGrayscale) {
				EZTwain.SetPixelType(1);//8-bit grayscale - only set if scanner dialog will not show
			}
			else {
				EZTwain.SetPixelType(2);//24-bit color
			}
			EZTwain.SetJpegQuality(ComputerPrefs.LocalComputer.ScanDocQuality);
			EZTwain.SetXferMech(EZTwain.XFERMECH_MEMORY);
			Cursor=Cursors.Default;
			hdib=EZTwain.Acquire(this.Handle);//This is where the options dialog would come up. The settings above will not populate this window.
			int errorCode=EZTwain.LastErrorCode();
			if(errorCode!=0) {
				string message="";
				if(errorCode==(int)EZTwainErrorCode.EZTEC_USER_CANCEL) {//19
					//message="\r\nScanning cancelled.";//do nothing
					return;
				}
				else if(errorCode==(int)EZTwainErrorCode.EZTEC_JPEG_DLL) {//22
					message="Missing dll\r\n\r\nRequired file EZJpeg.dll is missing.";
				}
				else if(errorCode==(int)EZTwainErrorCode.EZTEC_0_PAGES) {//38
					//message="\r\nScanning cancelled.";//do nothing
					return;
				}
				else if(errorCode==(int)EZTwainErrorCode.EZTEC_NO_PDF) {//43
					message="Missing dll\r\n\r\nRequired file EZPdf.dll is missing.";
				}
				else if(errorCode==(int)EZTwainErrorCode.EZTEC_DEVICE_PAPERJAM) {//76
					message="Paper jam\r\n\r\nPlease check the scanner document feeder and ensure there path is clear of any paper jams.";
				}
				else {
					message=errorCode+" "+((EZTwainErrorCode)errorCode).ToString();
				}
				MessageBox.Show(Lan.g(this,"Unable to scan. Please make sure you can scan using other software. Error: "+message));
				return;
			}
			if(hdib==(IntPtr)0) {//This is down here because there might also be an informative error code that we would like to use above.
				return;//User cancelled
			}
			double xdpi=EZTwain.DIB_XResolution(hdib);
			double ydpi=EZTwain.DIB_XResolution(hdib);
			IntPtr hbitmap=EZTwain.DIB_ToDibSection(hdib);
			bitmapScanned=Bitmap.FromHbitmap(hbitmap);
			bitmapScanned.SetResolution((float)xdpi,(float)ydpi);
			try {
				Clipboard.SetImage(bitmapScanned);//We do this because a customer requested it, and some customers probably use it.
			}
			catch {
				//Rarely, setting the clipboard image fails, in which case we should ignore the failure because most people do not use this feature.
			}
			ImageType imgType;
			if(scanType=="xray") {
				imgType=ImageType.Radiograph;
			}
			else if(scanType=="photo") {
				imgType=ImageType.Photo;
			}
			else {//Assume document
				imgType=ImageType.Document;
			}
			bool saved=true;
			if(ClaimPaymentNum!=0) {//eob
				EobAttach eob=null;
				try {
					eob=ImageStore.ImportEobAttach(bitmapScanned,ClaimPaymentNum);
				}
				catch(Exception ex) {
					saved=false;
					Cursor=Cursors.Default;
					MessageBox.Show(Lan.g(this,"Error saving eob")+": "+ex.Message);
				}
				if(bitmapScanned!=null) {
					bitmapScanned.Dispose();
					bitmapScanned=null;
				}
				if(hdib!=IntPtr.Zero) {
					EZTwain.DIB_Free(hdib);
				}
				Cursor=Cursors.Default;
				if(saved) {
					FillDocList(false);
					SelectTreeNode(GetNodeById(MakeIdEob(eob.EobAttachNum)));
				}
			}
			else if(EhrAmendmentCur!=null) {
				//We only allow users to scan in one amendment at a time.  Keep track of the old file name.
				string fileNameOld=EhrAmendmentCur.FileName;
				try {
					ImageStore.ImportAmdAttach(bitmapScanned,EhrAmendmentCur);
					SelectTreeNode(null);
					ImageStore.CleanAmdAttach(fileNameOld);//Delete the old scanned document.
				}
				catch(Exception ex) {
					saved=false;
					Cursor=Cursors.Default;
					MessageBox.Show(Lan.g(this,"Error saving amendment")+": "+ex.Message);
				}
				if(bitmapScanned!=null) {
					bitmapScanned.Dispose();
					bitmapScanned=null;
				}
				if(hdib!=IntPtr.Zero) {
					EZTwain.DIB_Free(hdib);
				}
				Cursor=Cursors.Default;
				if(saved) {
					FillDocList(false);
					SelectTreeNode(GetNodeById(MakeIdAmd(EhrAmendmentCur.EhrAmendmentNum)));
				}
			}
			else {//regular Images module
				Document doc = null;
				try {//Create corresponding image file.
					doc=ImageStore.Import(bitmapScanned,GetCurrentCategory(),imgType,PatCur);
				}
				catch(Exception ex) {
					saved=false;
					Cursor=Cursors.Default;
					MessageBox.Show(Lan.g(this,"Unable to save document")+": "+ex.Message);
				}
				if(bitmapScanned!=null) {
					bitmapScanned.Dispose();
					bitmapScanned=null;
				}
				if(hdib!=IntPtr.Zero) {
					EZTwain.DIB_Free(hdib);
				}
				Cursor=Cursors.Default;
				if(saved) {
					FillDocList(false);//Reload and keep new document selected.
					SelectTreeNode(GetNodeById(MakeIdDoc(doc.DocNum)));
					FormDocInfo formDocInfo=new FormDocInfo(PatCur,DocSelected,GetCurrentFolderName(treeDocuments.SelectedNode));
					formDocInfo.ShowDialog();
					if(formDocInfo.DialogResult!=DialogResult.OK) {
						DeleteSelection(false,false);
					}
					else {
						FillDocList(true);//Update tree, in case the new document's icon or category were modified in formDocInfo.
					}
				}
			}
		}
예제 #7
0
파일: ContrImages.cs 프로젝트: mnisl/OD
		private void treeDocuments_DragDrop(object sender,DragEventArgs e) {
			TreeNode nodeOver=treeDocuments.GetNodeAt(treeDocuments.PointToClient(Cursor.Position));
			if(nodeOver==null) {
				return;
			}
			ImageNodeId nodeOverId=(ImageNodeId)nodeOver.Tag;
			long nodeOverCategoryDefNum=0;
			if(nodeOverId.NodeType==ImageNodeType.Category) {
				nodeOverCategoryDefNum=DefC.Short[(int)DefCat.ImageCats][nodeOver.Index].DefNum;
			}
			else {
				nodeOverCategoryDefNum=DefC.Short[(int)DefCat.ImageCats][nodeOver.Parent.Index].DefNum;
			}
			Document docSave=new Document();
			ImageNodeId nodeId=new ImageNodeId();
			string[] arrayFiles = (string[])e.Data.GetData(DataFormats.FileDrop);
			string errorMessage="";
			for(int i=0;i<arrayFiles.Length;i++) {
				string draggedFilePath=arrayFiles[i];
				string fileName=draggedFilePath.Substring(draggedFilePath.LastIndexOf("\\")+1);
				if(Directory.Exists(draggedFilePath)) {
					errorMessage+="\r\n"+fileName;
					continue;
				}
				docSave=ImageStore.Import(draggedFilePath,nodeOverCategoryDefNum,PatCur);
				FillDocList(false);
				SelectTreeNode(GetNodeById(MakeIdDoc(docSave.DocNum)));
				FormDocInfo FormD=new FormDocInfo(PatCur,docSave,GetCurrentFolderName(treeDocuments.SelectedNode));
				FormD.ShowDialog();//some of the fields might get changed, but not the filename
				if(FormD.DialogResult!=DialogResult.OK) {
					DeleteSelection(false,false);
				}
				else {
					nodeId=MakeIdDoc(docSave.DocNum);
					DocSelected=docSave.Copy();
				}
			}
			if(docSave!=null && !MakeIdDoc(docSave.DocNum).Equals(nodeId)) {
				SelectTreeNode(GetNodeById(MakeIdDoc(docSave.DocNum)));
			}
			FillDocList(true);
			if(errorMessage!="") {
				MessageBox.Show(Lan.g(this,"The following items are directories and were not copied into the images folder for this patient.")+errorMessage);
			}
		}
예제 #8
0
 ///<summary>Valid values for scanType are "doc","xray",and "photo"</summary>
 private void ToolBarScan_Click(string scanType)
 {
     Cursor=Cursors.WaitCursor;
     Bitmap bitmapScanned=null;
     IntPtr hdib=IntPtr.Zero;
     //Try catch here prevents a crash when a customer who has no scanner installed tries to scan.
     try {
         //A user may have more than one scanning device.
         //The code below will allow the user to select one.
         xImageDeviceManager.Obfuscator.ActivateEZTwain();
         bool wPIXTypes=EZTwain.SelectImageSource(this.Handle);
         if(!wPIXTypes) {//user clicked Cancel
             return;
         }
         EZTwain.SetHideUI(false);
         if(!EZTwain.OpenDefaultSource()) {//if it can't open the scanner successfully
             Cursor=Cursors.Default;
             MsgBox.Show(this,"Default scanner could not be opened.  Check that the default scanner works from Windows Control Panel and from Windows Fax and Scan.");
             return;
         }
         hdib=EZTwain.AcquireMemory(this.Handle);
         double xdpi=EZTwain.DIB_XResolution(hdib);
         double ydpi=EZTwain.DIB_XResolution(hdib);
         IntPtr hbitmap=EZTwain.DIB_ToDibSection(hdib);
         bitmapScanned=Bitmap.FromHbitmap(hbitmap);
         bitmapScanned.SetResolution((float)xdpi,(float)ydpi);
         Clipboard.SetImage(bitmapScanned);//why do we do this?
     }
     catch(Exception ex) {
         Cursor=Cursors.Default;
         MessageBox.Show("The image could not be acquired from the scanner. "+
             "Please check to see that the scanner is properly connected to the computer. Specific error: "+ex.Message);
         return;
     }
     ImageType imgType;
     if(scanType=="xray") {
         imgType=ImageType.Radiograph;
     }
     else if(scanType=="photo") {
         imgType=ImageType.Photo;
     }
     else {//Assume document
         imgType=ImageType.Document;
     }
     bool saved=true;
     if(ClaimPaymentNum!=0){//eob
         EobAttach eob=null;
         try {
             eob=ImageStore.ImportEobAttach(bitmapScanned,ClaimPaymentNum);
         }
         catch(Exception ex){
             saved=false;
             Cursor=Cursors.Default;
             MessageBox.Show(Lan.g(this,"Error saving eob")+": "+ex.Message);
         }
         if(bitmapScanned!=null) {
             bitmapScanned.Dispose();
             bitmapScanned=null;
         }
         if(hdib!=IntPtr.Zero) {
             EZTwain.DIB_Free(hdib);
         }
         Cursor=Cursors.Default;
         if(saved) {
             FillDocList(false);
             SelectTreeNode(GetNodeById(MakeIdEob(eob.EobAttachNum)));
         }
     }
     else{//regular Images module
         Document doc = null;
         try {//Create corresponding image file.
             doc=ImageStore.Import(bitmapScanned,GetCurrentCategory(),imgType,PatCur);
         }
         catch(Exception ex) {
             saved=false;
             Cursor=Cursors.Default;
             MessageBox.Show(Lan.g(this,"Unable to save document")+": "+ex.Message);
         }
         if(bitmapScanned!=null) {
             bitmapScanned.Dispose();
             bitmapScanned=null;
         }
         if(hdib!=IntPtr.Zero) {
             EZTwain.DIB_Free(hdib);
         }
         Cursor=Cursors.Default;
         if(saved) {
             FillDocList(false);//Reload and keep new document selected.
             SelectTreeNode(GetNodeById(MakeIdDoc(doc.DocNum)));
             FormDocInfo formDocInfo=new FormDocInfo(PatCur,DocSelected,GetCurrentFolderName(treeDocuments.SelectedNode));
             formDocInfo.ShowDialog();
             if(formDocInfo.DialogResult!=DialogResult.OK) {
                 DeleteSelection(false,false);
             }
             else {
                 FillDocList(true);//Update tree, in case the new document's icon or category were modified in formDocInfo.
             }
         }
     }
 }
예제 #9
0
 private void ToolBarScanMulti_Click()
 {
     string tempFile=Path.GetTempFileName().Replace(".tmp", ".pdf");
     xImageDeviceManager.Obfuscator.ActivateEZTwain();
     if(!PrefC.GetBool(PrefName.ScannerSuppressDialog)) {
         EZTwain.SelectImageSource(this.Handle);
     }
     EZTwain.SetHideUI(PrefC.GetBool(PrefName.ScannerSuppressDialog));//if true, this will not bring up the scanner interface for the selected scanner a few lines down
     EZTwain.SetJpegQuality((int)PrefC.GetLong(PrefName.ScannerCompression));
     if(EZTwain.OpenDefaultSource()) {//if it opens the scanner successfully
         EZTwain.SetPixelType(2);//24-bit Color
         EZTwain.SetResolution((int)PrefC.GetLong(PrefName.ScannerResolution));
         EZTwain.AcquireMultipageFile(this.Handle,tempFile);
     }
     else {
         MsgBox.Show(this,"Default scanner could not be opened.  Check that the default scanner works from Windows Control Panel and from Windows Fax and Scan.");
         return;
     }
     int errorCode=EZTwain.LastErrorCode();
     if(errorCode!=0) {
         string message="";
         if(errorCode==(int)EZTwainErrorCode.EZTEC_USER_CANCEL) {//19
             //message="\r\nScanning cancelled.";//do nothing
             return;
         }
         else if(errorCode==(int)EZTwainErrorCode.EZTEC_JPEG_DLL) {//22
             message="\r\nRequired file EZJpeg.dll is missing.";
         }
         else if(errorCode==(int)EZTwainErrorCode.EZTEC_0_PAGES) {//38
             //message="\r\nScanning cancelled.";//do nothing
             return;
         }
         else if(errorCode==(int)EZTwainErrorCode.EZTEC_NO_PDF) {//43
             message="\r\nRequired file EZPdf.dll is missing.";
         }
         else if(errorCode==(int)EZTwainErrorCode.EZTEC_DEVICE_PAPERJAM) {//76
             message="\r\nPaper jam.";
         }
         MessageBox.Show(Lan.g(this,"Unable to scan. Please make sure you can scan using other software. Error code: ")+errorCode+" "+((EZTwainErrorCode)errorCode).ToString()+"\r\n"+message);
         return;
     }
     ImageNodeId nodeId=new ImageNodeId();
     bool copied=true;
     if(ClaimPaymentNum!=0){//eob
         EobAttach eob=null;
         try {
             eob=ImageStore.ImportEobAttach(tempFile,ClaimPaymentNum);
         }
         catch(Exception ex) {
             MessageBox.Show(Lan.g(this, "Unable to copy file, May be in use: ") + ex.Message + ": " + tempFile);
             copied = false;
         }
         if(copied) {
             FillDocList(false);
             SelectTreeNode(GetNodeById(MakeIdEob(eob.EobAttachNum)));
         }
         File.Delete(tempFile);
     }
     else{//regular Images module
         Document doc=null;
         try {
             doc=ImageStore.Import(tempFile, GetCurrentCategory(),PatCur);
         }
         catch(Exception ex) {
             MessageBox.Show(Lan.g(this, "Unable to copy file, May be in use: ") + ex.Message + ": " + tempFile);
             copied = false;
         }
         if(copied){
             FillDocList(false);
             SelectTreeNode(GetNodeById(MakeIdDoc(doc.DocNum)));
             FormDocInfo FormD=new FormDocInfo(PatCur,doc,GetCurrentFolderName(treeDocuments.SelectedNode));
             FormD.ShowDialog();//some of the fields might get changed, but not the filename
             if(FormD.DialogResult!=DialogResult.OK){
                 DeleteSelection(false,false);
             }
             else{
                 nodeId=MakeIdDoc(doc.DocNum);
                 DocSelected=doc.Copy();
             }
         }
         File.Delete(tempFile);
         //Reselect the last successfully added node when necessary. js This code seems to be copied from import multi.  Simplify it.
         if(doc!=null && !MakeIdDoc(doc.DocNum).Equals(nodeId)) {
             SelectTreeNode(GetNodeById(MakeIdDoc(doc.DocNum)));
         }
         FillDocList(true);
     }
 }