Exemplo n.º 1
0
 private void printDoc_EndPrint(object sender, PrintEventArgs e)
 {
     if (_printPreviewDialog != null)
     {
         _printPreviewDialog.Close();
     }
 }
Exemplo n.º 2
0
        // Les fonctions suivantes devraient être privées, mais on ne peut pas
        // réduire les droits d'accès des types gérés .NET
        /// <summary>
        /// Ne pas redéfinir.
        /// </summary>
        protected override void OnBeginPrint(PrintEventArgs p_arg)
        {
            m_corrections.X = -1; // Flag pour le recharger

            switch (m_typeImpression)
            {
            case TypeImpression.DEMANDE_APERÇU:
                base.OnBeginPrint(p_arg);
                DoBeginPrint(p_arg);
                m_typeImpression = TypeImpression.PRÉPARATION_APERÇU_TERMINÉE;
                break;

            case TypeImpression.PRÉPARATION_APERÇU_TERMINÉE:
                // base.OnBeginPrint(p_arg);

                if (ChoisirImpression())
                {
                    m_typeImpression = TypeImpression.DEMANDE_IMPRESSION_DANS_APERÇU;
                    ImprimerSelonChoix();
                    m_ppDlg.Close();
                }

                p_arg.Cancel = true;     // On l'a fait nous-mêmes !
                break;

            case TypeImpression.DEMANDE_IMPRESSION_DANS_APERÇU:
                break;

            default:
                // De Imprimer ou ImprimerTout()...
                base.OnBeginPrint(p_arg);
                DoBeginPrint(p_arg);
                break;
            }
        }
Exemplo n.º 3
0
 private void PreviewDialogOnKeyDown(object sender, KeyEventArgs keyEventArgs)
 {
     if (keyEventArgs.KeyCode == Keys.Escape)
     {
         _previewDialog.Close();
     }
 }
