Confirmation message when exiting OD

This forum is for programmers who have questions about the source code.
Post Reply
alhalwachi
Posts: 74
Joined: Fri Apr 02, 2010 2:26 pm

Confirmation message when exiting OD

Post by alhalwachi » Wed May 18, 2011 10:04 am

Dear All

I would like to add a confirmation pop up window with a "Are you sure you want to exit Open Dental" message when the user clicks on the "X" Exit button, how can I do that?

Alos, i want to do the same when the user clicks on the exit button of the patient edit form...

Please help, thanks

User avatar
wjstarck
Posts: 863
Joined: Tue Jul 31, 2007 7:18 am
Location: Keller, TX
Contact:

Re: Confirmation message when exiting OD

Post by wjstarck » Wed May 18, 2011 11:13 am

Just put this at the top of the FormOpenDental_FormClosing method on FormOpenDental like so:

Code: Select all

private void FormOpenDental_FormClosing(object sender,FormClosingEventArgs e) {
	DialogResult result = MessageBox.Show(Lan.g(this, "Are you sure you want to quit Open Dental?"), "", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
	if (result == DialogResult.No) {
		e.Cancel = true;
		return;

	} 
	try {
	Computers.ClearHeartBeat(Environment.MachineName);
	} catch { }
	FormUAppoint.AbortThread();
	//ICat.AbortThread
	//earlier, this wasn't working.  But I haven't tested it since moving it from Closing to FormClosing.
	if (ThreadCommandLine != null) {
		ThreadCommandLine.Abort();
	}

}
You can do something similar on FormPatientEdit
Cheers,

Bill Starck, DDS
Big Idea Software, LLC
Developer, EASy(Electronic Anesthesia System) for Open Dental
TX, USA

alhalwachi
Posts: 74
Joined: Fri Apr 02, 2010 2:26 pm

Re: Confirmation message when exiting OD

Post by alhalwachi » Thu May 19, 2011 4:24 am

Perfect, that worked just great form me BUT, how can i achieve the same with the Patient Edit form?

Thanks;

User avatar
wjstarck
Posts: 863
Joined: Tue Jul 31, 2007 7:18 am
Location: Keller, TX
Contact:

Re: Confirmation message when exiting OD

Post by wjstarck » Thu May 19, 2011 7:16 am

Just stick this at the top of method FormPatientEdit_Closing like so:

Code: Select all

private void FormPatientEdit_Closing(object sender, System.ComponentModel.CancelEventArgs e) {
	DialogResult result = MessageBox.Show(Lan.g(this, "Are you sure you want to close this window?"), "", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
	if (result == DialogResult.No) {
		e.Cancel = true;
		return;
	}
	if(DialogResult==DialogResult.OK){
		return;
	}
	if(IsNew){
		//for(int i=0;i<RefList.Length;i++){
		//	RefAttaches.Delete(RefList[i]);
		//}
		Patients.Delete(PatCur);
	}
}
Cheers,

Bill Starck, DDS
Big Idea Software, LLC
Developer, EASy(Electronic Anesthesia System) for Open Dental
TX, USA

alhalwachi
Posts: 74
Joined: Fri Apr 02, 2010 2:26 pm

Re: Confirmation message when exiting OD

Post by alhalwachi » Tue May 24, 2011 3:02 am

Thanks a lot for your help. I applied the above on the patient edit for as advised and it works perfectly BUT i get the same message when i click on the "OK"/"Cancel" buttons on the form, i only want this message to appear when i close the form or click 'Cancel" and not when clicking OK.

How can i do that?

User avatar
jordansparks
Site Admin
Posts: 5410
Joined: Sun Jun 17, 2007 3:59 pm
Location: Salem, Oregon
Contact:

Re: Confirmation message when exiting OD

Post by jordansparks » Tue May 24, 2011 3:42 am

Use a variable to keep track of when the user clicks ok or cancel. And then skip the message if they did so.
Jordan Sparks, DMD
http://www.opendental.com

Post Reply