Exemplo n.º 1
0
        private void FillCombo(ComboBox combo)
        {
            PrintSituation sit           = GetSit(combo);
            Printer        printerForSit = Printers.GetForSit(sit);
            string         printerName   = "";

            if (printerForSit != null)
            {
                printerName = printerForSit.PrinterName;
            }
            combo.Items.Clear();
            if (combo == comboDefault)
            {
                combo.Items.Add(Lan.g(this, "Windows default"));
            }
            else
            {
                combo.Items.Add(Lan.g(this, "default"));
            }
            for (int i = 0; i < PrinterSettings.InstalledPrinters.Count; i++)
            {
                combo.Items.Add(PrinterSettings.InstalledPrinters[i]);
                if (printerName == PrinterSettings.InstalledPrinters[i])
                {
                    combo.SelectedIndex = i + 1;
                }
            }
            if (combo.SelectedIndex == -1)
            {
                combo.SelectedIndex = 0;
            }
        }
Exemplo n.º 2
0
 ///<summary>Must supply the printSituation so that when user clicks print, we know where to send it.  Must supply total pages</summary>
 public PrintPreview(PrintSituation sit, PrintDocument document, int totalPages)
 {
     InitializeComponent();            // Required for Windows Form Designer support
     Sit        = sit;
     Document   = document;
     TotalPages = totalPages;
 }
Exemplo n.º 3
0
        ///<summary>Gets a PrintDocument that has some added functionality.  All printing in Open Dental should use this method (or an ODprintout object) for printing.</summary>
        ///<param name="printPageHandler">The handler that will get invoked when printing.  This defines how to draw each page.</param>
        ///<param name="printSit">ODprintout does not do anything with this field.  But when PrinterL.TrySetPrinter() is invoked we will provide the information if needed.</param>
        ///<param name="auditPatNum">ODprintout does not do anything with this field.  But when PrinterL.TrySetPrinter() is invoked we will provide the information if needed.</param>
        ///<param name="auditDescription">ODprintout does not do anything with this field.  But when PrinterL.TrySetPrinter() is invoked we will provide the information if needed.</param>
        ///<param name="margins">When set, this will override the default margins of "new Margins(25,25,40,40)".</param>
        ///<param name="printoutOrigin">Defaults to printer default.  Set to AtMargin if the graphics origin starts at the page margins; AtZero if the graphics origin is at the top-left corner of the printable page.</param>
        ///<param name="paperSize">When set, this will override the default paperSize of "new PaperSize("default",850,1100)".</param>
        ///<param name="totalPages">When creating an ODprintout for print previewing, this defines the total number of pages.  Required if multiple pages needed when using Classic printing in FormPrintPreview.</param>
        ///<param name="printoutOrientation">Defaults to printers default value.  Otherwise specify a value for either landscape or portrait.</param>
        ///<param name="duplex">Use default unless double-sided printing is required.</param>
        ///<param name="copies">Gets or sets the number of copies of the document to print.</param>
        ///<returns>A new ODprintout with the given args that serves as a conduit for centralized printing and previewing methods with nice error messages.</returns>
        public static ODprintout CreateODprintout(PrintPageEventHandler printPageHandler = null, string auditDescription = ""
                                                  , PrintSituation printSit = PrintSituation.Default, long auditPatNum   = 0, Margins margins   = null, PrintoutOrigin printoutOrigin        = PrintoutOrigin.Default
                                                  , PaperSize paperSize     = null, int totalPages = 1, PrintoutOrientation printoutOrientation = PrintoutOrientation.Default, Duplex duplex = Duplex.Default, short copies = 1
                                                  , bool isErrorSuppressed  = false)
        {
            ODprintout printout = new ODprintout(
                printPageHandler,
                printSit,
                auditPatNum,
                auditDescription,
                margins,
                printoutOrigin,
                paperSize,
                printoutOrientation,
                duplex,
                copies,
                totalPages
                );

            if (!isErrorSuppressed && printout.SettingsErrorCode != PrintoutErrorCode.Success)
            {
                ShowError(printout);
            }
            return(printout);
        }
Exemplo n.º 4
0
Arquivo: Printing.cs Projeto: mnisl/OD
 public XPSPrinterController(PrintSituation sit, long patNum)
 {
     _sit = sit;
     _patient = Patients.GetPat(patNum);
     string patfolder = ImageStore.GetPatientFolder(_patient, ImageStore.GetPreferredAtoZpath());
     this.FileName = Path.Combine(patfolder, string.Format("{0}.{1:yyyy.MM.dd.HH.mm.ss}.xps", sit, DateTime.Now));
 }
Exemplo n.º 5
0
		///<summary>Must supply the printSituation so that when user clicks print, we know where to send it.  Must supply total pages.  PatNum and AuditDescription used to make audit log entry.  PatNum can be 0.  Audit Log Text will show AuditDescription exactly.</summary>
		public FormPrintPreview(PrintSituation sit,PrintDocument document,int totalPages,long patNum,string auditDescription) {
			InitializeComponent();// Required for Windows Form Designer support
			Sit=sit;
			Document=document;
			TotalPages=totalPages;
			PatNumCur=patNum;
			AuditDescription=auditDescription;
		}
