private void button2_Click(object sender, EventArgs e) { try { HoTro ht = new HoTro(); string command = "select ProductId, MfgDate, ExpDate, ProdName, PurchasePrice, SalePrice,DisCount, BillSale.CreateDate" + " from product join ProductName" + " on Product.productNameid = ProductName.productNameid" + " join BillSale" + " on Product.BillSaleId = BillSale.BillSaleId"; SqlDataAdapter adapter = new SqlDataAdapter(command, ht.KetNoi()); BaoCao.DataSet2 dataset = new SSMP.BaoCao.DataSet2(); adapter.Fill(dataset, "DataTable1"); BaoCao.TestXuatCrystalReport report = new SSMP.BaoCao.TestXuatCrystalReport(); report.SetDataSource(dataset); crystalReportViewer1.ReportSource = report; } catch (Exception ex) { MessageBox.Show(ex.Message); MessageBox.Show(ex.StackTrace); } }
private void taiCrystalReport() { try { string tuNgay, denNgay; if (checkBoxNgay.Checked) { tuNgay = dateTimePicker1.Value.ToShortDateString(); denNgay = dateTimePicker2.Value.ToShortDateString(); } else { tuNgay = "1/1/2009"; denNgay = DateTime.Now.ToShortDateString(); } HoTro ht = new HoTro(); SqlConnection conn = ht.KetNoi(); string command = "select ProductId,convert(varchar,MfgDate,103) as 'MfgDate',convert(varchar,ExpDate,103) as 'ExpDate' , ProdName, PurchasePrice, SalePrice,DisCount,convert(varchar,BillSale.CreateDate,103) as 'CreateDate' " + " from product join ProductName" + " on Product.productNameid = ProductName.productNameid" + " join BillSale" + " on Product.BillSaleId = BillSale.BillSaleId" + " where BillSale.CreateDate >= '" + tuNgay + "' and BillSale.CreateDate <= '" + denNgay + "'"; SqlDataAdapter adapter = new SqlDataAdapter(command, conn); BaoCao.DataSet2 dataset = new SSMP.BaoCao.DataSet2(); adapter.Fill(dataset, "DataTable1"); BaoCao.TestXuatCrystalReport report = new SSMP.BaoCao.TestXuatCrystalReport(); report.SetDataSource(dataset); crystalReportViewer1.ReportSource = report; conn.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }