public static void AttachDoc(long statementNum, Document doc, bool doUpdateDoc = true) { if (RemotingClient.RemotingRole == RemotingRole.ClientWeb) { Meth.GetVoid(MethodBase.GetCurrentMethod(), statementNum, doc, doUpdateDoc); return; } if (doUpdateDoc) { Documents.Update(doc); } string command = "UPDATE statement SET DocNum=" + POut.Long(doc.DocNum) + " WHERE StatementNum=" + POut.Long(statementNum); Db.NonQ(command); }
/// <summary></summary> public static Document Import(string pathImportFrom, long docCategory, Patient pat) { string patFolder = ""; if (PrefC.UsingAtoZfolder) { patFolder = GetPatientFolder(pat, GetPreferredAtoZpath()); } Document doc = new Document(); //Document.Insert will use this extension when naming: if (Path.GetExtension(pathImportFrom) == "") //If the file has no extension { doc.FileName = ".jpg"; } else { doc.FileName = Path.GetExtension(pathImportFrom); } doc.DateCreated = File.GetLastWriteTime(pathImportFrom); doc.PatNum = pat.PatNum; if (HasImageExtension(doc.FileName)) { doc.ImgType = ImageType.Photo; } else { doc.ImgType = ImageType.Document; } doc.DocCategory = docCategory; Documents.Insert(doc, pat); //this assigns a filename and saves to db doc = Documents.GetByNum(doc.DocNum); try { SaveDocument(doc, pathImportFrom, patFolder); if (PrefC.UsingAtoZfolder) { Documents.Update(doc); } } catch { Documents.Delete(doc); throw; } return(doc); }
/* * public static Document Import(Bitmap image,long docCategory,Patient pat) { * string patFolder=""; * if(PrefC.UsingAtoZfolder) { * patFolder=GetPatientFolder(pat,GetPreferredAtoZpath()); * } * Document doc=new Document(); * doc.FileName=".jpg"; * doc.DateCreated=DateTime.Today; * doc.DocCategory=docCategory; * doc.PatNum=pat.PatNum; * doc.ImgType=ImageType.Photo; * //doc.RawBase64 handled further down. * //doc.Thumbnail="";//no thumbnail yet * Documents.Insert(doc,pat);//this assigns a filename and saves to db * doc=Documents.GetByNum(doc.DocNum); * try { * SaveDocument(doc,image,ImageFormat.Jpeg,patFolder); * if(PrefC.UsingAtoZfolder) { * Documents.Update(doc); * } * } * catch { * Documents.Delete(doc); * throw; * } * return doc; * }*/ /// <summary>Saves to either AtoZ folder or to db. Saves image as a jpg. Compression will differ depending on imageType.</summary> public static Document Import(Bitmap image, long docCategory, ImageType imageType, Patient pat) { string patFolder = ""; if (PrefC.UsingAtoZfolder) { patFolder = GetPatientFolder(pat, GetPreferredAtoZpath()); } Document doc = new Document(); doc.ImgType = imageType; doc.FileName = ".jpg"; doc.DateCreated = DateTime.Today; doc.PatNum = pat.PatNum; doc.DocCategory = docCategory; Documents.Insert(doc, pat); //creates filename and saves to db doc = Documents.GetByNum(doc.DocNum); long qualityL = 0; if (imageType == ImageType.Radiograph) { qualityL = 100; } else if (imageType == ImageType.Photo) { qualityL = 100; } else //Assume document //Possible values 0-100? { qualityL = PrefC.GetLong(PrefName.ScannerCompression); } ImageCodecInfo myImageCodecInfo; ImageCodecInfo[] encoders; encoders = ImageCodecInfo.GetImageEncoders(); myImageCodecInfo = null; for (int j = 0; j < encoders.Length; j++) { if (encoders[j].MimeType == "image/jpeg") { myImageCodecInfo = encoders[j]; } } EncoderParameters myEncoderParameters = new EncoderParameters(1); EncoderParameter myEncoderParameter = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, qualityL); myEncoderParameters.Param[0] = myEncoderParameter; //AutoCrop()? try { SaveDocument(doc, image, myImageCodecInfo, myEncoderParameters, patFolder); if (!PrefC.UsingAtoZfolder) { Documents.Update(doc); //because SaveDocument stuck the image in doc.RawBase64. //no thumbnail yet } } catch { Documents.Delete(doc); throw; } return(doc); }