Exemplo n.º 6
0
Arquivo: PrinterL.cs Projeto: mnisl/OD
		///<summary>Called from many places in the program.  Every single time we print, this function is used to figure out which printer to use.
		///It also handles displaying the dialog if necessary.  Tests to see if the selected printer is valid, and if not, then it gives user the 
		///option to print to an available printer.  PatNum and AuditDescription used to make audit log entry.  PatNum can be 0.  Audit Log Text will 
		///show AuditDescription exactly.</summary>
		public static bool SetPrinter(PrintDocument pd,PrintSituation sit,long patNum,string auditDescription){
			PrinterSettings pSet=pd.PrinterSettings;
			//pSet will always be new when this function is called
			//0.5. Get the name of the Windows default printer.
			//This method only works when the pSet is still new.
			//string winDefault=pSet.PrinterName;
			//1. If a default printer is set in OD,
			//and it is in the list of installed printers, use it.
			bool doPrompt=false;
			Printer printerForSit=Printers.GetForSit(PrintSituation.Default);//warning: this changes
			string printerName="";
			if(printerForSit!=null){
				printerName=printerForSit.PrinterName;
				doPrompt=printerForSit.DisplayPrompt;
				if(Printers.PrinterIsInstalled(printerName)) {
					pSet.PrinterName=printerName;
				}
			}
			//2. If a printer is set for this situation,
			//and it is in the list of installed printers, use it.
			if(sit!=PrintSituation.Default){
				printerForSit=Printers.GetForSit(sit);
				printerName="";
				if(printerForSit!=null){
					printerName=printerForSit.PrinterName;
					doPrompt=printerForSit.DisplayPrompt;
					if(Printers.PrinterIsInstalled(printerName)) {
						pSet.PrinterName=printerName;
					}
				}
			}
			//4. Present the dialog
			if(!doPrompt){
				//Create audit log entry for printing.  PatNum can be 0.
				SecurityLogs.MakeLogEntry(Permissions.Printing,patNum,auditDescription);
				return true;
			}
			PrintDialog dialog=new PrintDialog();
			//pSet.Collate is true here
			dialog.PrinterSettings=pSet;
			dialog.UseEXDialog=true;
			#if DEBUG
				//just use defaults
			#else
				DialogResult result=dialog.ShowDialog();
				//but dialog.PrinterSettings.Collate is false here.  I don't know what triggers the change.
				pSet.Collate=true;//force it back to true.
				if(result!=DialogResult.OK){
					return false;
				}
				//if(!dialog.PrinterSettings.IsValid){//not needed since we have already checked each name.
				//pd2.PrinterSettings=printDialog2.PrinterSettings;
				//}
			#endif
			//Create audit log entry for printing.  PatNum can be 0.
			SecurityLogs.MakeLogEntry(Permissions.Printing,patNum,auditDescription);
			return true;
		}
Exemplo n.º 7
0
 ///<summary>Must supply the printSituation so that when user clicks print, we know where to send it.  Must supply total pages.  PatNum and AuditDescription used to make audit log entry.  PatNum can be 0.  Audit Log Text will show AuditDescription exactly.</summary>
 public FormPrintPreview(PrintSituation sit, PrintDocument document, int totalPages, long patNum, string auditDescription)
 {
     InitializeComponent();            // Required for Windows Form Designer support
     Sit              = sit;
     Document         = document;
     TotalPages       = totalPages;
     PatNumCur        = patNum;
     AuditDescription = auditDescription;
 }
Exemplo n.º 8
0
		///<summary>Gets directly from database</summary>
		public static Printer GetOnePrinter(PrintSituation sit,long compNum) {
			if(RemotingClient.RemotingRole==RemotingRole.ClientWeb) {
				return Meth.GetObject<Printer>(MethodBase.GetCurrentMethod(),sit,compNum);
			}
			string command="SELECT * FROM printer WHERE "
				+"PrintSit = '"      +POut.Long((int)sit)+"' "
				+"AND ComputerNum ='"+POut.Long(compNum)+"'";
			return Crud.PrinterCrud.SelectOne(command);
		}
Exemplo n.º 9
0
        private PrintSituation GetSit(Control contr)
        {
            PrintSituation sit = PrintSituation.Default;

            switch (contr.Name)
            {
            default:
                MessageBox.Show("error. " + contr.Name);
                break;

            case "comboDefault":
            case "checkDefault":
                sit = PrintSituation.Default;
                break;

            case "comboAppointments":
            case "checkAppointments":
                sit = PrintSituation.Appointments;
                break;

            case "comboClaim":
            case "checkClaim":
                sit = PrintSituation.Claim;
                break;

            case "comboLabelSheet":
            case "checkLabelSheet":
                sit = PrintSituation.LabelSheet;
                break;

            case "comboLabelSingle":
            case "checkLabelSingle":
                sit = PrintSituation.LabelSingle;
                break;

            case "comboPostcard":
            case "checkPostcard":
                sit = PrintSituation.Postcard;
                break;

            case "comboRx":
            case "checkRx":
                sit = PrintSituation.Rx;
                break;

            case "comboStatement":
            case "checkStatement":
                sit = PrintSituation.Statement;
                break;

            case "comboTPPerio":
            case "checkTPPerio":
                sit = PrintSituation.TPPerio;
                break;
            }
            return(sit);
        }
