コード例 #1
0
        private void btnPQ_Click(object sender, EventArgs e)
        {
            int intStart = 1564;
            int intEnd   = 1564;



            int countInside = intStart;

            for (int j = 0; countInside <= intEnd; j++)
            {
                for (int i = 0; i < 2; i++)
                {
                    ThermalLabel _currentThermalLabel = null;
                    _currentThermalLabel = this.GenerateBasicThermalLabel222(countInside);

                    //Neodynamic.SDK.Printing.PrinterSettings _printerSettings = new Neodynamic.SDK.Printing.PrinterSettings();
                    Neodynamic.SDK.Printing.PrinterSettings _printerSettings = new Neodynamic.SDK.Printing.PrinterSettings();
                    _printerSettings.Communication.CommunicationType = CommunicationType.USB;
                    _printerSettings.PrinterName         = _Printer;
                    _printerSettings.Dpi                 = 203;
                    _printerSettings.ProgrammingLanguage = (ProgrammingLanguage)Enum.Parse(typeof(ProgrammingLanguage), "ZPL");
                    PrintOrientation _printOrientation = PrintOrientation.Portrait;

                    using (PrintJob pj = new PrintJob(_printerSettings))
                    {
                        pj.PrintOrientation = _printOrientation;
                        pj.ThermalLabel     = _currentThermalLabel;
                        pj.Print();
                    }
                }
                countInside++;
            }
        }
コード例 #2
0
 static PrintOrientation()
 {
     _table    = new PrintOrientation[4];
     DEFAULT   = new PrintOrientation(1);
     PORTRAIT  = new PrintOrientation(2);
     LANDSCAPE = new PrintOrientation(3);
 }
コード例 #3
0
ファイル: PrintOrientation.cs プロジェクト: 89sos98/npoi
 static PrintOrientation()
 { 
     _table = new PrintOrientation[4];
     DEFAULT = new PrintOrientation(1);
     PORTRAIT = new PrintOrientation(2);
     LANDSCAPE = new PrintOrientation(3);
 }
コード例 #4
0
        public virtual void PrintPage(string docName, object[] images, object[] additionalInfo, int startPage, int endPage, int scaleMode, PrintOrientation orientation, bool annotations, int copyCount, string printer, string driverName, string portName)
        {
            this.orientation  = orientation;
            this.startPage    = startPage;
            this.endPage      = endPage;
            this.images       = images;
            this.printingPage = -1;
            this.scaleMode    = scaleMode;
            this.annotations  = annotations;
            this.copyCount    = copyCount;
            System.Drawing.Printing.PrintDocument pd = new System.Drawing.Printing.PrintDocument();
            pd.DocumentName = docName;
            pd.PrinterSettings.PrinterName = printer;
            pd.PrinterSettings.MaximumPage = endPage;
            pd.PrinterSettings.Copies      = (short)copyCount;
            pd.DefaultPageSettings         = pd.DefaultPageSettings;
            pd.DefaultPageSettings.Margins = new System.Drawing.Printing.Margins((int)pd.DefaultPageSettings.HardMarginX, (int)pd.DefaultPageSettings.HardMarginX, (int)pd.DefaultPageSettings.HardMarginY, (int)pd.DefaultPageSettings.HardMarginY);

            if (pd.PrinterSettings.IsValid && images.Length > 0)
            {
                SetOrientation(IsLand(images[0] as Tiff.PageInfo), pd.DefaultPageSettings);
                pd.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(Print_PrintPage);
                pd.Print();
            }
        }
コード例 #5
0
 /// <summary>
 /// 设置打印纸张大小、旋转角度
 /// </summary>
 /// <param name="width">宽度。单位:像素(Pixcls)</param>
 /// <param name="height">高度。单位:像素(Pixcls)</param>
 /// <param name="orientation">打印方向</param>
 public IBluetoothPrinterProtocol SetPage(int width, int height, PrintOrientation orientation)
 {
     Width  = width;
     Height = height;
     Client.SetPage(width, height, (int)orientation);
     return(this);
 }