Exemplo n.º 4
0
 private void MyPageSetupItemClicked(object sender, EventArgs e)
 {
     try
     {
         dlgPrint.AllowSelection = true;
         dlgPrint.ShowNetwork    = true;
         dlgPrint.Document       = prn_Document;
         if (dlgPrint.ShowDialog() != System.Windows.Forms.DialogResult.OK)
         {
             return;
         }
         prn_Document.DefaultPageSettings.PaperSize = dlgPrint.Document.DefaultPageSettings.PaperSize;
         f_Refresh = true;
         prn_PreviewDialog.Close();
     }
     catch (Exception)
     {
     }
 }
        // 预览一组图像
        public void Preview(List <string> imageNameList)
        {
            if (imageNameList == null || imageNameList.Count == 0)
            {
                return;
            }
            this.ImageNameList = imageNameList;

            //设置打印总页数
            printDoc.DocumentName = imageNameList.Count.ToString();

            try
            {
                //申明并实例化previewDlg
                if (previewDlg == null)
                {
                    previewDlg          = new PrintPreviewDialog();
                    previewDlg.Document = printDoc;
                }
                else//根据its需求更改完下面一个后,如果关闭了预览窗口之后,再点击预览会出报错,是因为对象还没有释放,但是句柄没了,所以新加了else中的内容,wk,2018-8-21
                {
                    previewDlg.Close();
                    previewDlg          = new PrintPreviewDialog();
                    previewDlg.Document = printDoc;
                }

                //设置窗口尺寸和位置
                //previewDlg.ClientSize = new Size(640, 480);
                //previewDlg.Location = new Point(0, 0);

                //最大化窗口
                ((System.Windows.Forms.Form)previewDlg).WindowState = FormWindowState.Maximized;

                //previewDlg.ShowDialog();//原来的
                //应its需求,希望每次弹出的预览窗口在最上层,wk,2018-8-21
                ((System.Windows.Forms.Form)previewDlg).TopMost = true;
                ((System.Windows.Forms.Form)previewDlg).Show();
            }
            catch (System.Drawing.Printing.InvalidPrinterException)
            {
                MessageBox.Show("未安装打印机!", "打印", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "打印", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Exemplo n.º 6
0
 private void Print()
 {
     try
     {
         if (lvwUserList.SelectedRows.Count > 0)
         {
             printDocument            = new PrintDocument();
             printPreviewDialog       = new PrintPreviewDialog();
             printDocument.PrintPage += new PrintPageEventHandler(this.printDocument_PrintPage);
             printDocument.Print();
             printPreviewDialog.Close();
         }
     }
     catch (Exception)
     {
     }
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void printPreview_PrintClick(object sender, EventArgs e)
 {
     try
     {
         printDialog1.Document = _printDocument;
         if (printDialog1.ShowDialog() == DialogResult.OK)
         {
             _printDocument.Print();
             printPreviewDialog1.Close();
             printPreviewDialog1.Dispose();
         }
     }
     catch (Exception ex)
     {
         Log.WriteLine(ex);
         MessageBox.Show(ex.Message, ToString());
     }
 }
        private static void setupPrintButton(PrintPreviewDialog previewDialog, PdfDocument pdf, PrintSize printSize)
        {
            ToolStripButton openPrintDialog = new ToolStripButton
            {
                // reuse the image of the default print button
                Image        = ((ToolStrip)previewDialog.Controls[1]).ImageList.Images[0],
                DisplayStyle = ToolStripItemDisplayStyle.Image
            };

            openPrintDialog.Click += new EventHandler(delegate(object sender, EventArgs e)
            {
                if (ShowPrintDialog(pdf, printSize) == DialogResult.OK)
                {
                    previewDialog.Close();
                }
            });

            ((ToolStrip)previewDialog.Controls[1]).Items.RemoveAt(0);
            ((ToolStrip)previewDialog.Controls[1]).Items.Insert(0, openPrintDialog);
        }
Exemplo n.º 9
0
 /// <summary>
 /// 记录打印记录
 /// </summary>
 private void AddPrintRecord()
 {
     try
     {
         string strsql = "   select SortNumberInfo_ID from SortNumberInfo where SortNumberInfo_SmallTicket_ID in (select SmallTicket_ID from SmallTicket where SmallTicket_CarInfo_ID='" + carinfoid + "') order by SortNumberInfo_ID desc ";
         prdObj = LinQBaseDao.GetSingle(strsql);
         //记录打印
         PrintRecord prd = new PrintRecord();
         prd.PrintRecord_Time    = CommonalityEntity.GetServersTime();
         prd.PrintRecord_Remark  = "";
         prd.PrintRecord_Operate = CommonalityEntity.USERNAME;
         if (!string.IsNullOrEmpty(prdObj.ToString()))
         {
             prd.PrintRecord_SortNumberInfo_ID = int.Parse(prdObj.ToString());
         }
         PrintInfoDAL.InsertPrint(prd);
         printPreviewDialog.Close();
     }
     catch (Exception)
     {
     }
 }
        static void initPrintDocument()
        {
            using (pd = new PrintDocument())
            {
                pd.DocumentName = "ใบเสร็จค่าสินค้า";
                pd.PrinterSettings.PrinterName = printerName;

                GF.checkPaperSize(pd);
                GF.checkPaperSource(pd);

                GF.printError("THIS RAW KIND : " + rawKind);
                GF.printError("THIS PAPER SIZE : " + paperSize);

                if (rawKind != 0)
                {
                    pd.DefaultPageSettings.PaperSize.RawKind = rawKind;
                }
                if (paperSize != null)
                {
                    pd.DefaultPageSettings.PaperSize = paperSize;
                }

                GF.printError(pd.DefaultPageSettings.PaperSize.Width.ToString() + " x " + pd.DefaultPageSettings.PaperSize.Height.ToString());

                GF.printError("PD RAW KIND : " + pd.DefaultPageSettings.PaperSize.RawKind);
                GF.printError("PD PAPER SIZE : " + pd.DefaultPageSettings.PaperSize);

                if (printerResolution != null)
                {
                    pd.DefaultPageSettings.PrinterResolution = printerResolution;
                }

                pd.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0);

                pd.PrintPage += (sender, e) =>
                {
                    int    FontSize = 8;
                    string FontName = "Calibri";
                    regular              = new Font(FontName, FontSize);
                    boldUnderline        = new Font(FontName, FontSize, (FontStyle.Bold | FontStyle.Underline));
                    bold                 = new Font(FontName, FontSize, FontStyle.Bold);
                    brush                = new SolidBrush(Color.Black);
                    alignRight           = new StringFormat();
                    alignRight.Alignment = StringAlignment.Far;

                    int width = e.MarginBounds.Width;

                    string vat = "";
                    string net_price_before_vat = "";
                    string vat_amount           = "";
                    string total_amount         = "";
                    string cashier_name         = "";

                    Dictionary <string, string> values = new()
                    {
                        { "bill_id", bill_id },
                        { "issue_vat", (hasVat ? "1" : "0") }
                    };

                    Dictionary <string, object> Obj = DB.Post("Shop/getBillHeader/", values);

                    int top = 10;
                    if (Obj != null)
                    {
                        if (Obj.ContainsKey("result"))
                        {
                            Dictionary <string, object> item = GF.ToType <Dictionary <string, object> >(Obj["result"]);
                            if (item.Keys.Count > 0)
                            {
                                bill_no = item["bill_no"].ToString();

                                print_bill_header.draw(e, item["branch_id"].ToString(), out top);

                                top += 65;
                                e.Graphics.DrawString("ใบเสร็จรับเงิน / ใบกำกับภาษีอย่างย่อ", boldUnderline, brush, new PointF((float)(((width - GF.margin_right) / 2) - (e.Graphics.MeasureString("ใบเสร็จรับเงิน / ใบกำกับภาษีอย่างย่อ", boldUnderline).Width / 2)), top));

                                top += 25;
                                e.Graphics.DrawString("หมายเลขใบเสร็จ", bold, brush, new PointF((e.MarginBounds.Width) - e.Graphics.MeasureString(": " + bill_no, regular).Width - e.Graphics.MeasureString("หมายเลขใบเสร็จ", bold).Width - GF.margin_right + GF.margin_left, top));
                                e.Graphics.DrawString(": " + bill_no, regular, brush, new RectangleF(GF.margin_left, top, e.MarginBounds.Width - GF.margin_right, 15), alignRight);

                                top += 20;
                                e.Graphics.DrawString("วันที่", bold, brush, new PointF((e.MarginBounds.Width) - e.Graphics.MeasureString(": " + GF.formatDBDateTime(item["bill_datetime"].ToString()), regular).Width - e.Graphics.MeasureString("วันที่", bold).Width - GF.margin_right + GF.margin_left, top));
                                e.Graphics.DrawString(": " + GF.formatDBDateTime(item["bill_datetime"].ToString()), regular, brush, new RectangleF(GF.margin_left, top, e.MarginBounds.Width - GF.margin_right, 15), alignRight);

                                vat                  = item["vat"].ToString();
                                vat_amount           = item["vat_amount"].ToString();
                                net_price_before_vat = item["net_price_before_vat"].ToString();
                                total_amount         = item["total_price"].ToString();
                                cashier_name         = item["receive_by"].ToString();
                            }
                        }
                    }

                    string seps = "";
                    while (e.Graphics.MeasureString(seps, regular).Width < e.MarginBounds.Width)
                    {
                        seps += "-";
                    }

                    /*top += 25;
                     * e.Graphics.DrawString(seps, regular, brush, new PointF(left, top));*/

                    values = new()
                    {
                        { "bill_no", bill_no }
                    };

                    Obj = DB.Post("Shop/getDataByBillNo/", values);

                    if (Obj != null)
                    {
                        if (Obj.ContainsKey("result"))
                        {
                            Dictionary <string, object> item = GF.ToType <Dictionary <string, object> >(Obj["result"]);
                            if (item.Keys.Count > 0)
                            {
                                string Product_Data = item["product_data"].ToString();

                                string[] tmp_data = Product_Data.Split(new string[] { "!!" }, StringSplitOptions.None);
                                foreach (string product in tmp_data)
                                {
                                    string[] Item = product.Split(new string[] { "##" }, StringSplitOptions.None);

                                    top += 20;
                                    string item_name = Item[3].ToString() + " x " + Item[0].ToString() + " @" + Item[1].ToString() + ".00";
                                    e.Graphics.DrawString(item_name, regular, brush, new RectangleF(GF.margin_left, top, e.MarginBounds.Width - e.Graphics.MeasureString(item_name, regular).Width - GF.margin_right, 15));
                                    e.Graphics.DrawString(GF.formatNumber(Item[4].ToString()) + ".00", regular, brush, new RectangleF(GF.margin_left, top, e.MarginBounds.Width - GF.margin_right, 15), alignRight);
                                }

                                //======================================= SUB TOTAL ======================================//
                                top += 20;
                                e.Graphics.DrawString("ราคารวมก่อนภาษี", bold, brush, new PointF((e.MarginBounds.Width) - e.Graphics.MeasureString(": " + net_price_before_vat, bold).Width - e.Graphics.MeasureString("ราคารวมก่อนภาษี :", bold).Width - GF.margin_right + GF.margin_left, top));
                                e.Graphics.DrawString(": " + net_price_before_vat, bold, brush, new RectangleF(GF.margin_left, top, e.MarginBounds.Width - GF.margin_right, 15), alignRight);

                                top += 20;
                                e.Graphics.DrawString("ภาษี " + string.Format("{0:f2}", Convert.ToDouble(vat)) + "%", bold, brush, new PointF((e.MarginBounds.Width) - e.Graphics.MeasureString(": " + vat_amount, bold).Width - e.Graphics.MeasureString("ภาษี " + string.Format("{0:f2}", Convert.ToDouble(vat)) + "% : ", bold).Width - GF.margin_right + GF.margin_left, top));
                                e.Graphics.DrawString(": " + vat_amount, bold, brush, new RectangleF(GF.margin_left, top, e.MarginBounds.Width - GF.margin_right, 15), alignRight);

                                top += 20;
                                e.Graphics.DrawString("รวมเป็นเงิน", bold, brush, new PointF((e.MarginBounds.Width) - e.Graphics.MeasureString(": " + GF.formatNumber(total_amount) + ".00", bold).Width - e.Graphics.MeasureString("รวมเป็นเงิน :", bold).Width - GF.margin_right + GF.margin_left, top));
                                e.Graphics.DrawString(": " + GF.formatNumber(total_amount) + ".00", bold, brush, new RectangleF(GF.margin_left, top, e.MarginBounds.Width - GF.margin_right, 15), alignRight);

                                top += 15;
                                e.Graphics.DrawString(seps, regular, brush, new PointF(GF.margin_left, top));

                                //======================================= PAYMENT ======================================//
                                string Payment_Data = item["payment_data"].ToString();
                                tmp_data = Payment_Data.Split(new string[] { "!!" }, StringSplitOptions.None);
                                foreach (string payment in tmp_data)
                                {
                                    string[] Item = payment.Split(new string[] { "##" }, StringSplitOptions.None);

                                    top += 20;
                                    if (Item[0].ToString() == "0")
                                    {
                                        // CASH
                                        e.Graphics.DrawString("เงินสด", bold, brush, new PointF((e.MarginBounds.Width) - e.Graphics.MeasureString(": " + GF.formatNumber(Item[1].ToString()) + ".00", bold).Width - e.Graphics.MeasureString("เงินสด", bold).Width - GF.margin_right + GF.margin_left, top));
                                    }
                                    else if (Item[0].ToString() == "1")
                                    {
                                        // CARD
                                        string last4Digits = Item[2].ToString().Substring(Item[2].ToString().Length - 4, 4);
                                        e.Graphics.DrawString("บัตร XXXX-XXXX-XXXX-" + last4Digits, bold, brush, new PointF((e.MarginBounds.Width) - e.Graphics.MeasureString(": " + GF.formatNumber(Item[1].ToString()) + ".00", bold).Width - e.Graphics.MeasureString("บัตร XXXX-XXXX-XXXX-" + last4Digits, bold).Width - GF.margin_right + GF.margin_left, top));
                                    }
                                    e.Graphics.DrawString(": " + GF.formatNumber(Item[1].ToString()) + ".00", bold, brush, new RectangleF(GF.margin_left, top, e.MarginBounds.Width - GF.margin_right, 15), alignRight);
                                }
                            }
                        }
                    }

                    top += (13 * 3);
                    e.Graphics.DrawString("ผู้รับเงิน : " + cashier_name, bold, brush, new PointF((float)(((width - GF.margin_right) / 2) - (e.Graphics.MeasureString("ผู้รับเงิน : " + cashier_name, bold).Width / 2)), top));

                    top += (20);
                    string print_datetime = GF.NOW();
                    e.Graphics.DrawString("พิมพ์เมื่อ : " + print_datetime, bold, brush, new PointF((float)(((width - GF.margin_right) / 2) - (e.Graphics.MeasureString("พิมพ์เมื่อ : " + print_datetime, bold).Width / 2)), top));

                    top += (13 * 2);
                    CreateBarcode(bill_no, e, top);

                    e.Graphics.Dispose();
                };

                pd.EndPrint += (sender, e) =>
                {
                    if (e.PrintAction == PrintAction.PrintToPrinter)
                    {
                        if (PPD != null && !PPD.IsDisposed)
                        {
                            PPD.Close();
                        }

                        Sender.Activate();

                        GF.closeLoading();
                    }
                };
                GF.closeLoading();
                using (PPD = new PrintPreviewDialog())
                {
                    ((Form)PPD).FormClosed += (ss, ee) =>
                    {
                        Sender.Activate();
                    };
                    ((Form)PPD).TopMost         = true;
                    ((Form)PPD).WindowState     = FormWindowState.Maximized;
                    ((Form)PPD).FormBorderStyle = FormBorderStyle.None;
                    PPD.Document = pd;
                    PPD.PrintPreviewControl.Zoom         = 1;
                    PPD.PrintPreviewControl.UseAntiAlias = true;
                    PPD.Document.OriginAtMargins         = false;

                    if (isPreview)
                    {
                        PPD.ShowDialog();
                    }
                    else
                    {
                        pd.Print();
                    }
                }
            }
        static void initPrintDocument()
        {
            using (pd = new PrintDocument())
            {
                pd.DocumentName = "หัวใบเสร็จ";
                pd.PrinterSettings.PrinterName = printerName;

                //checkPaperSize(pd);
                //checkPaperSource(pd);

                Console.WriteLine("THIS RAW KIND : " + rawKind);
                Console.WriteLine("THIS PAPER SIZE : " + paperSize);

                if (rawKind != 0)
                {
                    pd.DefaultPageSettings.PaperSize.RawKind = rawKind;
                }
                if (paperSize != null)
                {
                    pd.DefaultPageSettings.PaperSize = paperSize;
                }

                Console.WriteLine(pd.DefaultPageSettings.PaperSize.Width.ToString() + " x " + pd.DefaultPageSettings.PaperSize.Height.ToString());

                Console.WriteLine("PD RAW KIND : " + pd.DefaultPageSettings.PaperSize.RawKind);
                Console.WriteLine("PD PAPER SIZE : " + pd.DefaultPageSettings.PaperSize);

                if (printerResolution != null)
                {
                    pd.DefaultPageSettings.PrinterResolution = printerResolution;
                }

                pd.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0);

                pd.PrintPage += (sender, e) =>
                {
                    print_bill_header.draw(e, branch_id, out int top);

                    e.Graphics.Dispose();
                };

                pd.EndPrint += (sender, e) =>
                {
                    if (e.PrintAction == PrintAction.PrintToPrinter)
                    {
                        if (PPD != null && !PPD.IsDisposed)
                        {
                            PPD.Close();
                        }

                        Sender.Activate();

                        GF.closeLoading();
                    }
                };
                GF.closeLoading();
                using (PPD = new PrintPreviewDialog())
                {
                    ((Form)PPD).FormClosed += (ss, ee) =>
                    {
                        Sender.Activate();
                    };
                    ((Form)PPD).TopMost         = true;
                    ((Form)PPD).WindowState     = FormWindowState.Maximized;
                    ((Form)PPD).FormBorderStyle = FormBorderStyle.None;
                    PPD.Document = pd;
                    PPD.PrintPreviewControl.Zoom         = 1;
                    PPD.PrintPreviewControl.UseAntiAlias = true;
                    PPD.Document.OriginAtMargins         = false;

                    PPD.ShowDialog();
                }
            }
        }