Example #1
0
 private void btnPrintSelected_Click(object sender, EventArgs e)
 {
     if (dgvDebit.Rows.Count == 0)
     {
         MessageBox.Show(@"No data");
         return;
     }
     try
     {
         this.Cursor = Cursors.WaitCursor;
         int id = Convert.ToInt32(dgvDebit.CurrentRow.Cells[0].Value);
         RPT.frm_Rpt_Product             frm    = new RPT.frm_Rpt_Product();
         RPT.rpt_Print_CustomerTransById Report = new RPT.rpt_Print_CustomerTransById();
         Report.SetDataSource(cls_Debit.Print_CustomerTrans_ByCustId(id));
         frm.crystalReportViewer1.ReportSource = Report;
         frm.ShowDialog();
         this.Cursor = Cursors.Default;
     }
     catch (IOException ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
        private void btnPrint_Click(object sender, EventArgs e)
        {
            if (rdbAll.Checked && RepKind == "Purchase")
            {
                // get last order to print

                try
                {
                    if (dgvReport.Rows.Count == 0)
                    {
                        return;
                    }
                    this.Cursor = Cursors.WaitCursor;
                    int Order_No = Convert.ToInt32(dgvReport.CurrentRow.Cells[0].Value);
                    RPT.rpt_PrintAll_Invoices MyReport = new RPT.rpt_PrintAll_Invoices();
                    RPT.frm_Rpt_Product       MyForm   = new RPT.frm_Rpt_Product();
                    MyReport.SetDataSource(cls_Invoice.stp_Search_Invoices(""));
                    //MyReport.Refresh();
                    MyForm.crystalReportViewer1.ReportSource = MyReport;
                    MyForm.ShowDialog();
                    this.Cursor = Cursors.Default;
                }
                catch (IOException ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            else if (rdbAll.Checked && RepKind == "Sales")
            {
                if (dgvReport.Rows.Count == 0)
                {
                    return;
                }
                this.Cursor = Cursors.WaitCursor;
                int Order_No = Convert.ToInt32(dgvReport.CurrentRow.Cells[0].Value);
                RPT.rpt_PrintAll_Orders MyReport = new RPT.rpt_PrintAll_Orders();
                RPT.frm_Rpt_Product     MyForm   = new RPT.frm_Rpt_Product();
                MyReport.SetDataSource(cls_Order.stp_Search_Orders(""));
                //MyReport.Refresh();
                MyForm.crystalReportViewer1.ReportSource = MyReport;
                MyForm.ShowDialog();
                this.Cursor = Cursors.Default;
            }
            else if (rdbAll.Checked && RepKind == "RPurchase")
            {
                if (dgvReport.Rows.Count == 0)
                {
                    return;
                }
                this.Cursor = Cursors.WaitCursor;
                RPT.rpt_PrintAll_RPurchase MyReport = new RPT.rpt_PrintAll_RPurchase();
                RPT.frm_Rpt_Product        MyForm   = new RPT.frm_Rpt_Product();
                MyReport.SetDataSource(cls_RInvoice.stp_Search_RInvoices(""));
                //MyReport.Refresh();
                MyForm.crystalReportViewer1.ReportSource = MyReport;
                MyForm.ShowDialog();
                this.Cursor = Cursors.Default;
            }
            else if (rdbAll.Checked && RepKind == "RSales")
            {
                if (dgvReport.Rows.Count == 0)
                {
                    return;
                }
                this.Cursor = Cursors.WaitCursor;
                RPT.rpt_PrintAll_RSales MyReport = new RPT.rpt_PrintAll_RSales();
                RPT.frm_Rpt_Product     MyForm   = new RPT.frm_Rpt_Product();
                MyReport.SetDataSource(cls_ROrder.stp_Search_ROrders(""));
                //MyReport.Refresh();
                MyForm.crystalReportViewer1.ReportSource = MyReport;
                MyForm.ShowDialog();
                this.Cursor = Cursors.Default;
            }
            else if (rdbAll.Checked && RepKind == "Credit")
            {
                try
                {
                    this.Cursor = Cursors.WaitCursor;
                    RPT.frm_Rpt_Product            frm    = new RPT.frm_Rpt_Product();
                    RPT.rpt_PrintAll_SupplierTrans Report = new RPT.rpt_PrintAll_SupplierTrans();
                    Report.SetDataSource(cls_Credit.stp_Search_SupplierTrans(""));
                    frm.crystalReportViewer1.ReportSource = Report;
                    frm.ShowDialog();
                    this.Cursor = Cursors.Default;
                }
                catch (IOException ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            else if (rdbAll.Checked && RepKind == "Debit")
            {
                try
                {
                    this.Cursor = Cursors.WaitCursor;
                    RPT.frm_Rpt_Product            frm    = new RPT.frm_Rpt_Product();
                    RPT.rpt_PrintAll_CustomerTrans Report = new RPT.rpt_PrintAll_CustomerTrans();
                    Report.SetDataSource(cls_Debit.stp_Search_CustomerTrans(""));
                    frm.crystalReportViewer1.ReportSource = Report;
                    frm.ShowDialog();
                    this.Cursor = Cursors.Default;
                }
                catch (IOException ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }

            // By Date

            if (rdbDate.Checked && RepKind == "Purchase")
            {
                try
                {
                    if (dgvReport.Rows.Count == 0)
                    {
                        return;
                    }
                    this.Cursor = Cursors.WaitCursor;
                    RPT.rpt_Print_PurchaseByDate MyReport = new RPT.rpt_Print_PurchaseByDate();
                    RPT.frm_Rpt_Product          MyForm   = new RPT.frm_Rpt_Product();
                    MyReport.SetDataSource(cls_Invoice.Print_Invoices_ByDate(dtpStart.Value, dtpEnd.Value));
                    //MyReport.Refresh();
                    MyForm.crystalReportViewer1.ReportSource = MyReport;
                    MyForm.ShowDialog();
                    this.Cursor = Cursors.Default;
                }
                catch (IOException ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            else if (rdbDate.Checked && RepKind == "Sales")
            {
                if (dgvReport.Rows.Count == 0)
                {
                    return;
                }
                this.Cursor = Cursors.WaitCursor;
                RPT.rpt_PrintSalesByDate MyReport = new RPT.rpt_PrintSalesByDate();
                RPT.frm_Rpt_Product      MyForm   = new RPT.frm_Rpt_Product();
                MyReport.SetDataSource(cls_Order.Print_Orders_ByDate(dtpStart.Value, dtpEnd.Value));
                //MyReport.Refresh();
                MyForm.crystalReportViewer1.ReportSource = MyReport;
                MyForm.ShowDialog();
                this.Cursor = Cursors.Default;
            }
            else if (rdbDate.Checked && RepKind == "RPurchase")
            {
                try
                {
                    if (dgvReport.Rows.Count == 0)
                    {
                        return;
                    }
                    this.Cursor = Cursors.WaitCursor;
                    RPT.rpt_Print_RPuchaseByDate MyReport = new RPT.rpt_Print_RPuchaseByDate();
                    RPT.frm_Rpt_Product          MyForm   = new RPT.frm_Rpt_Product();
                    MyReport.SetDataSource(cls_RInvoice.Print_RInvoices_ByDate(dtpStart.Value, dtpEnd.Value));
                    //MyReport.Refresh();
                    MyForm.crystalReportViewer1.ReportSource = MyReport;
                    MyForm.ShowDialog();
                    this.Cursor = Cursors.Default;
                }
                catch (IOException ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            else if (rdbDate.Checked && RepKind == "RSales")
            {
                if (dgvReport.Rows.Count == 0)
                {
                    return;
                }
                this.Cursor = Cursors.WaitCursor;

                RPT.rpt_Print_ROrderById MyReport = new RPT.rpt_Print_ROrderById();
                RPT.frm_Rpt_Product      MyForm   = new RPT.frm_Rpt_Product();
                MyReport.SetDataSource(cls_ROrder.Print_ROrders_ByDate(dtpStart.Value, dtpEnd.Value));
                //MyReport.Refresh();
                MyForm.crystalReportViewer1.ReportSource = MyReport;
                MyForm.ShowDialog();
                this.Cursor = Cursors.Default;
            }
            else if (rdbDate.Checked && RepKind == "Credit")
            {
                try
                {
                    this.Cursor = Cursors.WaitCursor;
                    RPT.frm_Rpt_Product frm = new RPT.frm_Rpt_Product();
                    RPT.rpt_Print_SupplierTransByDate Report = new RPT.rpt_Print_SupplierTransByDate();
                    Report.SetDataSource(cls_Credit.Print_SupplierTrans_ByDate(dtpStart.Value, dtpEnd.Value));
                    frm.crystalReportViewer1.ReportSource = Report;
                    frm.ShowDialog();
                    this.Cursor = Cursors.Default;
                }
                catch (IOException ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            else if (rdbDate.Checked && RepKind == "Debit")
            {
                try
                {
                    this.Cursor = Cursors.WaitCursor;
                    RPT.frm_Rpt_Product            frm    = new RPT.frm_Rpt_Product();
                    RPT.rpt_PrintAll_CustomerTrans Report = new RPT.rpt_PrintAll_CustomerTrans();
                    Report.SetDataSource(cls_Debit.Print_CustomerTrans_ByDate(dtpStart.Value, dtpEnd.Value));
                    frm.crystalReportViewer1.ReportSource = Report;
                    frm.ShowDialog();
                    this.Cursor = Cursors.Default;
                }
                catch (IOException ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }

            // By Suppllier-Customer
            if (rdbId.Checked && RepKind == "Purchase")
            {
                try
                {
                    if (dgvReport.Rows.Count == 0)
                    {
                        return;
                    }
                    this.Cursor = Cursors.WaitCursor;
                    RPT.rpt_Print_InvoiceById MyReport = new RPT.rpt_Print_InvoiceById();
                    RPT.frm_Rpt_Product       MyForm   = new RPT.frm_Rpt_Product();
                    MyReport.SetDataSource(cls_Invoice.Print_Invoices_BySupId(Convert.ToInt32(txtId.Text)));
                    //MyReport.Refresh();
                    MyForm.crystalReportViewer1.ReportSource = MyReport;
                    MyForm.ShowDialog();
                    this.Cursor = Cursors.Default;
                }
                catch (IOException ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            else if (rdbId.Checked && RepKind == "Sales")
            {
                if (dgvReport.Rows.Count == 0)
                {
                    return;
                }
                this.Cursor = Cursors.WaitCursor;
                RPT.rpt_Print_OrderById MyReport = new RPT.rpt_Print_OrderById();
                RPT.frm_Rpt_Product     MyForm   = new RPT.frm_Rpt_Product();
                MyReport.SetDataSource(cls_Order.Print_Orders_ByCust_Id(Convert.ToInt32(txtId.Text)));
                //MyReport.Refresh();
                MyForm.crystalReportViewer1.ReportSource = MyReport;
                MyForm.ShowDialog();
                this.Cursor = Cursors.Default;
            }
            else if (rdbId.Checked && RepKind == "RPurchase")
            {
                try
                {
                    if (dgvReport.Rows.Count == 0)
                    {
                        return;
                    }
                    this.Cursor = Cursors.WaitCursor;
                    RPT.rpt_Print_RInvoiceById MyReport = new RPT.rpt_Print_RInvoiceById();
                    RPT.frm_Rpt_Product        MyForm   = new RPT.frm_Rpt_Product();
                    MyReport.SetDataSource(cls_RInvoice.Print_RInvoices_BySupId(Convert.ToInt32(txtId.Text)));
                    //MyReport.Refresh();
                    MyForm.crystalReportViewer1.ReportSource = MyReport;
                    MyForm.ShowDialog();
                    this.Cursor = Cursors.Default;
                }
                catch (IOException ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            else if (rdbId.Checked && RepKind == "RSales")
            {
                if (dgvReport.Rows.Count == 0)
                {
                    return;
                }
                this.Cursor = Cursors.WaitCursor;
                RPT.rpt_Print_ROrderById MyReport = new RPT.rpt_Print_ROrderById();
                RPT.frm_Rpt_Product      MyForm   = new RPT.frm_Rpt_Product();
                MyReport.SetDataSource(cls_ROrder.Print_ROrders_ByCust_Id(Convert.ToInt32(txtId.Text)));
                MyForm.crystalReportViewer1.ReportSource = MyReport;
                MyForm.ShowDialog();
                this.Cursor = Cursors.Default;
            }
            else if (rdbId.Checked && RepKind == "Credit")
            {
                try
                {
                    this.Cursor = Cursors.WaitCursor;
                    RPT.frm_Rpt_Product             frm    = new RPT.frm_Rpt_Product();
                    RPT.rpt_Print_SupplierTransById Report = new RPT.rpt_Print_SupplierTransById();
                    Report.SetDataSource(cls_Credit.Print_SupplierTrans_BySupId(Convert.ToInt32(txtId.Text)));
                    frm.crystalReportViewer1.ReportSource = Report;
                    frm.ShowDialog();
                    this.Cursor = Cursors.Default;
                }
                catch (IOException ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            else if (rdbId.Checked && RepKind == "Debit")
            {
                try
                {
                    this.Cursor = Cursors.WaitCursor;
                    RPT.frm_Rpt_Product             frm    = new RPT.frm_Rpt_Product();
                    RPT.rpt_Print_CustomerTransById Report = new RPT.rpt_Print_CustomerTransById();
                    Report.SetDataSource(cls_Debit.Print_CustomerTrans_ByCustId(Convert.ToInt32(txtId.Text)));
                    frm.crystalReportViewer1.ReportSource = Report;
                    frm.ShowDialog();
                    this.Cursor = Cursors.Default;
                }
                catch (IOException ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }