コード例 #1
0
ファイル: FormStatementOptions.cs プロジェクト: mnisl/OD
		private void butPreviewClassic() {
			if(StmtCur.DocNum!=0 && checkIsSent.Checked) {//initiallySent && checkIsSent.Checked){
				//launch existing archive pdf
				Cursor=Cursors.WaitCursor;
				Patient pat=Patients.GetPat(StmtCur.PatNum);
				string patFolder=ImageStore.GetPatientFolder(pat,ImageStore.GetPreferredAtoZpath());
				//Currently unable to load Statements stored in database even though they get saved into the database.
				if(!File.Exists(ImageStore.GetFilePath(Documents.GetByNum(StmtCur.DocNum),patFolder))) {
					Cursor=Cursors.Default;
					MsgBox.Show(this,"File not found: " + Documents.GetByNum(StmtCur.DocNum).FileName);
					return;
				}
				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
				//No archive to use, so just preview on the fly
				if(initiallySent && checkIsSent.Checked && StmtCur.DocNum==0){
					MsgBox.Show(this,"There was no archived image of this statement.  The preview will be based on current data.");
				}
				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);
				//Would throw exception if no printer is installed.
				try {
					FormST.PrintStatement(StmtCur,true,dataSet,fam,pat);
				}
				catch {
					MsgBox.Show(this,"No printers installed.");
					Cursor=Cursors.Default;
					return;
				}
				FormST.ShowDialog();
				Cursor=Cursors.Default;
			}
		}
コード例 #2
0
ファイル: FormStatementOptions.cs プロジェクト: mnisl/OD
		private void butPrintClassic() {
			if(StmtCur.DocNum!=0 && checkIsSent.Checked 
				&& !StmtCur.IsInvoice)//Invoices are always recreated on the fly in order to show "Copy" when needed.
			{
				//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 
					&& !StmtCur.IsInvoice)//for invoice, we don't notify user that it's a recreation
				{
					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.CreateStatementPdfClassic(StmtCur,pat,fam,dataSet);
#if DEBUG
				FormST.PrintStatement(StmtCur,true,dataSet,fam,pat);
				FormST.ShowDialog();
#else
					FormST.PrintStatement(StmtCur,false,dataSet,fam,pat);
#endif
				if(StmtCur.IsInvoice && checkIsInvoiceCopy.Visible) {//for foreign countries
					StmtCur.IsInvoiceCopy=true;
					Statements.Update(StmtCur);
				}
				Cursor=Cursors.Default;
			}
			DialogResult=DialogResult.OK;
		}
コード例 #3
0
ファイル: FormBilling.cs プロジェクト: nampn/ODental
 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
 }
コード例 #4
0
ファイル: FormStatementOptions.cs プロジェクト: mnisl/OD
		private void butEmailClassic() {
			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.CreateStatementPdfClassic(StmtCur,pat,fam,dataSet);
				if(!CreateEmailMessage()) {
					Cursor=Cursors.Default;
					return;
				}
				if(StmtCur.IsInvoice && checkIsInvoiceCopy.Visible) {//for foreign countries
					StmtCur.IsInvoiceCopy=true;
					Statements.Update(StmtCur);
				}
				Cursor=Cursors.Default;
			}
			DialogResult=DialogResult.OK;
		}
コード例 #5
0
ファイル: FormStatementOptions.cs プロジェクト: nampn/ODental
 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;
 }
コード例 #6
0
ファイル: FormStatementOptions.cs プロジェクト: nampn/ODental
 private void butPreview_Click(object sender,EventArgs e)
 {
     if(StmtCur.DocNum!=0 && checkIsSent.Checked){//initiallySent && checkIsSent.Checked){
         //launch existing archive pdf
         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
         //No archive to use, so just preview on the fly
         if(initiallySent && checkIsSent.Checked && StmtCur.DocNum==0){
             MsgBox.Show(this,"There was no archived image of this statement.  The preview will be based on current data.");
         }
         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.PrintStatement(StmtCur,true,dataSet,fam,pat);
         FormST.ShowDialog();
         Cursor=Cursors.Default;
     }
 }
コード例 #7
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=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;
		}
