Exemple #1
0
		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;
		}
Exemple #2
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;
			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
		}
Exemple #3
0
		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;
		}
Exemple #4
0
		private void PrintStatementClassic(Statement stmt) {
			Cursor=Cursors.WaitCursor;
			Statements.Insert(stmt);
			FormRpStatement FormST=new FormRpStatement();
			DataSet dataSet=AccountModules.GetStatementDataSet(stmt);
			FormST.CreateStatementPdfClassic(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) {
				if(!Security.IsAuthorized(Permissions.EmailSend)) {
					Cursor=Cursors.Default;
					return;
				}
				string attachPath=EmailAttaches.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=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
					Statements.Delete(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;

		}