private void Print()
        {
            using (var form = new Yes_No_Dialog(parent, "Are you sure you want to print this purchase order?", "Warning", "No", "Yes", 0, this.Location, this.Size))
            {
                var result = form.ShowDialog();
                if (result == DialogResult.OK && form.ReturnValue1 == "1")
                {
                    if (secondThreadFormHandle == IntPtr.Zero)
                    {
                        Loading_Form form2 = new Loading_Form(parent, this.Location, this.Size, "PRINTING", "PDF")
                        {
                        };
                        form2.HandleCreated   += SecondFormHandleCreated;
                        form2.HandleDestroyed += SecondFormHandleDestroyed;
                        form2.RunInNewThread(false);
                    }

                    PDFGenerator PDFG = new PDFGenerator(parent, externalID.Length > 0 ? externalID : parent.CurrentID, externalID.Length > 0, externalID.Length > 0 ? externalID : parent.CurrentID);

                    string pdfPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), (externalID.Length > 0 ? externalID : parent.CurrentID) + ".pdf");

                    ProcessStartInfo info = new ProcessStartInfo();
                    info.Verb           = "print";
                    info.FileName       = pdfPath;
                    info.CreateNoWindow = true;
                    info.WindowStyle    = ProcessWindowStyle.Hidden;

                    Process p = new Process();
                    p.StartInfo = info;
                    p.Start();

                    p.WaitForInputIdle();
                    System.Threading.Thread.Sleep(3000);
                    if (false == p.CloseMainWindow())
                    {
                        p.Kill();
                    }

                    try
                    {
                        File.Delete(pdfPath);
                    }
                    catch
                    {
                        Console.WriteLine("Error deleting print image file");
                    }

                    if (secondThreadFormHandle != IntPtr.Zero)
                    {
                        PostMessage(secondThreadFormHandle, WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
                    }
                }
            }
        }
Пример #2
0
        private void button2_Click(object sender, EventArgs e)
        {
            Grey_Out();
            if (Checked_Items.Count > 0)
            {
                Application.DoEvents();

                using (var form = new Yes_No_Dialog(parent, "Are you sure you want to print " + Checked_Items.Count + " purchase order PDF(s)?", "Warning", "No", "Yes", 0, this.Location, this.Size))
                {
                    var result = form.ShowDialog();
                    if (result == DialogResult.OK && form.ReturnValue1 == "1")
                    {
                        if (secondThreadFormHandle == IntPtr.Zero)
                        {
                            Loading_Form form2 = new Loading_Form(parent, this.Location, this.Size, "PRINTING", "PDF(s)")
                            {
                            };
                            form2.HandleCreated   += SecondFormHandleCreated;
                            form2.HandleDestroyed += SecondFormHandleDestroyed;
                            form2.RunInNewThread(false);
                        }

                        foreach (string g in Checked_Items)
                        {
                            PDFGenerator PDFG = new PDFGenerator(parent, g, true, g);

                            string pdfPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), g + ".pdf");

                            ProcessStartInfo info = new ProcessStartInfo();
                            info.Verb           = "print";
                            info.FileName       = pdfPath;
                            info.CreateNoWindow = true;
                            info.WindowStyle    = ProcessWindowStyle.Hidden;

                            Process p = new Process();
                            p.StartInfo = info;
                            p.Start();

                            p.WaitForInputIdle();
                            System.Threading.Thread.Sleep(3000);
                            if (false == p.CloseMainWindow())
                            {
                                p.Kill();
                            }

                            try
                            {
                                File.Delete(pdfPath);
                            }
                            catch
                            {
                                Console.WriteLine("Error deleting print image file");
                            }
                        }

                        if (secondThreadFormHandle != IntPtr.Zero)
                        {
                            PostMessage(secondThreadFormHandle, WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
                        }

                        deselectAll.PerformClick();
                    }
                }
            }
            else
            {
                Form_Message_Box FMB = new Form_Message_Box(parent, "No orders selected", true, -25, this.Location, this.Size);
                FMB.ShowDialog();
            }
            Grey_In();
        }
 private void button1_Click(object sender, EventArgs e)
 {
     PDFGenerator PDFG = new PDFGenerator(parent, externalID.Length > 0 ? externalID : parent.CurrentID, externalID.Length > 0);
 }