Example #1
0
        public void LoadData()
        {
            if (dateTimePickerFrom.Value.Date >= dateTimePickerTo.Value.Date)
            {
                MessageBox.Show("Дата начала должна быть меньше даты окончания", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            try
            {
                ReportParameter parameter = new ReportParameter("ReportParameterPeriod", "c " + dateTimePickerFrom.Value.ToShortDateString() + " по " + dateTimePickerTo.Value.ToShortDateString());
                reportViewer.LocalReport.SetParameters(parameter);

                var requests = logic.GetRequests(new ReportBindingModel {
                    DateFrom = dateTimePickerFrom.Value.Date, DateTo = dateTimePickerTo.Value.Date
                });
                var cars = logic.GetCars();
                List <ReportCarsViewModel> dataSourceCars = new List <ReportCarsViewModel>();
                foreach (var car in cars)
                {
                    dataSourceCars.Add(new ReportCarsViewModel {
                        CarName = car.CarName, FullPrice = car.FullPrice, Price = car.Price, Year = car.Year
                    });
                }
                List <ReportRequestsViewModel> dataSourceRequests = new List <ReportRequestsViewModel>();
                foreach (var reqs in requests)
                {
                    foreach (var req in reqs)
                    {
                        dataSourceRequests.Add(new ReportRequestsViewModel {
                            RequestName = req.RequestName, DateCreate = req.DateCreate
                        });
                    }
                }
                ReportDataSource sourceCars     = new ReportDataSource("DataSetCars", dataSourceCars);
                ReportDataSource sourceRequests = new ReportDataSource("DataSetRequests", dataSourceRequests);
                reportViewer.LocalReport.DataSources.Add(sourceCars);
                reportViewer.LocalReport.DataSources.Add(sourceRequests);
                reportViewer.RefreshReport();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
            this.reportViewer.RefreshReport();
        }