private void btnPreviewSalesReport_Click(object sender, EventArgs e) { string query = "select materialname = c.material, d.quantity, d.totalamount, d.discount from sales as d left join " + "materialsetup as c on d.materiaid = c.id where d.datesold >= '" + dteStartDate.Value.ToString("yyyy-MM-dd") + "' and " + "d.datesold <= '" + dteEndDate.Value.ToString("yyy-MM-dd") + " 23:59'"; DataTable dt = null; using (var cmd = new SqlCommand(query, new SqlConnection(cs))) { dt = new DataTable("salesReport"); cmd.Connection.Open(); dt.Load(cmd.ExecuteReader()); } if (dt != null && dt.Rows.Count >= 1) { var reportform = new frmPrint() { ReportData = dt, ReportFile = "salesreport.rdlc", DataSetName = "salesReport", ZoomLevel = 100 }; reportform.Show(); } }
private void Print_Click(object sender, EventArgs e) { if (dataGridView2.SelectedRows.Count == 0) { return; } int p_id = Convert.ToInt32(dataGridView2.SelectedRows[0].Cells["orderid"].Value); // get data for print var dt = new DataTable("report"); using (var _cmd = new SqlCommand()) { _cmd.CommandText = "select sales.Id, MaterialName = MaterialSetup.Material, sales.Quantity, sales.AmountPerYard, sales.Discount, sales.TotalAmount, GrandTotal = (select sum(TotalAmount) from sales where OrderId = @order_id), OrderId from sales inner join " + "MaterialSetup on sales.MateriaId = MaterialSetup.Id where orderid = @order_id"; _cmd.Parameters.AddWithValue("order_id", p_id); _cmd.Connection = new SqlConnection(cs); _cmd.Connection.Open(); var dr = _cmd.ExecuteReader(); dt.Load(dr); } var receipt_form = new frmPrint() { ReportFile = "receipt.rdlc", ReportData = dt, DataSetName = "SalesReceipt", ZoomLevel = 75 }; receipt_form.Show(); }