Exemple #1
0
 private void butSend_Click(object sender, System.EventArgs e)
 {
     if(gridBill.SelectedIndices.Length==0){
         MessageBox.Show(Lan.g(this,"Please select items first."));
         return;
     }
     labelPrinted.Text=Lan.g(this,"Printed=")+"0";
     labelEmailed.Text=Lan.g(this,"E-mailed=")+"0";
     labelSentElect.Text=Lan.g(this,"SentElect=")+"0";
     if(!MsgBox.Show(this,true,"Please be prepared to wait up to ten minutes while all the bills get processed.\r\nOnce complete, the pdf print preview will be launched in Adobe Reader.  You will print from that program.  Continue?")){
         return;
     }
     Cursor=Cursors.WaitCursor;
     isPrinting=true;
     FormRpStatement FormST=new FormRpStatement();
     Statement stmt;
     Random rnd;
     string fileName;
     string filePathAndName;
     string attachPath;
     EmailMessage message;
     EmailAttach attach;
     Family fam;
     Patient pat;
     string patFolder;
     int skipped=0;
     int emailed=0;
     int printed=0;
     int sentelect=0;
     //FormEmailMessageEdit FormEME=new FormEmailMessageEdit();
     //if(ImageStore.UpdatePatient == null){
     //	ImageStore.UpdatePatient = new FileStore.UpdatePatientDelegate(Patients.Update);
     //}
     //OpenDental.Imaging.ImageStoreBase imageStore;
     //Concat all the pdf's together to create one print job.
     //Also, if a statement is to be emailed, it does that here and does not attach it to the print job.
     //If something fails badly, it's no big deal, because we can click the radio button to see "sent" bills, and unsend them from there.
       PdfDocument outputDocument=new PdfDocument();
     PdfDocument inputDocument;
     PdfPage page;
     string savedPdfPath;
     PrintDocument pd=null;
     XmlWriterSettings xmlSettings=new XmlWriterSettings();
     xmlSettings.OmitXmlDeclaration=true;
     xmlSettings.Encoding=Encoding.UTF8;
     xmlSettings.Indent=true;
     xmlSettings.IndentChars="   ";
     StringBuilder strBuildElect=new StringBuilder();
     XmlWriter writerElect=XmlWriter.Create(strBuildElect,xmlSettings);
     //OpenDental.Bridges.Tesia_statements.GeneratePracticeInfo(writerElect);
     OpenDental.Bridges.EHG_statements.GeneratePracticeInfo(writerElect);
     DataSet dataSet;
     List<long> stateNumsElect=new List<long>();
     for(int i=0;i<gridBill.SelectedIndices.Length;i++){
         stmt=Statements.CreateObject(PIn.Long(table.Rows[gridBill.SelectedIndices[i]]["StatementNum"].ToString()));
         fam=Patients.GetFamily(stmt.PatNum);
         pat=fam.GetPatient(stmt.PatNum);
         patFolder=ImageStore.GetPatientFolder(pat,ImageStore.GetPreferredAtoZpath());
         dataSet=AccountModules.GetStatementDataSet(stmt);
         if(stmt.Mode_==StatementMode.Email){
             if(PrefC.GetString(PrefName.EmailSMTPserver)==""){
                 MsgBox.Show(this,"You need to enter an SMTP server name in e-mail setup before you can send e-mail.");
                 Cursor=Cursors.Default;
                 isPrinting=false;
                 //FillGrid();//automatic
                 return;
             }
             if(pat.Email==""){
                 skipped++;
                 continue;
             }
         }
         stmt.IsSent=true;
         stmt.DateSent=DateTime.Today;
         FormST.CreateStatementPdf(stmt,pat,fam,dataSet);
         if(stmt.DocNum==0){
             MsgBox.Show(this,"Failed to save PDF.  In Setup, DataPaths, please make sure the top radio button is checked.");
             Cursor=Cursors.Default;
             isPrinting=false;
             return;
         }
         //imageStore = OpenDental.Imaging.ImageStore.GetImageStore(pat);
         savedPdfPath=ImageStore.GetFilePath(Documents.GetByNum(stmt.DocNum),patFolder);
         if(stmt.Mode_==StatementMode.InPerson || stmt.Mode_==StatementMode.Mail){
             if(pd==null){
                 pd=new PrintDocument();
             }
             inputDocument=PdfReader.Open(savedPdfPath,PdfDocumentOpenMode.Import);
             for(int idx=0;idx<inputDocument.PageCount;idx++){
                 page=inputDocument.Pages[idx];
                 outputDocument.AddPage(page);
             }
             printed++;
             labelPrinted.Text=Lan.g(this,"Printed=")+printed.ToString();
             Application.DoEvents();
             Statements.MarkSent(stmt.StatementNum,stmt.DateSent);
         }
         if(stmt.Mode_==StatementMode.Email){
             attachPath=FormEmailMessageEdit.GetAttachPath();
             rnd=new Random();
             fileName=DateTime.Now.ToString("yyyyMMdd")+"_"+DateTime.Now.TimeOfDay.Ticks.ToString()+rnd.Next(1000).ToString()+".pdf";
             filePathAndName=ODFileUtils.CombinePaths(attachPath,fileName);
             File.Copy(savedPdfPath,filePathAndName);
             //Process.Start(filePathAndName);
             message=new EmailMessage();
             message.PatNum=pat.PatNum;
             message.ToAddress=pat.Email;
             message.FromAddress=PrefC.GetString(PrefName.EmailSenderAddress);
             string str;
             str=PrefC.GetString(PrefName.BillingEmailSubject);
             str=str.Replace("[nameF]",pat.GetNameFirst());
             str=str.Replace("[nameFL]",pat.GetNameFL());
             str=str.Replace("[namePref]",pat.Preferred);
             str=str.Replace("[PatNum]",pat.PatNum.ToString());
             message.Subject=str;
             str=PrefC.GetString(PrefName.BillingEmailBodyText);
             str=str.Replace("[nameF]",pat.GetNameFirst());
             str=str.Replace("[nameFL]",pat.GetNameFL());
             str=str.Replace("[namePref]",pat.Preferred);
             str=str.Replace("[PatNum]",pat.PatNum.ToString());
             message.BodyText=str;
             attach=new EmailAttach();
             attach.DisplayedFileName="Statement.pdf";
             attach.ActualFileName=fileName;
             message.Attachments.Add(attach);
             try{
                 FormEmailMessageEdit.SendEmail(message);
                 emailed++;
                 labelEmailed.Text=Lan.g(this,"E-mailed=")+emailed.ToString();
                 Application.DoEvents();
             }
             catch{
                 //Cursor=Cursors.Default;
                 //MessageBox.Show(ex.Message);
                 //return;
                 skipped++;
                 continue;
             }
             Statements.MarkSent(stmt.StatementNum,stmt.DateSent);
         }
         if(stmt.Mode_==StatementMode.Electronic) {
             stateNumsElect.Add(stmt.StatementNum);
             //OpenDental.Bridges.Tesia_statements.GenerateOneStatement(writerElect,stmt,pat,fam,dataSet);
             OpenDental.Bridges.EHG_statements.GenerateOneStatement(writerElect,stmt,pat,fam,dataSet);
             sentelect++;
             labelSentElect.Text=Lan.g(this,"SentElect=")+sentelect.ToString();
             Application.DoEvents();
             //do this later:
             //Statements.MarkSent(stmt.StatementNum,stmt.DateSent);
         }
     }
     //now print-------------------------------------------------------------------------------------
     if(pd!=null){
         string tempFileOutputDocument=Path.GetTempFileName()+".pdf";
         outputDocument.Save(tempFileOutputDocument);
         try{
             Process.Start(tempFileOutputDocument);
         }
         catch(Exception ex){
             MessageBox.Show(Lan.g(this,"Error: Please make sure Adobe Reader is installed.")+ex.Message);
         }
         //}
     }
     //finish up elect and send if needed------------------------------------------------------------
     if(sentelect>0) {
         //OpenDental.Bridges.Tesia_statements.GenerateWrapUp(writerElect);
         OpenDental.Bridges.EHG_statements.GenerateWrapUp(writerElect);
         writerElect.Close();
         try {
             //OpenDental.Bridges.Tesia_statements.Send(strBuildElect.ToString());
             OpenDental.Bridges.EHG_statements.Send(strBuildElect.ToString());
             //CodeBase.MsgBoxCopyPaste msgbox=new MsgBoxCopyPaste(strBuildElect.ToString());
             //msgbox.ShowDialog();
             //loop through all statements and mark sent
             for(int i=0;i<stateNumsElect.Count;i++) {
                 Statements.MarkSent(stateNumsElect[i],DateTime.Today);
             }
         }
         catch(Exception ex) {
             MsgBoxCopyPaste msgbox=new MsgBoxCopyPaste(ex.Message);
             msgbox.ShowDialog();
             //MessageBox.Show();
             sentelect=0;
             labelSentElect.Text=Lan.g(this,"SentElect=")+sentelect.ToString();
         }
     }
     else {
         writerElect.Close();
     }
     string msg="";
     if(skipped>0){
         msg+=Lan.g(this,"Skipped due to missing or bad email address: ")+skipped.ToString()+"\r\n";
     }
     msg+=Lan.g(this,"Printed: ")+printed.ToString()+"\r\n"
         +Lan.g(this,"E-mailed: ")+emailed.ToString()+"\r\n"
         +Lan.g(this,"SentElect: ")+sentelect.ToString();
     MessageBox.Show(msg);
     Cursor=Cursors.Default;
     isPrinting=false;
     FillGrid();//not automatic
 }
 private void butPrint_Click(object sender,EventArgs e)
 {
     if(StmtCur.DocNum!=0 && checkIsSent.Checked){
         //launch existing archive pdf. User can click print from within Acrobat.
         Cursor=Cursors.WaitCursor;
         Patient pat=Patients.GetPat(StmtCur.PatNum);
         string patFolder=ImageStore.GetPatientFolder(pat,ImageStore.GetPreferredAtoZpath());
         Process.Start(ImageStore.GetFilePath(Documents.GetByNum(StmtCur.DocNum),patFolder));
         Cursor=Cursors.Default;
     }
     else{//was not initially sent, or else user has unchecked the sent box
         if(initiallySent && checkIsSent.Checked && StmtCur.DocNum==0){
             MsgBox.Show(this,"There was no archived image of this statement.  The printout will be based on current data.");
         }
         //So create an archive
         if(listMode.SelectedIndex==(int)StatementMode.Email){
             listMode.SelectedIndex=(int)StatementMode.InPerson;
         }
         checkIsSent.Checked=true;
         Cursor=Cursors.WaitCursor;
         if(!SaveToDb()){
             Cursor=Cursors.Default;
             return;
         }
         FormRpStatement FormST=new FormRpStatement();
         Family fam=Patients.GetFamily(StmtCur.PatNum);
         Patient pat=fam.GetPatient(StmtCur.PatNum);
         DataSet dataSet=AccountModules.GetStatementDataSet(StmtCur);
         FormST.CreateStatementPdf(StmtCur,pat,fam,dataSet);
         #if DEBUG
             FormST.PrintStatement(StmtCur,true,dataSet,fam,pat);
             FormST.ShowDialog();
         #else
             FormST.PrintStatement(StmtCur,false,dataSet,fam,pat);
         #endif
         Cursor=Cursors.Default;
     }
     DialogResult=DialogResult.OK;
 }
		/// <summary>Saves the statement.  Attaches a pdf to it by creating a doc object.  Prints it or emails it.  </summary>
		private void PrintStatement(Statement stmt) {
			Cursor=Cursors.WaitCursor;
			Statements.Insert(stmt);
			FormRpStatement FormST=new FormRpStatement();
			DataSet dataSet=AccountModules.GetStatementDataSet(stmt);
			FormST.CreateStatementPdf(stmt,PatCur,FamCur,dataSet);
			//if(ImageStore.UpdatePatient == null){
			//	ImageStore.UpdatePatient = new FileStore.UpdatePatientDelegate(Patients.Update);
			//}
			Patient guar=Patients.GetPat(stmt.PatNum);
			string guarFolder=ImageStore.GetPatientFolder(guar,ImageStore.GetPreferredAtoZpath());
			//OpenDental.Imaging.ImageStoreBase imageStore = OpenDental.Imaging.ImageStore.GetImageStore(guar);
			if(stmt.Mode_==StatementMode.Email) {
				string attachPath=EmailMessages.GetEmailAttachPath();
				Random rnd=new Random();
				string fileName=DateTime.Now.ToString("yyyyMMdd")+"_"+DateTime.Now.TimeOfDay.Ticks.ToString()+rnd.Next(1000).ToString()+".pdf";
				string filePathAndName=ODFileUtils.CombinePaths(attachPath,fileName);
				File.Copy(ImageStore.GetFilePath(Documents.GetByNum(stmt.DocNum),guarFolder),filePathAndName);
				//Process.Start(filePathAndName);
				EmailMessage message=Statements.GetEmailMessageForStatement(stmt,guar);
				EmailAttach attach=new EmailAttach();
				attach.DisplayedFileName="Statement.pdf";
				attach.ActualFileName=fileName;
				message.Attachments.Add(attach);
				FormEmailMessageEdit FormE=new FormEmailMessageEdit(message);
				FormE.IsNew=true;
				FormE.ShowDialog();
				//If user clicked delete or cancel, delete pdf and statement
				if(FormE.DialogResult==DialogResult.Cancel) {
					Patient pat;
					string patFolder;
					if(stmt.DocNum!=0) {
						//delete the pdf
						pat=Patients.GetPat(stmt.PatNum);
						patFolder=ImageStore.GetPatientFolder(pat,ImageStore.GetPreferredAtoZpath());
						List<Document> listdocs=new List<Document>();
						listdocs.Add(Documents.GetByNum(stmt.DocNum));
						try {  
							ImageStore.DeleteDocuments(listdocs,patFolder);
						}
						catch {  //Image could not be deleted, in use.
							//This should never get hit because the file was created by this user within this method.  
							//If the doc cannot be deleted, then we will not stop them, they will have to manually delete it from the images module.
						}
					}
					//delete statement
					Procedures.DetachFromInvoice(stmt.StatementNum);
					Adjustments.DetachFromInvoice(stmt.StatementNum);
					Statements.DeleteObject(stmt);
				}
			}
			else {//not email
				#if DEBUG
					//don't bother to check valid path because it's just debug.
					string imgPath=ImageStore.GetFilePath(Documents.GetByNum(stmt.DocNum),guarFolder);
					DateTime now=DateTime.Now;
					while(DateTime.Now<now.AddSeconds(5) && !File.Exists(imgPath)) {//wait up to 5 seconds.
						Application.DoEvents();
					}
					Process.Start(imgPath);
				#else
					FormST.PrintStatement(stmt,false,dataSet,FamCur,PatCur);
				#endif
			}
			Cursor=Cursors.Default;
		}
 private void butEmail_Click(object sender,EventArgs e)
 {
     if(StmtCur.DocNum!=0 && checkIsSent.Checked){
         //remail existing archive pdf?
         //or maybe tell user they can't do that?
         MsgBox.Show(this,"Email was already sent.");
         return;
     }
     else{//was not initially sent, or else user has unchecked the sent box
         //So create an archive
         if(listMode.SelectedIndex!=(int)StatementMode.Email){
             listMode.SelectedIndex=(int)StatementMode.Email;
         }
         checkIsSent.Checked=true;
         Cursor=Cursors.WaitCursor;
         if(!SaveToDb()){
             return;
         }
         FormRpStatement FormST=new FormRpStatement();
         Family fam=Patients.GetFamily(StmtCur.PatNum);
         Patient pat=fam.GetPatient(StmtCur.PatNum);
         DataSet dataSet=AccountModules.GetStatementDataSet(StmtCur);
         FormST.CreateStatementPdf(StmtCur,pat,fam,dataSet);
         if(!CreateEmailMessage()){
             Cursor=Cursors.Default;
             return;
         }
         Cursor=Cursors.Default;
     }
     DialogResult=DialogResult.OK;
 }