コード例 #6
0
        private void btnPrint_Click(object sender, EventArgs e)
        {
            ThermalLabel _currentThermalLabel = null;

            _currentThermalLabel = this.GenerateBasicThermalLabel();

            //Neodynamic.SDK.Printing.PrinterSettings _printerSettings = new Neodynamic.SDK.Printing.PrinterSettings();
            Neodynamic.SDK.Printing.PrinterSettings _printerSettings = new Neodynamic.SDK.Printing.PrinterSettings();
            _printerSettings.Communication.CommunicationType = CommunicationType.USB;
            _printerSettings.PrinterName         = _Printer;
            _printerSettings.Dpi                 = 203;
            _printerSettings.ProgrammingLanguage = (ProgrammingLanguage)Enum.Parse(typeof(ProgrammingLanguage), "ZPL");
            PrintOrientation _printOrientation = PrintOrientation.Portrait;

            int    x = 0;
            bool   isPrinterValid = false;
            string printerName    = _Printer;
            string query          = string.Format("SELECT * from Win32_Printer "
                                                  + "WHERE Name LIKE '%{0}'",
                                                  printerName);

            ManagementObjectSearcher   searcher = new ManagementObjectSearcher(query);
            ManagementObjectCollection coll     = searcher.Get();

            foreach (ManagementObject printer in coll)
            {
                foreach (PropertyData property in printer.Properties)
                {
                    //Console.WriteLine(string.Format("{0}: {1}",
                    //                                property.Name,
                    //                                property.Value));
                    if (x == 85)
                    {
                        isPrinterValid = (bool)property.Value;
                    }
                    x++;
                }
            }

            if (isPrinterValid)
            {
                MessageBox.Show("Impresora no conectada o apagada. Asegúrese de que la impresora esté conectada y que esté encendida. \nPuede imprimir la etiqueta en otro momento en el menú ACTUALIZAR.", "Conecte y encieda la impresora", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                for (int i = 0; i < 2; i++)
                {
                    using (PrintJob pj = new PrintJob(_printerSettings))
                    {
                        pj.PrintOrientation = _printOrientation;
                        pj.ThermalLabel     = _currentThermalLabel;
                        pj.Print();
                    }
                }
                this.Close();
            }
        }
コード例 #7
0
        public PrintAllDialog(int[] docIDs, PrintAllFoldersType folderType)
        {
            switch (folderType)
            {
            case PrintAllFoldersType.WorkFolder:
            case PrintAllFoldersType.SearchFolder:
            case PrintAllFoldersType.InquiryFolder:
                values = new int[docIDs.Length];
                docIDs.CopyTo(values, 0);
                break;

            case PrintAllFoldersType.ArchivFolder:
                break;
            }

            using (
                var dialog = new DocPrintDialog(0, Environment.Settings.Folders.Add("Print"), 0,
                                                Environment.StringResources.GetString("Dialog_PrintAllDialog_Title1")))
            {
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    printImage  = dialog.PrintImage;
                    mainOnly    = dialog.PrintOnlyMain;
                    eForm       = dialog.PrintEForm;
                    orientation = dialog.Orientation;
                    scaleMode   = dialog.ScaleMode;
                    annotations = dialog.Annotations;
                    copiescount = dialog.CopiesCount;
                    prn         = new PrinterOp(DocPrintDialog.Printer, this);
                    printerInfo = Environment.Printers.List[DocPrintDialog.Printer] as PrinterInfo ?? prn.GetInfo();
                }
            }

            if (printImage || eForm)
            {
                InitializeComponent();
            }
            else
            {
                Load  += PrintAllDialog_Load;
                values = null;
                return;
            }

            InitLayoutProperties();
        }
