Exemplo n.º 1
0
        private void btnPrint_Click(object sender, RoutedEventArgs e)
        {
            if (ResultGridView.Items.Count > 0)
            {
                DataTable dtOrders = ((DataView)ResultGridView.ItemsSource).Table;
                DataTable dtRestaurantInfo = GlobalClass.GetRestaurantInfo();
                string AddressLine1 = "";
                string AddressLine2 = "";
                if (dtRestaurantInfo != null)
                {
                    if (dtRestaurantInfo.Rows.Count > 0)
                    {
                        AddressLine1 = dtRestaurantInfo.Rows[0]["RestaurantName"].ToString() + ", " + dtRestaurantInfo.Rows[0]["Address"].ToString();
                        AddressLine2 = "Phone: " + dtRestaurantInfo.Rows[0]["PhoneNumber"].ToString() + "    " + dtRestaurantInfo.Rows[0]["WebsiteURL"].ToString() + "    " + dtRestaurantInfo.Rows[0]["Email"].ToString();
                    }
                }
                ReportParameter[] arrParams = new ReportParameter[4];
                arrParams[0] = new ReportParameter("rpm_FromDate", dtFromDate.Value.ToShortDateString());
                arrParams[1] = new ReportParameter("rpm_ToDate", dtToDate.Value.ToShortDateString());
                arrParams[2] = new ReportParameter("rpm_AddressLine1", AddressLine1);
                arrParams[3] = new ReportParameter("rpm_AddressLine2", AddressLine2);
                string reportPath = Environment.CurrentDirectory + "\\ReportSrc";
                ReportPrintClass objReportPrintClass = new ReportPrintClass("PublicDataSet_OrdersList_SellReport", dtOrders, reportPath + "\\Report_Sell.rdlc", arrParams, 8.27, 11.69, 0.5, 0.5, 0.2, 0.2);

                PrinterSettings ps = new PrinterSettings();
                PrinterSettings.StringCollection printersList = PrinterSettings.InstalledPrinters;
                string[] arrPrinters = new string[printersList.Count];
                for (int i = 0; i < printersList.Count; i++)
                {
                    arrPrinters[i] = printersList[i];

                }
                CustomPrintDialog objCustomPrintDialog = new CustomPrintDialog(arrPrinters);
                if (objCustomPrintDialog.ShowDialog() == true)
                {
                    objReportPrintClass.Print(objCustomPrintDialog.printerName, 1);
                }
                objReportPrintClass.Dispose();
            }
            else
            {
                MessageBox.Show("There is no item to print!","", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        private void btnPrint_Click(object sender, RoutedEventArgs e)
        {
            Cursor = Cursors.Wait;
            if (OrderGridView.ItemsSource != null)
            {
                DataTable dtOrderDetail=((DataView)OrderGridView.ItemsSource).Table;

                DataTable dtRestaurantInfo = GlobalClass.GetRestaurantInfo();
                string AddressLine1 = "";
                string AddressLine2 = "";
                if (dtRestaurantInfo != null)
                {
                    if (dtRestaurantInfo.Rows.Count > 0)
                    {
                        AddressLine1 = dtRestaurantInfo.Rows[0]["RestaurantName"].ToString() + ", " + dtRestaurantInfo.Rows[0]["Address"].ToString();
                        AddressLine2 = "Phone: " + dtRestaurantInfo.Rows[0]["PhoneNumber"].ToString() + "    " + dtRestaurantInfo.Rows[0]["WebsiteURL"].ToString() + "    " + dtRestaurantInfo.Rows[0]["Email"].ToString();
                    }
                }
                ReportParameter[] arrParams = new ReportParameter[6];
                arrParams[0] = new ReportParameter("rpm_Date", GlobalClass.GetCurrentDateTime().ToShortDateString());
                arrParams[1] = new ReportParameter("rpm_CustomerName",txbCustomerName.Text);
                arrParams[2] = new ReportParameter("rpm_OrderNo", txbOrderNo.Text);
                arrParams[3] = new ReportParameter("rpm_TableNo", txbTableNo.Text);
                arrParams[4] = new ReportParameter("rpm_AddressLine1", AddressLine1);
                arrParams[5] = new ReportParameter("rpm_AddressLine2", AddressLine2);
                string reportPath = Environment.CurrentDirectory + "\\ReportSrc";
                ReportPrintClass objReportPrintClass = new ReportPrintClass("PublicDataSet_OrderDetail", dtOrderDetail, reportPath + "\\Report_Receipt.rdlc", arrParams, 8.27, 11.69, 0.5, 0.5, 0.2, 0.2);

                PrinterSettings ps = new PrinterSettings();
                PrinterSettings.StringCollection printersList = PrinterSettings.InstalledPrinters;
                string[] arrPrinters = new string[printersList.Count];
                for (int i = 0; i < printersList.Count; i++)
                {
                    arrPrinters[i] = printersList[i];

                }
                Cursor = Cursors.Arrow;
                CustomPrintDialog objCustomPrintDialog = new CustomPrintDialog(arrPrinters);
                if (objCustomPrintDialog.ShowDialog() == true)
                {
                    objReportPrintClass.Print(objCustomPrintDialog.printerName, 1);
                }
                objReportPrintClass.Dispose();
            }
        }