I want the Print button excute print
What I have tried:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.Reporting.WinForms;
using System.Data.SqlClient;
namespace MK_POS
{
public partial class frmReceipt : Form
{
SqlConnection cn = new SqlConnection();
SqlCommand cm = new SqlCommand();
SqlDataReader dr;
DBConnection dbcon = new DBConnection();
frmPOS f;
public frmReceipt(frmPOS frm)
{
InitializeComponent();
cn = new SqlConnection(dbcon.MyConnection());
f = frm;
this.KeyPreview = true;
getStoreInfo();
}
private void frmReceipt_Load(object sender, EventArgs e)
{
this.reportViewer1.RefreshReport();
}
public void LoadReport(string pcash, string pchange)
{
ReportDataSource rptDataSource;
try
{
this.reportViewer1.LocalReport.ReportPath = Application.StartupPath + @"\Reports\Receipt.rdlc";
this.reportViewer1.LocalReport.DataSources.Clear();
DataSet1 ds = new DataSet1();
SqlDataAdapter da = new SqlDataAdapter();
cn.Open();
da.SelectCommand = new SqlCommand("select c.id, c.transno, c.pcode, c.price, c.qty, c.disc, c.total, c.sdate, c.status, p.pdesc from tblcart as c inner join tblproduct as p on p.pcode = c.pcode where transno like '" + f.lblTransno.Text + "'", cn);
da.Fill(ds.Tables["dtSold"]);
cn.Close();
ReportParameter pVatable = new ReportParameter("pVatable", f.lblVatable.Text);
ReportParameter pVat = new ReportParameter("pVat", f.lblVat.Text);
ReportParameter pDiscount = new ReportParameter("pDiscount", f.lblDiscount.Text);
ReportParameter pTotal = new ReportParameter("pTotal", f.lblTotal.Text);
ReportParameter pCash = new ReportParameter("pCash", pcash);
ReportParameter pChange = new ReportParameter("pChange", pchange);
ReportParameter pTransaction = new ReportParameter("pTransaction", "Invoice #: " + f.lblTransno.Text);
ReportParameter pCashier = new ReportParameter("pCashier", f.lblUser.Text);
ReportParameter pHeader = new ReportParameter("pHeader", lblStore.Text);
ReportParameter pAddress = new ReportParameter("pAddress", lblAddress.Text);
ReportParameter pEmail = new ReportParameter("pEmail", "Email: " + lblEmail.Text);
ReportParameter pPhone = new ReportParameter("pPhone", "Phone: " + lblPhone.Text);
ReportParameter dVat = new ReportParameter("dVat", "TIN No.: " + lblVat.Text);
reportViewer1.LocalReport.SetParameters(pHeader);
reportViewer1.LocalReport.SetParameters(pAddress);
reportViewer1.LocalReport.SetParameters(pEmail);
reportViewer1.LocalReport.SetParameters(pPhone);
reportViewer1.LocalReport.SetParameters(dVat);
reportViewer1.LocalReport.SetParameters(pVatable);
reportViewer1.LocalReport.SetParameters(pVat);
reportViewer1.LocalReport.SetParameters(pDiscount);
reportViewer1.LocalReport.SetParameters(pTotal);
reportViewer1.LocalReport.SetParameters(pCash);
reportViewer1.LocalReport.SetParameters(pChange);
reportViewer1.LocalReport.SetParameters(pTransaction);
reportViewer1.LocalReport.SetParameters(pCashier);
rptDataSource = new ReportDataSource("DataSet1", ds.Tables["dtSold"]);
reportViewer1.LocalReport.DataSources.Add(rptDataSource);
reportViewer1.SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.PrintLayout);
reportViewer1.ZoomMode = ZoomMode.Percent;
reportViewer1.ZoomPercent = 100;
}
catch (Exception ex)
{
cn.Close();
MessageBox.Show(ex.Message);
}
}
public void getStoreInfo()
{
cn.Open();
cm = new SqlCommand("select * from tblStore", cn);
dr = cm.ExecuteReader();
dr.Read();
if (dr.HasRows)
{
lblStore.Text = dr["store"].ToString();
lblAddress.Text = dr["address"].ToString();
lblEmail.Text = dr["email"].ToString();
lblPhone.Text = dr["phone"].ToString();
lblVat.Text = dr["tin"].ToString();
}
dr.Close();
cn.Close();
}
private void btnClose_Click(object sender, EventArgs e)
{
this.Dispose();
}
private void frmReceipt_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape)
{
btnClose_Click(sender, e);
}
}
private void btnPrint_Click(object sender, EventArgs e)
{
}
}
}