Exemplo n.º 10
0
 ///<summary>Gets a PrintDocument that has some added functionality.  All printing in Open Dental should use this method (or an ODprintout object) for printing.</summary>
 ///<param name="printPageEventHandler">The handler that will get invoked when printing.  This defines how to draw each page.</param>
 ///<param name="printSit">ODprintout does not do anything with this field. But when ValidationDelegate is invoked we will provide the information if needed.</param>
 ///<param name="auditPatNum">ODprintout does not do anything with this field. But when ValidationDelegate is invoked we will provide the information if needed.</param>
 ///<param name="auditDescription">ODprintout does not do anything with this field. But when ValidationDelegate is invoked we will provide the information if needed.</param>
 ///<param name="margins">When set, this will override the default margins of "new Margins(25,25,40,40)".</param>
 ///<param name="printoutOrigin">Defaults to printer default.  Set to AtMargin if the graphics origin starts at the page margins; AtZero if the graphics origin is at the top-left corner of the printable page.</param>
 ///<param name="paperSize">When set, this will override the default paperSize of "new PaperSize("default",850,1100)".</param>
 ///<param name="totalPages">When creating an ODprintout for print previewing, this defines the total number of pages.</param>
 ///<param name="printoutOrientation">Defaults to printers default value.  Otherwise specify a value for either landscape or portrait.</param>
 ///<param name="duplex">Typically set when performing double-sided printing.</param>
 ///<param name="copies">Gets or sets the number of copies of the document to print.</param>
 ///<param name="totalPages">ODprintout does not do anything with this field. But when ValidationDelegate is invoked we will provide the information if needed. Defaults to 1.</param>
 ///<param name="printOrPreviewExceptionDelegate">Any custom delegate that the calling method wants to happen when printing or previewing throws an exception.</param>
 ///<param name="tryPreviewDelegate">Required to be implemented if the calling method needs the ability to preview.</param>
 ///<param name="tryPrintOrDebugPreviewDelegate">Same as tryPreviewDelegate, but defines isPreview based on if program is in DEBUG mode.</param>
 ///<returns>A new ODprintout with the given args that serves as a conduit safe printing and previewing methods.</returns>
 public ODprintout(PrintPageEventHandler printPageEventHandler = null, PrintSituation printSit = PrintSituation.Default, long auditPatNum = 0, string auditDescription   = ""
                   , Margins margins = null, PrintoutOrigin printoutOrigin = PrintoutOrigin.Default, PaperSize paperSize = null, PrintoutOrientation printoutOrientation = PrintoutOrientation.Default
                   , Duplex duplex   = Duplex.Default, short copies        = 1, int totalPages = 1) : base()
 {
     CurPrintout = this;
     _printDoc   = new PrintDocument();
     //if(InitPrintSettings!=null) {
     //	_printDoc.PrinterSettings=InitPrintSettings;
     //	InitPrintSettings=null;
     //}
     Situation        = printSit;
     AuditPatNum      = auditPatNum;
     AuditDescription = auditDescription;
     TotalPages       = totalPages;
     if (!HasValidSettings)
     {
         return;
     }
     _printDoc.PrintPage += printPageEventHandler;
     if (printoutOrientation != PrintoutOrientation.Default)
     {
         _printDoc.DefaultPageSettings.Landscape = (printoutOrientation == PrintoutOrientation.Landscape)?true:false;
     }
     if (printoutOrigin != PrintoutOrigin.Default)
     {
         _printDoc.OriginAtMargins = (printoutOrigin == PrintoutOrigin.AtMargin)?true:false;
     }
     _printDoc.DefaultPageSettings.Margins = (margins ?? new Margins(25, 25, 40, 40));
     if (paperSize == null)
     {
         //This prevents a bug caused by some printer drivers not reporting their papersize.
         //But remember that other countries use A4 paper instead of 8 1/2 x 11.
         if ((InvalidMinDefaultPageWidth != -1 && _printDoc.DefaultPageSettings.PrintableArea.Width <= InvalidMinDefaultPageWidth) ||
             (InvalidMinDefaultPageHeight != -1 && _printDoc.DefaultPageSettings.PrintableArea.Height <= InvalidMinDefaultPageHeight))
         {
             _printDoc.DefaultPageSettings.PaperSize = new PaperSize("default", 850, 1100);
         }
         InvalidMinDefaultPageHeight = 0;
         InvalidMinDefaultPageWidth  = -1;
     }
     else
     {
         _printDoc.DefaultPageSettings.PaperSize = paperSize;
     }
     _printDoc.PrinterSettings.Copies = copies;
     if (duplex != Duplex.Default)
     {
         _printDoc.PrinterSettings.Duplex = duplex;
     }
     if (ODBuild.IsWeb())
     {
         //https://referencesource.microsoft.com/#System.Drawing/commonui/System/Drawing/Printing/PrintDocument.cs,3f3c2622b65be86a
         //The PrintController property will create a PrintControllerWithStatusDialog if no print controller is explictly set.
         _printDoc.PrintController = new StandardPrintController();              //Default PrintController shows a dialog that locks up web.
     }
 }
Exemplo n.º 11
0
        ///<summary>Called from many places in the program.  Every single time we print, this function is used to figure out which printer to use.  It also handles displaying the dialog if necessary.  Tests to see if the selected printer is valid, and if not, then it gives user the option to print to an available printer.</summary>
        public static bool SetPrinter(PrintDocument pd, PrintSituation sit)
        {
            PrinterSettings pSet = pd.PrinterSettings;
            //pSet will always be new when this function is called
            //0.5. Get the name of the Windows default printer.
            //This method only works when the pSet is still new.
            //string winDefault=pSet.PrinterName;
            //1. If a default printer is set in OD,
            //and it is in the list of installed printers, use it.
            bool    prompt        = false;
            Printer printerForSit = GetForSit(PrintSituation.Default);          //warning: this changes
            string  printerName   = "";

            if (printerForSit != null)
            {
                printerName = printerForSit.PrinterName;
                prompt      = printerForSit.DisplayPrompt;
                if (PrinterIsInstalled(printerName))
                {
                    pSet.PrinterName = printerName;
                }
            }
            //2. If a printer is set for this situation,
            //and it is in the list of installed printers, use it.
            if (sit != PrintSituation.Default)
            {
                printerForSit = GetForSit(sit);
                printerName   = "";
                if (printerForSit != null)
                {
                    printerName = printerForSit.PrinterName;
                    prompt      = printerForSit.DisplayPrompt;
                    if (PrinterIsInstalled(printerName))
                    {
                        pSet.PrinterName = printerName;
                    }
                }
            }
            //4. Present the dialog
            if (!prompt)
            {
                return(true);
            }
            PrintDialog dialog = new PrintDialog();

            dialog.PrinterSettings = pSet;
            if (dialog.ShowDialog() != DialogResult.OK)
            {
                return(false);
            }
            //if(!dialog.PrinterSettings.IsValid){//not needed since we have already checked each name.
            //pd2.PrinterSettings=printDialog2.PrinterSettings;
            //}
            return(true);
        }