コード例 #8
0
        /// <summary>
        /// Creates a new instance of the PdfPrintMultiplePages class.
        /// </summary>
        /// <param name="horizontal">The number of pages to print horizontally.</param>
        /// <param name="vertical">The number of pages to print vertically.</param>
        /// <param name="orientation">The orientation in which PDF pages are layed out on
        /// the physical page.</param>
        /// <param name="margin">The margin between PDF pages in device units.</param>
        public PdfPrintMultiplePages(int horizontal, int vertical, PrintOrientation orientation, float margin)
        {
            if (horizontal < 1)
            {
                throw new ArgumentOutOfRangeException("horizontal cannot be less than one");
            }
            if (vertical < 1)
            {
                throw new ArgumentOutOfRangeException("vertical cannot be less than one");
            }
            if (margin < 0)
            {
                throw new ArgumentOutOfRangeException("margin cannot be less than zero");
            }

            Horizontal  = horizontal;
            Vertical    = vertical;
            Orientation = orientation;
            Margin      = margin;
        }
コード例 #9
0
        public PrintAllDialog(int[] values)
        {
            this.values = values;
            using (
                var dialog = new DocPrintDialog(0, Environment.Settings.Folders.Add("Print"), 0,
                                                Environment.StringResources.GetString("Dialog_PrintAllDialog_Title1"))
            {
                PrintImage = false
            })
            {
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    printImage  = dialog.PrintImage;
                    mainOnly    = dialog.PrintOnlyMain;
                    eForm       = dialog.PrintEForm;
                    orientation = dialog.Orientation;
                    scaleMode   = dialog.ScaleMode;
                    annotations = dialog.Annotations;
                    copiescount = dialog.CopiesCount;
                    prn         = new PrinterOp(DocPrintDialog.Printer, this);
                    printerInfo = Environment.Printers.List[DocPrintDialog.Printer] as PrinterInfo ?? prn.GetInfo();
                }
            }

            if (printImage || eForm)
            {
                InitializeComponent();
            }
            else
            {
                Load  += PrintAllDialog_Load;
                values = null;
                return;
            }

            InitLayout();
        }
コード例 #10
0
 public bool SetOrientation(Image imgEdit, PrintOrientation orientation, bool change,
                            bool duplex, short copiesCount)
 {
     return(SetOrientation(imgEdit, orientation, change, duplex, copiesCount, false, 0));
 }
コード例 #11
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;

            try
            {
                //Update printer comm object...
                if (this.tabPrintComm.SelectedIndex == 0)
                {
                    //USB
                    _printerSettings.Communication.CommunicationType = CommunicationType.USB;
                    _printerSettings.PrinterName = cboPrinters.SelectedItem.ToString();
                }
                else if (this.tabPrintComm.SelectedIndex == 1)
                {
                    //Parallel
                    _printerSettings.Communication.CommunicationType = CommunicationType.Parallel;
                    _printerSettings.Communication.ParallelPortName  = this.txtParallelPort.Text;
                }
                else if (this.tabPrintComm.SelectedIndex == 2)
                {
                    //Serial
                    _printerSettings.Communication.CommunicationType     = CommunicationType.Serial;
                    _printerSettings.Communication.SerialPortName        = cboSerialPorts.SelectedItem.ToString();
                    _printerSettings.Communication.SerialPortBaudRate    = int.Parse(this.txtBaudRate.Text);
                    _printerSettings.Communication.SerialPortDataBits    = int.Parse(this.txtDataBits.Text);
                    _printerSettings.Communication.SerialPortFlowControl = (SerialPortHandshake)Enum.Parse(typeof(SerialPortHandshake), cboFlowControl.SelectedItem.ToString());
                    _printerSettings.Communication.SerialPortParity      = (SerialPortParity)Enum.Parse(typeof(SerialPortParity), cboParity.SelectedItem.ToString());
                    _printerSettings.Communication.SerialPortStopBits    = (SerialPortStopBits)Enum.Parse(typeof(SerialPortStopBits), cboStopBits.SelectedItem.ToString());
                }
                else if (this.tabPrintComm.SelectedIndex == 3)
                {
                    //Network
                    _printerSettings.Communication.CommunicationType = CommunicationType.Network;
                    System.Net.IPAddress ipAddress = System.Net.IPAddress.None;

                    try
                    {
                        ipAddress = System.Net.IPAddress.Parse(this.txtIPAddress.Text);
                    }
                    catch
                    { }

                    if (ipAddress != System.Net.IPAddress.None) //use IP
                    {
                        _printerSettings.Communication.NetworkIPAddress = ipAddress;
                    }
                    else //try Host Name
                    {
                        _printerSettings.PrinterName = this.txtIPAddress.Text;
                    }

                    _printerSettings.Communication.NetworkPort = int.Parse(this.txtIPPort.Text);
                }

                _printerSettings.Dpi = double.Parse(this.txtDpi.Text);
                if (string.IsNullOrWhiteSpace(((ComboBoxItem)cboProgLang.SelectedItem).Content.ToString()))
                {
                    this.chkPrintAsGraphic.IsChecked = true;
                }
                else
                {
                    _printerSettings.ProgrammingLanguage = (ProgrammingLanguage)Enum.Parse(typeof(ProgrammingLanguage), ((ComboBoxItem)cboProgLang.SelectedItem).Content.ToString());
                }


                _copies           = int.Parse(this.txtCopies.Text);
                _printOrientation = (PrintOrientation)Enum.Parse(typeof(PrintOrientation), ((ComboBoxItem)cboPrintOrientation.SelectedItem).Content.ToString());
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                this.DialogResult = false;
            }
        }
