Beispiel #1
0
        private void GenerateReport()
        {
            try
            {
                int driverid  = ddl_Driver.SelectedValue.ToInt();
                int vehicleId = ddlVehicle.SelectedValue.ToInt();

                string Error = "";
                if (driverid == 0 && !chkAllDriver.Checked)
                {
                    Error = "Required :  Driver";
                }
                if (vehicleId == 0)
                {
                    if (string.IsNullOrEmpty(Error))
                    {
                        Error = "Required :  Vehicle";
                    }
                    else
                    {
                        Error += Environment.NewLine + "Required :  Vehicle";
                    }
                }
                if (!string.IsNullOrEmpty(Error))
                {
                    ENUtils.ShowMessage(Error);
                    return;
                }

                if (dtpFromDate.Value != null && dtpFromDate.Value.Value.Year == 1753)
                {
                    dtpFromDate.Value = null;
                }

                if (dtpTillDate.Value != null && dtpTillDate.Value.Value.Year == 1753)
                {
                    dtpTillDate.Value = null;
                }

                DateTime?fromDate = dtpFromDate.Value.ToDateorNull();
                DateTime?tillDate = dtpTillDate.Value.ToDateorNull();


                if (tillDate != null)
                {
                    tillDate = tillDate + TimeSpan.Parse("23:59:59");
                }


                using (TaxiDataContext db = new TaxiDataContext())
                {
                    this.stp_JobHIstoryResultBindingSource.DataSource = db.stp_JobHIstory(fromDate, tillDate, driverid, vehicleId).ToList().OrderByDescending(c => c.BookingDate);
                }


                Microsoft.Reporting.WinForms.ReportParameter[] param = new Microsoft.Reporting.WinForms.ReportParameter[4];

                string address = AppVars.objSubCompany.Address;
                string telNo   = "Tel No. " + AppVars.objSubCompany.TelephoneNo;

                param[0] = new Microsoft.Reporting.WinForms.ReportParameter("Report_Parameter_Header", AppVars.objSubCompany.CompanyName.ToStr());
                param[1] = new Microsoft.Reporting.WinForms.ReportParameter("Report_Parameter_Address", address);
                param[2] = new Microsoft.Reporting.WinForms.ReportParameter("Report_Parameter_Telephone", telNo);

                string heading = string.Empty;
                if (fromDate != null && tillDate != null)
                {
                    heading = string.Format("{0:dd/MM/yyyy}", fromDate) + " to " + string.Format("{0:dd/MM/yyyy}", tillDate);
                }
                param[3] = new Microsoft.Reporting.WinForms.ReportParameter("Report_Parameter_Criteria", heading);

                reportViewer1.LocalReport.SetParameters(param);

                this.reportViewer1.ZoomPercent = 100;
                this.reportViewer1.ZoomMode    = Microsoft.Reporting.WinForms.ZoomMode.Percent;
                this.reportViewer1.RefreshReport();
            }
            catch (Exception ex)
            {
                ENUtils.ShowMessage(ex.Message);
            }
        }