New restrictions for OpenDentBusiness

This forum is for programmers who have questions about the source code.
Post Reply
User avatar
jordansparks
Site Admin
Posts: 5742
Joined: Sun Jun 17, 2007 3:59 pm
Location: Salem, Oregon
Contact:

New restrictions for OpenDentBusiness

Post by jordansparks » Tue May 12, 2009 6:47 am

There are some new rules to follow in OpenDentBusiness which were implied but haven't been posted yet. That's why I had to roll back the changes in AnestheticRecords. I did add a copy of the file so that you could simply copy and paste out of there. Here is a very quick rundown of the new rules for OpenDentBusiness.DataInterface classes:
1. No public static variables.
2. All methods must start with either:
a. //No need to check RemotingRole; no call to db.
or
b. a pattern similar to:
if(RemotingClient.RemotingRole==RemotingRole.ClientWeb) {
Meth.GetVoid(MethodBase.GetCurrentMethod());
return;
}
or
if(RemotingClient.RemotingRole==RemotingRole.ClientWeb) {
return Meth.GetTable(MethodBase.GetCurrentMethod(),insPlan);
}
or
if(RemotingClient.RemotingRole==RemotingRole.ClientWeb) {
return Meth.GetObject<Patient>(MethodBase.GetCurrentMethod(),patNum,isGuarantor,lName);
}

3. Absolutely no passing of queries between methods other than the rare use of Reports.GetTable().
4. No UI logic or elements in the business layer.

The recent changes to AnestheticRecords violated #1, 2, and 4. Sorry.
Jordan Sparks, DMD
http://www.opendental.com

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

Re: New restrictions for OpenDentBusiness

Post by jordansparks » Tue May 12, 2009 7:06 am

If you're looking for someplace to stick your UI classes that are fairly specific to a db table and need to be buried deeper down than a Form, then I suggest creating an "L" class in OpenDental/DataInterface.
Jordan Sparks, DMD
http://www.opendental.com

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

Re: New restrictions for OpenDentBusiness

Post by wjstarck » Tue May 12, 2009 8:28 am

No worries...that explanation helps tremendously, thanks.
Cheers,

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

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

Re: New restrictions for OpenDentBusiness

Post by wjstarck » Tue May 12, 2009 8:53 am

Does this look OK then, assuming I place this class in OpenDental/DataInterface?

Code: Select all

using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Printing;
using System.Collections;
using System.ComponentModel;
using System.Globalization;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using Microsoft.Win32;
using CodeBase;
using System.IO;
using OpenDentBusiness;

namespace OpenDental{

///<summary>Prints the contents of the active window</summary>
public class PrintWindowL{

