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; }
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); } }
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); } }
///<summary></summary> private ImageNodeId MakeIdAmd(long ehrAmendmentNum) { ImageNodeId nodeId=new ImageNodeId(); nodeId.NodeType=ImageNodeType.Amd; nodeId.PriKey=ehrAmendmentNum; return nodeId; }
/// <summary>Refreshes list from db, then fills the treeview. Set keepSelection to true in order to keep the current selection active.</summary> private void FillDocList(bool keepSelection) { ImageNodeId nodeIdSelection=new ImageNodeId(); if(keepSelection && treeDocuments.SelectedNode!=null) { nodeIdSelection=(ImageNodeId)treeDocuments.SelectedNode.Tag; } //(keepSelection?GetNodeIdentifier(treeDocuments.SelectedNode):""); //Clear current tree contents. treeDocuments.SelectedNode=null; treeDocuments.Nodes.Clear(); if(ClaimPaymentNum!=0) { List<EobAttach> listEobs=EobAttaches.Refresh(ClaimPaymentNum); for(int i=0;i<listEobs.Count;i++) { TreeNode node=new TreeNode(listEobs[i].FileName); node.Tag=MakeIdEob(listEobs[i].EobAttachNum); node.ImageIndex=2; node.SelectedImageIndex=node.ImageIndex;//redundant? treeDocuments.Nodes.Add(node); if(((ImageNodeId)node.Tag).Equals(nodeIdSelection)) { SelectTreeNode(node); } } return; } else if(EhrAmendmentCur!=null) { if(EhrAmendmentCur.FileName!=null && EhrAmendmentCur.FileName!="") { TreeNode node=new TreeNode(EhrAmendmentCur.FileName); node.Tag=MakeIdAmd(EhrAmendmentCur.EhrAmendmentNum); node.ImageIndex=2; node.SelectedImageIndex=node.ImageIndex;//redundant? treeDocuments.Nodes.Add(node); if(((ImageNodeId)node.Tag).Equals(nodeIdSelection)) { SelectTreeNode(node); } } return; } //the rest of this is for normal images module------------------------------------------------------------------------------------------------- if(PatCur==null) { return; } //Add all predefined folder names to the tree. for(int i=0;i<DefC.Short[(int)DefCat.ImageCats].Length;i++) { treeDocuments.Nodes.Add(new TreeNode(DefC.Short[(int)DefCat.ImageCats][i].ItemName)); treeDocuments.Nodes[i].Tag=MakeIdDef(DefC.Short[(int)DefCat.ImageCats][i].DefNum); treeDocuments.Nodes[i].SelectedImageIndex=1; treeDocuments.Nodes[i].ImageIndex=1; } //Add all relevant documents and mounts as stored in the database to the tree for the current patient. DataSet ds=Documents.RefreshForPatient(new string[] { PatCur.PatNum.ToString() }); DataRowCollection rows=ds.Tables["DocumentList"].Rows; for(int i=0;i<rows.Count;i++) { TreeNode node=new TreeNode(rows[i]["description"].ToString()); int parentFolder=PIn.Int(rows[i]["docFolder"].ToString()); treeDocuments.Nodes[parentFolder].Nodes.Add(node); if(rows[i]["DocNum"].ToString()=="0") {//must be a mount node.Tag=MakeIdMount(PIn.Long(rows[i]["MountNum"].ToString())); } else {//doc node.Tag=MakeIdDoc(PIn.Long(rows[i]["DocNum"].ToString())); } node.ImageIndex=2+Convert.ToInt32(rows[i]["ImgType"].ToString()); node.SelectedImageIndex=node.ImageIndex; if(((ImageNodeId)node.Tag).Equals(nodeIdSelection)) { SelectTreeNode(node); } } if(PrefC.GetBool(PrefName.ImagesModuleTreeIsCollapsed)) { TreeNode selectedNode=treeDocuments.SelectedNode;//Save the selection so we can reselect after collapsing. treeDocuments.CollapseAll();//Invalidates tree and clears selection too. treeDocuments.SelectedNode=selectedNode;//This will expand any category/folder nodes necessary to show the selection. if(PatNumPrev==PatCur.PatNum) {//Maintain previously expanded nodes when patient not changed. for(int i=0;i<ExpandedCats.Count;i++) { for(int j=0;j<treeDocuments.Nodes.Count;j++) { if(ExpandedCats[i]==((ImageNodeId)treeDocuments.Nodes[j].Tag).PriKey) { treeDocuments.Nodes[j].Expand(); break; } } } } else {//Patient changed. ExpandedCats.Clear(); } PatNumPrev=PatCur.PatNum; } else { treeDocuments.ExpandAll();//Invalidates tree too. } }
private void TreeDocuments_MouseLeave(object sender,EventArgs e) { treeDocuments.Cursor=Cursors.Default; NodeIdentifierDown=new ImageNodeId(); }
///<summary>Mouse selections were chosen to be implemented in this particular way, just to make the same code work the same way under both Windows and MONO.</summary> private void TreeDocuments_MouseDown(object sender,MouseEventArgs e) { TreeNode node=treeDocuments.GetNodeAt(e.Location); if(node==null){ NodeIdentifierDown=new ImageNodeId(); return; } NodeIdentifierDown=(ImageNodeId)node.Tag; //Always select the node on a mouse-down press for either right or left buttons. //If the left button is pressed, then the document is either being selected or dragged, so //setting the image at the beginning of the drag will either display the image as expected, or //automatically display the image while the document is being dragged (since it is in a different thread). //If the right button is pressed, then the user wants to view the properties of the image they are //clicking on, so displaying the image (in a different thread) will give the user a chance to view //the image corresponding to a delete, info display, etc... SelectTreeNode(node); //Remember that a new selection has begun, so that if the document is being dragged, the appropriate delay time can be used. TimeMouseMoved=new DateTime(1,1,1); }
///<summary></summary> private ImageNodeId MakeIdDoc(long docNum) { ImageNodeId nodeId=new ImageNodeId(); nodeId.NodeType=ImageNodeType.Doc; nodeId.PriKey=docNum; return nodeId; //return docNum+"*"+mountNum; }
///<summary></summary> private ImageNodeId MakeIdMount(long mountNum) { ImageNodeId nodeId=new ImageNodeId(); nodeId.NodeType=ImageNodeType.Mount; nodeId.PriKey=mountNum; return nodeId; }
///<summary>Returns the current tree node with the given node id.</summary> private TreeNode GetNodeById(ImageNodeId nodeId) { return GetNodeById(nodeId,treeDocuments.Nodes);//This defines the root node. }
///<summary>Searches the current object tree for a row which has the given unique document number. This will work for a tree with any number of nested folders, as long as tags are defined only for items which correspond to data rows.</summary> private TreeNode GetNodeById(ImageNodeId nodeId,TreeNodeCollection rootNodes) { if(rootNodes==null) { return null; } foreach(TreeNode node in rootNodes) { if(node==null) { continue; } if(((ImageNodeId)node.Tag).Equals(nodeId)) { return node; } //Check the child nodes. TreeNode child=GetNodeById(nodeId,node.Nodes); if(child!=null) { return child; } } return null; }
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); } }
///<summary></summary> private void TreeDocuments_MouseUp(object sender,System.Windows.Forms.MouseEventArgs e) { treeDocuments.Cursor=Cursors.Default; if(NodeIdentifierDown.NodeType==ImageNodeType.None) { return; } if(e.Button!=MouseButtons.Left) { return;//Dragging can only happen with the left mouse button. } if(TimeMouseMoved.Year==1) {//No valid mouse movements occurred after the mouse down event and before the mouse up event. //If the user moused down, then immediately moused up or moved slightly then moused up on the original source node before moving elsewhere. return;//Do not move the document. //This fixed a bug where users were able to accidentally move images while they were loading. The user would mouse down, then mouse up //(to select the image), then start moving the mouse to do something else and the image would unexpectedly move to another image category. //NOTE: For some reason, if the user tries to move an image while it is loading, then the move action will be ignored, because the //mouse events fire out of order (mouse down, then mouse up, then mouse move). However, this seems like a minor issue, because //users typically intuitively know that certain commands are ignored while loading is in progress. If this situation occurs to a user, //they will probably know that they need to try again. The second time they try to move the image it will move, because once the image //is loaded, clicking on the image will not cause it to reload. Also, the move will work the first time if the mouse up event happens //after loading is completed. Therefore, this minor issue can only happen on very slow computers or very large images. //To fix the minor issue in the future, we might consider somehow forcing the mouse events to fire in order, even when images are loading. } //TimeSpan timeSpanDrag=(TimeSpan)(DateTime.Now-TimeMouseMoved); //if(timeSpanDrag.Milliseconds < 200) { //js 3/31/2012. Was 250 // return;//Too short of a drag and drop. Probably human error //} TreeNode nodeOver=treeDocuments.GetNodeAt(e.Location); 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; } TreeNode nodeOriginal=GetNodeById(NodeIdentifierDown); long nodeOriginalCategoryDefNum=0; if(NodeIdentifierDown.NodeType==ImageNodeType.Category) { nodeOriginalCategoryDefNum=DefC.Short[(int)DefCat.ImageCats][nodeOriginal.Index].DefNum; } else { nodeOriginalCategoryDefNum=DefC.Short[(int)DefCat.ImageCats][nodeOriginal.Parent.Index].DefNum; } if(nodeOverCategoryDefNum==nodeOriginalCategoryDefNum) { return;//category hasn't changed } if(NodeIdentifierDown.NodeType==ImageNodeType.Mount) { Mount mount=Mounts.GetByNum(NodeIdentifierDown.PriKey); string mountSourceCat=DefC.GetDef(DefCat.ImageCats,mount.DocCategory).ItemName; string mountDestCat=DefC.GetDef(DefCat.ImageCats,nodeOverCategoryDefNum).ItemName; mount.DocCategory=nodeOverCategoryDefNum; SecurityLogs.MakeLogEntry(Permissions.ImageEdit,mount.PatNum,Lan.g(this,"Mount moved from")+" "+mountSourceCat+" "+Lan.g(this,"to")+" "+mountDestCat,mount.MountNum); Mounts.Update(mount); } else if(NodeIdentifierDown.NodeType==ImageNodeType.Doc) { Document doc=Documents.GetByNum(NodeIdentifierDown.PriKey); string docSourceCat=DefC.GetDef(DefCat.ImageCats,doc.DocCategory).ItemName; string docDestCat=DefC.GetDef(DefCat.ImageCats,nodeOverCategoryDefNum).ItemName; doc.DocCategory=nodeOverCategoryDefNum; string logText=Lan.g(this,"Document moved")+": "+doc.FileName; if(doc.Description!="") { string docDescript=doc.Description; if(docDescript.Length>50) { docDescript=docDescript.Substring(0,50); } logText+=" "+Lan.g(this,"with description")+" "+docDescript; } logText+=" "+Lan.g(this,"from category")+" "+docSourceCat+" "+Lan.g(this,"to category")+" "+docDestCat; SecurityLogs.MakeLogEntry(Permissions.ImageEdit,doc.PatNum,logText,doc.DocNum); Documents.Update(doc); } FillDocList(true); NodeIdentifierDown=new ImageNodeId(); }
///<summary>Mouse selections were chosen to be implemented in this particular way, just to make the same code work the same way under both Windows and MONO.</summary> private void TreeDocuments_MouseUp(object sender,System.Windows.Forms.MouseEventArgs e) { if(NodeIdentifierDown.NodeType==ImageNodeType.None){ return; } TreeNode node=treeDocuments.GetNodeAt(e.Location); TreeNode sourceNode=GetNodeById(NodeIdentifierDown); TimeSpan timeSpanDrag=(TimeSpan)(DateTime.Now-TimeMouseMoved); //Dragging a document? if(e.Button==MouseButtons.Left//Dragging can only happen with the left mouse button. && GetCurrentFolderName(node)!=GetCurrentFolderName(GetNodeById(NodeIdentifierDown)) //Only necessary if the document in question has changed categories. && timeSpanDrag.Milliseconds>250) //Only takes effect if it happens over a period of time longer than .25 seconds. { treeDocuments.Cursor=Cursors.Default; //Find the destination folder. long destinationCategory; if(node.Parent!=null) { destinationCategory=DefC.Short[(int)DefCat.ImageCats][node.Parent.Index].DefNum; } else { destinationCategory=DefC.Short[(int)DefCat.ImageCats][node.Index].DefNum; } //Update the object's document category in the database. ImageNodeId nodeId=(ImageNodeId)treeDocuments.SelectedNode.Tag; ImageNodeId nodeIdNew=new ImageNodeId(); if(nodeId.NodeType==ImageNodeType.Mount) { Mount mount=Mounts.GetByNum(nodeId.PriKey); mount.DocCategory=destinationCategory; Mounts.Update(mount); nodeIdNew=MakeIdMount(mount.MountNum); } else if(nodeId.NodeType==ImageNodeType.Doc){ Document doc=Documents.GetByNum(nodeId.PriKey); doc.DocCategory=destinationCategory; Documents.Update(doc); nodeIdNew=MakeIdDoc(doc.DocNum); } FillDocList(true); NodeIdentifierDown=nodeIdNew; } }
///<summary></summary> private void TreeDocuments_MouseDown(object sender,MouseEventArgs e) { NodeIdentifierDown=new ImageNodeId(); TreeNode nodeOver=treeDocuments.GetNodeAt(e.Location); if(nodeOver==null) { return; } ImageNodeId nodeIdDown=(ImageNodeId)nodeOver.Tag; if(nodeIdDown.NodeType==ImageNodeType.Doc || nodeIdDown.NodeType==ImageNodeType.Mount) { //These are the only types that can be dragged. NodeIdentifierDown=nodeIdDown; TimeMouseMoved=new DateTime(1,1,1);//For time delay. This will be set the moment the mouse actually starts moving } //Always select the node on a mouse-down press for either right or left buttons. //If the left button is pressed, then the document is either being selected or dragged, so //setting the image at the beginning of the drag will either display the image as expected, or //automatically display the image while the document is being dragged (since it is in a different thread). //If the right button is pressed, then the user wants to view the properties of the image they are //clicking on, so displaying the image (in a different thread) will give the user a chance to view //the image corresponding to a delete, info display, etc... SelectTreeNode(nodeOver); }
///<summary></summary> private ImageNodeId MakeIdDef(long defNum) { ImageNodeId nodeId=new ImageNodeId(); nodeId.NodeType=ImageNodeType.Category; nodeId.PriKey=defNum; return nodeId; }
///<summary></summary> private void TreeDocuments_MouseUp(object sender,System.Windows.Forms.MouseEventArgs e) { treeDocuments.Cursor=Cursors.Default; if(NodeIdentifierDown.NodeType==ImageNodeType.None) { return; } if(e.Button!=MouseButtons.Left) { return;//Dragging can only happen with the left mouse button. } TimeSpan timeSpanDrag=(TimeSpan)(DateTime.Now-TimeMouseMoved); //if(timeSpanDrag.Milliseconds < 200) { //js 3/31/2012. Was 250 // return;//Too short of a drag and drop. Probably human error //} TreeNode nodeOver=treeDocuments.GetNodeAt(e.Location); 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; } TreeNode nodeOriginal=GetNodeById(NodeIdentifierDown); long nodeOriginalCategoryDefNum=0; if(NodeIdentifierDown.NodeType==ImageNodeType.Category) { nodeOriginalCategoryDefNum=DefC.Short[(int)DefCat.ImageCats][nodeOriginal.Index].DefNum; } else { nodeOriginalCategoryDefNum=DefC.Short[(int)DefCat.ImageCats][nodeOriginal.Parent.Index].DefNum; } if(nodeOverCategoryDefNum==nodeOriginalCategoryDefNum) { return;//category hasn't changed } if(NodeIdentifierDown.NodeType==ImageNodeType.Mount) { Mount mount=Mounts.GetByNum(NodeIdentifierDown.PriKey); mount.DocCategory=nodeOverCategoryDefNum; Mounts.Update(mount); } else if(NodeIdentifierDown.NodeType==ImageNodeType.Doc) { Document doc=Documents.GetByNum(NodeIdentifierDown.PriKey); doc.DocCategory=nodeOverCategoryDefNum; Documents.Update(doc); } FillDocList(true); NodeIdentifierDown=new ImageNodeId(); }
///<summary></summary> private ImageNodeId MakeIdEob(long eobAttachNum) { ImageNodeId nodeId=new ImageNodeId(); nodeId.NodeType=ImageNodeType.Eob; nodeId.PriKey=eobAttachNum; return nodeId; }
///<summary>Selection doesn't only happen by the tree and mouse clicks, but can also happen by automatic processes, such as image import, image paste, etc...</summary> private void SelectTreeNode(TreeNode node) { //Select the node always, but perform additional tasks when necessary (i.e. load an image, or mount). treeDocuments.SelectedNode=node; treeDocuments.Invalidate(); //Clear the copy document number for mount item swapping whenever a new mount is potentially selected. IdxDocToCopy=-1; //We only perform a load if the new selection is different than the old selection. ImageNodeId nodeId=new ImageNodeId(); if(node!=null) { nodeId=(ImageNodeId)node.Tag; } if(nodeId.Equals(NodeIdentifierOld)) { return; } pictureBoxMain.Visible=true; if(axAcroPDF1!=null) { axAcroPDF1.Dispose();//Clear any previously loaded Acrobat .pdf file. } DocSelected=new Document(); NodeIdentifierOld=nodeId; //Disable all item tools until the currently selected node is loaded properly in the picture box. EnableAllTreeItemTools(false); if(ToolBarPaint.Buttons["Hand"]!=null) { ToolBarPaint.Buttons["Hand"].Pushed=true; } if(ToolBarPaint.Buttons["Crop"]!=null) { ToolBarPaint.Buttons["Crop"].Pushed=false; } //Stop any current image processing. This will avoid having the ImageRenderingNow set to a valid image after //the current image has been erased. This will also avoid concurrent access to the the currently loaded images by //the main and worker threads. EraseCurrentImages(); if(nodeId.NodeType==ImageNodeType.Category) { //A folder was selected (or unselection, but I am not sure unselection would be possible here). //The panel note control is made invisible to start and then made visible for the appropriate documents. This //line prevents the possibility of showing a signature box after selecting a folder node. panelNote.Visible=false; //Make sure the controls are sized properly in the image module since the visibility of the panel note might //have just changed. ResizeAll(); } else if(nodeId.NodeType==ImageNodeType.Eob) { EobAttach eob=EobAttaches.GetOne(nodeId.PriKey); ImagesCur=ImageStore.OpenImagesEob(eob); if(ImagesCur[0]==null) { if(ImageHelper.HasImageExtension(eob.FileName)) { MessageBox.Show(Lan.g(this,"File not found: ") + eob.FileName); } else if(Path.GetExtension(eob.FileName).ToLower()==".pdf") {//Adobe acrobat file. try { axAcroPDF1=new AxAcroPDFLib.AxAcroPDF(); this.Controls.Add(axAcroPDF1); axAcroPDF1.Visible=true; axAcroPDF1.Size=pictureBoxMain.Size; axAcroPDF1.Location=pictureBoxMain.Location; axAcroPDF1.OnError+=new EventHandler(pdfFileError); string pdfFilePath=ODFileUtils.CombinePaths(ImageStore.GetEobFolder(),eob.FileName); if(!File.Exists(pdfFilePath)) { MessageBox.Show(Lan.g(this,"File not found: ") + eob.FileName); } else { axAcroPDF1.LoadFile(pdfFilePath);//The return status of this function doesn't seem to be helpful. pictureBoxMain.Visible=false; } } catch { //An exception can happen if they do not have Adobe Acrobat Reader version 8.0 or later installed. //Simply ignore this exception and do nothing. We never used to display .pdf files anyway, so we //essentially revert back to the old behavior in this case. } } //return;? } EnableTreeItemTools(pictureBoxMain.Visible,true,true,pictureBoxMain.Visible,true,pictureBoxMain.Visible,pictureBoxMain.Visible,pictureBoxMain.Visible, pictureBoxMain.Visible,pictureBoxMain.Visible,pictureBoxMain.Visible,pictureBoxMain.Visible,pictureBoxMain.Visible,pictureBoxMain.Visible); } else if(nodeId.NodeType==ImageNodeType.Doc) { //Reload the doc from the db. We don't just keep reusing the tree data, because it will become more and //more stale with age if the program is left open in the image module for long periods of time. DocSelected=Documents.GetByNum(nodeId.PriKey); IdxSelectedInMount=0; ImagesCur=ImageStore.OpenImages(new Document[] { DocSelected },PatFolder); bool isExportable=pictureBoxMain.Visible; if(ImagesCur[0]==null) { if(ImageHelper.HasImageExtension(DocSelected.FileName)) { MessageBox.Show(Lan.g(this,"File not found: ") + DocSelected.FileName); } else if(Path.GetExtension(DocSelected.FileName).ToLower()==".pdf") {//Adobe acrobat file. try { axAcroPDF1=new AxAcroPDFLib.AxAcroPDF(); this.Controls.Add(axAcroPDF1); axAcroPDF1.Visible=true; axAcroPDF1.Size=pictureBoxMain.Size; axAcroPDF1.Location=pictureBoxMain.Location; axAcroPDF1.OnError+=new EventHandler(pdfFileError); string pdfFilePath=ODFileUtils.CombinePaths(PatFolder,DocSelected.FileName); if(!File.Exists(pdfFilePath)) { MessageBox.Show(Lan.g(this,"File not found: ") + DocSelected.FileName); } else { axAcroPDF1.LoadFile(pdfFilePath);//The return status of this function doesn't seem to be helpful. pictureBoxMain.Visible=false; isExportable=true; } } catch { //An exception can happen if they do not have Adobe Acrobat Reader version 8.0 or later installed. //Simply ignore this exception and do nothing. We never used to display .pdf files anyway, so we //essentially revert back to the old behavior in this case. } } } SetBrightnessAndContrast(); EnableTreeItemTools(pictureBoxMain.Visible,true,true,pictureBoxMain.Visible,true,pictureBoxMain.Visible,pictureBoxMain.Visible,pictureBoxMain.Visible, pictureBoxMain.Visible,pictureBoxMain.Visible,pictureBoxMain.Visible,pictureBoxMain.Visible,pictureBoxMain.Visible,isExportable); } else if(nodeId.NodeType==ImageNodeType.Mount) { //Creates a complete initial mount image. No need to call invalidate until changes are made to the mount later. MountItemsForSelected=MountItems.GetItemsForMount(nodeId.PriKey); DocsInMount=Documents.GetDocumentsForMountItems(MountItemsForSelected); IdxSelectedInMount=-1;//No selection to start. ImagesCur=ImageStore.OpenImages(DocsInMount,PatFolder); MountSelected=Mounts.GetByNum(nodeId.PriKey); ImageRenderingNow=new Bitmap(MountSelected.Width,MountSelected.Height); ImageHelper.RenderMountImage(ImageRenderingNow,ImagesCur,MountItemsForSelected,DocsInMount,IdxSelectedInMount); EnableTreeItemTools(true,true,true,true,false,false,false,true,true,true,false,false,false,true); } else if(nodeId.NodeType==ImageNodeType.Amd) { EhrAmendment amd=EhrAmendments.GetOne(nodeId.PriKey); ImagesCur=ImageStore.OpenImagesAmd(amd); if(ImagesCur[0]==null) { if(ImageHelper.HasImageExtension(amd.FileName)) { MessageBox.Show(Lan.g(this,"File not found: ") + amd.FileName); } else if(Path.GetExtension(amd.FileName).ToLower()==".pdf") {//Adobe acrobat file. try { axAcroPDF1=new AxAcroPDFLib.AxAcroPDF(); this.Controls.Add(axAcroPDF1); axAcroPDF1.Visible=true; axAcroPDF1.Size=pictureBoxMain.Size; axAcroPDF1.Location=pictureBoxMain.Location; axAcroPDF1.OnError+=new EventHandler(pdfFileError); string pdfFilePath=ODFileUtils.CombinePaths(ImageStore.GetAmdFolder(),amd.FileName); if(!File.Exists(pdfFilePath)) { MessageBox.Show(Lan.g(this,"File not found: ") + amd.FileName); } else { axAcroPDF1.LoadFile(pdfFilePath);//The return status of this function doesn't seem to be helpful. pictureBoxMain.Visible=false; } } catch { //An exception can happen if they do not have Adobe Acrobat Reader version 8.0 or later installed. //Simply ignore this exception and do nothing. We never used to display .pdf files anyway, so we //essentially revert back to the old behavior in this case. } } //return;? } EnableTreeItemTools(pictureBoxMain.Visible,true,true,pictureBoxMain.Visible,true,pictureBoxMain.Visible,pictureBoxMain.Visible,pictureBoxMain.Visible, pictureBoxMain.Visible,pictureBoxMain.Visible,pictureBoxMain.Visible,pictureBoxMain.Visible,pictureBoxMain.Visible,pictureBoxMain.Visible); } if(nodeId.NodeType==ImageNodeType.Doc || nodeId.NodeType==ImageNodeType.Mount || nodeId.NodeType==ImageNodeType.Eob || nodeId.NodeType==ImageNodeType.Amd) { WidthsImagesCur=new int[ImagesCur.Length]; HeightsImagesCur=new int[ImagesCur.Length]; for(int i=0;i<ImagesCur.Length;i++) { if(ImagesCur[i]!=null) { WidthsImagesCur[i]=ImagesCur[i].Width; HeightsImagesCur[i]=ImagesCur[i].Height; } } //Adjust visibility of panel note control based on if the new document has a signature. SetPanelNoteVisibility(DocSelected); //Resize controls in our window to adjust for a possible change in the visibility of the panel note control. ResizeAll(); //Refresh the signature and note in case the last document also had a signature. FillSignature(); } if(nodeId.NodeType==ImageNodeType.Mount) { ReloadZoomTransCrop(ImageRenderingNow.Width,ImageRenderingNow.Height,new Document(), new Rectangle(0,0,pictureBoxMain.Width,pictureBoxMain.Height),out ZoomImage, out ZoomLevel,out ZoomOverall,out PointTranslation); RenderCurrentImage(new Document(),ImageRenderingNow.Width,ImageRenderingNow.Height,ZoomImage,PointTranslation); } if(nodeId.NodeType==ImageNodeType.Doc || nodeId.NodeType==ImageNodeType.Eob || nodeId.NodeType==ImageNodeType.Amd) { //Render the initial image within the current bounds of the picturebox (if the document is an image). InvalidateSettings(ImageSettingFlags.ALL,true); } }
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); } }