コード例 #12
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            if (this.cboProgLang.SelectedItem.ToString() == "" && this.tabControl1.SelectedIndex != 0)
            {
                this.errorProvider1.SetError(this.cboProgLang, "Please select the printer's programming language");
                return;
            }
            else if (this.cboProgLang.SelectedItem.ToString() == "" && this.tabControl1.SelectedIndex == 0)
            {
                this.chkPrintAsGraphic.Checked = true;
            }
            else
            {
                this.errorProvider1.SetError(this.cboProgLang, "");
            }

            this.DialogResult = DialogResult.OK;

            try
            {
                //Update printer comm object...
                if (this.tabControl1.SelectedIndex == 0)
                {
                    //USB
                    _printerSettings.Communication.CommunicationType = CommunicationType.USB;
                    _printerSettings.PrinterName = this.cboPrinters.SelectedItem.ToString();
                }
                else if (this.tabControl1.SelectedIndex == 1)
                {
                    //Parallel
                    _printerSettings.Communication.CommunicationType = CommunicationType.Parallel;
                    _printerSettings.Communication.ParallelPortName  = this.txtParallelPort.Text;
                }
                else if (this.tabControl1.SelectedIndex == 2)
                {
                    //Serial
                    _printerSettings.Communication.CommunicationType     = CommunicationType.Serial;
                    _printerSettings.Communication.SerialPortName        = this.cboSerialPorts.SelectedItem.ToString();
                    _printerSettings.Communication.SerialPortBaudRate    = int.Parse(this.txtBaudRate.Text);
                    _printerSettings.Communication.SerialPortDataBits    = int.Parse(this.txtDataBits.Text);
                    _printerSettings.Communication.SerialPortFlowControl = (SerialPortHandshake)Enum.Parse(typeof(SerialPortHandshake), this.cboFlowControl.SelectedItem.ToString());
                    _printerSettings.Communication.SerialPortParity      = (SerialPortParity)Enum.Parse(typeof(SerialPortParity), this.cboParity.SelectedItem.ToString());
                    _printerSettings.Communication.SerialPortStopBits    = (SerialPortStopBits)Enum.Parse(typeof(SerialPortStopBits), this.cboStopBits.SelectedItem.ToString());
                }
                else if (this.tabControl1.SelectedIndex == 3)
                {
                    //Network
                    _printerSettings.Communication.CommunicationType = CommunicationType.Network;
                    System.Net.IPAddress ipAddress = System.Net.IPAddress.None;

                    try
                    {
                        ipAddress = System.Net.IPAddress.Parse(this.txtIPAddress.Text);
                    }
                    catch
                    { }

                    if (ipAddress != System.Net.IPAddress.None) //use IP
                    {
                        _printerSettings.Communication.NetworkIPAddress = ipAddress;
                    }
                    else //try Host Name
                    {
                        _printerSettings.PrinterName = this.txtIPAddress.Text;
                    }

                    _printerSettings.Communication.NetworkPort = int.Parse(this.txtIPPort.Text);
                }

                _printerSettings.Dpi = (double)this.nudDpi.Value;

                if (this.chkPrintAsGraphic.Checked == false)
                {
                    _printerSettings.ProgrammingLanguage = (ProgrammingLanguage)Enum.Parse(typeof(ProgrammingLanguage), this.cboProgLang.SelectedItem.ToString());
                }


                _copies           = (int)this.nudCopies.Value;
                _printOrientation = (PrintOrientation)Enum.Parse(typeof(PrintOrientation), this.cboPrintOrientation.SelectedItem.ToString());
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.DialogResult = DialogResult.Abort;
            }
        }