		//
		//Variables used for printing functionality..
		//
		public PrintDialog printDialog;
		public System.IO.Stream streamToPrint;
		public FileStream fileStream;
		public PrintDocument printDocument;
		public IntPtr thisHandle;
		public string streamType;
		[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
		public static extern bool BitBlt(
			IntPtr hdcDest, // handle to destination DC
			int nXDest, // x-coord of destination upper-left corner
			int nYDest, // y-coord of destination upper-left corner
			int nWidth, // width of destination rectangle
			int nHeight, // height of destination rectangle
			IntPtr hdcSrc, // handle to source DC
			int nXSrc, // x-coordinate of source upper-left corner
			int nYSrc, // y-coordinate of source upper-left corner
			System.Int32 dwRop); // raster operation code
		
			public void printDocument_PrintPage(object sender, PrintPageEventArgs e){
				System.IO.StreamReader streamReader = new StreamReader(this.streamToPrint);
				System.Drawing.Image image = System.Drawing.Image.FromStream(this.streamToPrint);
				int x = e.MarginBounds.X;
				int y = e.MarginBounds.Y;
				int width = image.Width;
				int height = image.Height;
				if  ((width / e.MarginBounds.Width) > (height / e.MarginBounds.Height))
					{
						width =  image.Width * e.MarginBounds.Width /image.Width; 
						height = image.Height * e.MarginBounds.Width/image.Width; 
					}
				else
					{
						width = image.Width * e.MarginBounds.Width / image.Height;
						height = image.Height; //e.MarginBounds.Height;
					}
				System.Drawing.Rectangle destRect = new System.Drawing.Rectangle(x, y, width, height);
				e.Graphics.DrawImage(image, destRect, 0, 0, image.Width,image.Height,System.Drawing.GraphicsUnit.Pixel);
		}

		public void PrintWindow(IntPtr thisHandle){
			string tempFile = Path.GetTempPath() + "PrintPage.jpg";
			CaptureWindowToFile(thisHandle, tempFile, System.Drawing.Imaging.ImageFormat.Jpeg) ;
			FileStream fileStream = new FileStream(tempFile, FileMode.Open, FileAccess.Read);
			StartPrint(fileStream,"Image");
			fileStream.Close();
			if (System.IO.File.Exists(tempFile)) {
					System.IO.File.Delete(tempFile);
				}
		}

		public void StartPrint(Stream streamToPrint, string streamType){
			printDocument = new PrintDocument();
			this.printDocument.PrintPage += new PrintPageEventHandler(printDocument_PrintPage);
			this.streamToPrint = streamToPrint;
			this.streamType = streamType;
			System.Windows.Forms.PrintDialog PrintDialog1 = new PrintDialog();
			PrintDialog1.AllowSomePages = true;
			PrintDialog1.ShowHelp = true;
			PrintDialog1.Document = printDocument;
			PrintDialog1.UseEXDialog = true; //needed because PrintDialog was not showing on 64 bit Vista systems
				if (PrintDialog1.ShowDialog() == DialogResult.OK) {
						try {
								this.printDocument.Print();
							}
						catch {
								MessageBox.Show("That printer was not found. Please check connections or try another printer");
							}
					}
		}

		public static void CaptureWindowToFile(IntPtr handle, string filename, ImageFormat format){
			Image img = CaptureWindow(handle);
			img.Save(filename,format);
		}

		public static Image CaptureWindow(IntPtr handle){
			// get the hDC of the target window
			IntPtr hdcSrc = User32.GetWindowDC(handle);
			// get the size
			User32.RECT windowRect = new User32.RECT();
			User32.GetWindowRect(handle,ref windowRect);
			int width = windowRect.right - windowRect.left;
			int height = windowRect.bottom - windowRect.top;
			// create a device context we can copy to
			IntPtr hdcDest = GDI32.CreateCompatibleDC(hdcSrc);
			// create a bitmap we can copy it to,
			// using GetDeviceCaps to get the width/height
			IntPtr hBitmap = GDI32.CreateCompatibleBitmap(hdcSrc,width,height); 
			// select the bitmap object
			IntPtr hOld = GDI32.SelectObject(hdcDest,hBitmap);
			// bitblt over
			GDI32.BitBlt(hdcDest,0,0,width,height,hdcSrc,0,0,GDI32.SRCCOPY);
			// restore selection
			GDI32.SelectObject(hdcDest,hOld);
			// clean up 
			GDI32.DeleteDC(hdcDest);
			User32.ReleaseDC(handle,hdcSrc);
			// get a .NET image object for it
			Image img = Image.FromHbitmap(hBitmap);
			// free up the Bitmap object
			GDI32.DeleteObject(hBitmap);
				return img;
			}

			private class GDI32{
				public const int SRCCOPY = 0x00CC0020; // BitBlt dwRop parameter
					[DllImport("gdi32.dll")]
				public static extern bool BitBlt(IntPtr hObject,int nXDest,int nYDest,
					int nWidth,int nHeight,IntPtr hObjectSource,
					int nXSrc,int nYSrc,int dwRop);
					[DllImport("gdi32.dll")]
				public static extern IntPtr CreateCompatibleBitmap(IntPtr hDC,int nWidth, 
					int nHeight);
					[DllImport("gdi32.dll")]
				public static extern IntPtr CreateCompatibleDC(IntPtr hDC);
					[DllImport("gdi32.dll")]
				public static extern bool DeleteDC(IntPtr hDC);
					[DllImport("gdi32.dll")]
				public static extern bool DeleteObject(IntPtr hObject);
					[DllImport("gdi32.dll")]
				public static extern IntPtr SelectObject(IntPtr hDC,IntPtr hObject);
				}

			private class User32{
					[StructLayout(LayoutKind.Sequential)]
					
			public struct RECT{
					public int left;
					public int top;
					public int right;
					public int bottom;
				}
					[DllImport("user32.dll")]
			public static extern IntPtr GetDesktopWindow();
					[DllImport("user32.dll")]
			public static extern IntPtr GetWindowDC(IntPtr hWnd);
					[DllImport("user32.dll")]
			public static extern IntPtr ReleaseDC(IntPtr hWnd,IntPtr hDC);
					[DllImport("user32.dll")]
			public static extern IntPtr GetWindowRect(IntPtr hWnd,ref RECT rect);
			}
	
	}
}
Cheers,

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

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

Re: New restrictions for OpenDentBusiness

Post by jordansparks » Tue May 12, 2009 11:10 am

Sure. Just not in OpenDentBusiness/Data Interface.
Jordan Sparks, DMD
http://www.opendental.com

Post Reply