Ejemplo 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;
            }
        }
Ejemplo n.º 2
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;
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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);
 }
Ejemplo n.º 5
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    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)
            {
                return(true);
            }
            PrintDialog dialog = new PrintDialog();

            //pSet.Collate is true here
            dialog.PrinterSettings = pSet;
            dialog.UseEXDialog     = true;
                        #if DEBUG
            return(true);
                        #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;
            //}
            return(true);
                        #endif
        }