コード例 #8
0
ファイル: FormBilling.cs プロジェクト: mnisl/OD
		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;
			EmailAddress emailAddress;
			Family fam;
			Patient pat;
			Clinic clinic;
			string patFolder;
			int skipped=0;
			int skippedElect=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);
			if(PrefC.GetString(PrefName.BillingUseElectronic)=="1") {
				OpenDental.Bridges.EHG_statements.GeneratePracticeInfo(writerElect);
			} 
			else if(PrefC.GetString(PrefName.BillingUseElectronic)=="2") {
				OpenDental.Bridges.POS_statements.GeneratePracticeInfo(writerElect);
			} 
			else if(PrefC.GetString(PrefName.BillingUseElectronic)=="3") {
				OpenDental.Bridges.ClaimX_Statements.GeneratePracticeInfo(writerElect);
			}
			DataSet dataSet;
			List<long> stateNumsElect=new List<long>();
			//TODO: Query the database to get an updated list of unsent bills and compare them to the local list to make sure that we do not resend statements that have already been sent by another user.
			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);
				emailAddress=EmailAddresses.GetByClinic(pat.ClinicNum);
				if(stmt.Mode_==StatementMode.Email){
					if(emailAddress.SMTPserver==""){
						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=DateTimeOD.Today;
				if(PrefC.GetBool(PrefName.StatementsUseSheets)){
					FormST.CreateStatementPdfSheets(stmt,pat,fam,dataSet);
				}
				else{
					FormST.CreateStatementPdfClassic(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=EmailAttaches.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=Statements.GetEmailMessageForStatement(stmt,pat);
					attach=new EmailAttach();
					attach.DisplayedFileName="Statement.pdf";
					attach.ActualFileName=fileName;
					message.Attachments.Add(attach);
					try{
						EmailMessages.SendEmailUnsecure(message,emailAddress);
						message.SentOrReceived=EmailSentOrReceived.Sent;
						message.MsgDateTime=DateTime.Now;
						EmailMessages.Insert(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) {
					Patient guar=fam.ListPats[0];
					if(guar.Address.Trim()=="" || guar.City.Trim()=="" || guar.State.Trim()=="" || guar.Zip.Trim()=="") {
						skippedElect++;
						continue;
					}
					bool statementWritten=true;
					if(PrefC.GetString(PrefName.BillingUseElectronic)=="1") {
						try {
							OpenDental.Bridges.EHG_statements.GenerateOneStatement(writerElect,stmt,pat,fam,dataSet);
						}
						catch(Exception ex){
							MessageBox.Show(Lan.g(this,"Error sending statement")+": "+Environment.NewLine+ex.ToString());
							statementWritten=false;
						}
					}
					else if(PrefC.GetString(PrefName.BillingUseElectronic)=="2") {
						OpenDental.Bridges.POS_statements.GenerateOneStatement(writerElect,stmt,pat,fam,dataSet);
					}
					else if(PrefC.GetString(PrefName.BillingUseElectronic)=="3") {
						OpenDental.Bridges.ClaimX_Statements.GenerateOneStatement(writerElect,stmt,pat,fam,dataSet);
					}
					if(statementWritten) {
						stateNumsElect.Add(stmt.StatementNum);
						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=PrefL.GetRandomTempFile(".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) {
				if(PrefC.GetString(PrefName.BillingUseElectronic)=="1") {
					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],DateTimeOD.Today);
						}
					} 
					catch(Exception ex) {
						string errorMsg=ex.Message;
						if(ex.Message.Contains("(404) Not Found")) {
							//The full error is "The remote server returned an error: (404) Not Found."  We convert the message into a more user friendly message.
							errorMsg=Lan.g(this,"The connection to the server could not be established or was lost, or the upload timed out.  "
								+"Ensure your internet connection is working and that your firewall is not blocking this application.  "
								+"If the upload timed out after 10 minutes, try sending 25 statements or less in each batch to reduce upload time.");
						}
						MsgBoxCopyPaste msgbox=new MsgBoxCopyPaste(errorMsg);
						msgbox.ShowDialog();
						sentelect=0;
						labelSentElect.Text=Lan.g(this,"SentElect=")+sentelect.ToString();
					}
				}
				if(PrefC.GetString(PrefName.BillingUseElectronic)=="2") {
					OpenDental.Bridges.POS_statements.GenerateWrapUp(writerElect);
					writerElect.Close();
					SaveFileDialog dlg=new SaveFileDialog();
					dlg.FileName="Statements.xml";
					if(dlg.ShowDialog()!=DialogResult.OK) {
						sentelect=0;
						labelSentElect.Text=Lan.g(this,"SentElect=")+sentelect.ToString();
					}
					File.WriteAllText(dlg.FileName,strBuildElect.ToString());
					for(int i=0;i<stateNumsElect.Count;i++) {
						Statements.MarkSent(stateNumsElect[i],DateTimeOD.Today);
					}
				}
				if(PrefC.GetString(PrefName.BillingUseElectronic)=="3") {
					OpenDental.Bridges.ClaimX_Statements.GenerateWrapUp(writerElect);
					writerElect.Close();
					SaveFileDialog dlg=new SaveFileDialog();
					dlg.InitialDirectory=@"C:\StatementX\";//Clint from ExtraDent requested this default path.
					if(!Directory.Exists(dlg.InitialDirectory)) {
						try {
							Directory.CreateDirectory(dlg.InitialDirectory);
						} 
						catch {}
					}
					dlg.FileName="Statements.xml";
					if(dlg.ShowDialog()!=DialogResult.OK) {
						sentelect=0;
						labelSentElect.Text=Lan.g(this,"SentElect=")+sentelect.ToString();
					}
					File.WriteAllText(dlg.FileName,strBuildElect.ToString());
					for(int i=0;i<stateNumsElect.Count;i++) {
						Statements.MarkSent(stateNumsElect[i],DateTimeOD.Today);
					}
				}
			}
			else {
				writerElect.Close();
			}
			string msg="";
			if(skipped>0){
				msg+=Lan.g(this,"Skipped due to missing or bad email address: ")+skipped.ToString()+"\r\n";
			}
			if(skippedElect>0) {
				msg+=Lan.g(this,"Skipped due to missing or bad mailing address: ")+skippedElect.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
		}
コード例 #9
0
ファイル: ContrAccount.cs プロジェクト: nampn/ODental
 /// <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;
 }