コード例 #13
0
 /// <summary>
 /// 设置纸张
 /// </summary>
 /// <param name="width">宽度</param>
 /// <param name="height">高度</param>
 /// <param name="orientation">旋转角度</param>
 public CPCLPrintCommand SetPage(int width, int height, PrintOrientation orientation = PrintOrientation.None)
 {
     Init(width, height);
     CommandInfo.PagerRotate = (int)orientation;
     return(this);
 }
コード例 #14
0
        public void PrintOrPreview(CharsPerLine CPL,
			string PPrintBlock, string PTitle,
			string PSubTitle, PrintPreview PVOption,
			PrintOrientation Layout,string ColHdr1,string ColHdr2,
			string ColHdr3)
        {
            PrintOrPreview(CPL,PPrintBlock,PTitle,PSubTitle,PVOption,Layout,ColHdr1,ColHdr2,ColHdr3,"");
        }
コード例 #15
0
        public void PrintOrPreview(CharsPerLine CPL,
			string PPrintBlock, string PTitle,
			string PSubTitle, PrintPreview PVOption,
			PrintOrientation Layout,string ColHdr1,string ColHdr2,
			string ColHdr3,string ColHdr4)
        {
            PrintPreviewDialog previewDialog;
            tbm = new TBMemoLine();
            Portrait =(Layout==PrintOrientation.Portrait);
            msRptString=PPrintBlock;
            _Title = PTitle;
            _SubTitle=PSubTitle;
            SetUpColHdrArray(ColHdr1,ColHdr2,ColHdr3,ColHdr4);
            miChrPerLine=(int) CPL;
            // create two memoline objects so that we can use
            // nested calls to memoline w/o stepping
            // on each other, used only when wordwrap is on

            if (sFooter.Length == 0)
            {
                sFooter = "Printed on: " + DateTime.Now.ToString();
            }

            // chars per line will vary based on the margins
            switch (CPL)
            {
                case CharsPerLine.CPL80:
                    DetailFontSize = DETAIL_FONT_SIZE_80;
                    break;
                case CharsPerLine.CPL96:
                    DetailFontSize = DETAIL_FONT_SIZE_96;
                    break;
                case CharsPerLine.CPL120:
                    DetailFontSize = DETAIL_FONT_SIZE_120;
                    break;
                case CharsPerLine.CPL160:
                    DetailFontSize = DETAIL_FONT_SIZE_160;
                    break;
                default:
                    throw new System.Exception("Invalid CharsPerLine parameter");
            }

            // set up memoline
            miNL = tbm.MLCount(msRptString);
            if(miNL==0)
            {
                MessageBox.Show("No lines to print in report string.");
                return;
            }

            mI=0;
            PrintDoc = new PrintDocument();
            PrintDoc.PrintPage += new PrintPageEventHandler(this.OnPrintPage);
            PrintDoc.DefaultPageSettings.Landscape=(Layout == PrintOrientation.Landscape);
            PrintDoc.DocumentName=_Title;

            if(PVOption == PrintPreview.Preview)
            {
                previewDialog = new PrintPreviewDialog();
                previewDialog.Document = PrintDoc;
                previewDialog.ShowDialog();
                previewDialog.Dispose();
            }
            else
                PrintDoc.Print();
        }