Exemplo n.º 12
0
        ///<summary>Gets the set printer whether or not it is valid.  Returns null if the current computer OR printer cannot be found.</summary>
        public static Printer GetForSit(PrintSituation sit)
        {
            //No need to check RemotingRole; no call to db.
            Computer compCur = Computers.GetCur();

            if (compCur == null)
            {
                return(null);
            }
            return(GetFirstOrDefault(x => x.ComputerNum == compCur.ComputerNum && x.PrintSit == sit));
        }
Exemplo n.º 13
0
        private void FillCheck(CheckBox check)
        {
            PrintSituation sit           = GetSit(check);
            Printer        printerForSit = Printers.GetForSit(sit);

            if (printerForSit == null)
            {
                check.Checked = false;
                return;
            }
            check.Checked = printerForSit.DisplayPrompt;
        }
Exemplo n.º 14
0
        ///<summary>Gets directly from database</summary>
        public static Printer GetOnePrinter(PrintSituation sit, long compNum)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                return(Meth.GetObject <Printer>(MethodBase.GetCurrentMethod(), sit, compNum));
            }
            string command = "SELECT * FROM printer WHERE "
                             + "PrintSit = '" + POut.Long((int)sit) + "' "
                             + "AND ComputerNum ='" + POut.Long(compNum) + "'";

            return(Crud.PrinterCrud.SelectOne(command));
        }
Exemplo n.º 15
0
        ///<summary></summary>
        public static Printer GetOnePrinter(PrintSituation sit, int compNum)
        {
            string command = "SELECT * FROM printer WHERE "
                             + "PrintSit = '" + POut.PInt((int)sit) + "' "
                             + "AND ComputerNum ='" + POut.PInt(compNum) + "'";

            Printer[] printerList = RefreshAndFill(command);
            if (printerList.Length == 0)
            {
                return(null);
            }
            return(printerList[0]);
        }
Exemplo n.º 16
0
        ///<summary>Gets the set printer whether or not it is valid.</summary>
        public static Printer GetForSit(PrintSituation sit)
        {
            Computer compCur = Computers.GetCur();

            for (int i = 0; i < List.Length; i++)
            {
                if (List[i].ComputerNum == compCur.ComputerNum &&
                    List[i].PrintSit == sit)
                {
                    return(List[i]);
                }
            }
            return(null);
        }
Exemplo n.º 17
0
        ///<summary>Surround with try/catch.</summary>
        public static void PrintBatch(List <Sheet> sheetBatch)
        {
            //currently no validation for parameters in a batch because of the way it was created.
            //could validate field names here later.
            SheetList     = sheetBatch;
            sheetsPrinted = 0;
            PrintDocument pd = new PrintDocument();

            pd.OriginAtMargins = true;
            pd.PrintPage      += new PrintPageEventHandler(pd_PrintPage);
            if (sheetBatch[0].Width > 0 && sheetBatch[0].Height > 0)
            {
                pd.DefaultPageSettings.PaperSize = new PaperSize("Default", sheetBatch[0].Width, sheetBatch[0].Height);
            }
            PrintSituation sit = PrintSituation.Default;

            pd.DefaultPageSettings.Landscape = sheetBatch[0].IsLandscape;
            switch (sheetBatch[0].SheetType)
            {
            case SheetTypeEnum.LabelPatient:
            case SheetTypeEnum.LabelCarrier:
            case SheetTypeEnum.LabelReferral:
                sit = PrintSituation.LabelSingle;
                break;

            case SheetTypeEnum.ReferralSlip:
                sit = PrintSituation.Default;
                break;
            }
            //later: add a check here for print preview.
                        #if DEBUG
            pd.DefaultPageSettings.Margins = new Margins(20, 20, 0, 0);
            FormPrintPreview printPreview = new FormPrintPreview(sit, pd, SheetList.Count, 0, "Batch of " + sheetBatch[0].Description + " printed");
            printPreview.ShowDialog();
                        #else
            try {
                if (!PrinterL.SetPrinter(pd, sit, 0, "Batch of " + sheetBatch[0].Description + " printed"))
                {
                    return;
                }
                pd.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0);
                pd.Print();
            }
            catch (Exception ex) {
                throw ex;
                //MessageBox.Show(Lan.g("Sheet","Printer not available"));
            }
                        #endif
        }
Exemplo n.º 18
0
		///<summary>Gets the set printer whether or not it is valid.</summary>
		public static Printer GetForSit(PrintSituation sit){
			//No need to check RemotingRole; no call to db.
			if(list==null) {
				RefreshCache();
			}
			Computer compCur=Computers.GetCur();
			for(int i=0;i<list.Length;i++){
				if(list[i].ComputerNum==compCur.ComputerNum
					&& list[i].PrintSit==sit)
				{
					return list[i];
				}
			}
			return null;
		}
