public void PrintGPI(PrintTo ToPrint, String PrinterName, String InvoiceNote, Boolean IsPreInvoice)
        {
            Double AllPositive            = this.GetPositiveAmount();
            Double AllNegative            = this.GetNegativeAmount();
            Double DropPercentageCustomer = 0.00;
            Double DropPercentageItem     = 0.00;

            if (Retail < 2500 && !this.IsGiftAvenue && !this.IsGPI)
            {
                DataTable dtInv = GetCurrentTotalsByBrochure();
                if (dtInv != null)
                {
                    if (LastInvoicedAmount == 0 && Retail < 2500 && Retail > 0)
                    {
                        if (!IsPreInvoice)
                        {
                            SubtractBrochureProfitPercent(InvoicedAmount, dtInv);
                        }
                        else
                        {
                            DropPercentageCustomer = -5.00;
                        }
                    }
                    DropPercentageItem = -5.00;
                }
                else
                {
                    return;
                }
            }

            this.Note  = InvoiceNote;
            this.Note += "\n" + GetStringOverageInvoice();

            DataSet ds = new DataSet();

            ds.Tables.Add(oMySql.GetDataTable(String.Format("Select * From Customer Where CompanyID='{0}' And CustomerID='{1}'", CompanyID, ID), "Customer"));

            DataTable dvInv = new DataTable();

            dvInv = GetTotalDataTableGPI("ProductID", DropPercentageCustomer, DropPercentageItem);
            ds.Tables.Add(CreateDetailTable(dvInv)); //Detail


            DataTable dtTotals = GetCurrentTotalsGPI(DropPercentageCustomer, DropPercentageItem); //GetTotalDataTable("CustomerID");

            //GetCurrentTotalsByBrochure();
            if (dtTotals != null)
            {
                ds.Tables.Add(dtTotals); //Detail



                frmViewReport oViewReport = new frmViewReport();
                //ds.WriteXml("Invoice.xml", XmlWriteMode.WriteSchema);
                InvoiceHeaderDetailGPI oRpt = new InvoiceHeaderDetailGPI();
                oRpt.SetDataSource(ds);
                oRpt.SetParameterValue("PrevInvoice", AllPositive);                            //LastInvoicedAmount);
                oRpt.SetParameterValue("Payments", AllNegative);                               //PaymentsAmount+Charges);
                oRpt.SetParameterValue("AddedAmount", AddedAmount);
                oRpt.SetParameterValue("BalanceDue", AllPositive + AllNegative + AddedAmount); //AmountDue);
                oRpt.SetParameterValue("InvoiceNote", this.Note);

                Company oCompany = new Company(this.CompanyID);
                oRpt.SetParameterValue("CompanyName", oCompany.Name);

                if (this.BrochureID == "C" || this.BrochureID_2 == "C" || this.BrochureID_3 == "C")
                {
                    oRpt.SetParameterValue("txtFee", "E Card Ship Fee".ToUpper());
                }
                else
                {
                    oRpt.SetParameterValue("txtFee", "IMPRINT FEE");
                }

                if (this.IsPostPay)
                {
                    oRpt.SetParameterValue("Terms", "");
                }
                else
                {
                    oRpt.SetParameterValue("Terms", "TERMS: NET DUE UPON DELIVERY");
                }

                if (ToPrint == PrintTo.File)
                {
                    PDF oPDF = new PDF();
                    oPDF.FileName = Application.StartupPath + "\\" + this.Name + ".pdf";
                    oPDF.ExportReport(oRpt, "pdf", Application.StartupPath + "\\", this.Name);

                    Smtp oSmtp = new Smtp();
                    oSmtp.Subject = "Invoice for " + this.Name + "   " + DateTime.Now.ToShortDateString() + "   " + DateTime.Now.ToShortTimeString();
                    oSmtp.To      = "<" + "*****@*****.**" + ">"; //this.eMail + ">";
                    oSmtp.From    = "\"Signature Fundraising Customer Service\" <*****@*****.**>";

                    String strTitle = "Invoice\n\r";

                    oSmtp.Body       = strTitle;
                    oSmtp.Attachment = oPDF.FileName;
                    if (!oSmtp.Send())
                    {
                        return;
                    }
                }
                else if (ToPrint == PrintTo.Printer)
                {
                    oRpt.PrintOptions.PrinterName = PrinterName;
                    oRpt.PrintToPrinter(1, true, 1, 100);
                }
                else if (ToPrint == PrintTo.Viewer)
                {
                    oViewReport.cReport.ReportSource = oRpt;
                    oViewReport.ShowDialog();
                    //oViewReport.cReport.PrintReport();
                }


                if (!IsPreInvoice)
                {
                    UpdateInventory();

                    //Update Statement
                    if (LastInvoicedAmount != InvoicedAmount)
                    {
                        UpdateInvoicedAmount(InvoicedAmount - LastInvoicedAmount); //Adding Line ,,,,
                        AddedAmount = 0.00;
                    }
                }


                this.UpdateCurrentTotals();
                ds.Dispose();
                oRpt.Dispose();
            }
            return;
        }
        public Boolean PrintStatement(String PrinterName, PrinterDevice Device)
        {
            if (_Total == 0)
            {
                Total = GetTotal();
                Update();
            }

            frmViewReport oViewReport = new frmViewReport();
            //DataSet ds1 = oMySql.GetCustomerStatement(CompanyID, ID);

            DataSet ds = new DataSet();

            ds.Tables.Add(oMySql.GetDataTable(String.Format("Select * From Vendor Where CompanyID='{0}' And VendorID='{1}'", CompanyID, this.VendID), "Vendor"));
            ds.Tables.Add(oMySql.GetDataTable(String.Format("Select * From Purchase Where CompanyID='{0}' And PurchaseID='{1}'", CompanyID, this.ID), "Purchase"));
            ds.Tables.Add(oMySql.GetDataTable(String.Format("Select * From PaymentProvider  Where CompanyID='{0}' And PurchaseID='{1}' Order by Date", CompanyID, ID), "Statement"));

            PurchaseStatement oRpt = new PurchaseStatement();

            //   ds.WriteXml("PrintStatement1.xml", XmlWriteMode.WriteSchema);
            oRpt.SetDataSource(ds);

            oRpt.SetParameterValue("CompanyName", base.Name);


            if (Device == PrinterDevice.Printer)
            {
                oRpt.PrintOptions.PrinterName = PrinterName;
                oRpt.PrintToPrinter(1, true, 1, 100);
            }
            else if (Device == PrinterDevice.eMail)
            {
                PDF oPDF = new PDF();
                oPDF.FileName = Application.StartupPath + "\\" + this.ID + ".pdf";
                oPDF.ExportReport(oRpt, "pdf", Application.StartupPath + "\\", this.ID);

                Smtp oSmtp = new Smtp();
                oSmtp.Subject = base.ID + " - Statement " + DateTime.Now.ToShortDateString() + "   " + DateTime.Now.ToShortTimeString() + "(" + this.ID + " - " + this.Name + ")";


                if (PrinterName != "")
                {
                    oSmtp.To = "\"" + this.Name + "\" <" + PrinterName + ">"; //this.eMail + ">";
                }

                /*
                 * else if (this.isEmail(this.eMail) && File.Exists(oPDF.FileName))
                 * {
                 *
                 * oSmtp.To = "\"" + this.Chairperson + "\" <" + this.eMail + ">";
                 * if (this.isEmail(this.oCustomerExtra.eMail))
                 * {
                 *  oSmtp.To = "\"" + this.Chairperson + "\" <" + this.oCustomerExtra.eMail + ">";
                 * }
                 *
                 * oSmtp.To = "\"" + "Scott Elsbree" + "\" <" + "*****@*****.**" + ">"; //this.eMail + ">";
                 * }
                 */
                else
                {
                    oSmtp.To = "\"" + "Scott Elsbree" + "\" <" + "*****@*****.**" + ">"; //this.eMail + ">";
                }

                oSmtp.From = "\"Signature Fundraising Customer Service\" <*****@*****.**>";

                String strTitle = "\n\r";



                strTitle += "Thank you for choosing Signature Fundraising.  As of today we have not received complete payment for your account.\n\r";
                strTitle += "We have attached a copy of your most recent statement showing the balance due.  Please remember that  according to\n\r";
                strTitle += "the agreement we have with your organization interest will accrue on any unpaid balance after 20 days of delivery.\n\r";
                strTitle += "We have also attached a check by fax form that will enable you to send payment to us right away.  If you have any \n\r";
                strTitle += "questions, you may reply to this e-mail or call us at 1-800-645-3863.\n\r";

                strTitle += "\n\nThank you.\n\r";
                strTitle += "Signature Fundraising\n\r";


                //String strTitle = "This statement amount due is for a total of :\n\r  $ " + this.StatementAmountDue.ToString() + " \n\r" ;
                //This invoice is for a total of ::invoice amount::, of which ::payment amount:: has already been received.

                /*
                 * if (PrinterName == "" && !this.isEmail(this.eMail))
                 *  strTitle += " WRONG EMAIL ADDRESS: " + this.eMail + " of " + this.ID + " : " + this.Name;
                 *
                 * if (PrinterName == "" && !File.Exists(oPDF.FileName))
                 *  strTitle += " NO PDF FILE : " + this.eMail + " of " + this.ID + " : " + this.Name;
                 * else
                 *  oSmtp.Attachment = oPDF.FileName;
                 */
                oSmtp.Body        = strTitle;
                oSmtp.Attachment  = "Check by Fax Form.pdf";
                oSmtp.Credentials = new System.Net.NetworkCredential("*****@*****.**", "sigfund");
                // oSmtp.BCC = "*****@*****.**";

                if (!oSmtp.Send())
                {
                    Console.WriteLine(oSmtp.Error);
                    oRpt.Dispose();
                    oViewReport.Dispose();
                    return(false);
                }
                //while (File.GetAttributes(oPDF.FileName) == FileAttributes.ReadOnly) ;

                /*
                 * ReadFile:
                 * try
                 * {
                 *  if (File.Exists(oPDF.FileName))
                 *      File.Delete(oPDF.FileName);
                 * }
                 * catch (IOException ex)
                 * {
                 *  Console.WriteLine(ex.Message);
                 *  goto ReadFile;
                 * }
                 */
            }
            else
            {
                oViewReport.cReport.ReportSource = oRpt;
                oViewReport.ShowDialog();
            }

            oRpt.Dispose();
            oViewReport.Dispose();

            return(true);
        }