コード例 #16
0
        private void btnPrint_Click(object sender, EventArgs e)
        {
            if (_aObject.IdAssets == 0)
            {
                MessageBox.Show("Busque primero un Activo Fijo.", "Campo Faltante", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                ThermalLabel _currentThermalLabel = null;
                _currentThermalLabel = this.GenerateBasicThermalLabel();

                Neodynamic.SDK.Printing.PrinterSettings _printerSettings = new Neodynamic.SDK.Printing.PrinterSettings();
                _printerSettings.Communication.CommunicationType = CommunicationType.USB;
                _printerSettings.PrinterName         = _Printer;
                _printerSettings.Dpi                 = 203;
                _printerSettings.ProgrammingLanguage = (ProgrammingLanguage)Enum.Parse(typeof(ProgrammingLanguage), "ZPL");
                PrintOrientation _printOrientation = PrintOrientation.Portrait;

                int    x = 0;
                bool   isPrinterValid = false;
                string printerName    = _Printer;
                string query          = string.Format("SELECT * from Win32_Printer "
                                                      + "WHERE Name LIKE '%{0}'",
                                                      printerName);

                ManagementObjectSearcher   searcher = new ManagementObjectSearcher(query);
                ManagementObjectCollection coll     = searcher.Get();

                foreach (ManagementObject printer in coll)
                {
                    foreach (PropertyData property in printer.Properties)
                    {
                        //Console.WriteLine(string.Format("{0}: {1}",
                        //                                property.Name,
                        //                                property.Value));
                        if (x == 85)
                        {
                            isPrinterValid = (bool)property.Value;
                        }
                        x++;
                    }
                }

                if (isPrinterValid)
                {
                    MessageBox.Show("Impresora no conectada o apagada. Asegúrese de que la impresora esté conectada y que esté encendida para poder imprimir.", "Conecte y encieda la impresora", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    try
                    {
                        using (PrintJob pj = new PrintJob(_printerSettings))
                        {
                            pj.PrintOrientation = _printOrientation;
                            pj.ThermalLabel     = _currentThermalLabel;
                            pj.Print();
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Error: " + ex);
                    }
                }
            }
        }
コード例 #17
0
 public virtual string PrintOrientation(PrintOrientation printOrientation)
 {
     return($"^PO{(char) printOrientation}");
 }
コード例 #18
0
        public bool SetOrientation(Image imgEdit, PrintOrientation orientation, bool change,
                                   bool duplex, short copiesCount, bool changeSize, short paperSize)
        {
            var    nullPtr       = new IntPtr(0);
            IntPtr printerHandle = nullPtr;
            IntPtr bufPtr        = nullPtr;

            PrinterDefaults pd;

            pd.pDatatype     = 0;
            pd.pDevMode      = 0;
            pd.DesiredAccess = PRINTER_USER_ACCESS;

            const string preError = "\n\n";

            bool open   = false;
            bool result = false;

            try
            {
                open = OpenPrinter(printerName, out printerHandle, ref pd);

                if (open)
                {
                    int nSize;
                    GetPrinter(printerHandle, 9, IntPtr.Zero, 0, out nSize);
                    if (nSize <= 4)
                    {
                        GetPrinter(printerHandle, 8, IntPtr.Zero, 0, out nSize);
                        if (nSize > 4)
                        {
                            bufPtr = Marshal.AllocHGlobal(nSize);
                            if (GetPrinter(printerHandle, 8, bufPtr, nSize, out nSize))
                            {
                                result = SetPrinter(printerHandle, 9, bufPtr, 0);

                                if (!result)
                                {
                                    throw new Exception(
                                              preError +
                                              Environment.StringResources.GetString("Error") + " SetPrinter()" +
                                              "\n" +
                                              Environment.StringResources.GetString("PrinterOp_PrinterProperties_Error2") +
                                              ": " + Marshal.GetLastWin32Error());
                                }
                            }
                            else
                            {
                                throw new Exception(
                                          preError +
                                          Environment.StringResources.GetString("Error") + " GetPrinter()" +
                                          "\n" + Environment.StringResources.GetString("PrinterOp_PrinterProperties_Error2") +
                                          ": " + Marshal.GetLastWin32Error());
                            }

                            Marshal.FreeHGlobal(bufPtr);
                            bufPtr = nullPtr;
                            GetPrinter(printerHandle, 9, IntPtr.Zero, 0, out nSize);
                        }
                    }

                    if (nSize > 4)
                    {
                        bufPtr = Marshal.AllocHGlobal(nSize);
                        if (GetPrinter(printerHandle, 9, bufPtr, nSize, out nSize))
                        {
                            IntPtr dmPtr = Marshal.ReadIntPtr(new IntPtr((int)bufPtr));

                            if ((int)dmPtr == 0)
                            {
                                throw new Exception(
                                          preError +
                                          Environment.StringResources.GetString("PrinterOp_PrinterProperties_Error1") +
                                          "\n" + Environment.StringResources.GetString("PrinterOp_PrinterProperties_Error2") +
                                          ": " + Marshal.GetLastWin32Error());
                            }

                            var _dm = (DevMode)Marshal.PtrToStructure(dmPtr, typeof(DevMode));

                            if (change)
                            {
                                if (changeSize)
                                {
                                    oldPaperSize = _dm.dmPaperSize;
                                    if (_dm.dmPaperSize != paperSize)
                                    {
                                        if (oldPaperSize == DMPAPER_USER)
                                        {
                                            oldPaperLength = _dm.dmPaperLength;
                                            oldPaperWigth  = _dm.dmPaperWidth;
                                        }

                                        _dm.dmPaperSize = paperSize;
                                    }
                                }
                                oldOrientation = _dm.dmOrientation;
                                switch (orientation)
                                {
                                case PrintOrientation.Book:
                                    if (_dm.dmOrientation != DMORIENT_PORTRAIT)
                                    {
                                        _dm.dmOrientation = DMORIENT_PORTRAIT;
                                    }
                                    break;

                                case PrintOrientation.Album:
                                    if (_dm.dmOrientation != DMORIENT_LANDSCAPE)
                                    {
                                        _dm.dmOrientation = DMORIENT_LANDSCAPE;
                                    }
                                    break;

                                case PrintOrientation.Auto:
                                    if (imgEdit.Height / imgEdit.VerticalResolution >=
                                        imgEdit.Width / imgEdit.HorizontalResolution)
                                    {
                                        goto case PrintOrientation.Book;
                                    }
                                    else
                                    {
                                        goto case PrintOrientation.Album;
                                    }
                                }

                                _dm.dmCopies = copiesCount;
                            }
                            else
                            {
                                if (changeSize)
                                {
                                    if (_dm.dmPaperSize != oldPaperSize)
                                    {
                                        _dm.dmPaperSize = oldPaperSize;
                                        if (oldPaperSize == DMPAPER_USER)
                                        {
                                            _dm.dmPaperLength = oldPaperLength;
                                            _dm.dmPaperWidth  = oldPaperWigth;
                                        }
                                    }
                                }
                                if (_dm.dmOrientation != oldOrientation)
                                {
                                    _dm.dmOrientation = oldOrientation;
                                }
                                _dm.dmCopies = 1;
                            }
                            Marshal.StructureToPtr(_dm, dmPtr, true);
                            result = SetPrinter(printerHandle, 9, bufPtr, 0);
                            Marshal.FreeHGlobal(bufPtr);
                            bufPtr = nullPtr;

                            if (!result)
                            {
                                throw new Exception(
                                          preError +
                                          Environment.StringResources.GetString("Error") + " SetPrinter()" +
                                          "\n" + Environment.StringResources.GetString("PrinterOp_PrinterProperties_Error2") +
                                          ": " + Marshal.GetLastWin32Error());
                            }
                        }
                        else
                        {
                            throw new Exception(
                                      preError +
                                      Environment.StringResources.GetString("Error") + " GetPrinter()" +
                                      "\n" + Environment.StringResources.GetString("PrinterOp_PrinterProperties_Error2") +
                                      ": " + Marshal.GetLastWin32Error());
                        }
                    }
                }
                else
                {
                    throw new Exception(
                              preError +
                              Environment.StringResources.GetString("PrinterOp_PrinterProperties_Error3") + " " + printerName +
                              "\n" + Environment.StringResources.GetString("PrinterOp_PrinterProperties_Error2") + ": " +
                              Marshal.GetLastWin32Error());
                }
            }
            catch (Exception ex)
            {
                Data.Env.WriteToLog(ex);
                MessageForm.Show(ex.Message, Environment.StringResources.GetString("Error"));
            }
            finally
            {
                if (open && printerHandle != nullPtr)
                {
                    ClosePrinter(printerHandle);
                }
                if (bufPtr != nullPtr)
                {
                    Marshal.FreeHGlobal(bufPtr);
                }
            }

            return(result);
        }
コード例 #19
0
        public PrintAllDialog(int folderID, int empID, PrintAllFoldersType folderType)
        {
            switch (folderType)
            {
            case PrintAllFoldersType.WorkFolder:
                using (
                    var dt = Environment.DocData.GetWorkFolderDocs(folderID, empID,
                                                                   Environment.CurCultureInfo.
                                                                   TwoLetterISOLanguageName))
                {
                    if (dt.Rows.Count > 0)
                    {
                        values = new int[dt.Rows.Count];
                        for (int i = 0; i < values.Length; i++)
                        {
                            values[i] = (int)dt.Rows[i][Environment.DocData.IDField];
                        }
                    }
                    else
                    {
                        Load  += PrintAllDialog_Load;
                        values = null;
                        return;
                    }
                    dt.Dispose();
                }
                break;

            case PrintAllFoldersType.ArchivFolder:
                break;

            case PrintAllFoldersType.SearchFolder:
                using (
                    var dt = Environment.DocData.GetFoundDocs(Environment.CurCultureInfo.Name, empID,
                                                              Environment.UserSettings.PersonID))
                {
                    if (dt.Rows.Count > 0)
                    {
                        values = new int[dt.Rows.Count];
                        for (int i = 0; i < values.Length; i++)
                        {
                            values[i] = (int)dt.Rows[i][Environment.DocData.IDField];
                        }
                    }
                    else
                    {
                        Load  += PrintAllDialog_Load;
                        values = null;
                        return;
                    }
                    dt.Dispose();
                }
                break;

            case PrintAllFoldersType.InquiryFolder:
                string xml = Environment.QueryData.GetField(Environment.QueryData.XMLField, folderID).ToString();
                string sql = Data.DALC.Documents.Search.Options.GetSQL(xml);
                using (
                    DataTable dt = Environment.DocData.GetQueryDocs(sql,
                                                                    Environment.CurCultureInfo.
                                                                    TwoLetterISOLanguageName, empID,
                                                                    Environment.UserSettings.PersonID))
                {
                    if (dt.Rows.Count > 0)
                    {
                        values = new int[dt.Rows.Count];
                        for (int i = 0; i < values.Length; i++)
                        {
                            values[i] = (int)dt.Rows[i][Environment.DocData.IDField];
                        }
                    }
                    else
                    {
                        Load  += PrintAllDialog_Load;
                        values = null;
                        return;
                    }
                    dt.Dispose();
                }
                break;
            }

            using (
                var dialog = new DocPrintDialog(0, Environment.Settings.Folders.Add("Print"), values,
                                                Environment.StringResources.GetString("Dialog_PrintAllDialog_Title1")))
            {
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    printImage  = dialog.PrintImage;
                    mainOnly    = dialog.PrintOnlyMain;
                    eForm       = dialog.PrintEForm;
                    orientation = dialog.Orientation;
                    scaleMode   = dialog.ScaleMode;
                    annotations = dialog.Annotations;
                    copiescount = dialog.CopiesCount;
                    prn         = new PrinterOp(DocPrintDialog.Printer, this);
                    printerInfo = Environment.Printers.List[DocPrintDialog.Printer] as PrinterInfo ?? prn.GetInfo();
                }
            }

            if (printImage || eForm)
            {
                InitializeComponent();
            }
            else
            {
                Load  += PrintAllDialog_Load;
                values = null;
                return;
            }

            InitLayoutProperties();
        }