Exemplo n.º 19
0
        ///<summary>Attempts to print a PrintDocument that has some added functionality.  All printing in Open Dental should use this method (or an ODprintout object) for printing.</summary>
        ///<param name="printPageEventHandler">The handler that will get invoked when printing.  This defines how to draw each page.</param>
        ///<param name="printSit">ODprintout does not do anything with this field.  But when PrinterL.TrySetPrinter() is invoked we will provide the information if needed.</param>
        ///<param name="auditPatNum">ODprintout does not do anything with this field.  But when PrinterL.TrySetPrinter() is invoked we will provide the information if needed.</param>
        ///<param name="auditDescription">ODprintout does not do anything with this field.  But when PrinterL.TrySetPrinter() is invoked we will provide the information if needed.</param>
        ///<param name="margins">When set, this will override the default margins of "new Margins(25,25,40,40)".</param>
        ///<param name="printoutOrigin">Defaults to printer default.  Set to AtMargin if the graphics origin starts at the page margins; AtZero if the graphics origin is at the top-left corner of the printable page.</param>
        ///<param name="printoutOrientation">Defaults to printers default value.  Otherwise specify a value for either landscape or portrait.</param>
        ///<param name="duplex">Use default unless double-sided printing is required.</param>
        ///<returns>Returns true if succesfully printed.</returns>
        public static bool TryPrint(PrintPageEventHandler printPageEventHandler, string auditDescription = "", long auditPatNum = 0
                                    , PrintSituation printSit = PrintSituation.Default, Margins margins = null, PrintoutOrigin printoutOrigin = PrintoutOrigin.Default
                                    , PrintoutOrientation printoutOrientation = PrintoutOrientation.Default, Duplex duplex = Duplex.Default)
        {
            ODprintout printout = new ODprintout(
                printPageEventHandler,
                printSit,
                auditPatNum,
                auditDescription,
                margins,
                printoutOrigin,
                printoutOrientation: printoutOrientation,
                duplex: duplex
                );

            return(TryPrint(printout));
        }
Exemplo n.º 20
0
        ///<summary>Either does an insert or an update to the database if need to create a Printer object.  Or it also deletes a printer object if needed.</summary>
        public static void PutForSit(PrintSituation sit, string computerName, string printerName, bool displayPrompt)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                Meth.GetVoid(MethodBase.GetCurrentMethod(), sit, computerName, printerName, displayPrompt);
                return;
            }
            //Computer[] compList=Computers.Refresh();
            //Computer compCur=Computers.GetCur();
            string command = "SELECT ComputerNum FROM computer "
                             + "WHERE CompName = '" + POut.String(computerName) + "'";
            DataTable table = Db.GetTable(command);

            if (table.Rows.Count == 0)
            {
                return;                //computer not yet entered in db.
            }
            long compNum = PIn.Long(table.Rows[0][0].ToString());
            //only called from PrinterSetup window. Get info directly from db, then refresh when closing window.
            Printer existing = GetOnePrinter(sit, compNum); //GetForSit(sit);

            if (printerName == "" && !displayPrompt)        //then should not be an entry in db
            {
                if (existing != null)                       //need to delete Printer
                {
                    Delete(existing);
                }
            }
            else if (existing == null)
            {
                Printer cur = new Printer();
                cur.ComputerNum   = compNum;
                cur.PrintSit      = sit;
                cur.PrinterName   = printerName;
                cur.DisplayPrompt = displayPrompt;
                Insert(cur);
            }
            else
            {
                existing.PrinterName   = printerName;
                existing.DisplayPrompt = displayPrompt;
                Update(existing);
            }
        }
Exemplo n.º 21
0
        ///<summary>Gets the set printer whether or not it is valid.</summary>
        public static Printer GetForSit(PrintSituation sit)
        {
            //No need to check RemotingRole; no call to db.
            if (list == null)
            {
                RefreshCache();
            }
            Computer compCur = Computers.GetCur();

            for (int i = 0; i < list.Length; i++)
            {
                if (list[i].ComputerNum == compCur.ComputerNum &&
                    list[i].PrintSit == sit)
                {
                    return(list[i]);
                }
            }
            return(null);
        }
Exemplo n.º 22
0
        ///<summary>Attempts to print if in RELEASE mode or if in DEBUG mode will open ODprintout in FormPrintPreview.</summary>
        ///<param name="printPageEventHandler">The handler that will get invoked when printing.  This defines how to draw each page.</param>
        ///<param name="auditDescription">ODprintout does not do anything with this field.  But when PrinterL.TrySetPrinter() is invoked we will provide the information if needed.</param>
        ///<param name="printSit">ODprintout does not do anything with this field.  But when PrinterL.TrySetPrinter() is invoked we will provide the information if needed.</param>
        ///<param name="margins">When set, this will override the default margins of "new Margins(25,25,40,40)".</param>
        ///<param name="printoutOrigin">Defaults to printer default.  Set to AtMargin if the graphics origin starts at the page margins; AtZero if the graphics origin is at the top-left corner of the printable page.</param>
        ///<param name="printoutOrientation">Defaults to printers default value.  Otherwise specify a value for either landscape or portrait.</param>
        ///<returns>Returns true if succesfully printed, or if preview is shown and OK is clicked.</returns>
        public static bool TryPrintOrDebugClassicPreview(PrintPageEventHandler printPageEventHandler, string auditDescription, Margins margins = null
                                                         , int totalPages = 1, PrintSituation printSit = PrintSituation.Default, PrintoutOrigin printoutOrigin = PrintoutOrigin.Default
                                                         , PrintoutOrientation printoutOrientation = PrintoutOrientation.Default, bool isForcedPreview = false, long auditPatNum = 0, PaperSize paperSize = null)
        {
            ODprintout printout = new ODprintout(
                printPageEventHandler,
                printSit,
                auditPatNum,
                auditDescription,
                margins,
                printoutOrigin,
                paperSize,
                printoutOrientation,
                totalPages: totalPages
                );

            if (ODBuild.IsDebug() || isForcedPreview)
            {
                return(PreviewClassic(printout));
            }
            return(TryPrint(printout));
        }