Exemple #5
0
 /// <summary>Saves the statement.  Attaches a pdf to it by creating a doc object.  Prints it or emails it.  </summary>
 private void PrintStatement(Statement stmt)
 {
     Cursor=Cursors.WaitCursor;
     Statements.Insert(stmt);
     FormRpStatement FormST=new FormRpStatement();
     DataSet dataSet=AccountModules.GetStatementDataSet(stmt);
     FormST.CreateStatementPdf(stmt,PatCur,FamCur,dataSet);
     //if(ImageStore.UpdatePatient == null){
     //	ImageStore.UpdatePatient = new FileStore.UpdatePatientDelegate(Patients.Update);
     //}
     Patient guar=Patients.GetPat(stmt.PatNum);
     string guarFolder=ImageStore.GetPatientFolder(guar,ImageStore.GetPreferredAtoZpath());
     //OpenDental.Imaging.ImageStoreBase imageStore = OpenDental.Imaging.ImageStore.GetImageStore(guar);
     if(stmt.Mode_==StatementMode.Email){
         string attachPath=FormEmailMessageEdit.GetAttachPath();
         Random rnd=new Random();
         string fileName=DateTime.Now.ToString("yyyyMMdd")+"_"+DateTime.Now.TimeOfDay.Ticks.ToString()+rnd.Next(1000).ToString()+".pdf";
         string filePathAndName=ODFileUtils.CombinePaths(attachPath,fileName);
         File.Copy(ImageStore.GetFilePath(Documents.GetByNum(stmt.DocNum),guarFolder),filePathAndName);
         //Process.Start(filePathAndName);
         EmailMessage message=new EmailMessage();
         message.PatNum=guar.PatNum;
         message.ToAddress=guar.Email;
         message.FromAddress=PrefC.GetString(PrefName.EmailSenderAddress);
         string str;
         str=PrefC.GetString(PrefName.BillingEmailSubject);
         str=str.Replace("[nameF]",guar.GetNameFirst());
         str=str.Replace("[nameFL]",guar.GetNameFL());
         str=str.Replace("[namePref]",guar.Preferred);
         str=str.Replace("[PatNum]",guar.PatNum.ToString());
         message.Subject=str;
         str=PrefC.GetString(PrefName.BillingEmailBodyText);
         str=str.Replace("[nameF]",guar.GetNameFirst());
         str=str.Replace("[nameFL]",guar.GetNameFL());
         str=str.Replace("[namePref]",guar.Preferred);
         str=str.Replace("[PatNum]",guar.PatNum.ToString());
         message.BodyText=str;
         EmailAttach attach=new EmailAttach();
         attach.DisplayedFileName="Statement.pdf";
         attach.ActualFileName=fileName;
         message.Attachments.Add(attach);
         FormEmailMessageEdit FormE=new FormEmailMessageEdit(message);
         FormE.IsNew=true;
         FormE.ShowDialog();
     }
     else{
         #if DEBUG
             //don't bother to check valid path because it's just debug.
             string imgPath=ImageStore.GetFilePath(Documents.GetByNum(stmt.DocNum),guarFolder);
             DateTime now=DateTime.Now;
             while(DateTime.Now<now.AddSeconds(5) && !File.Exists(imgPath)) {//wait up to 5 seconds.
                 Application.DoEvents();
             }
             Process.Start(imgPath);
         #else
             FormST.PrintStatement(stmt,false,dataSet,FamCur,PatCur);
         #endif
     }
     Cursor=Cursors.Default;
 }