Example #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                HoTro ht = new HoTro();
                string command = "select ProductId, MfgDate, ExpDate, ProdName, PurchasePrice, SalePrice,DisCount,StatusName, BillPurchase.CreateDate"
                                    + " from product join ProductName"
                                    + " on Product.productNameid =  ProductName.productNameid"
                                    + " join ProductStatus"
                                    + " on Product.StatusId =  ProductStatus.StatusId"
                                    + " join BillPurchase"
                                    + " on Product.BillPurchaseId =  BillPurchase.BillPurchaseId";

                SqlDataAdapter adapter = new SqlDataAdapter(command, ht.KetNoi());
                BaoCao.DataSet1 dataset = new SSMP.BaoCao.DataSet1();
                adapter.Fill(dataset, "DataTable1");
                BaoCao.TestNhapCrystalReport report = new SSMP.BaoCao.TestNhapCrystalReport();
                report.SetDataSource(dataset);
                crystalReportViewer1.ReportSource = report;

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                MessageBox.Show(ex.StackTrace);
            }
        }
Example #2
0
        private void taiCrystalReport()
        {
            try
            {
                HoTro ht = new HoTro();
                SqlConnection conn = ht.KetNoi();
                string tuNgay, denNgay;
                if (checkBoxNgay.Checked)
                {
                    tuNgay = dateTimePicker1.Value.ToShortDateString();
                    denNgay = dateTimePicker2.Value.ToShortDateString();
                }
                else
                {
                    tuNgay = "1/1/2009";
                    denNgay = DateTime.Now.ToShortDateString();
                }

                string command = "select ProductId, convert(varchar,MfgDate,103) as 'MfgDate',convert(varchar,ExpDate,103) as 'ExpDate', ProdName, PurchasePrice, SalePrice,DisCount,StatusName,  convert(varchar,BillPurchase.CreateDate,103) as 'CreateDate' "
                                    + " from product join ProductName"
                                    + " on Product.productNameid =  ProductName.productNameid"
                                    + " join ProductStatus"
                                    + " on Product.StatusId =  ProductStatus.StatusId"
                                    + " join BillPurchase"
                                    + " on Product.BillPurchaseId =  BillPurchase.BillPurchaseId"
                +" where BillPurchase.CreateDate >= '" + tuNgay + "' and BillPurchase.CreateDate <= '" + denNgay + "'";
                SqlDataAdapter adapter = new SqlDataAdapter(command, conn);
                BaoCao.DataSet1 dataset = new SSMP.BaoCao.DataSet1();
                adapter.Fill(dataset, "DataTable1");
                BaoCao.TestNhapCrystalReport report = new SSMP.BaoCao.TestNhapCrystalReport();
                report.SetDataSource(dataset);
                crystalReportViewer1.ReportSource = report;
                conn.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                MessageBox.Show(ex.StackTrace);
            }
        }