Exemplo n.º 23
0
        ///<summary>Either does an insert or an update to the database if need to create a Printer object.  Or it also deletes a printer object if needed.</summary>
        public static void PutForSit(PrintSituation sit, string computerName, string printerName
                                     , bool displayPrompt)
        {
            //Computer[] compList=Computers.Refresh();
            //Computer compCur=Computers.GetCur();
            string command = "SELECT ComputerNum FROM computer "
                             + "WHERE CompName = '" + POut.PString(computerName) + "'";
            DataTable table = General.GetTable(command);

            if (table.Rows.Count == 0)
            {
                return;                //computer not yet entered in db.
            }
            int     compNum  = PIn.PInt(table.Rows[0][0].ToString());
            Printer existing = GetOnePrinter(sit, compNum); //GetForSit(sit);

            if (printerName == "" && !displayPrompt)        //then should not be an entry in db
            {
                if (existing != null)                       //need to delete Printer
                {
                    Delete(existing);
                }
            }
            else if (existing == null)
            {
                Printer cur = new Printer();
                cur.ComputerNum   = compNum;
                cur.PrintSit      = sit;
                cur.PrinterName   = printerName;
                cur.DisplayPrompt = displayPrompt;
                Insert(cur);
            }
            else
            {
                existing.PrinterName   = printerName;
                existing.DisplayPrompt = displayPrompt;
                Update(existing);
            }
        }
Exemplo n.º 24
0
		///<summary>Must supply the printSituation so that when user clicks print, we know where to send it.  Must supply total pages</summary>
		public PrintPreview(PrintSituation sit,PrintDocument document,int totalPages){
			InitializeComponent();// Required for Windows Form Designer support
			Sit=sit;
			Document=document;
			TotalPages=totalPages;
		}
Exemplo n.º 25
0
        ///<summary>Attempts to print if in RELEASE mode or if in DEBUG mode will open ODprintout in FormRpPrintPreview.</summary>
        ///<param name="printPageHandler">The handler that will get invoked when printing.  This defines how to draw each page.</param>
        ///<param name="auditDescription">ODprintout does not do anything with this field.  But when PrinterL.TrySetPrinter() is invoked we will provide the information if needed.</param>
        ///<param name="printSit">ODprintout does not do anything with this field.  But when PrinterL.TrySetPrinter() is invoked we will provide the information if needed.</param>
        ///<param name="auditPatNum">ODprintout does not do anything with this field.  But when PrinterL.TrySetPrinter() is invoked we will provide the information if needed.</param>
        ///<param name="margins">When set, this will override the default margins of "new Margins(25,25,40,40)".</param>
        ///<param name="printoutOrigin">Defaults to printer default.  Set to AtMargin if the graphics origin starts at the page margins; AtZero if the graphics origin is at the top-left corner of the printable page.</param>
        ///<param name="printoutOrientation">Defaults to printers default value.  Otherwise specify a value for either landscape or portrait.</param>
        ///<returns>Returns true if succesfully printed, or if preview is shown and OK is clicked.</returns>
        public static bool TryPrintOrDebugRpPreview(PrintPageEventHandler printPageHandler, string auditDescription
                                                    , PrintoutOrientation printoutOrientation = PrintoutOrientation.Default, PrintSituation printSit = PrintSituation.Default, long auditPatNum = 0
                                                    , Margins margins = null, PrintoutOrigin printoutOrigin = PrintoutOrigin.Default, bool isForcedPreview = false)
        {
            ODprintout printout = new ODprintout(
                printPageHandler,
                printSit,
                auditPatNum,
                auditDescription,
                margins,
                printoutOrigin,
                printoutOrientation: printoutOrientation,
                duplex: Duplex.Default
                );

            if (ODBuild.IsDebug() || isForcedPreview)
            {
                return(RpPreview(printout));
            }
            return(TryPrint(printout));
        }
Exemplo n.º 26
0
		///<summary>Either does an insert or an update to the database if need to create a Printer object.  Or it also deletes a printer object if needed.</summary>
		public static void PutForSit(PrintSituation sit,string computerName, string printerName,bool displayPrompt){
			if(RemotingClient.RemotingRole==RemotingRole.ClientWeb) {
				Meth.GetVoid(MethodBase.GetCurrentMethod(),sit,computerName,printerName,displayPrompt);
				return;
			}
			//Computer[] compList=Computers.Refresh();
			//Computer compCur=Computers.GetCur();
			string command="SELECT ComputerNum FROM computer "
				+"WHERE CompName = '"+POut.String(computerName)+"'";
 			DataTable table=Db.GetTable(command);
			if(table.Rows.Count==0){
				return;//computer not yet entered in db.
			}
			long compNum=PIn.Long(table.Rows[0][0].ToString());
			//only called from PrinterSetup window. Get info directly from db, then refresh when closing window. 
			Printer existing=GetOnePrinter(sit,compNum);   //GetForSit(sit);
			if(printerName=="" && !displayPrompt){//then should not be an entry in db
				if(existing!=null){//need to delete Printer
					Delete(existing);
				}
			}
			else if(existing==null){
				Printer cur=new Printer();
				cur.ComputerNum=compNum;
				cur.PrintSit=sit;
				cur.PrinterName=printerName;
				cur.DisplayPrompt=displayPrompt;
				Insert(cur);
			}
			else{
				existing.PrinterName=printerName;
				existing.DisplayPrompt=displayPrompt;
				Update(existing);
			}
		}
