private void butPrint_Click(object sender, EventArgs e) { if (!TryToSaveData()) { return; } SheetCur = Sheets.GetSheet(SheetCur.SheetNum); //whether this is a new sheet, or one pulled from the database, //it will have the extra parameter we are looking for. //A new sheet will also have a PatNum parameter which we will ignore. FormSheetOutputFormat FormS = new FormSheetOutputFormat(); if (SheetCur.SheetType == SheetTypeEnum.ReferralSlip || SheetCur.SheetType == SheetTypeEnum.ReferralLetter) { FormS.PaperCopies = 2; } else { FormS.PaperCopies = 1; } if (SheetCur.PatNum != 0 && SheetCur.SheetType != SheetTypeEnum.DepositSlip) { Patient pat = Patients.GetPat(SheetCur.PatNum); if (SheetCur.SheetType == SheetTypeEnum.LabSlip) { FormS.IsForLab = true; //Changes label to "E-mail to Lab:" } else if (pat.Email != "") { FormS.EmailPatOrLabAddress = pat.Email; FormS.EmailPatOrLab = true; FormS.PaperCopies--; } } Referral referral = null; if (SheetCur.SheetType == SheetTypeEnum.ReferralSlip || SheetCur.SheetType == SheetTypeEnum.ReferralLetter) { FormS.Email2Visible = true; SheetParameter parameter = SheetParameter.GetParamByName(SheetCur.Parameters, "ReferralNum"); if (parameter == null) //it can be null sometimes because of old bug in db. { FormS.Email2Visible = false; //prevents trying to attach email to nonexistent referral. } else { long referralNum = PIn.Long(parameter.ParamValue.ToString()); referral = Referrals.GetReferral(referralNum); if (referral.EMail != "") { FormS.Email2Address = referral.EMail; FormS.Email2 = true; FormS.PaperCopies--; } } } else { FormS.Email2Visible = false; } FormS.ShowDialog(); if (FormS.DialogResult != DialogResult.OK) { return; } if (FormS.PaperCopies > 0) { SheetPrinting.Print(SheetCur, FormS.PaperCopies, RxIsControlled); } EmailMessage message; Random rnd = new Random(); string attachPath = FormEmailMessageEdit.GetAttachPath(); string fileName; string filePathAndName; //Graphics g=this.CreateGraphics(); if (FormS.EmailPatOrLab) { fileName = DateTime.Now.ToString("yyyyMMdd") + "_" + DateTime.Now.TimeOfDay.Ticks.ToString() + rnd.Next(1000).ToString() + ".pdf"; filePathAndName = ODFileUtils.CombinePaths(attachPath, fileName); SheetPrinting.CreatePdf(SheetCur, filePathAndName); //Process.Start(filePathAndName); message = new EmailMessage(); message.PatNum = SheetCur.PatNum; message.ToAddress = FormS.EmailPatOrLabAddress; message.FromAddress = PrefC.GetString(PrefName.EmailSenderAddress); message.Subject = SheetCur.Description.ToString(); //this could be improved EmailAttach attach = new EmailAttach(); string shortFileName = Regex.Replace(SheetCur.Description.ToString(), @"[^\w'@-_()&]", ""); attach.DisplayedFileName = shortFileName + ".pdf"; attach.ActualFileName = fileName; message.Attachments.Add(attach); FormEmailMessageEdit FormE = new FormEmailMessageEdit(message); FormE.IsNew = true; FormE.ShowDialog(); } if ((SheetCur.SheetType == SheetTypeEnum.ReferralSlip || SheetCur.SheetType == SheetTypeEnum.ReferralLetter) && FormS.Email2) { //email referral fileName = DateTime.Now.ToString("yyyyMMdd") + "_" + DateTime.Now.TimeOfDay.Ticks.ToString() + rnd.Next(1000).ToString() + ".pdf"; filePathAndName = ODFileUtils.CombinePaths(attachPath, fileName); SheetPrinting.CreatePdf(SheetCur, filePathAndName); //Process.Start(filePathAndName); message = new EmailMessage(); message.PatNum = SheetCur.PatNum; message.ToAddress = FormS.Email2Address; message.FromAddress = PrefC.GetString(PrefName.EmailSenderAddress); message.Subject = SheetCur.Description.ToString() + " to " + Referrals.GetNameFL(referral.ReferralNum); //this could be improved EmailAttach attach = new EmailAttach(); string shortFileName = Regex.Replace(SheetCur.Description.ToString(), @"[^\w,'@-_()&]", ""); attach.DisplayedFileName = shortFileName + ".pdf"; attach.ActualFileName = fileName; message.Attachments.Add(attach); FormEmailMessageEdit FormE = new FormEmailMessageEdit(message); FormE.IsNew = true; FormE.ShowDialog(); } //g.Dispose(); DialogResult = DialogResult.OK; }
private void SaveAttachment() { Patient PatCur = Patients.GetPat(PatNum); //if(PatCur.ImageFolder=="") { // MsgBox.Show(this,"Invalid patient image folder."); // return; //} if (!PrefC.UsingAtoZfolder) { MsgBox.Show(this, "Error. Not using AtoZ images folder."); return; } string patfolder = ImageStore.GetPatientFolder(PatCur, ImageStore.GetPreferredAtoZpath()); //ODFileUtils.CombinePaths( //FormPath.GetPreferredImagePath(),PatCur.ImageFolder.Substring(0,1).ToUpper(),PatCur.ImageFolder); //if(!Directory.Exists(patfolder)) { // MsgBox.Show(this,"Patient folder not found in AtoZ folder."); // return; //} Document doc = Docs[gridMain.GetSelectedIndex()]; if (!ImageHelper.HasImageExtension(doc.FileName)) { MsgBox.Show(this, "Invalid file. Only images may be attached, no other file format."); return; } string oldPath = ODFileUtils.CombinePaths(patfolder, doc.FileName); Random rnd = new Random(); string newName = DateTime.Now.ToString("yyyyMMdd") + "_" + DateTime.Now.TimeOfDay.Ticks.ToString() + rnd.Next(1000).ToString() + Path.GetExtension(oldPath); string attachPath = FormEmailMessageEdit.GetAttachPath(); string newPath = ODFileUtils.CombinePaths(attachPath, newName); try { if (ImageHelper.HasImageExtension(oldPath)) { if (doc.CropH != 0 || doc.CropW != 0 || doc.CropX != 0 || doc.CropY != 0 || doc.DegreesRotated != 0 || doc.IsFlipped || doc.WindowingMax != 0 || doc.WindowingMin != 0) { //this does result in a significantly larger images size if jpg. A later optimization would recompress it. Bitmap bitmapold = (Bitmap)Bitmap.FromFile(oldPath); Bitmap bitmapnew = ImageHelper.ApplyDocumentSettingsToImage(doc, bitmapold, ImageSettingFlags.ALL); bitmapnew.Save(newPath); } else { File.Copy(oldPath, newPath); } } else { File.Copy(oldPath, newPath); } ClaimAttachNew = new ClaimAttach(); ClaimAttachNew.DisplayedFileName = Docs[gridMain.GetSelectedIndex()].FileName; ClaimAttachNew.ActualFileName = newName; DialogResult = DialogResult.OK; } catch (FileNotFoundException ex) { MessageBox.Show(Lan.g(this, "File not found: ") + ex.Message); return; } catch (Exception ex) { MessageBox.Show(ex.Message); } }