private void navBarItemPreview_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e) { try { using (XtraReportDemo report = new XtraReportDemo()) { PrinterSettings ps = new PrinterSettings(); //use PrinterName if the printer is not the default one ////ps.PrinterName = ""; //Specify PrinterName using (Graphics g = ps.CreateMeasurementGraphics(ps.DefaultPageSettings)) { var margins = DevExpress.XtraPrinting.Native.DeviceCaps.GetMinMargins(g); //in default report units; do conversion with the help PSUnitConverter when needed } report.Margins.Left = 0; //work report.Margins.Right = 0; //work report.Margins.Top = 200; //not work report.Margins.Bottom = 200; //not work ReportPrintTool printTool = new ReportPrintTool(report); //report.CreateDocument(); printTool.PrintingSystem.ShowMarginsWarning = false; printTool.AutoShowParametersPanel = false; printTool.ShowPreviewDialog(); printTool.Dispose(); //SetShowPreviewTools(report); } } catch (Exception catchException) { } finally { } }
/// <summary> /// Cria um XtraReport a partir do nome do relatório salvo no banco. /// </summary> /// <param name="reportName"></param> /// <param name="showParams"></param> /// <returns></returns> public static XtraReport CreateReportByName(string reportName, bool showParams = true) { using (var ctx = new ReportContext()) { try { var current = ctx.ReportImageDao.First(r => r.ReportName == reportName); string dir = Path.GetTempPath().Replace("Temp", "Reports"); FileManagerIts.CreateDirectory(dir); string path = Path.Combine(dir, current.ReportName + ".repx"); //salva o report no disco FileManagerIts.WriteBytesToFile(path, current.ReportImageData); //carregue a estrutura do relatório XtraReport report = XtraReport.FromFile(path, true); if (showParams == false) { //nao exibe foreach (var p in report.Parameters) { p.Visible = false; } } //objeto para chamar a tela de parametros ReportPrintTool reportPrintTool = new ReportPrintTool(report); ReportUtil.SetParamDataSource(report.DataSource as SqlDataSource, AppConfigManager.Configuration.AppConfig); //criar o documento report.CreateDocument(); //libera memoria da ferramenta reportPrintTool.Dispose(); //retorna o relatorio return(report); } catch (Exception ex) { XMessageIts.ExceptionMessageDetails(ex, "Impossível gerar relatório !", "Falha ao gerar relatório"); LoggerUtilIts.GenerateLogs(ex); return(null); } } }
public static void InitPrint() { report.Parameters["pAmountPaid"].Value = parameters.Balance; report.Parameters["pSalesId"].Value = parameters.AmountPaid; report.Parameters["pCashierId"].Value = parameters.Cashier; report.Parameters["pChange"].Value = parameters.SalesId; report.Parameters["pShopName"].Value = parameters.ShopName; //var picBox = report.AllControls<XRPictureBox>().FirstOrDefault(); //picBox.Image = Image.FromFile(Directory.GetFiles(@"Logo\")[0]); ReportPrintTool printTool = new ReportPrintTool(report); printTool.PrintingSystem.ShowPrintStatusDialog = false; report.RequestParameters = false; report.CreateDocument(false); printTool.Print(); printTool.Dispose(); report.Dispose(); }
private void BtnPayment_Click(object sender, EventArgs e) { SalesModel model = new SalesModel(); if (string.IsNullOrEmpty(txtPaidAmount.Text) || !op.ContainsValidNumbers(txtPaidAmount.Text, txtReturnAmnt.Text, txtTotal.Text)) { return; } //Parsing values of controls to variables to prevent cross-thread calls var salesId = lblSalesId.Text; salesId = od.SalesId; repo.GetSalesId(od); var amount = txtPaidAmount.Text; var grandTotal = decimal.Parse(txtTotal.Text); var balance = txtReturnAmnt.Text; var subtotal = decimal.Parse(txtSubtotal.Text); var customer = txtCustomer.Text; var status = statusCombo.Text; var discount = Convert.ToDecimal(txtDiscount.Text); var items = txtQuantityBought.Text; AdminView admin = new AdminView(); var shopname = admin.lblShopName.Text; shopname = sd.Shopname; Dashboard dash = new Dashboard(); var cashier = dash.lblName.Text; cashier = account.Username; var contact = dash.lblContact.Text; var location = dash.lblLocation.Text; AppSettings app = new AppSettings(); app.GetAppSettings(sd); var confirm = MessageBox.Show("Do you want to Print receipt", "Printing Receipt", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (confirm == DialogResult.No) { if (string.IsNullOrEmpty(Settings.Default.PrinterName)) { //Just Commiting Without Printing shop.SaveChanges(shoppingCart, cashier, salesId, status, customer, discount, grandTotal, subtotal, items); shop.SaveCartItems(shoppingCart, discount, salesId); DecreaseQty(); btnReset.PerformClick(); this.Refresh(); return; } } else if (confirm == DialogResult.Yes) { //Committing And Printing //Executing Commitment && Print Operations Concurrently Parallel.Invoke(new Action[] { () => { //Begining Print Operation Receipt receipt = new Receipt(); receipt.Parameters["pShopName"].Value = shopname; receipt.Parameters["pTelephone"].Value = contact; receipt.Parameters["pLocation"].Value = location; receipt.Parameters["pStatus"].Value = status; receipt.Parameters["pCashierId"].Value = cashier; receipt.Parameters["pDate"].Value = DateTime.Now; receipt.Parameters["pAmountPaid"].Value = amount; receipt.Parameters["pChange"].Value = balance; receipt.Parameters["pSalesID"].Value = salesId; receipt.Parameters["pCustomer"].Value = customer; receipt.Parameters["pGrandTotal"].Value = grandTotal; receipt.DataSource = GetDataset(); receipt.DataMember = GetDataset().Tables[0].TableName; ReportPrintTool printTool = new ReportPrintTool(receipt); ReportPrintTool tool = new ReportPrintTool(receipt); //tool.ShowPreviewDialog(); printTool.PrintingSystem.ShowPrintStatusDialog = false; receipt.RequestParameters = false; receipt.CreateDocument(false); printTool.Print(); printTool.Dispose(); receipt.Dispose(); }, () => { //Saving Everything and Appending Changes shoppingCart.Invoke((MethodInvoker) delegate { shop.SaveChanges(shoppingCart, cashier, salesId, status, customer, discount, grandTotal, subtotal, items); shop.SaveCartItems(shoppingCart, discount, salesId); DecreaseQty(); }); } }); } btnReset.PerformClick(); GC.Collect(); }
private static void printReport(int idreport, bool requestParameters = true, bool visibleParameters = true, bool ribbon = false) { try { using (var ctx = new ReportContext()) { var current = ctx.ReportImageDao.Find(idreport); string reportDir = Path.GetTempPath().Replace("Temp", "Reports"); string path = Path.Combine(reportDir, current.ReportName + ".repx"); //var pathPrnx = Path.Combine(Application.StartupPath, "Reports", current.ReportName + ".prnx"); //carregue a estrutura do relatório XtraReport xreport = new XtraReport(); if (!File.Exists(path)) { FileManagerIts.WriteBytesToFile(path, current.ReportImageData); } xreport.LoadLayout(path); var ds = xreport.DataSource as SqlDataSource; var appConf = AppConfigManager.Configuration.AppConfig; if (ds == null) { ds = new SqlDataSource(appConf.ServerName); } SetParamDataSource(ds, appConf); ds.Connection.CreateConnectionString(); ds.RebuildResultSchema(); //objeto para gerar a tela de parametros ReportPrintTool reportPrintTool = new ReportPrintTool(xreport); //permissao para solicitar os parametros xreport.RequestParameters = requestParameters; //permissao para exibir os parametros if (visibleParameters == false) { foreach (var p in xreport.Parameters) { p.Visible = false; } } //chama a tela de parametros xreport.CreateDocument(); //libera memoria da ferramenta reportPrintTool.Dispose(); if (ribbon) { //chama o ribbon para exibir o relatório xreport.ShowRibbonPreview(); } else { xreport.ShowPreview(); } ////carregando o relatório manualmente ////salva o documento gerado em prnx //xreport.PrintingSystem.SaveDocument(pathPrnx); //// Create a PrintingSystem instance. //PrintingSystem ps = new PrintingSystem(); //// Load the document from a file. //ps.LoadDocument(pathPrnx); ////ribbon form para visualizar o relatório //PrintPreviewRibbonFormEx preview = new PrintPreviewRibbonFormEx(); //preview.PrintingSystem = ps; ////xtraform para visualizar o relatório //PrintPreviewFormEx prev = new PrintPreviewFormEx(); //prev.PrintingSystem = ps; ////exibe o relatorio //preview.ShowDialog(); } } catch (Exception ex) { XMessageIts.Erro("Falha gerar relatório\n\n" + ex.Message, "Atenção!!!"); LoggerUtilIts.GenerateLogs(ex); } }