Exemplo n.º 27
0
 ///<summary>DEPRECATED.</summary>
 public static bool SetPrinter(PrintDocument printdoc, PrintSituation printSit, long patNum, string auditDescription)
 {
     return(SetPrinter(printdoc.PrinterSettings, printSit, patNum, auditDescription));
 }
Exemplo n.º 28
0
        ///<summary>Attempts to preview (FormPrintPreview) a PrintDocument that has some added functionality.  All printing in Open Dental should use this method (or an ODprintout object) for printing.</summary>
        ///<param name="printPageHandler">The handler that will get invoked when printing.  This defines how to draw each page.</param>
        ///<param name="auditDescription">ODprintout does not do anything with this field.  But when PrinterL.TrySetPrinter() is invoked we will provide the information if needed.</param>
        ///<param name="printSit">ODprintout does not do anything with this field.  But when PrinterL.TrySetPrinter() is invoked we will provide the information if needed.</param>
        ///<param name="margins">When set, this will override the default margins of "new Margins(25,25,40,40)".</param>
        ///<param name="printoutOrigin">Defaults to printer default.  Set to AtMargin if the graphics origin starts at the page margins; AtZero if the graphics origin is at the top-left corner of the printable page.</param>
        ///<param name="paperSize">When set, this will override the default paperSize of "new PaperSize("default",850,1100)".</param>
        ///<param name="totalPages">When creating an ODprintout for print previewing, this defines the total number of pages.</param>
        ///<param name="printoutOrientation">Defaults to printers default value.  Otherwise specify a value for either landscape or portrait.</param>
        ///<returns>Returns true if preview is shown and OK is clicked.</returns>
        public static bool TryPreview(PrintPageEventHandler printPageHandler, string auditDescription, PrintSituation printSit = PrintSituation.Default
                                      , Margins margins = null, PrintoutOrigin printoutOrigin = PrintoutOrigin.Default, PaperSize paperSize = null, PrintoutOrientation printoutOrientation = PrintoutOrientation.Default
                                      , int totalPages  = 1)
        {
            ODprintout printout = new ODprintout(
                printPageHandler,
                printSit,
                auditDescription: auditDescription,
                margins: margins,
                printoutOrigin: printoutOrigin,
                paperSize: paperSize,
                printoutOrientation: printoutOrientation,
                totalPages: totalPages
                );

            return(PreviewClassic(printout));
        }
Exemplo n.º 29
0
        ///<Summary></Summary>
        public static void Print(Sheet sheet, int copies, bool isRxControlled)
        {
            //parameter null check moved to SheetFiller.
            //could validate field names here later.
            SheetList = new List <Sheet>();
            for (int i = 0; i < copies; i++)
            {
                SheetList.Add(sheet.Copy());
            }
            sheetsPrinted = 0;
            PrintDocument pd = new PrintDocument();

            pd.OriginAtMargins = true;
            pd.PrintPage      += new PrintPageEventHandler(pd_PrintPage);
            if (pd.DefaultPageSettings.PrintableArea.Width == 0)
            {
                //prevents bug in some printers that do not specify paper size
                pd.DefaultPageSettings.PaperSize = new PaperSize("paper", 850, 1100);
            }
            if (sheet.SheetType == SheetTypeEnum.LabelPatient ||
                sheet.SheetType == SheetTypeEnum.LabelCarrier ||
                sheet.SheetType == SheetTypeEnum.LabelAppointment ||
                sheet.SheetType == SheetTypeEnum.LabelReferral)
            {            //I think this causes problems for non-label sheet types.
                if (sheet.Width > 0 && sheet.Height > 0)
                {
                    pd.DefaultPageSettings.PaperSize = new PaperSize("Default", sheet.Width, sheet.Height);
                }
            }
            PrintSituation sit = PrintSituation.Default;

            pd.DefaultPageSettings.Landscape = sheet.IsLandscape;
            switch (sheet.SheetType)
            {
            case SheetTypeEnum.LabelPatient:
            case SheetTypeEnum.LabelCarrier:
            case SheetTypeEnum.LabelReferral:
            case SheetTypeEnum.LabelAppointment:
                sit = PrintSituation.LabelSingle;
                break;

            case SheetTypeEnum.ReferralSlip:
                sit = PrintSituation.Default;
                break;

            case SheetTypeEnum.Rx:
                if (isRxControlled)
                {
                    sit = PrintSituation.RxControlled;
                }
                else
                {
                    sit = PrintSituation.Rx;
                }
                break;
            }
            //later: add a check here for print preview.
                        #if DEBUG
            pd.DefaultPageSettings.Margins = new Margins(20, 20, 0, 0);
            FormPrintPreview printPreview;
            printPreview = new FormPrintPreview(sit, pd, SheetList.Count, sheet.PatNum, sheet.Description + " sheet from " + sheet.DateTimeSheet.ToShortDateString() + " printed");
            printPreview.ShowDialog();
                        #else
            try {
                if (sheet.PatNum != null)
                {
                    if (!PrinterL.SetPrinter(pd, sit, sheet.PatNum, sheet.Description + " sheet from " + sheet.DateTimeSheet.ToShortDateString() + " printed"))
                    {
                        return;
                    }
                }
                else
                {
                    if (!PrinterL.SetPrinter(pd, sit, 0, sheet.Description + " sheet from " + sheet.DateTimeSheet.ToShortDateString() + " printed"))
                    {
                        return;
                    }
                }
                pd.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0);
                pd.Print();
            }
            catch (Exception ex) {
                throw ex;
                //MessageBox.Show(Lan.g("Sheet","Printer not available"));
            }
                        #endif
        }
