using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Microsoft.Reporting.WinForms;

namespace Baza_Reklam
{
    public partial class LetterViewer : Form
    {
        private short nrAMT;
        private short nrGS1;
        private short nrGS2;

        public LetterViewer(int custId, short nrAMT, short nrGS1, short nrGS2, DateTime dataWysylki)
        {
            InitializeComponent();

            this.nrAMT = nrAMT;
            this.nrGS1 = nrGS1;
            this.nrGS2 = nrGS2;

            KLIENCITableAdapter.FillByCustomerId(REKLAMADataSet.KLIENCI, custId);
            ListaReklamDoWydaniaNrTableAdapter.ClearBeforeFill = false;
            ListaReklamDoWydaniaNrTableAdapter.FillByCustomerId(REKLAMADataSet.ListaReklamDoWydaniaNr, custId, "AMT",
                                                                nrAMT);
            ListaReklamDoWydaniaNrTableAdapter.FillByCustomerId(REKLAMADataSet.ListaReklamDoWydaniaNr, custId, "GS",
                                                                nrGS1);
            ListaReklamDoWydaniaNrTableAdapter.FillByCustomerId(REKLAMADataSet.ListaReklamDoWydaniaNr, custId, "GS",
                                                                nrGS2);

            List<ReportParameter> paramList = new List<ReportParameter>();

            paramList.Add(new ReportParameter("nrAMT", nrAMT.ToString()));
            paramList.Add(new ReportParameter("nrGS1", nrGS1.ToString()));
            paramList.Add(new ReportParameter("nrGS2", nrGS2.ToString()));
            paramList.Add(new ReportParameter("data_wysylki", dataWysylki.ToShortDateString()));
            reportViewer1.LocalReport.SetParameters(paramList);

            reportViewer1.LocalReport.SubreportProcessing += SubreportProcessing;
        }

        public LetterViewer(List<int> custId, short nrAMT, short nrGS1, short nrGS2, DateTime dataWysylki)
        {
            InitializeComponent();

            this.nrAMT = nrAMT;
            this.nrGS1 = nrGS1;
            this.nrGS2 = nrGS2;

            KLIENCITableAdapter.ClearBeforeFill = false;
            ListaReklamDoWydaniaNrTableAdapter.ClearBeforeFill = false;

            foreach (int i in custId)
            {
                KLIENCITableAdapter.FillByCustomerId(REKLAMADataSet.KLIENCI, i);
                ListaReklamDoWydaniaNrTableAdapter.FillByCustomerId(REKLAMADataSet.ListaReklamDoWydaniaNr, i, "AMT",
                                                                    nrAMT);
                ListaReklamDoWydaniaNrTableAdapter.FillByCustomerId(REKLAMADataSet.ListaReklamDoWydaniaNr, i, "GS",
                                                                    nrGS1);
                ListaReklamDoWydaniaNrTableAdapter.FillByCustomerId(REKLAMADataSet.ListaReklamDoWydaniaNr, i, "GS",
                                                                    nrGS2);
            }

            List<ReportParameter> paramList = new List<ReportParameter>();

            paramList.Add(new ReportParameter("nrAMT", nrAMT.ToString()));
            paramList.Add(new ReportParameter("nrGS1", nrGS1.ToString()));
            paramList.Add(new ReportParameter("nrGS2", nrGS2.ToString()));
            paramList.Add(new ReportParameter("data_wysylki", dataWysylki.ToShortDateString()));
            reportViewer1.LocalReport.SetParameters(paramList);
            reportViewer1.LocalReport.SubreportProcessing += SubreportProcessing;
        }

        private void LetterViewer_Load(object sender, EventArgs e)
        {
            reportViewer1.RefreshReport();
        }

        private void SubreportProcessing(object sender, SubreportProcessingEventArgs e)
        {
            e.DataSources.Add(new ReportDataSource("REKLAMADataSet_ListaReklamDoWydaniaNr",
                                                   REKLAMADataSet.ListaReklamDoWydaniaNr));
        }
    }
}