Esempio n. 1
0
        private Boolean PrintBilling(System.Web.UI.Control sender)
        {
            bool boRetValue = false;

            int iPrintedBills = 0, iBills = 0;

            foreach (DataListItem item in lstItem.Items)
            {
                HtmlInputCheckBox chkList = (HtmlInputCheckBox)item.FindControl("chkList");

                if (chkList != null)
                {
                    if (chkList.Checked == true)
                    {
                        iBills++;
                        ImageButton imgPrintBilling = (ImageButton)item.FindControl("imgPrintBilling");
                        if (DateTime.Parse(imgPrintBilling.ToolTip) != DateTime.MinValue && DateTime.Parse(imgPrintBilling.ToolTip) != Constants.C_DATE_MIN_VALUE)
                        {
                            Billing clsBilling       = new Billing();
                            System.Data.DataTable dt = clsBilling.ListBillingDateAsDataTable(CreditType.Individual, long.Parse(chkList.Value), DateTime.Parse(imgPrintBilling.ToolTip));
                            clsBilling.CommitAndDispose();

                            if (dt.Rows.Count > 0)
                            {
                                if (dt.Rows[0]["BillingFile"].ToString().IndexOf(".pdf") > -1)
                                {
                                    if (PdfHelper.PrintPDFs(Constants.ROOT_DIRECTORY_BILLING_WoutG + "/" + dt.Rows[0]["BillingFile"].ToString()))
                                    {
                                        iPrintedBills++;
                                    }
                                }
                                else
                                {
                                    if (PrinterHelper.PrintFile(Constants.ROOT_DIRECTORY_BILLING_WoutG + "/" + dt.Rows[0]["BillingFile"].ToString()))
                                    {
                                        iPrintedBills++;
                                    }
                                }
                            }
                        }
                        boRetValue = true;
                    }
                }
            }

            if (boRetValue)
            {
                string javaScript = "window.alert(" + iPrintedBills.ToString() + "/" + iBills.ToString() + " bills has been successfully printed.');";
                System.Web.UI.ScriptManager.RegisterClientScriptBlock(sender, sender.GetType(), "openwindow", javaScript, true);
            }
            else
            {
                string javaScript = "window.alert('Sorry there was no billing file to print.');";
                System.Web.UI.ScriptManager.RegisterClientScriptBlock(sender, sender.GetType(), "openwindow", javaScript, true);
            }
            return(boRetValue);
        }
        private void printthefile()
        {
            PrinterHelper printhelp          = new PrinterHelper();
            string        defaultprintername = printhelp.DefaultPrinterName();

            System.Windows.Controls.PrintDialog pd = new System.Windows.Controls.PrintDialog();
            //  pd.ShowDialog();

            printhelp.PrintFile(filename);

            printhelp.kill();
        }