Exemplo n.º 30
0
 private static bool SetPrinter(PrinterSettings pSet, PrintSituation printSit, long patNum, string auditDescription)
 {
     #region 1 - Set default printer if available from this computer.
     //pSet will always be new when this function is called.
     //Get the name of the Windows default printer.
     //This method only works when the pSet is still new.
     //string winDefault=pSet.PrinterName;
     //1. If a default printer is set in OD,
     //and it is in the list of installed printers, use it.
     bool    doPrompt      = false;
     Printer printerForSit = Printers.GetForSit(PrintSituation.Default);          //warning: this changes
     string  printerName   = "";
     if (printerForSit != null)
     {
         printerName = printerForSit.PrinterName;
         doPrompt    = printerForSit.DisplayPrompt;
         if (Printers.PrinterIsInstalled(printerName))
         {
             pSet.PrinterName = printerName;
         }
     }
     #endregion 1
     #region 2 - If a printer is set for this situation, and it is in the list of installed printers, use it.
     if (printSit != PrintSituation.Default)
     {
         printerForSit = Printers.GetForSit(printSit);
         printerName   = "";
         if (printerForSit != null)
         {
             printerName = printerForSit.PrinterName;
             doPrompt    = printerForSit.DisplayPrompt;
             if (Printers.PrinterIsInstalled(printerName))
             {
                 pSet.PrinterName = printerName;
             }
         }
     }
     #endregion 2
     #region 3 - Present the dialog
     if (doPrompt)
     {
         PrintDialog dialog = new PrintDialog();
         dialog.AllowSomePages  = true;
         dialog.PrinterSettings = pSet;
         dialog.UseEXDialog     = true;
         DialogResult result = dialog.ShowDialog();
         pSet.Collate = true;
         if (result != DialogResult.OK)
         {
             return(false);
         }
         if (pSet.PrintRange != PrintRange.AllPages && pSet.ToPage < 1)
         {
             //User set the range to not print any pages.
             return(false);
         }
     }
     #endregion 3
     //Create audit log entry for printing.  PatNum can be 0.
     if (!string.IsNullOrEmpty(auditDescription))
     {
         SecurityLogs.MakeLogEntry(Permissions.Printing, patNum, auditDescription);
     }
     return(true);
 }
Exemplo n.º 31
0
        ///<summary>Called from many places in the program.  Every single time we print, this function is used to figure out which printer to use.
        ///It also handles displaying the dialog if necessary.  Tests to see if the selected printer is valid, and if not, then it gives user the
        ///option to print to an available printer.  PatNum and AuditDescription used to make audit log entry.  PatNum can be 0.  Audit Log Text will
        ///show AuditDescription exactly.</summary>
        public static bool SetPrinter(PrintDocument pd, PrintSituation sit, long patNum, string auditDescription)
        {
            PrinterSettings pSet = pd.PrinterSettings;

            //pSet will always be new when this function is called
            //0.5. Get the name of the Windows default printer.
            //This method only works when the pSet is still new.
            //string winDefault=pSet.PrinterName;
            //1. If a default printer is set in OD,
            //and it is in the list of installed printers, use it.
            if (pSet.PrinterName == null)
            {
                MessageBox.Show("Error: " +
                                "\r\nYou may not have a printer installed\r\n" +
                                "If you do have a printer installed, restarting the workstation may resolve the problem."
                                );
                return(false);
            }
            bool    doPrompt      = false;
            Printer printerForSit = Printers.GetForSit(PrintSituation.Default);          //warning: this changes
            string  printerName   = "";

            if (printerForSit != null)
            {
                printerName = printerForSit.PrinterName;
                doPrompt    = printerForSit.DisplayPrompt;
                if (Printers.PrinterIsInstalled(printerName))
                {
                    pSet.PrinterName = printerName;
                }
            }
            //2. If a printer is set for this situation,
            //and it is in the list of installed printers, use it.
            if (sit != PrintSituation.Default)
            {
                printerForSit = Printers.GetForSit(sit);
                printerName   = "";
                if (printerForSit != null)
                {
                    printerName = printerForSit.PrinterName;
                    doPrompt    = printerForSit.DisplayPrompt;
                    if (Printers.PrinterIsInstalled(printerName))
                    {
                        pSet.PrinterName = printerName;
                    }
                }
            }
            //4. Present the dialog
            if (!doPrompt)
            {
                //Create audit log entry for printing.  PatNum can be 0.
                SecurityLogs.MakeLogEntry(Permissions.Printing, patNum, auditDescription);
                return(true);
            }
            PrintDialog dialog = new PrintDialog();

            //pSet.Collate is true here
            dialog.AllowSomePages  = true;
            dialog.PrinterSettings = pSet;
            dialog.UseEXDialog     = true;
                        #if DEBUG
            //just use defaults
                        #else
            DialogResult result = dialog.ShowDialog();
            //but dialog.PrinterSettings.Collate is false here.  I don't know what triggers the change.
            pSet.Collate = true;                  //force it back to true.
            if (result != DialogResult.OK)
            {
                return(false);
            }
            //if(!dialog.PrinterSettings.IsValid){//not needed since we have already checked each name.
            //pd2.PrinterSettings=printDialog2.PrinterSettings;
            //}
                        #endif
            //Create audit log entry for printing.  PatNum can be 0.
            SecurityLogs.MakeLogEntry(Permissions.Printing, patNum, auditDescription);
            return(true);
        }