| 1 | using System;
|
|---|
| 2 | using System.Collections.Generic;
|
|---|
| 3 | using System.ComponentModel;
|
|---|
| 4 | using System.Data;
|
|---|
| 5 | using System.Drawing;
|
|---|
| 6 | using System.Text;
|
|---|
| 7 | using System.Windows.Forms;
|
|---|
| 8 | using Baza_Reklam.raportyTableAdapters;
|
|---|
| 9 | using Microsoft.Reporting.WinForms;
|
|---|
| 10 | using System.Drawing.Printing;
|
|---|
| 11 | using System.Drawing.Imaging;
|
|---|
| 12 | using System.Reflection;
|
|---|
| 13 | using System.IO;
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 | namespace Baza_Reklam
|
|---|
| 17 | {
|
|---|
| 18 | public partial class FactureViewer : Form
|
|---|
| 19 | {
|
|---|
| 20 | private InvoiceProviderTableAdapter invoiceProviderTableAdapter;
|
|---|
| 21 | private int idFaktury;
|
|---|
| 22 | private readonly int idKorekty;
|
|---|
| 23 | private readonly int idPoprzedniejKorekty;
|
|---|
| 24 |
|
|---|
| 25 | /// <summary>
|
|---|
| 26 | /// true - faktura, false - proforma
|
|---|
| 27 | /// </summary>
|
|---|
| 28 | bool proforma;
|
|---|
| 29 | DataSet ds;
|
|---|
| 30 |
|
|---|
| 31 | public FactureViewer(int idFakt, bool rodzaj, int old)
|
|---|
| 32 | {
|
|---|
| 33 | InitializeComponent();
|
|---|
| 34 |
|
|---|
| 35 | idFaktury = idFakt;
|
|---|
| 36 |
|
|---|
| 37 | proforma = rodzaj;
|
|---|
| 38 |
|
|---|
| 39 | btnRefresh.Click += btnRefresh_Old_Click;
|
|---|
| 40 |
|
|---|
| 41 | fakturaTableAdapter1.Connection.ConnectionString = ConnString.getConnString().Value;
|
|---|
| 42 | fakturA_DETAILSTableAdapter1.Connection.ConnectionString = ConnString.getConnString().Value;
|
|---|
| 43 | fAKTURYTableAdapter.Connection.ConnectionString = ConnString.getConnString().Value;
|
|---|
| 44 | proformaTableAdapter.Connection.ConnectionString = ConnString.getConnString().Value;
|
|---|
| 45 |
|
|---|
| 46 | ds = new DataSet();
|
|---|
| 47 |
|
|---|
| 48 | //zczytuje dane z pliku z tlumaczeniami
|
|---|
| 49 | Stream s = Assembly.GetExecutingAssembly().GetManifestResourceStream("Baza_Reklam.Raporty.faktura.xml");
|
|---|
| 50 | ds.ReadXml(s);
|
|---|
| 51 |
|
|---|
| 52 | fAKTURYTableAdapter.FillByIdFaktury(rEKLAMADataSet.FAKTURY, idFakt);
|
|---|
| 53 |
|
|---|
| 54 | //ustawienie parametrów, nowych datasoure dla raportu
|
|---|
| 55 |
|
|---|
| 56 | //ustawianie danych dla raportu
|
|---|
| 57 | if (proforma)
|
|---|
| 58 | {
|
|---|
| 59 | jezykComboBox.Enabled = false;
|
|---|
| 60 | reportViewer1.LocalReport.ReportEmbeddedResource = "Baza_Reklam.Raporty.proformaReversed.rdlc";
|
|---|
| 61 | reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("Faktura", proformaTableAdapter.GetDataByIdFaktury(idFakt)));
|
|---|
| 62 | }
|
|---|
| 63 | else
|
|---|
| 64 | {
|
|---|
| 65 | typComboBox.Enabled = false;
|
|---|
| 66 | reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("Faktura", fakturaTableAdapter1.GetDataByIdFaktury(idFakt)));
|
|---|
| 67 | reportViewer1.LocalReport.ReportEmbeddedResource = "Baza_Reklam.Raporty.fakturaReversed.rdlc";
|
|---|
| 68 | }
|
|---|
| 69 |
|
|---|
| 70 | reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("FakturaDetails", fakturA_DETAILSTableAdapter1.GetDataByIdFaktury(idFakt)));
|
|---|
| 71 | reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("tlumaczenia", ds.Tables[0]));
|
|---|
| 72 |
|
|---|
| 73 | List<ReportParameter> paramList = new List<ReportParameter>();
|
|---|
| 74 |
|
|---|
| 75 | //Produkcja ma domylnie bez podpisu
|
|---|
| 76 |
|
|---|
| 77 | if (User.Instance().IsProdukcja)
|
|---|
| 78 | {
|
|---|
| 79 | podpisCheckBox.CheckState = CheckState.Unchecked;
|
|---|
| 80 | paramList.Add(new ReportParameter("podpis", podpisCheckBox.Checked.ToString(), true));
|
|---|
| 81 | reportViewer1.LocalReport.SetParameters(paramList);
|
|---|
| 82 | }
|
|---|
| 83 |
|
|---|
| 84 | jezykComboBox.SelectedIndex = 0;
|
|---|
| 85 | typComboBox.SelectedIndex = 1;
|
|---|
| 86 | }
|
|---|
| 87 |
|
|---|
| 88 | private static bool IsFakturaPoznanOrKatowice(string roz, int nabywca)
|
|---|
| 89 | {
|
|---|
| 90 | return roz.ToUpper() == "KAT" || roz.ToUpper() == "POZ" || nabywca == 678 || nabywca == 18845;
|
|---|
| 91 | }
|
|---|
| 92 |
|
|---|
| 93 | public FactureViewer(int idFakt, bool r)
|
|---|
| 94 | {
|
|---|
| 95 | Init(idFakt, r, string.Empty);
|
|---|
| 96 | }
|
|---|
| 97 |
|
|---|
| 98 | /// <param name="idFakt">ID_Faktury</param>
|
|---|
| 99 | /// <param name="r">true = proforma</param>
|
|---|
| 100 | /// <param name="kodKlienta"></param>
|
|---|
| 101 | public FactureViewer(int idFakt, bool r, string kodKlienta)
|
|---|
| 102 | {
|
|---|
| 103 | Init(idFakt, r, kodKlienta);
|
|---|
| 104 | }
|
|---|
| 105 |
|
|---|
| 106 | public void Init(int idFakt, bool r, string kodKlienta)
|
|---|
| 107 | {
|
|---|
| 108 | invoiceProviderTableAdapter = new InvoiceProviderTableAdapter();
|
|---|
| 109 | invoiceProviderTableAdapter.ClearBeforeFill = true;
|
|---|
| 110 | invoiceProviderTableAdapter.Connection.ConnectionString = ConnString.getConnString().Value;
|
|---|
| 111 |
|
|---|
| 112 | InitializeComponent();
|
|---|
| 113 |
|
|---|
| 114 | btnRefresh.Click += btnRefresh_Click;
|
|---|
| 115 |
|
|---|
| 116 | idFaktury = idFakt;
|
|---|
| 117 | proforma = r;
|
|---|
| 118 |
|
|---|
| 119 | fakturaTableAdapter1.Connection.ConnectionString = ConnString.getConnString().Value;
|
|---|
| 120 | fAKTURA_DETAILS2TableAdapter.Connection.ConnectionString = ConnString.getConnString().Value;
|
|---|
| 121 | fAKTURYTableAdapter.Connection.ConnectionString = ConnString.getConnString().Value;
|
|---|
| 122 | proformaTableAdapter.Connection.ConnectionString = ConnString.getConnString().Value;
|
|---|
| 123 |
|
|---|
| 124 | ds = new DataSet();
|
|---|
| 125 |
|
|---|
| 126 | //zczytuje dane z pliku z tlumaczeniami
|
|---|
| 127 | Stream s = Assembly.GetExecutingAssembly().GetManifestResourceStream("Baza_Reklam.Raporty.faktura.xml");
|
|---|
| 128 | ds.ReadXml(s);
|
|---|
| 129 |
|
|---|
| 130 | fAKTURYTableAdapter.FillByIdFaktury(rEKLAMADataSet.FAKTURY, idFakt);
|
|---|
| 131 |
|
|---|
| 132 | //ustawienie parametrów, nowych datasoure dla raportu
|
|---|
| 133 |
|
|---|
| 134 | //ustawianie danych dla raportu
|
|---|
| 135 | typComboBox.Enabled = false;
|
|---|
| 136 |
|
|---|
| 137 | raporty.FakturaDataTable fakturaDataTable = fakturaTableAdapter1.GetDataByIdFaktury(idFakt);
|
|---|
| 138 | raporty.FakturaRow faktura = (raporty.FakturaRow)fakturaDataTable.Rows[0];
|
|---|
| 139 | raporty.FAKTURA_DETAILS2DataTable fakturaDetails = fAKTURA_DETAILS2TableAdapter.GetDataIdFaktury(idFakt);
|
|---|
| 140 |
|
|---|
| 141 |
|
|---|
| 142 | bool isPoznanKatowice = IsFakturaPoznanOrKatowice(faktura.NUMER_ROZ, faktura.ID_NABYWCY);
|
|---|
| 143 |
|
|---|
| 144 | if (IsFakturaPoznanOrKatowice(faktura.NUMER_ROZ, faktura.ID_NABYWCY))
|
|---|
| 145 | reportViewer1.LocalReport.ReportEmbeddedResource = "Baza_Reklam.Raporty.fakturaKatowicePoznan.rdlc";
|
|---|
| 146 | else
|
|---|
| 147 | {
|
|---|
| 148 | object sumObject = fakturaDetails.Compute("Sum(ILOSC)", string.Empty);
|
|---|
| 149 | int numberOfTitles = GetDistinctCount(fakturaDetails, "SYMB");
|
|---|
| 150 | int numberOfAds = GetDistinctCount(fakturaDetails, "ReklamaId");
|
|---|
| 151 | /*
|
|---|
| 152 | if (Convert.ToInt32(sumObject) > 5 || numberOfTitles > 1 || numberOfAds > 1) //raport, gdzie specyfikacja nie miesci sie na pierwszej stronie
|
|---|
| 153 | reportViewer1.LocalReport.ReportEmbeddedResource = "Baza_Reklam.Raporty.fakturaReversed2.rdlc";
|
|---|
| 154 | else // specyfikacja zmiesci sie na pierwszej stronie
|
|---|
| 155 | reportViewer1.LocalReport.ReportEmbeddedResource = "Baza_Reklam.Raporty.fakturaReversed2_1page.rdlc";
|
|---|
| 156 | */
|
|---|
| 157 | reportViewer1.LocalReport.ReportEmbeddedResource = "Baza_Reklam.Raporty.fakturaReversed2.rdlc";
|
|---|
| 158 | }
|
|---|
| 159 |
|
|---|
| 160 | reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("Faktura", fakturaDataTable));
|
|---|
| 161 | reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("FakturaDetails2", fakturaDetails));
|
|---|
| 162 | reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("tlumaczenia", ds.Tables[0]));
|
|---|
| 163 |
|
|---|
| 164 |
|
|---|
| 165 | //SJ:
|
|---|
| 166 | //TODO: jak z Poznaniem i Katowicami, czy pobieranie SystemKsiegowyId nie jest b³êdem?
|
|---|
| 167 | //TODO: add InvoiceProviderId column to Invoices table
|
|---|
| 168 | int invoiceProviderId = Convert.ToInt32(rEKLAMADataSet.FAKTURY.Rows[0]["SystemKsiegowyId"]);
|
|---|
| 169 |
|
|---|
| 170 |
|
|---|
| 171 | //czy tu czasem nie zwraca z³ych danych
|
|---|
| 172 | reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("Baza_Reklam_InvoiceProvider",
|
|---|
| 173 | InvoiceProviderFactory.GetInvoiceProvidersById(invoiceProviderId)));
|
|---|
| 174 |
|
|---|
| 175 | List<ReportParameter> paramList = new List<ReportParameter>();
|
|---|
| 176 |
|
|---|
| 177 | //Produkcja ma domylnie bez podpisu
|
|---|
| 178 | if (User.Instance().IsProdukcja)
|
|---|
| 179 | {
|
|---|
| 180 | podpisCheckBox.CheckState = CheckState.Unchecked;
|
|---|
| 181 | }
|
|---|
| 182 |
|
|---|
| 183 | paramList.Add(new ReportParameter("podpis", podpisCheckBox.Checked.ToString(), true));
|
|---|
| 184 |
|
|---|
| 185 | if (!isPoznanKatowice)
|
|---|
| 186 | {
|
|---|
| 187 | if (faktura.Iswaluta_kursNull())
|
|---|
| 188 | paramList.Add(new ReportParameter("kursWaluty", "1", true));
|
|---|
| 189 | else
|
|---|
| 190 | paramList.Add(new ReportParameter("kursWaluty", faktura.waluta_kurs.ToString(), true));
|
|---|
| 191 | }
|
|---|
| 192 |
|
|---|
| 193 |
|
|---|
| 194 | if (proforma)
|
|---|
| 195 | {
|
|---|
| 196 | paramList.Add(new ReportParameter("proforma", "True", true));
|
|---|
| 197 | paramList.Add(new ReportParameter("kodKlienta", kodKlienta, true));
|
|---|
| 198 | }
|
|---|
| 199 | else
|
|---|
| 200 | {
|
|---|
| 201 | paramList.Add(new ReportParameter("proforma", "False", true));
|
|---|
| 202 | paramList.Add(new ReportParameter("kodKlienta", string.Empty, true));
|
|---|
| 203 | }
|
|---|
| 204 |
|
|---|
| 205 | if (!faktura.Issuma_zaplatNull() && faktura.suma_zaplat > 0)
|
|---|
| 206 | zaplaconoCheckBox.Checked = true;
|
|---|
| 207 |
|
|---|
| 208 | paramList.Add(new ReportParameter("zaplacono", zaplaconoCheckBox.Checked.ToString(), true));
|
|---|
| 209 |
|
|---|
| 210 | reportViewer1.LocalReport.SetParameters(paramList);
|
|---|
| 211 |
|
|---|
| 212 | jezykComboBox.SelectedIndex = 0;
|
|---|
| 213 | typComboBox.SelectedIndex = 1;
|
|---|
| 214 | }
|
|---|
| 215 |
|
|---|
| 216 | private int GetDistinctCount(DataTable dataTable, string column)
|
|---|
| 217 | {
|
|---|
| 218 | List<string> titles = new List<string>();
|
|---|
| 219 |
|
|---|
| 220 | foreach(DataRow dataRow in dataTable.Rows)
|
|---|
| 221 | {
|
|---|
| 222 | if(!titles.Contains(dataRow[column].ToString()))
|
|---|
| 223 | titles.Add(dataRow[column].ToString());
|
|---|
| 224 | }
|
|---|
| 225 |
|
|---|
| 226 | return titles.Count;
|
|---|
| 227 | }
|
|---|
| 228 |
|
|---|
| 229 | /// <summary>
|
|---|
| 230 | /// Przy pierwszej korekcie idKorygowanejFaktury = idPoprzedniejKorekty
|
|---|
| 231 | /// </summary>
|
|---|
| 232 | public FactureViewer(int idKorekty, int idKorygowanejFaktury, int idPoprzedniejKorekty)
|
|---|
| 233 | {
|
|---|
| 234 | invoiceProviderTableAdapter = new InvoiceProviderTableAdapter();
|
|---|
| 235 | invoiceProviderTableAdapter.ClearBeforeFill = true;
|
|---|
| 236 | invoiceProviderTableAdapter.Connection.ConnectionString = ConnString.getConnString().Value;
|
|---|
| 237 |
|
|---|
| 238 | InitializeComponent();
|
|---|
| 239 |
|
|---|
| 240 | powodKorektyComboBox.Enabled = true;
|
|---|
| 241 | opisTextBox.ReadOnly = !User.Instance().IsKierownik;
|
|---|
| 242 | opisTextBox.BackColor = User.Instance().IsKierownik ? Color.White : Color.WhiteSmoke;
|
|---|
| 243 |
|
|---|
| 244 | reportViewer1.LocalReport.ReportEmbeddedResource = "Baza_Reklam.Raporty.fakturaKorekta.rdlc";
|
|---|
| 245 |
|
|---|
| 246 | idFaktury = idKorygowanejFaktury;
|
|---|
| 247 | this.idKorekty = idKorekty;
|
|---|
| 248 | this.idPoprzedniejKorekty = idPoprzedniejKorekty;
|
|---|
| 249 |
|
|---|
| 250 | btnRefresh.Click += zapiszKorektaButton_Click;
|
|---|
| 251 |
|
|---|
| 252 | fakturaTableAdapter1.Connection.ConnectionString = ConnString.getConnString().Value;
|
|---|
| 253 | fAKTURA_DETAILS2TableAdapter.Connection.ConnectionString = ConnString.getConnString().Value;
|
|---|
| 254 | fAKTURYTableAdapter.Connection.ConnectionString = ConnString.getConnString().Value;
|
|---|
| 255 | proformaTableAdapter.Connection.ConnectionString = ConnString.getConnString().Value;
|
|---|
| 256 |
|
|---|
| 257 | ds = new DataSet();
|
|---|
| 258 |
|
|---|
| 259 | //zczytuje dane z pliku z tlumaczeniami
|
|---|
| 260 | Stream s = Assembly.GetExecutingAssembly().GetManifestResourceStream("Baza_Reklam.Raporty.faktura.xml");
|
|---|
| 261 | ds.ReadXml(s);
|
|---|
| 262 |
|
|---|
| 263 | fAKTURYTableAdapter.FillByIdFaktury(rEKLAMADataSet.FAKTURY, idKorekty);
|
|---|
| 264 |
|
|---|
| 265 | //ustawienie parametrów, nowych datasoure dla raportu
|
|---|
| 266 |
|
|---|
| 267 | typComboBox.Enabled = false;
|
|---|
| 268 |
|
|---|
| 269 | reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("Korekta", fakturaTableAdapter1.GetDataByIdFaktury(idKorekty)));
|
|---|
| 270 |
|
|---|
| 271 | reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("Faktura_Original", fakturaTableAdapter1.GetDataByIdFaktury(idFaktury)));
|
|---|
| 272 |
|
|---|
| 273 | reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("Faktura", fakturaTableAdapter1.GetDataByIdFaktury(idPoprzedniejKorekty)));
|
|---|
| 274 |
|
|---|
| 275 | ////piersza korekta
|
|---|
| 276 | //if (idPoprzedniejKorekty == idFaktury)
|
|---|
| 277 | // reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("FakturaDetails2",
|
|---|
| 278 | // fAKTURA_DETAILS2TableAdapter.
|
|---|
| 279 | // GetDataIdFaktury(idFaktury)));
|
|---|
| 280 | //else
|
|---|
| 281 | // reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("FakturaDetails2",
|
|---|
| 282 | // fAKTURA_DETAILS2TableAdapter.GetDataIdFaktury(idPoprzedniejKorekty)));
|
|---|
| 283 |
|
|---|
| 284 | reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("FakturaDetails2", fAKTURA_DETAILS2TableAdapter.GetDataIdFaktury(idPoprzedniejKorekty)));
|
|---|
| 285 |
|
|---|
| 286 |
|
|---|
| 287 |
|
|---|
| 288 | reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("FakturaDetailsKorekty", fAKTURA_DETAILS2TableAdapter.GetDataIdFaktury(idKorekty)));
|
|---|
| 289 | reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("tlumaczenia", ds.Tables[0]));
|
|---|
| 290 |
|
|---|
| 291 | //TODO: add InvoiceProviderId column to Invoices table
|
|---|
| 292 | int invoiceProviderId = Convert.ToInt32(rEKLAMADataSet.FAKTURY.Rows[0]["SystemKsiegowyId"]);
|
|---|
| 293 |
|
|---|
| 294 | reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("Baza_Reklam_InvoiceProvider",
|
|---|
| 295 | InvoiceProviderFactory.GetInvoiceProvidersById(invoiceProviderId)));
|
|---|
| 296 |
|
|---|
| 297 | List<ReportParameter> paramList = new List<ReportParameter>();
|
|---|
| 298 |
|
|---|
| 299 | //Produkcja ma domylnie bez podpisu
|
|---|
| 300 |
|
|---|
| 301 | if (User.Instance().IsProdukcja)
|
|---|
| 302 | {
|
|---|
| 303 | podpisCheckBox.CheckState = CheckState.Unchecked;
|
|---|
| 304 | paramList.Add(new ReportParameter("podpis", podpisCheckBox.Checked.ToString(), true));
|
|---|
| 305 | reportViewer1.LocalReport.SetParameters(paramList);
|
|---|
| 306 | }
|
|---|
| 307 | jezykComboBox.SelectedIndex = 0;
|
|---|
| 308 | typComboBox.SelectedIndex = 1;
|
|---|
| 309 |
|
|---|
| 310 | }
|
|---|
| 311 |
|
|---|
| 312 | private void FactureViewer_Load(object sender, EventArgs e)
|
|---|
| 313 | {
|
|---|
| 314 | reportViewer1.RefreshReport();
|
|---|
| 315 | reportViewer1.RefreshReport();
|
|---|
| 316 |
|
|---|
| 317 | nUMERTextBox.Enabled = User.Instance().IsKierownik;
|
|---|
| 318 | }
|
|---|
| 319 |
|
|---|
| 320 | private void btnRefresh_Old_Click(object sender, EventArgs e)
|
|---|
| 321 | {
|
|---|
| 322 | Cursor = Cursors.WaitCursor;
|
|---|
| 323 |
|
|---|
| 324 | //zapisanie zmian w polu "opis" faktury
|
|---|
| 325 | fAKTURYBindingSource.EndEdit();
|
|---|
| 326 | fAKTURYTableAdapter.Update(rEKLAMADataSet.FAKTURY);
|
|---|
| 327 | fAKTURYTableAdapter.FillByIdFaktury(rEKLAMADataSet.FAKTURY, idFaktury);
|
|---|
| 328 |
|
|---|
| 329 | reportViewer1.Reset();
|
|---|
| 330 | reportViewer1.LocalReport.ReportEmbeddedResource = proforma ? "Baza_Reklam.Raporty.proformaReversed.rdlc" : "Baza_Reklam.Raporty.fakturaReversed.rdlc";
|
|---|
| 331 |
|
|---|
| 332 | //ustawienie parametrów, nowych datasoure dla raportu
|
|---|
| 333 | List<ReportParameter> paramList = new List<ReportParameter>();
|
|---|
| 334 |
|
|---|
| 335 | if (proforma)
|
|---|
| 336 | {
|
|---|
| 337 | //paramList.Add(new ReportParameter("typ", typComboBox.SelectedItem.ToString(), true));
|
|---|
| 338 | paramList.Add(new ReportParameter("podpis", podpisCheckBox.Checked.ToString(), true));
|
|---|
| 339 | reportViewer1.LocalReport.SetParameters(paramList);
|
|---|
| 340 | reportViewer1.LocalReport.DataSources.Clear();
|
|---|
| 341 | reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("Faktura", proformaTableAdapter.GetDataByIdFaktury(idFaktury)));
|
|---|
| 342 | }
|
|---|
| 343 | else
|
|---|
| 344 | {
|
|---|
| 345 | paramList.Add(new ReportParameter("jezyk", jezykComboBox.SelectedItem.ToString(), true));
|
|---|
| 346 | paramList.Add(new ReportParameter("podpis", podpisCheckBox.Checked.ToString(), true));
|
|---|
| 347 | reportViewer1.LocalReport.SetParameters(paramList);
|
|---|
| 348 | reportViewer1.LocalReport.DataSources.Clear();
|
|---|
| 349 | reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("Faktura", fakturaTableAdapter1.GetDataByIdFaktury(idFaktury)));
|
|---|
| 350 | }
|
|---|
| 351 |
|
|---|
| 352 | reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("FakturaDetails", fakturA_DETAILSTableAdapter1.GetDataByIdFaktury(idFaktury)));
|
|---|
| 353 | reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("tlumaczenia", ds.Tables[0]));
|
|---|
| 354 |
|
|---|
| 355 | reportViewer1.RefreshReport();
|
|---|
| 356 | //MessageBox.Show(reportViewer1.LocalReport.ReportEmbeddedResource);
|
|---|
| 357 | Cursor = Cursors.Default;
|
|---|
| 358 |
|
|---|
| 359 | }
|
|---|
| 360 |
|
|---|
| 361 | private void zapiszKorektaButton_Click(object sender, EventArgs e)
|
|---|
| 362 | {
|
|---|
| 363 | Cursor = Cursors.WaitCursor;
|
|---|
| 364 |
|
|---|
| 365 | //zapisanie zmian w polu "opis" faktury
|
|---|
| 366 | fAKTURYBindingSource.EndEdit();
|
|---|
| 367 | fAKTURYTableAdapter.Update(rEKLAMADataSet.FAKTURY);
|
|---|
| 368 | fAKTURYTableAdapter.FillByIdFaktury(rEKLAMADataSet.FAKTURY, idKorekty);
|
|---|
| 369 |
|
|---|
| 370 | reportViewer1.LocalReport.DataSources.Clear();
|
|---|
| 371 |
|
|---|
| 372 | //ustawienie parametrów, nowych datasoure dla raportu
|
|---|
| 373 | List<ReportParameter> paramList = new List<ReportParameter>();
|
|---|
| 374 | paramList.Add(new ReportParameter("jezyk", jezykComboBox.SelectedItem.ToString(), true));
|
|---|
| 375 | paramList.Add(new ReportParameter("podpis", podpisCheckBox.Checked.ToString(), true));
|
|---|
| 376 |
|
|---|
| 377 | reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("Korekta", fakturaTableAdapter1.GetDataByIdFaktury(idKorekty)));
|
|---|
| 378 | reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("Faktura", fakturaTableAdapter1.GetDataByIdFaktury(idPoprzedniejKorekty)));
|
|---|
| 379 | reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("Faktura_Original", fakturaTableAdapter1.GetDataByIdFaktury(idFaktury)));
|
|---|
| 380 | reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("FakturaDetails2", fAKTURA_DETAILS2TableAdapter.GetDataIdFaktury(idPoprzedniejKorekty)));
|
|---|
| 381 |
|
|---|
| 382 | reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("FakturaDetailsKorekty", fAKTURA_DETAILS2TableAdapter.GetDataIdFaktury(idKorekty)));
|
|---|
| 383 |
|
|---|
| 384 | reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("tlumaczenia", ds.Tables[0]));
|
|---|
| 385 |
|
|---|
| 386 | //TODO: add InvoiceProviderId column to Invoices table
|
|---|
| 387 | int invoiceProviderId = Convert.ToInt32(rEKLAMADataSet.FAKTURY.Rows[0]["SystemKsiegowyId"]);
|
|---|
| 388 |
|
|---|
| 389 | reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("Baza_Reklam_InvoiceProvider",
|
|---|
| 390 | InvoiceProviderFactory.GetInvoiceProvidersById(invoiceProviderId)));
|
|---|
| 391 |
|
|---|
| 392 | paramList.Add(new ReportParameter("podpis", podpisCheckBox.Checked.ToString(), true));
|
|---|
| 393 | reportViewer1.LocalReport.SetParameters(paramList);
|
|---|
| 394 |
|
|---|
| 395 | reportViewer1.RefreshReport();
|
|---|
| 396 | //MessageBox.Show(reportViewer1.LocalReport.ReportEmbeddedResource);
|
|---|
| 397 | Cursor = Cursors.Default;
|
|---|
| 398 |
|
|---|
| 399 | }
|
|---|
| 400 |
|
|---|
| 401 | private void btnRefresh_Click(object sender, EventArgs e)
|
|---|
| 402 | {
|
|---|
| 403 | Cursor = Cursors.WaitCursor;
|
|---|
| 404 |
|
|---|
| 405 | //zapisanie zmian w polu "opis" faktury
|
|---|
| 406 | fAKTURYBindingSource.EndEdit();
|
|---|
| 407 | fAKTURYTableAdapter.Update(rEKLAMADataSet.FAKTURY);
|
|---|
| 408 | fAKTURYTableAdapter.FillByIdFaktury(rEKLAMADataSet.FAKTURY, idFaktury);
|
|---|
| 409 |
|
|---|
| 410 | //ustawienie parametrów, nowych datasoure dla raportu
|
|---|
| 411 | List<ReportParameter> paramList = new List<ReportParameter>();
|
|---|
| 412 |
|
|---|
| 413 | paramList.Add(new ReportParameter("jezyk", jezykComboBox.SelectedItem.ToString(), true));
|
|---|
| 414 | paramList.Add(new ReportParameter("podpis", podpisCheckBox.Checked.ToString(), true));
|
|---|
| 415 |
|
|---|
| 416 | if (proforma)
|
|---|
| 417 | {
|
|---|
| 418 | paramList.Add(new ReportParameter("proforma", "True", true));
|
|---|
| 419 | }
|
|---|
| 420 | else
|
|---|
| 421 | {
|
|---|
| 422 | paramList.Add(new ReportParameter("proforma", "False", true));
|
|---|
| 423 | }
|
|---|
| 424 |
|
|---|
| 425 | paramList.Add(new ReportParameter("zaplacono", zaplaconoCheckBox.Checked.ToString(), true));
|
|---|
| 426 |
|
|---|
| 427 | reportViewer1.LocalReport.SetParameters(paramList);
|
|---|
| 428 |
|
|---|
| 429 |
|
|---|
| 430 |
|
|---|
| 431 | reportViewer1.LocalReport.DataSources.Clear();
|
|---|
| 432 | reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("Faktura", fakturaTableAdapter1.GetDataByIdFaktury(idFaktury)));
|
|---|
| 433 | reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("FakturaDetails2", fAKTURA_DETAILS2TableAdapter.GetDataIdFaktury(idFaktury)));
|
|---|
| 434 | reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("tlumaczenia", ds.Tables[0]));
|
|---|
| 435 |
|
|---|
| 436 | //TODO: add InvoiceProviderId column to Invoices table
|
|---|
| 437 | int invoiceProviderId = Convert.ToInt32(rEKLAMADataSet.FAKTURY.Rows[0]["SystemKsiegowyId"]);
|
|---|
| 438 |
|
|---|
| 439 | reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("Baza_Reklam_InvoiceProvider",
|
|---|
| 440 | InvoiceProviderFactory.GetInvoiceProvidersById(invoiceProviderId)));
|
|---|
| 441 |
|
|---|
| 442 | reportViewer1.RefreshReport();
|
|---|
| 443 | //MessageBox.Show(reportViewer1.LocalReport.ReportEmbeddedResource);
|
|---|
| 444 | Cursor = Cursors.Default;
|
|---|
| 445 |
|
|---|
| 446 | }
|
|---|
| 447 |
|
|---|
| 448 | // drukowanie raportu lokalnego
|
|---|
| 449 | private int m_currentPageIndex;
|
|---|
| 450 | private IList<Stream> m_streams;
|
|---|
| 451 |
|
|---|
| 452 | private Stream CreateStream(string name,
|
|---|
| 453 | string fileNameExtension, Encoding encoding,
|
|---|
| 454 | string mimeType, bool willSeek)
|
|---|
| 455 | {
|
|---|
| 456 | Stream stream = new FileStream(name +
|
|---|
| 457 | "." + fileNameExtension, FileMode.Create);
|
|---|
| 458 | m_streams.Add(stream);
|
|---|
| 459 | return stream;
|
|---|
| 460 | }
|
|---|
| 461 |
|
|---|
| 462 | private void Export(LocalReport report)
|
|---|
| 463 | {
|
|---|
| 464 | const string deviceInfo = "<DeviceInfo>" +
|
|---|
| 465 | " <OutputFormat>EMF</OutputFormat>" +
|
|---|
| 466 | " <PageWidth>19cm</PageWidth>" +
|
|---|
| 467 | " <PageHeight>25cm</PageHeight>" +
|
|---|
| 468 | " <MarginTop>1cm</MarginTop>" +
|
|---|
| 469 | " <MarginLeft>1cm</MarginLeft>" +
|
|---|
| 470 | " <MarginRight>1cm</MarginRight>" +
|
|---|
| 471 | " <MarginBottom>0cm</MarginBottom>" +
|
|---|
| 472 | "</DeviceInfo>";
|
|---|
| 473 | Warning[] warnings;
|
|---|
| 474 | m_streams = new List<Stream>();
|
|---|
| 475 | report.Render("Image", deviceInfo, CreateStream,
|
|---|
| 476 | out warnings);
|
|---|
| 477 | foreach (Stream stream in m_streams)
|
|---|
| 478 | stream.Position = 0;
|
|---|
| 479 | }
|
|---|
| 480 |
|
|---|
| 481 | private void PrintPage(object sender, PrintPageEventArgs ev)
|
|---|
| 482 | {
|
|---|
| 483 | Metafile pageImage = new
|
|---|
| 484 | Metafile(m_streams[m_currentPageIndex]);
|
|---|
| 485 | ev.Graphics.DrawImage(pageImage, ev.PageBounds);
|
|---|
| 486 | m_currentPageIndex++;
|
|---|
| 487 | ev.HasMorePages = (m_currentPageIndex < m_streams.Count);
|
|---|
| 488 | }
|
|---|
| 489 |
|
|---|
| 490 | private void Print(PrinterSettings printerSettings)
|
|---|
| 491 | {
|
|---|
| 492 | if (m_streams == null || m_streams.Count == 0)
|
|---|
| 493 | return;
|
|---|
| 494 |
|
|---|
| 495 | PrintDocument printDoc = new PrintDocument();
|
|---|
| 496 | printDoc.PrinterSettings = printerSettings;
|
|---|
| 497 | printDoc.PrinterSettings.Duplex = Duplex.Vertical;
|
|---|
| 498 | printDoc.PrintPage += PrintPage;
|
|---|
| 499 | printDoc.Print();
|
|---|
| 500 | }
|
|---|
| 501 |
|
|---|
| 502 | private void Run()
|
|---|
| 503 | {
|
|---|
| 504 | PrintDialog printDialog = new PrintDialog();
|
|---|
| 505 | if (printDialog.ShowDialog() == DialogResult.OK)
|
|---|
| 506 | {
|
|---|
| 507 | Export(reportViewer1.LocalReport);
|
|---|
| 508 | m_currentPageIndex = 0;
|
|---|
| 509 | Print(printDialog.PrinterSettings);
|
|---|
| 510 | Dispose();
|
|---|
| 511 | }
|
|---|
| 512 | }
|
|---|
| 513 |
|
|---|
| 514 | private void Dispose()
|
|---|
| 515 | {
|
|---|
| 516 | if (m_streams != null)
|
|---|
| 517 | {
|
|---|
| 518 | foreach (Stream stream in m_streams)
|
|---|
| 519 | stream.Close();
|
|---|
| 520 | m_streams = null;
|
|---|
| 521 | }
|
|---|
| 522 | }
|
|---|
| 523 |
|
|---|
| 524 | public void HandlePrint(object sender, CancelEventArgs e)
|
|---|
| 525 | {
|
|---|
| 526 | Run();
|
|---|
| 527 | e.Cancel = true;
|
|---|
| 528 | }
|
|---|
| 529 |
|
|---|
| 530 | private void powodKorektyComboBox_SelectedIndexChanged(object sender, EventArgs e)
|
|---|
| 531 | {
|
|---|
| 532 | DataRowView row = (DataRowView)fAKTURYBindingSource.Current;
|
|---|
| 533 | row["opis"] = powodKorektyComboBox.SelectedItem.ToString();
|
|---|
| 534 | fAKTURYBindingSource.EndEdit();
|
|---|
| 535 |
|
|---|
| 536 | opisTextBox.Text = powodKorektyComboBox.SelectedItem.ToString();
|
|---|
| 537 | }
|
|---|
| 538 | }
|
|---|
| 539 | } |
|---|