root/Baza Reklam 2 - Faktury/OrderDetails.cs @ 82

Wersja 82, 61.3 KB (wprowadzona przez dorota, 17 years temu)
Line 
1using System;
2using System.Collections.Specialized;
3using System.Collections.Generic;
4using System.ComponentModel;
5using System.Data;
6using System.Data.SqlClient;
7using System.Drawing;
8using System.Text;
9using System.Windows.Forms;
10using System.Text.RegularExpressions;
11using System.Diagnostics;
12
13namespace Baza_Reklam
14{
15    public partial class OrderDetails : Form
16    {
17        SLOWNIKDataSet.Kursy_WalutRow kurs;
18
19        //zmienna wy³¹czaj¹ca obs³ugê zdarzeñ, gdy formularz jest ukryty
20        private bool obslugaZdarzen;
21
22        //zmienna ustawiana na TRUE przy wznawianiu lub dodawnaniu nowego zamówienia
23        private bool nowyRekord;
24        private bool bylyZmiany;
25        private bool juzSieUkazaloWgazecie;
26        private double maksymalnyRabat = (double)0.3;
27
28        //numery reklam dla nowych zamówieñ       
29        StringDictionary numeryReklam = new StringDictionary();
30
31        private static OrderDetails orderDetails;
32
33        public static OrderDetails getOrderDetails()
34        {
35            if (orderDetails == null)
36            {
37                orderDetails = new OrderDetails();
38            }
39
40            return orderDetails;
41        }
42
43        private ErrorProvider errProvider;
44
45        // przechowuje id aktualnie wyœwietlanej reklamy
46        private int reklamaId;
47
48        // przechowuje id klienta , którego dotyczy aktualnie wyœwietlana reklama
49        private int customerId;
50
51
52        Baza_Reklam.REKLAMADataSetTableAdapters.zmianyEmisjiTableAdapter
53            zmianyEmisjiTableAdapter = new Baza_Reklam.REKLAMADataSetTableAdapters.zmianyEmisjiTableAdapter();
54
55        //private event ZmianaParametrowZamowienia
56
57        private OrderDetails()
58        {
59            InitializeComponent();
60
61            this.rEKLAMADataSet.UKAZE_SIE_W_NR.Constraints.Remove("FAKTURY_UKAZE_SIE_W_NR");
62
63            errProvider = new ErrorProvider();
64
65            // funckje formatuj¹ce Decimal <-> %
66            rABATTextBox.DataBindings[0].Format += new ConvertEventHandler(DecimalToProcent);
67            rABATTextBox.DataBindings[0].Parse += new ConvertEventHandler(ProcentToDecimal);
68
69            pROCENT_PROWIZJITextBox.DataBindings[0].Format += new ConvertEventHandler(DecimalToProcent);
70            pROCENT_PROWIZJITextBox.DataBindings[0].Parse += new ConvertEventHandler(ProcentToDecimal);
71
72            pVATComboBox.DataBindings[0].Format += new ConvertEventHandler(DecimalToProcent);
73            pVATComboBox.DataBindings[0].Parse += new ConvertEventHandler(ProcentToDecimal);
74
75            rEKLAMADataSet.UKAZE_SIE_W_NR.TableNewRow += nowaEmisja;
76
77            nAZWY_MODULOWTableAdapter.Connection.ConnectionString = ConnString.getConnString().Value;
78            gRZBIETYTableAdapter.Connection.ConnectionString = ConnString.getConnString().Value;
79            pROMOCJETableAdapter.Connection.ConnectionString = ConnString.getConnString().Value;
80            lISTA_TYPOW_REKLAMYTableAdapter.Connection.ConnectionString = ConnString.getConnString().Value;
81            lISTA_TYTULOWTableAdapter.Connection.ConnectionString = ConnString.getConnString().Value;
82            kursy_WalutTableAdapter.Connection.ConnectionString = ConnString.getConnString().Value;
83            rEKLAMATableAdapter.Connection.ConnectionString = ConnString.getConnString().Value;
84            uKAZE_SIE_W_NRTableAdapter.Connection.ConnectionString = ConnString.getConnString().Value;
85            rEKLAMA_STRONATableAdapter.Connection.ConnectionString = ConnString.getConnString().Value;
86            reklama_Info_DodTableAdapter.Connection.ConnectionString = ConnString.getConnString().Value;
87            aGENCITableAdapter.Connection.ConnectionString = ConnString.getConnString().Value;
88            ogl_dzialyTableAdapter.Connection.ConnectionString = ConnString.getConnString().Value;
89            ogl_rozdzialyTableAdapter.Connection.ConnectionString = ConnString.getConnString().Value;
90            zmianyEmisjiTableAdapter.Connection.ConnectionString = ConnString.getConnString().Value;
91
92            this.nAZWY_MODULOWTableAdapter.Fill(this.sLOWNIKDataSet.NAZWY_MODULOW);
93            this.gRZBIETYTableAdapter.Fill(this.sLOWNIKDataSet.GRZBIETY);
94            this.pROMOCJETableAdapter.Fill(this.sLOWNIKDataSet.PROMOCJE);
95
96            if (User.getUser().St_kierownik || User.getUser().St_produkcja)
97            {
98                this.lISTA_TYPOW_REKLAMYTableAdapter.Fill(this.sLOWNIKDataSet.LISTA_TYPOW_REKLAMY);
99            }
100            else
101            {
102                this.lISTA_TYPOW_REKLAMYTableAdapter.FillByBezBezplatnych(this.sLOWNIKDataSet.LISTA_TYPOW_REKLAMY);
103            }
104            this.lISTA_TYTULOWTableAdapter.Fill(this.sLOWNIKDataSet.LISTA_TYTULOW);
105            this.aGENCITableAdapter.FillByAktywny(this.sLOWNIKDataSet.AGENCI);
106            this.ogl_dzialyTableAdapter.Fill(this.sLOWNIKDataSet.ogl_dzialy);
107            this.ogl_rozdzialyTableAdapter.Fill(this.sLOWNIKDataSet.ogl_rozdzialy);
108
109            usunToolStripMenuItem.Click += usunEmisje;
110            anulujToolStripMenuItem.Click += anulujEmisje;
111            zmienToolStripMenuItem.Click += zmienEmisje;
112
113            walutyComboBox.SelectedIndex = 0;
114        }
115
116        private void OrderDetails_Load(object sender, EventArgs e)
117        {
118            wyroznienie_exportedCheckBox.Enabled = User.getUser().St_produkcja;
119        }
120
121        /// <summary>
122        /// Filtruje modu³y i grzbiety wg tytu³u gazety.
123        /// </summary>
124        private void tYTULComboBox_SelectedIndexChanged(object sender, EventArgs e)
125        {
126            if (obslugaZdarzen)
127            {
128                if (tYTULComboBox.SelectedValue != null)
129                {
130                    this.nAZWYMODULOWBindingSource.Filter = "tytul='" + tYTULComboBox.SelectedValue.ToString() + "'";
131                    this.iD_REKLAMYTextBox.Text = (nowyRekord) ? this.numeryReklam[tYTULComboBox.SelectedValue.ToString()] : this.iD_REKLAMYTextBox.Text;
132                    this.gRZBIETYBindingSource.Filter = "Nazwa like '%" + tYTULComboBox.SelectedValue.ToString() + "%'";
133                    int i = lISTATYTULOWBindingSource.Find("SYMB", tYTULComboBox.SelectedValue);
134                    this.maksymalnyRabat = Convert.ToDouble(((DataRowView)lISTATYTULOWBindingSource.List[i])["max_rabat"]);
135
136                    DataRowView row = (DataRowView)lISTATYTULOWBindingSource.Current;
137                    this.ogl_dzialyBindingSource.Filter = "TYTUL=" + row["id"].ToString();
138
139                    switch (tYTULComboBox.SelectedValue.ToString())
140                    {
141                        case "AMT":
142                            this.ogl_dzialyBindingSource.Filter = "TYTUL='2'";
143                            break;
144                        case "GS":
145                            this.ogl_dzialyBindingSource.Filter = "TYTUL='1'";
146                            break;
147                        case "AGRO":
148                            this.ogl_dzialyBindingSource.Filter = "TYTUL='7'";
149                            break;
150                        case "adMot":
151                            this.ogl_dzialyBindingSource.Filter = "TYTUL='6'";
152                            break;
153                        default:
154                            this.ogl_dzialyBindingSource.Filter = "";
155                            break;
156                    }
157                }
158            }
159        }
160
161        private void grzbietComboBox_SelectedIndexChanged(object sender, EventArgs e)
162        {
163            if (obslugaZdarzen)
164            {
165                if ((int)grzbietComboBox.SelectedValue == 9)
166                {
167                    this.iD_REKLAMYTextBox.Text = (nowyRekord) ? this.numeryReklam["slaski"] : this.iD_REKLAMYTextBox.Text;
168                }
169                else
170                {
171                    this.iD_REKLAMYTextBox.Text = (nowyRekord) ? this.numeryReklam[tYTULComboBox.SelectedValue.ToString()] : this.iD_REKLAMYTextBox.Text;
172                }
173            }
174        }
175
176        private void anulujButton_Click(object sender, EventArgs e)
177        {
178            if (nowyRekord)
179            {
180                //usuwa dodany wczesniej do bazy wiersz   
181                if (rEKLAMABindingSource.Current != null)
182                {
183                    rEKLAMABindingSource.RemoveCurrent();
184                    rEKLAMABindingSource.EndEdit();
185                    rEKLAMATableAdapter.Update(this.rEKLAMADataSet.REKLAMA);
186                }
187            }
188            else
189            {
190                //usuwa zmiany w zleceniu           
191                rEKLAMADataSet.REKLAMA.RejectChanges();
192                rEKLAMADataSet.UKAZE_SIE_W_NR.RejectChanges();
193            }
194
195            this.obslugaZdarzen = false;
196            liczbaEmisjiLabel.Text = "-";
197
198            this.DialogResult = bylyZmiany ? DialogResult.OK : DialogResult.Cancel;
199        }
200
201        /// <summary>
202        /// Zapisuje zmiany w wierszu oraz dodaje rekordy do "UKAZE SIE W NR" i "InfoDod"
203        /// </summary>
204        private void dodajButton_Click(object sender, EventArgs e)
205        {
206            this.Cursor = Cursors.WaitCursor;
207
208            this.Validate();
209            rEKLAMABindingSource.EndEdit();
210
211            DataRowView row = (DataRowView)rEKLAMABindingSource.Current;
212           
213            /*
214            if (!(brutto_EuroTextBox.Text != "0" ^ walutyComboBox.SelectedIndex == -1))
215            {
216                MessageBox.Show("Popraw walutê!");
217                this.Cursor = Cursors.Default;
218                return;
219            }*/
220
221            if (wyroznienieCheckBox.Checked ^ Convert.ToDecimal(row["wyroznienie_kwota"]) != 0)
222            {
223                MessageBox.Show("Zosta³a zmieniona opcja wyró¿nienia. Zamówienie nale¿y ponownie przeliczyæ");
224                this.Cursor = Cursors.Default;
225                return;
226            }
227
228            row["USERID"] = User.getUser().Login;
229
230            rEKLAMAUKAZESIEWNRBindingSource.EndEdit();
231            rEKLAMAReklamaInfoDodBindingSource.EndEdit();
232
233            //MessageBox.Show(rEKLAMAUKAZESIEWNRBindingSource.List.Count.ToString() + " " + rEKLAMADataSet.UKAZE_SIE_W_NR.Count.ToString());
234
235            this.rEKLAMATableAdapter.Update(this.rEKLAMADataSet.REKLAMA);
236            this.uKAZE_SIE_W_NRTableAdapter.Update(this.rEKLAMADataSet.UKAZE_SIE_W_NR);
237            this.reklama_Info_DodTableAdapter.Update(this.rEKLAMADataSet.Reklama_Info_Dod);
238            this.zmianyEmisjiTableAdapter.Update(this.rEKLAMADataSet.zmianyEmisji);
239            MessageBox.Show("Zmiany zapisane");
240
241            zmiany();
242
243            nowyRekord = false;
244            bylyZmiany = true;
245            //this.obslugaZdarzen = false;
246
247            this.Cursor = Cursors.Default;
248        }
249
250        private void sZERTextBox_Validating(object sender, CancelEventArgs e)
251        {
252            if (!sZERTextBox.Text.Equals(""))
253            {
254                if (!Regex.IsMatch(sZERTextBox.Text, "^[0-8]{1}$", RegexOptions.IgnoreCase))
255                {
256                    e.Cancel = true;
257
258                    errProvider.SetError((Control)sender, "1-8");
259                    return;
260                }
261
262            }
263            errProvider.SetError((Control)sender, "");
264        }
265
266        private void wYSTextBox_Validating(object sender, CancelEventArgs e)
267        {
268            if (!sZERTextBox.Text.Equals(""))
269            {
270                if (!Regex.IsMatch(sZERTextBox.Text, "^[0-8]{1}$", RegexOptions.IgnoreCase))
271                {
272                    e.Cancel = true;
273
274                    errProvider.SetError((Control)sender, "1-8");
275                    return;
276                }
277
278            }
279            errProvider.SetError((Control)sender, "");
280        }
281
282        /// <summary>
283        /// formatowanie do decimal -> %
284        /// </summary>
285        private void DecimalToProcent(object sender, ConvertEventArgs cevent)
286        {
287            if (Convert.ToDecimal(cevent.Value) > 1)
288            {
289                //  cevent.Value = Convert.ToDecimal(cevent.Value) / 100;
290            }
291            cevent.Value = String.Format("{0:P}", cevent.Value);
292        }
293
294        /// <summary>
295        /// formatowanie do % -> decimal
296        /// </summary>
297        private void ProcentToDecimal(object sender, ConvertEventArgs cevent)
298        {
299            string pom = cevent.Value.ToString();
300            if (cevent.Value.ToString().EndsWith("%"))
301            {
302                pom = cevent.Value.ToString().Substring(0, cevent.Value.ToString().Length - 1);
303            }
304            decimal p = Decimal.Parse(pom) / 100;
305            cevent.Value = p.ToString();
306        }
307
308        private void promocjaComboBox_TextChanged(object sender, EventArgs e)
309        {
310            if (obslugaZdarzen)
311            {
312                if (promocjaComboBox.Text == "")
313                {
314                    if (rEKLAMABindingSource.Current != null)
315                    {
316                        DataRowView row = (DataRowView)rEKLAMABindingSource.Current;
317                        row["PROMOCJA"] = DBNull.Value;
318                        rEKLAMABindingSource.EndEdit();
319                    }
320                }
321            }
322        }
323
324        private void zATWIERDZONO_DO_DRUKUCheckBox_Click(object sender, EventArgs e)
325        {
326            if (zATWIERDZONO_DO_DRUKUCheckBox.Checked)
327            {
328                if (rEKLAMABindingSource.Current != null)
329                {
330                    DataRowView row = (DataRowView)rEKLAMABindingSource.Current;
331
332                    sprawdzBledy();
333
334                    if (!User.getUser().St_kierownik)
335                    {
336                        if (Convert.ToDouble(row["rabat"]) > this.maksymalnyRabat)
337                        {
338                            MessageBox.Show("Rabat wy¿szy ni¿ " + this.maksymalnyRabat.ToString("P") + ". Zamówienie musi byæ zatwierdzone do druku przez kierownika");
339                            zATWIERDZONO_DO_DRUKUCheckBox.CheckState = CheckState.Unchecked;
340                        }
341
342                        if (nAZWYMODULOWBindingSource.Current != null)
343                        {
344                            DataRowView r = (DataRowView)nAZWYMODULOWBindingSource.Current;
345                            //decimal cenaJedn = Convert.ToDecimal(row["CENA JEDN"]);
346                            decimal cenaMinMod = Convert.ToDecimal(r["CENA_MIN"]);
347
348                            decimal cenaJedn = Convert.ToDecimal(row["NETTO"]) / (Convert.ToDecimal(row["SZER"]) * Convert.ToDecimal(row["WYS"]) * Convert.ToDecimal(row["KROTNOŒÆ"]));
349                            cenaJedn = Math.Round(cenaJedn, 2);
350
351                            if (cenaJedn < cenaMinMod)
352                            {
353                                MessageBox.Show("Cena modu³u ni¿sza ni¿ cena cennikowa. Zamówienie musi byæ zatwierdzone do druku przez kierownika");
354                                zATWIERDZONO_DO_DRUKUCheckBox.CheckState = CheckState.Unchecked;
355                            }
356                        }
357
358                        string typ = Convert.ToString(row["typ"]);
359                        if ((typ == "BEZP£ATNA") || (typ == "BARTER") || (typ == "REKLAMACJA"))
360                        {
361                            MessageBox.Show("Zamówienie musi byæ zatwierdzone do druku przez kierownika");
362                            zATWIERDZONO_DO_DRUKUCheckBox.CheckState = CheckState.Unchecked;
363                        }
364                    }
365                }
366            }
367        }
368
369        private void pROCENT_PROWIZJITextBox_Leave(object sender, EventArgs e)
370        {
371            rEKLAMABindingSource.EndEdit();
372        }
373       
374        /// <summary>
375        /// Blokuje czêœæ formuklarze w zale¿noœci od stanu zamówienia i praw u¿ytkownika...
376        /// </summary>
377        private void OrderDetails_Shown(object sender, EventArgs e)
378        {
379            tYTULComboBox.SelectedIndex = -1;
380            mOD_TYPComboBox.SelectedIndex = -1;
381            ogl_dzialComboBox.SelectedIndex = -1;
382            ogl_rozdzialComboBox.SelectedIndex = -1;
383           // walutyComboBox.SelectedIndex = 0;
384            kurs = null;
385            obslugaZdarzen = true;
386         
387            rEKLAMABindingSource.ResetBindings(false);
388            blokowanieZrealizowanychEmisji();
389            zmiany();
390
391        }
392
393        private void ukazeSieDataGridView_DataError(object sender, DataGridViewDataErrorEventArgs e)
394        {
395            if (rEKLAMAUKAZESIEWNRBindingSource.Current != null)
396            {
397                rEKLAMAUKAZESIEWNRBindingSource.RemoveCurrent();
398            }
399            blokowanieZrealizowanychEmisji();
400        }
401
402        private void ukazeSieDataGridView_Leave(object sender, EventArgs e)
403        {
404            Validate();
405
406            rEKLAMAUKAZESIEWNRBindingSource.EndEdit();
407
408            liczbaEmisjiLabel.Text = rEKLAMAUKAZESIEWNRBindingSource.List.Count.ToString();
409
410            if (rEKLAMABindingSource.Current != null)
411            {
412                DataRowView row = (DataRowView)rEKLAMABindingSource.Current;
413
414                if (row["ID_FAKTURY"] == DBNull.Value)
415                {
416                    kROTNOSCTextBox.Text = rEKLAMAUKAZESIEWNRBindingSource.List.Count.ToString();
417                }
418            }
419        }
420
421        /// <summary>
422        /// Blokuje emisje,które ju¿ siê ukaza³y.
423        /// </summary>
424        private void blokowanieZrealizowanychEmisji()
425        {
426            //  ukazeSieDataGridView.Enabled = true;
427            foreach (DataGridViewRow r in ukazeSieDataGridView.Rows)
428            {
429                REKLAMADataSet.UKAZE_SIE_W_NRRow em =
430                    (REKLAMADataSet.UKAZE_SIE_W_NRRow)((DataRowView)r.DataBoundItem).Row;
431
432                //anulowana
433                if (em.status == 2)
434                {
435                    r.ReadOnly = true;
436                    r.DefaultCellStyle.ForeColor = Color.Red;
437                }
438               
439                foreach (DataGridViewRow s in ukazaloSieDataGridView.Rows)
440                {
441                    if (em.Nr_Wydania.ToString() == s.Cells["NR_WYDANIA"].Value.ToString())
442                    {
443                        r.ReadOnly = true;
444                        r.DefaultCellStyle.BackColor = Color.MintCream;
445                        this.juzSieUkazaloWgazecie = true;
446                        break;
447                    }
448                }
449            }
450
451        }
452       
453
454        public void zablokujGroupBoxa(GroupBox g)
455        {
456            foreach (Control c in g.Controls)
457            {
458                if (c is TextBox)
459                {
460                    ((TextBox)c).ReadOnly = true;
461                }
462
463                if (c is ComboBox)
464                {
465                    ((ComboBox)c).Enabled = false;
466                }
467            }
468        }
469
470        public void odblokujGroupBoxa(GroupBox g)
471        {
472            foreach (Control c in g.Controls)
473            {
474                if (c is TextBox)
475                {
476                    ((TextBox)c).ReadOnly = false;
477                }
478
479                if (c is ComboBox)
480                {
481                    ((ComboBox)c).Enabled = true;
482                }
483            }
484        }
485
486        /// <summary>
487        /// Blokuje kontrolki zwi¹zane z danymi zamówienia
488        /// </summary>
489        private void zablokujGroupBoxy()
490        {
491            zablokujGroupBoxa(groupBox1);
492
493            if (!(User.getUser().St_produkcja | User.getUser().St_kierownik))
494            {
495                zablokujGroupBoxa(groupBox2);
496            }
497            zablokujGroupBoxa(groupBox3);
498            zablokujGroupBoxa(groupBox4);
499
500            //lokalizacje mo¿na zmieniaæ
501            sTRONATextBox.ReadOnly = false;
502
503        }
504
505        /// <summary>
506        /// Odblokuje kontrolki zwi¹zane z danymi zamówienia
507        /// </summary>
508        private void odblokujGroupBoxy()
509        {
510            odblokujGroupBoxa(groupBox1);
511            odblokujGroupBoxa(groupBox2);
512            odblokujGroupBoxa(groupBox3);
513            odblokujGroupBoxa(groupBox4);
514        }
515
516        /// <summary>
517        /// Buduje nr zamowienia dla danego handlowca
518        /// </summary>
519        private string nrRek(string symAgenta, string tagAgenta)
520        {
521            if (User.getUser().St_handlowiec)
522            {
523                string nr = Baza_Reklam.Utils.numerNowejReklamy(symAgenta, tagAgenta).ToString();
524                switch (nr.Length)
525                {
526                    case 1:
527                        nr = tagAgenta + "00" + nr + "_00";
528                        break;
529                    case 2:
530                        nr = tagAgenta + "0" + nr + "_00";
531                        break;
532                    case 3:
533                        nr = tagAgenta + nr + "_00";
534                        break;
535                }
536                return nr;
537            }
538            return "";
539        }
540
541        /// <summary>
542        /// Sprawdza poprawnoœæ zamówienia... pewnie niekompletnie
543        /// </summary>
544        private void sprawdzBledy()
545        {
546            if (ogl_dzialComboBox.SelectedValue == null)
547            {
548                MessageBox.Show("Wybierz dzia³.");
549                zATWIERDZONO_DO_DRUKUCheckBox.CheckState = CheckState.Unchecked;
550                return;
551            }
552
553
554            if (mOD_TYPComboBox.Text == "")
555            {
556                MessageBox.Show("Wybierz rodzaj modu³u.");
557                zATWIERDZONO_DO_DRUKUCheckBox.CheckState = CheckState.Unchecked;
558                return;
559            }
560
561            string grzbiet = grzbietComboBox.Text;
562            string tytul = tYTULComboBox.Text;
563
564            if (grzbiet == "")
565            {
566                MessageBox.Show("Wybierz grzbiet.");
567                zATWIERDZONO_DO_DRUKUCheckBox.CheckState = CheckState.Unchecked;
568                return;
569            }
570            else
571            {
572                if (!grzbiet.Contains(tytul))
573                {
574                    MessageBox.Show("Wybierz poprawny grzbiet.");
575                    zATWIERDZONO_DO_DRUKUCheckBox.CheckState = CheckState.Unchecked;
576                    return;
577                }
578            }
579
580            //lokalizacja
581            if (sTRONATextBox.Text == "")
582            {
583                MessageBox.Show("Podaj lokalizacjê.");
584                zATWIERDZONO_DO_DRUKUCheckBox.CheckState = CheckState.Unchecked;
585                return;
586            }
587
588            if (rEKLAMAUKAZESIEWNRBindingSource.List.Count == 0)
589            {
590                MessageBox.Show("Brak wyznaczonych emisji.");
591                zATWIERDZONO_DO_DRUKUCheckBox.CheckState = CheckState.Unchecked;
592                return;
593            }
594        }
595
596        /// <summary>
597        /// Przelicza wartoœæ zamówienia.
598        /// </summary>
599        private void przelicz()
600        {
601            DataRowView row = (DataRowView)rEKLAMABindingSource.Current;
602
603            if ((row["KROTNOŒÆ"] != null) && (row["CENA JEDN"] != null) && (row["VAT"] != null)
604              && (row["PROCENT PROWIZJI"] != null) && (row["RABAT"] != null)
605              && (row["SZER"] != null) && (row["WYS"] != null))
606            {
607                int szer = Convert.ToInt32(row["SZER"]);
608                int wys = Convert.ToInt32(row["WYS"]);
609                int krotnosc = Convert.ToInt32(row["KROTNOŒÆ"]);
610
611                if (krotnosc == 0)
612                {
613                    MessageBox.Show("Iloœæ emisji równa siê  0");
614                    return;
615                }
616
617                decimal cenaJednostkowa = Convert.ToDecimal(row["CENA JEDN"]);
618                decimal vatProcent = Convert.ToDecimal(row["VAT"]);
619                decimal prowizjaProcent = Convert.ToDecimal(row["PROCENT PROWIZJI"]);
620                decimal rabatProcent = Convert.ToDecimal(row["RABAT"]);
621
622
623                //rabatWartosc
624                decimal rabatWartosc = rabatProcent * cenaJednostkowa;
625                rabatWartosc = Math.Round(rabatWartosc, 2);
626
627                //netto
628                decimal netto = (cenaJednostkowa - rabatWartosc) * krotnosc;
629                netto = Math.Round(netto, 2);
630
631                nettoBezBOTextBox.Text = String.Format("{0:C}", netto);
632
633                //cena modulu
634                decimal cenaModulu = netto / (szer * wys * krotnosc);
635                cenaModulu = Math.Round(cenaModulu, 2);
636
637                if (Convert.ToBoolean(row["wyroznienie"]) == true)
638                {
639                    row["wyroznienie_procent"] = 0.15M;
640                    decimal kwotaWyroznienia = Math.Round(netto * 0.15M, 2);
641                    row["wyroznienie_kwota"] = kwotaWyroznienia;
642                    netto = netto + kwotaWyroznienia;
643                }
644                else
645                {
646                    row["wyroznienie_procent"] = 0;
647                    row["wyroznienie_kwota"] = 0;
648                }
649
650                //vatWartosc
651                decimal vatWartosc = vatProcent * netto;
652                vatWartosc = Math.Round(vatWartosc, 2);
653
654                //brutto
655                decimal brutto = netto + vatWartosc;
656                brutto = Math.Round(brutto, 2);
657
658                //prowizja
659                decimal prowizjaWartosc = prowizjaProcent * netto;
660                prowizjaWartosc = Math.Round(prowizjaWartosc, 2);
661
662                cenaModuluLabel.Text = String.Format("{0:C}", cenaModulu);
663                row["RABAT WARTOŒÆ"] = rabatWartosc.ToString();
664                row["NETTO"] = netto.ToString();
665                row["BRUTTO"] = brutto.ToString();
666                row["PVAT"] = vatWartosc.ToString();
667                row["PROWIZJA"] = prowizjaWartosc.ToString();
668
669                rEKLAMABindingSource.EndEdit();
670            }
671
672        }
673
674        /// <summary>
675        /// Przelicza kwotê w z³otówkach na wybran¹ walutê.
676        /// </summary>
677        private void przeliczNaWalute(SLOWNIKDataSet.Kursy_WalutRow kurs)
678        {
679            if (rEKLAMABindingSource.Current != null)
680            {
681                DataRowView row = (DataRowView)rEKLAMABindingSource.Current;
682
683                if (row["BRUTTO"] != DBNull.Value)
684                {
685
686                    decimal brutto = Convert.ToDecimal(row["BRUTTO"]);
687                    brutto = Math.Round(brutto, 2);
688
689                    // waluty
690                    row["waluta_tabela_nr"] = kurs.Numer_Tabeli;
691                    row["waluta_Przelicznik"] = kurs.przelicznik;
692                    row["waluta_kurs_z_dnia"] = kurs.Data_Publikacji;
693                    row["Brutto_Euro_Miano"] = kurs.Kod_Waluty;
694                       
695                    //zmiana kursu dla poznania
696                    if (User.getUser().IdAgencji == 6)
697                    {
698                        row["waluta_kurs"] = kurs.Kurs_Sredni_Poznan;
699                        row["Brutto_Euro"] = Math.Round(brutto / Convert.ToDecimal(kurs.Kurs_Sredni_Poznan) * Convert.ToInt32(kurs.przelicznik), 2);
700                    }
701                    else
702                    {
703                        row["waluta_kurs"] = kurs.Kurs_Sredni;
704                        row["Brutto_Euro"] = Math.Round(brutto / Convert.ToDecimal(kurs.Kurs_Sredni) * Convert.ToInt32(kurs.przelicznik), 2);
705                    }
706
707                    // zmiana domyœlnego konta do faktury dla EUR
708                    if (User.getUser().IdAgencji != 4 & (row["Brutto_Euro_Miano"].ToString() == "EUR"))
709                    {
710                        if (User.getUser().IdAgencji == 1223940396 | User.getUser().IdAgencji == 1223940398)
711                        {
712                            row["FAKTURA ID KONTA"] = 3;
713                        }
714                        else
715                        {
716                            row["FAKTURA ID KONTA"] = 5;
717                        }
718                    }
719
720                    rEKLAMABindingSource.EndEdit();
721                }
722            }
723        }
724
725        /// <summary>
726        /// Przelicza kwotê w walucie na z³otówki.
727        /// </summary>
728        private void przeliczWaluteNaZlotowki(SLOWNIKDataSet.Kursy_WalutRow kurs)
729        {
730            DataRowView row = (DataRowView)rEKLAMABindingSource.Current;
731
732            if (row["Brutto_Euro"] != DBNull.Value)
733            {
734                // waluty
735                row["waluta_tabela_nr"] = kurs.Numer_Tabeli;
736                row["waluta_Przelicznik"] = kurs.przelicznik;
737                row["waluta_kurs"] = kurs.Kurs_Sredni;
738                row["waluta_kurs_z_dnia"] = kurs.Data_Publikacji;
739                row["Brutto_Euro_Miano"] = kurs.Kod_Waluty;
740
741                //zmiana kursu dla poznania
742                if (User.getUser().IdAgencji == 6)
743                {
744                    row["waluta_kurs"] = kurs.Kurs_Sredni_Poznan;
745                }
746             
747                int szer = Convert.ToInt32(row["SZER"]);
748                int wys = Convert.ToInt32(row["WYS"]);
749                int krotnosc = Convert.ToInt32(row["KROTNOŒÆ"]);
750
751                if (krotnosc == 0)
752                {
753                    MessageBox.Show("Iloœæ emisji równa siê  0");
754                    return;
755                }
756
757                decimal vatProcent = Convert.ToDecimal(row["VAT"]);
758                decimal prowizjaProcent = Convert.ToDecimal(row["PROCENT PROWIZJI"]);
759                decimal rabatProcent = Convert.ToDecimal(row["RABAT"]);
760
761                //przeliczanie z waluty na zlotowki   
762                decimal brutto = Math.Round(Convert.ToDecimal(row["Brutto_Euro"]) * Convert.ToDecimal(row["waluta_kurs"]) / Convert.ToInt32(row["waluta_Przelicznik"]), 2);
763
764                decimal netto = brutto / (1 + vatProcent);
765                netto = Math.Round(netto, 2);
766
767                decimal nettoZBO = netto;
768
769                if (Convert.ToBoolean(row["wyroznienie"]) == true)
770                {
771                    row["wyroznienie_procent"] = 0.15M;
772                    decimal nettoBezBO = Math.Round(netto / 1.15M, 2);
773                    row["wyroznienie_kwota"] = Math.Round(netto - nettoBezBO, 2);
774                    netto = nettoBezBO;
775                }
776                else
777                {
778                    row["wyroznienie_procent"] = 0;
779                    row["wyroznienie_kwota"] = 0;
780                }
781
782                nettoBezBOTextBox.Text = String.Format("{0:C}", netto);
783
784                decimal vatWartosc = vatProcent * nettoZBO;
785                vatWartosc = Math.Round(vatWartosc, 2);
786
787                decimal prowizjaWartosc = prowizjaProcent * nettoZBO;
788                prowizjaWartosc = Math.Round(prowizjaWartosc, 2);
789
790                decimal rabatWartosc = netto * rabatProcent / (krotnosc * (1 - rabatProcent));
791                rabatWartosc = Math.Round(rabatWartosc, 2);
792
793                decimal cenaJednostkowa = (netto / (decimal)krotnosc) + rabatWartosc;
794                cenaJednostkowa = Math.Round(cenaJednostkowa, 2);
795
796                //cena modulu
797                decimal cenaModulu = netto / (szer * wys * krotnosc);
798                cenaModulu = Math.Round(cenaModulu, 2);
799
800                cenaModuluLabel.Text = String.Format("{0:C}", cenaModulu);
801                row["RABAT WARTOŒÆ"] = rabatWartosc.ToString();
802                row["NETTO"] = nettoZBO.ToString();
803                row["BRUTTO"] = brutto.ToString();
804                row["PVAT"] = vatWartosc.ToString();
805                row["PROWIZJA"] = prowizjaWartosc.ToString();
806                row["CENA JEDN"] = cenaJednostkowa.ToString();
807
808
809                // zmiana domyœlnego konta do faktury dla EUR
810                if (User.getUser().IdAgencji != 4 & (row["Brutto_Euro_Miano"].ToString() == "EUR"))
811                {
812                    if (User.getUser().IdAgencji == 1223940396 | User.getUser().IdAgencji == 1223940398)
813                    {
814                        row["FAKTURA ID KONTA"] = 3;
815                    }
816                    else
817                    {
818                        row["FAKTURA ID KONTA"] = 5;
819                    }
820                }
821
822                rEKLAMABindingSource.EndEdit();
823
824            }
825        }
826
827        public void dodajNoweZamowienie(int custId, string kodKlienta)
828        {           
829            this.nowyRekord = true;
830            this.bylyZmiany = false;
831            this.juzSieUkazaloWgazecie = false;
832
833            this.numeryReklam.Clear();
834
835            string nr;
836            foreach (DataRowView r in lISTATYTULOWBindingSource.List)
837            {
838                nr = nrRek(User.getUser().Symbol_agenta, r["SYMB2"].ToString().Trim() + User.getUser().Kod_agenta);
839                this.numeryReklam.Add((string)r["SYMB"], nr);
840            }
841            //autosalon œl¹ski
842            nr = nrRek(User.getUser().Symbol_agenta, "G" + User.getUser().Kod_agenta);
843            this.numeryReklam.Add("slaski", nr);
844
845            this.rEKLAMADataSet.REKLAMA.Clear();
846            this.rEKLAMADataSet.UKAZE_SIE_W_NR.Clear();
847            this.rEKLAMADataSet.Reklama_Info_Dod.Clear();
848
849            this.customerId = custId;
850
851            DataView datatable = (DataView)this.rEKLAMABindingSource.List;
852            DataRowView row = datatable.AddNew();
853
854            row["CustomerId"] = this.customerId;
855            row["DATA ZAMÓWIENIA"] = DateTime.Now;
856            row["nick name"] = kodKlienta;
857            if (Utils.czyKlientMaNrVIES(this.customerId))
858            {
859                row["VAT"] = 0;
860            }
861
862            if (User.getUser().St_handlowiec | User.getUser().St_subhandlowiec)
863            {
864                row["symbol akwizytora"] = User.getUser().Symbol_agenta;
865                row["ID Reklamy"] = this.numeryReklam["AMT"];
866
867                //Katowice
868                if (User.getUser().IdAgencji == 4)
869                {
870                    row["customerId_Sub"] = 678;
871                }
872
873                //Poznan
874                if (User.getUser().IdAgencji == 6)
875                {
876                    row["customerId_Sub"] = 18845;
877                }
878            }
879
880            row["USERID"] = User.getUser().Login;
881
882            Validate();
883         
884            rEKLAMABindingSource.EndEdit();
885            rEKLAMATableAdapter.Update(rEKLAMADataSet.REKLAMA);
886            rEKLAMABindingSource.MoveLast();
887        }
888
889        public void pokazSzczegolyZamowienia(int rekId)
890        {
891            this.nowyRekord = false;
892            this.bylyZmiany = false;
893            this.reklamaId = rekId;
894
895            this.rEKLAMATableAdapter.ClearBeforeFill = true;
896            this.rEKLAMATableAdapter.FillByReklamaId(this.rEKLAMADataSet.REKLAMA, reklamaId);
897            this.reklama_Info_DodTableAdapter.FillByReklamaId(this.rEKLAMADataSet.Reklama_Info_Dod, reklamaId);
898            this.rEKLAMA_STRONATableAdapter.FillByReklamaId(this.rEKLAMADataSet.REKLAMA_STRONA, this.reklamaId);
899            this.uKAZE_SIE_W_NRTableAdapter.FillByReklamaId(this.rEKLAMADataSet.UKAZE_SIE_W_NR, this.reklamaId);
900        }
901
902        public void wznowZamowienie(int rekId)
903        {
904            this.nowyRekord = true;
905            this.bylyZmiany = false;
906            this.juzSieUkazaloWgazecie = false;
907
908            REKLAMADataSet.REKLAMADataTable old = this.rEKLAMATableAdapter.GetDataByReklamaId(rekId);
909            DataRow oldRow = old.Rows[0];
910
911            this.rEKLAMADataSet.REKLAMA.Clear();
912            this.rEKLAMADataSet.UKAZE_SIE_W_NR.Clear();
913            this.rEKLAMADataSet.Reklama_Info_Dod.Clear();
914
915            DataView datatable = (DataView)this.rEKLAMABindingSource.List;
916            DataRowView newRow = datatable.AddNew();
917
918            this.customerId = Convert.ToInt32(oldRow["CustomerID"]);
919
920            newRow["CustomerID"] = oldRow["CustomerID"];
921            newRow["DATA ZAMÓWIENIA"] = DateTime.Now;
922            newRow["SYMBOL AKWIZYTORA"] = oldRow["SYMBOL AKWIZYTORA"];
923            newRow["ID REKLAMY"] = oldRow["ID REKLAMY"];
924            newRow["TYTU£"] = oldRow["TYTU£"];
925            newRow["TYP"] = oldRow["TYP"];
926            newRow["NICK NAME"] = oldRow["NICK NAME"];
927            newRow["SZER"] = oldRow["SZER"];
928            newRow["WYS"] = oldRow["WYS"];
929            newRow["MOD_TYP"] = oldRow["MOD_TYP"];
930            newRow["KROTNOŒÆ"] = oldRow["KROTNOŒÆ"];
931            newRow["ODSTÊP"] = oldRow["ODSTÊP"];
932            newRow["KOLOR"] = oldRow["KOLOR"];
933            newRow["RABAT"] = oldRow["RABAT"];
934            newRow["CENA JEDN"] = oldRow["CENA JEDN"];
935            newRow["VAT"] = oldRow["VAT"];
936            newRow["PROCENT PROWIZJI"] = oldRow["PROCENT PROWIZJI"];
937            newRow["PROMOCJA"] = oldRow["PROMOCJA"];
938            newRow["GRZBIET"] = oldRow["GRZBIET"];
939            newRow["STRONA"] = oldRow["STRONA"];
940            newRow["customerId_Sub"] = oldRow["customerId_Sub"];
941            newRow["ogl_dzial"] = oldRow["ogl_dzial"];
942            newRow["ogl_rozdzial"] = oldRow["ogl_rozdzial"];
943
944            //zmiana numerka
945            try
946            {
947                string starySym = newRow["Id reklamy"].ToString();
948                string symPart1 = starySym.Substring(0, starySym.Length - 2);
949                string symPart2 = starySym.Substring(starySym.Length - 2, 2);
950                int nowyNr = Int32.Parse(symPart2);
951                nowyNr++;
952                switch (nowyNr.ToString().Length)
953                {
954                    case 1:
955                        newRow["Id reklamy"] = symPart1 + "0" + nowyNr.ToString();
956                        break;
957                    default:
958                        newRow["Id reklamy"] = symPart1 + nowyNr.ToString();
959                        break;
960                }
961            }
962            catch (Exception e1)
963            {
964                newRow["Id reklamy"] = oldRow["Id reklamy"];
965            }
966
967            this.numeryReklam.Clear();
968            string nr;
969            foreach (DataRowView r in lISTATYTULOWBindingSource.List)
970            {
971                nr = nrRek(User.getUser().Symbol_agenta, r["SYMB2"].ToString().Trim() + User.getUser().Kod_agenta);
972                this.numeryReklam.Add((string)r["SYMB"], nr);
973            }
974            //autosalon œl¹ski
975            nr = nrRek(User.getUser().Symbol_agenta, "G" + User.getUser().Kod_agenta);
976            this.numeryReklam.Add("slaski", nr);
977
978            Validate();
979
980            rEKLAMABindingSource.EndEdit();
981            rEKLAMATableAdapter.Update(rEKLAMADataSet.REKLAMA);
982            rEKLAMABindingSource.MoveLast();
983        }
984
985        private void dataGridView1_RowLeave(object sender, DataGridViewCellEventArgs e)
986        {
987            try
988            {
989                DataRowView rowView = dataGridView1[e.ColumnIndex, e.RowIndex].OwningRow.DataBoundItem as DataRowView;
990
991                if ((rowView != null) && rowView.IsNew)
992                {
993                    rowView["Data"] = DateTime.Now;
994                }
995            }
996            catch (Exception e1)
997            {
998                throw e1;
999            }
1000
1001            dataGridView1.Refresh();
1002        }
1003
1004        private void dataGridView1_Leave(object sender, EventArgs e)
1005        {
1006            this.dataGridView1.EndEdit();
1007
1008            Validate();
1009
1010            this.rEKLAMAReklamaInfoDodBindingSource.EndEdit();
1011        }
1012
1013        private void OrderDetails_FormClosing(object sender, FormClosingEventArgs e)
1014        {
1015            if (nowyRekord)
1016            {
1017                if (rEKLAMABindingSource.Current != null)
1018                {
1019                    rEKLAMABindingSource.RemoveCurrent();
1020                    rEKLAMABindingSource.EndEdit();
1021                    rEKLAMATableAdapter.Update(this.rEKLAMADataSet.REKLAMA);
1022                }
1023
1024            }
1025            else
1026            {
1027                //usuwa zmiany w zleceniu           
1028                rEKLAMADataSet.REKLAMA.RejectChanges();
1029                rEKLAMADataSet.UKAZE_SIE_W_NR.RejectChanges();
1030            }
1031
1032            this.obslugaZdarzen = false;
1033            liczbaEmisjiLabel.Text = "-";
1034            this.nettoBezBOTextBox.Clear();
1035            this.DialogResult = bylyZmiany ? DialogResult.OK : DialogResult.Cancel;
1036        }
1037
1038        /// <summary>
1039        /// Koloruje formularz, blokuje pola etc.
1040        /// </summary>
1041        private void zmiany()
1042        {
1043            if (this.rEKLAMABindingSource.Current != null)
1044            {
1045                DataRowView reklamRow = (DataRowView)this.rEKLAMABindingSource.Current;
1046
1047                bool zablokujProwizje = Convert.ToBoolean(reklamRow["zablokuj_prowizje"]);
1048                bool zatwiedzonoDoDruku = reklamRow["ZATWIERDZONO DO DRUKU"] == DBNull.Value ? false : Convert.ToBoolean(reklamRow["ZATWIERDZONO DO DRUKU"]);
1049                bool kierownikZatwierdzil = reklamRow["kier_zatwierdzil"] == DBNull.Value ? false : Convert.ToBoolean(reklamRow["kier_zatwierdzil"]);
1050                bool rabatPonad30 = (bool)(Convert.ToDouble(reklamRow["rabat"]) > this.maksymalnyRabat);
1051                bool wystawionoFakture = reklamRow["FAKTURA WYSTAWIONO"] == DBNull.Value ? false : Convert.ToBoolean(reklamRow["FAKTURA WYSTAWIONO"]);
1052
1053                //blokowanie prowizji
1054                pROWIZJATextBox.ReadOnly = zablokujProwizje;
1055                pROCENT_PROWIZJITextBox.ReadOnly = zablokujProwizje;
1056
1057                //oznaczenie ZD
1058                ZDpanel.BackColor = zatwiedzonoDoDruku ? Color.LightGreen : Color.Red;
1059
1060                //UPRAWnienia
1061                kier_notatkaTextBox.ReadOnly = !User.getUser().St_kierownik;
1062                kier_zatwierdzilCheckBox.Enabled = User.getUser().St_kierownik;
1063                zablokuj_prowizjeCheckBox.Enabled = User.getUser().St_kierownik;
1064
1065                if (!User.getUser().St_kierownik)
1066                {
1067                    if (wystawionoFakture)
1068                    {
1069                        zablokujGroupBoxy();
1070                    }
1071                    else
1072                    {
1073                        odblokujGroupBoxy();
1074                    }
1075                }
1076
1077                blokowanieZrealizowanychEmisji();
1078            }
1079        }
1080
1081
1082        private void ukazeSieDataGridView_KeyUp(object sender, KeyEventArgs e)
1083        {
1084
1085            if (e.Control && e.KeyCode == Keys.C)
1086            {
1087                if (this.ukazeSieDataGridView.GetCellCount(DataGridViewElementStates.Selected) > 0)
1088                {
1089                    try
1090                    {
1091                        // Add the selection to the clipboard.
1092                        Clipboard.SetDataObject(
1093                            this.ukazeSieDataGridView.GetClipboardContent());
1094                    }
1095                    catch (System.Runtime.InteropServices.ExternalException)
1096                    {
1097
1098                    }
1099                }
1100            }
1101
1102            if (e.Control && e.KeyCode == Keys.V)
1103            {
1104                Validate();
1105
1106                rEKLAMAUKAZESIEWNRBindingSource.EndEdit();
1107
1108                //czy user ma uprawnienia do dodawania wierszy
1109                if (ukazeSieDataGridView.AllowUserToAddRows)
1110                {
1111                    char[] rowSplitter = { '\r', '\n' };
1112                    char[] columnSplitter = { '\t' };
1113
1114                    IDataObject dataInClipboard = Clipboard.GetDataObject();
1115                    string stringInClipboard = (string)dataInClipboard.GetData(DataFormats.Text);
1116
1117                    string[] rowsInClipboard = stringInClipboard.Split(rowSplitter, StringSplitOptions.RemoveEmptyEntries);
1118
1119                    string nrWydania = "0";
1120
1121                    for (int iRow = 0; iRow < rowsInClipboard.Length; iRow++)
1122                    {
1123                        string[] valuesInRow = rowsInClipboard[iRow].Split(columnSplitter);
1124
1125                        for (int i = 0; i <= valuesInRow.Length - 1; i++)
1126                        {
1127                            if (valuesInRow[i] != "")
1128                            {
1129                                nrWydania = valuesInRow[i];
1130
1131                                try
1132                                {
1133                                    DataView datatable = (DataView)this.rEKLAMAUKAZESIEWNRBindingSource.List;
1134                                    DataRowView row = datatable.AddNew();
1135                                    row["Nr Wydania"] = nrWydania;
1136
1137                                    rEKLAMAUKAZESIEWNRBindingSource.EndEdit();
1138                                }
1139                                catch (Exception e1)
1140                                {
1141                                    Debugger.Log(0, "ttt", e1.Message);
1142                                }
1143                            }
1144                        }
1145                    }
1146                }
1147            }
1148        }
1149
1150        private void ogl_dzialComboBox_SelectedValueChanged(object sender, EventArgs e)
1151        {
1152            if (obslugaZdarzen)
1153            {
1154                if ((ogl_dzialComboBox.SelectedValue != null) && (lISTATYTULOWBindingSource.Current != null))
1155                {
1156                    DataRowView row = (DataRowView)lISTATYTULOWBindingSource.Current;
1157                    oglrozdzialyBindingSource.Filter = "dzial=" + ogl_dzialComboBox.SelectedValue.ToString();
1158
1159                    switch (tYTULComboBox.SelectedValue.ToString())
1160                    {
1161                        case "AMT":
1162                            oglrozdzialyBindingSource.Filter += " AND TYTU£='2'";
1163                            break;
1164                        case "GS":
1165                            oglrozdzialyBindingSource.Filter += " AND TYTU£='1'";
1166                            break;
1167                        case "AGRO":
1168                            oglrozdzialyBindingSource.Filter += " AND TYTU£='7'";
1169                            break;
1170                        case "adMot":
1171                            oglrozdzialyBindingSource.Filter += " AND TYTU£='6'";
1172                            break;
1173                        default:
1174                            break;
1175                    }
1176
1177                    DataRowView Rekrow = (DataRowView)rEKLAMABindingSource.Current;
1178
1179                    if (Rekrow["ogl_rozdzial"] == DBNull.Value)
1180                    {
1181                        ogl_rozdzialComboBox.SelectedIndex = -1;
1182                        ogl_rozdzialComboBox.SelectedIndex = -1;
1183                    }
1184                }
1185            }
1186        }
1187
1188        private void EmailButton_Click(object sender, EventArgs e)
1189        {
1190            StringBuilder tresc = new StringBuilder();
1191
1192            tresc.Append("Potwierdzamy przyjêcie podpisanego zamówienia na publikacjê reklamy w ");
1193
1194            if (tYTULComboBox.Text != "adMoto")
1195            {
1196                tresc.Append(" gazecie \"" + tYTULComboBox.Text + "\"");
1197            }
1198            else
1199            {
1200                tresc.Append(" portalu internetowym " + tYTULComboBox.Text);
1201            }
1202
1203            tresc.Append(" o wartoœci " + bRUTTOTextBox.Text + ".");
1204            //String.Format("{0:P}", cevent.Value);
1205
1206            tresc.AppendLine("");
1207            tresc.AppendLine("Reklamy zostan¹ wyemitowane zgodnie z umow¹ w wydaniu(-ach) nr: \n");
1208
1209            foreach (DataGridViewRow r in ukazeSieDataGridView.Rows)
1210            {
1211                if (r.Cells["nrWydaniaDataGridViewTextBoxColumn"].Value != null)
1212                {
1213                    tresc.Append(r.Cells["nrWydaniaDataGridViewTextBoxColumn"].Value.ToString() + ", ");
1214                }
1215            }
1216
1217            tresc.Remove(tresc.Length - 2, 1);
1218
1219            tresc.AppendLine(" w/w tytu³u i udokumentowane faktur¹ VAT przes³an¹ na wskazany adres.");
1220
1221            MailForm mf = new MailForm(Utils.customerId(this.reklamaId), "Potwierdzenie z³o¿enia zamówienia " + iD_REKLAMYTextBox.Text, "", tresc.ToString());
1222
1223            mf.ShowDialog();
1224        }
1225
1226        private void button3_Click(object sender, EventArgs e)
1227        {
1228            ogl_rozdzialComboBox.SelectedIndex = -1;
1229            ogl_rozdzialComboBox.SelectedIndex = -1;
1230        }
1231
1232        private void kalendarzButton_Click(object sender, EventArgs e)
1233        {
1234            if (tYTULComboBox.SelectedValue != null)
1235            {
1236                // nie moze byc Copy() bo moze zawierac wiersza do skasowania
1237                REKLAMADataSet.UKAZE_SIE_W_NRDataTable table =
1238                    (REKLAMADataSet.UKAZE_SIE_W_NRDataTable)
1239                    this.rEKLAMADataSet.UKAZE_SIE_W_NR.Copy();
1240
1241                REKLAMADataSet.REKLAMARow reklama = (REKLAMADataSet.REKLAMARow)
1242                    ((DataRowView)(this.rEKLAMABindingSource.Current)).Row;
1243
1244                KalendarzEmisji kalendarz =
1245                    new KalendarzEmisji(tYTULComboBox.SelectedValue.ToString(), reklama, table);
1246
1247                if (kalendarz.ShowDialog() == DialogResult.OK)
1248                {
1249                    DataRow[] rows = kalendarz.Emisje.Select("1=1", "[nr wydania] asc");
1250                   // this.rEKLAMADataSet.UKAZE_SIE_W_NR.Clear();
1251                    for (int i = 0; i < rows.Length; i++)
1252                    {
1253                        if (rEKLAMADataSet.UKAZE_SIE_W_NR.FindByID(
1254                            Convert.ToDecimal(rows[i]["id"])) == null){
1255                        this.rEKLAMADataSet.UKAZE_SIE_W_NR.ImportRow(
1256                            (REKLAMADataSet.UKAZE_SIE_W_NRRow)rows[i]);
1257                        }
1258                    }
1259
1260                    kalendarz.Close();
1261               
1262                }
1263               
1264                ukazeSieDataGridView.EndEdit();
1265                rEKLAMAUKAZESIEWNRBindingSource.EndEdit();
1266
1267                // int il = this.rEKLAMADataSet.UKAZE_SIE_W_NR.Count;
1268                int il = ukazeSieDataGridView.Rows.Count;
1269                this.kROTNOSCTextBox.Text = il.ToString();
1270                this.liczbaEmisjiLabel.Text = il.ToString();
1271                rEKLAMABindingSource.EndEdit();
1272
1273                PrzeliczCaleZamowienie();
1274            }
1275
1276        }
1277
1278        private void nowaEmisja(object sender, DataTableNewRowEventArgs e)
1279        {
1280            ((REKLAMADataSet.UKAZE_SIE_W_NRRow)e.Row).dataDodania = DateTime.Today;
1281        }
1282
1283        private void ukazeSieDataGridView_CellContextMenuStripNeeded(object sender, DataGridViewCellContextMenuStripNeededEventArgs e)
1284        {
1285            DataGridViewRow clickedRow = ukazeSieDataGridView.Rows[e.RowIndex];
1286
1287            if (!ukazeSieDataGridView.SelectedRows.Contains(clickedRow))
1288            {
1289                e.ContextMenuStrip = null;
1290                return;
1291            }
1292
1293            zmienToolStripMenuItem.Visible = true;
1294            usunToolStripMenuItem.Visible = true;
1295            anulujToolStripMenuItem.Visible = false;
1296
1297            if (ukazeSieDataGridView.SelectedRows.Count == 1)
1298            {
1299                if (clickedRow.Selected)
1300                {
1301                    if (clickedRow.DefaultCellStyle.BackColor == Color.MintCream)
1302                    {
1303                        zmienToolStripMenuItem.Visible = false;
1304                        usunToolStripMenuItem.Visible = false;
1305                        anulujToolStripMenuItem.Visible = false;
1306
1307                        e.ContextMenuStrip = emisjeContextMenuStrip;
1308                        return;
1309                    }
1310
1311                    DataRowView emisja = (DataRowView)ukazeSieDataGridView.Rows[e.RowIndex].DataBoundItem;
1312                    REKLAMADataSet.UKAZE_SIE_W_NRRow emisjaRow = (REKLAMADataSet.UKAZE_SIE_W_NRRow)emisja.Row;
1313
1314                    if (emisjaRow.zafakturowana)
1315                    {
1316                        zmienToolStripMenuItem.Visible = true;
1317                        usunToolStripMenuItem.Visible = false;
1318                        anulujToolStripMenuItem.Visible = true;
1319
1320                        e.ContextMenuStrip = emisjeContextMenuStrip;
1321                        return;
1322                    }
1323                }
1324            }
1325               
1326            else if (ukazeSieDataGridView.SelectedRows.Count > 1)
1327            {
1328                zmienToolStripMenuItem.Visible = false;
1329                usunToolStripMenuItem.Visible = true;
1330                anulujToolStripMenuItem.Visible = false;
1331
1332                foreach (DataGridViewRow r in ukazeSieDataGridView.SelectedRows)
1333                {
1334                    if (r.DefaultCellStyle.BackColor == Color.MintCream)
1335                    {
1336                        usunToolStripMenuItem.Visible = false;
1337                        break;
1338                    }
1339
1340                    if (Convert.ToBoolean(((DataRowView)r.DataBoundItem)["zafakturowana"]) == true)
1341                    {
1342                        usunToolStripMenuItem.Visible = false;
1343                        break;
1344                    }
1345                }
1346
1347                e.ContextMenuStrip = emisjeContextMenuStrip;
1348                return;
1349            }
1350
1351            e.ContextMenuStrip = emisjeContextMenuStrip;
1352                 
1353        }
1354
1355        public void usunEmisje(object sender, EventArgs e)
1356        {
1357            foreach (DataGridViewRow r in ukazeSieDataGridView.SelectedRows)
1358            {
1359                ukazeSieDataGridView.Rows.Remove(r);
1360            }
1361
1362            ukazeSieDataGridView.EndEdit();
1363            rEKLAMAUKAZESIEWNRBindingSource.EndEdit();
1364
1365           // int il = this.rEKLAMADataSet.UKAZE_SIE_W_NR.Count;
1366            int il = ukazeSieDataGridView.Rows.Count;
1367            this.kROTNOSCTextBox.Text = il.ToString();
1368            this.liczbaEmisjiLabel.Text = il.ToString();
1369            rEKLAMABindingSource.EndEdit();
1370
1371            PrzeliczCaleZamowienie();
1372
1373        }
1374
1375        private void anulujEmisje(object sender, EventArgs e)
1376        {
1377            if (ukazeSieDataGridView.CurrentCell != null)
1378            {
1379                DataGridViewRow r1 = ukazeSieDataGridView.CurrentCell.OwningRow;
1380
1381                REKLAMADataSet.UKAZE_SIE_W_NRRow row = (REKLAMADataSet.UKAZE_SIE_W_NRRow)(((DataRowView)r1.DataBoundItem).Row);
1382
1383                row.status = 2;
1384                row.dataAnulowania = DateTime.Now;
1385            }
1386        }
1387
1388        private void zmienEmisje(object sender, EventArgs e)
1389        {
1390            if (tYTULComboBox.SelectedValue != null)
1391            {
1392                REKLAMADataSet.UKAZE_SIE_W_NRDataTable table =
1393                (REKLAMADataSet.UKAZE_SIE_W_NRDataTable)
1394                this.rEKLAMADataSet.UKAZE_SIE_W_NR.Copy();
1395
1396                REKLAMADataSet.REKLAMARow reklama = (REKLAMADataSet.REKLAMARow)
1397                 ((DataRowView)(this.rEKLAMABindingSource.Current)).Row;
1398
1399                KalendarzEmisji kalendarz = new KalendarzEmisji(
1400                    tYTULComboBox.SelectedValue.ToString(),
1401                    reklama,
1402                    table,
1403                    (short)ukazeSieDataGridView.CurrentCell.Value);
1404
1405                if (kalendarz.ShowDialog() == DialogResult.OK)
1406                {
1407                    if (ukazeSieDataGridView.CurrentCell != null)
1408                    {
1409                        DataGridViewRow r1 = ukazeSieDataGridView.CurrentCell.OwningRow;
1410                        REKLAMADataSet.UKAZE_SIE_W_NRRow row = (REKLAMADataSet.UKAZE_SIE_W_NRRow)(((DataRowView)r1.DataBoundItem).Row);
1411
1412                        if (row.zafakturowana && (row.Nr_Wydania != kalendarz.NowaEmisja))
1413                        {
1414                            rEKLAMADataSet.zmianyEmisji.AddzmianyEmisjiRow(row, row.Nr_Wydania, kalendarz.NowaEmisja, DateTime.Now);
1415                        }
1416
1417                        row.Nr_Wydania = kalendarz.NowaEmisja;
1418                        kalendarz.Close();       
1419                       
1420                        row.EndEdit();
1421                        this.rEKLAMADataSet.UKAZE_SIE_W_NR.EndInit();
1422                        this.rEKLAMAUKAZESIEWNRBindingSource.ResetBindings(false);
1423                    }
1424                }
1425               
1426            }
1427        }
1428             
1429
1430        private void ukazeSieDataGridView_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
1431        {
1432            if (ukazaloSieDataGridView.Rows.Count > 0)
1433            {
1434                tYTULComboBox.Enabled = false;
1435            }
1436            else
1437            {
1438                tYTULComboBox.Enabled = true;
1439            }
1440        }
1441
1442        private void ukazeSieDataGridView_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
1443        {
1444            blokowanieZrealizowanychEmisji();
1445        }
1446
1447        private void walutyComboBox_SelectedIndexChanged(object sender, EventArgs e)
1448        {
1449            if (obslugaZdarzen)
1450            {
1451                if (walutyComboBox.SelectedIndex != -1)
1452                {
1453                    kurs = PobierzKurs(walutyComboBox.SelectedItem.ToString());
1454                    PrzeliczCaleZamowienie();
1455                }
1456            }
1457        }
1458
1459        private void PrzeliczCaleZamowienie()
1460        {
1461            DataRowView row = (DataRowView)rEKLAMABindingSource.Current;
1462            REKLAMADataSet.REKLAMARow reklama = (REKLAMADataSet.REKLAMARow)row.Row;
1463
1464            if (walutyComboBox.SelectedIndex != 0)
1465            {
1466                 if (reklama.IsBrutto_EuroNull()){
1467                     reklama.Brutto_Euro = 0;
1468                     reklama.EndEdit();
1469                 }
1470           
1471                if (kurs != null)
1472                {
1473                    przeliczWaluteNaZlotowki(kurs);
1474                }
1475                else
1476                {
1477                    kurs = PobierzKurs(walutyComboBox.SelectedItem.ToString());
1478
1479                    if (kurs != null)
1480                    {
1481                        MessageBox.Show("Wyst¹pi³ b³¹d!");
1482                    }
1483                    else
1484                    {
1485                        przeliczWaluteNaZlotowki(kurs);
1486                    }
1487                }
1488            }
1489            else
1490            {
1491              if (row["id_faktury"] == DBNull.Value)
1492                {
1493                    row["waluta_tabela_nr"] = DBNull.Value;
1494                    row["waluta_Przelicznik"] = DBNull.Value;
1495                    row["waluta_kurs"] = DBNull.Value;
1496                    row["waluta_kurs_z_dnia"] = DBNull.Value;
1497                    row["Brutto_Euro"] = DBNull.Value;
1498                    row["Brutto_Euro_Miano"] = DBNull.Value;
1499                    row["FAKTURA ID KONTA"] = 1;
1500
1501                    rEKLAMABindingSource.EndEdit();
1502                    przelicz();
1503                }
1504                else
1505                {
1506                    MessageBox.Show("Faktura zosta³a ju¿ wystawiona!");
1507                }
1508            }
1509        }
1510
1511        private SLOWNIKDataSet.Kursy_WalutRow PobierzKurs(string kodWaluty)
1512        {         
1513            SLOWNIKDataSet.Kursy_WalutDataTable kursy = kursy_WalutTableAdapter.GetDataByDataPublikacji(
1514                kodWaluty, DateTime.Today);
1515
1516            if (kursy.Count == 0)
1517            {
1518                return null;
1519            }
1520            else
1521            {
1522                return kursy[0];
1523            }
1524        }
1525         
1526        private void brutto_EuroTextBox_Leave(object sender, EventArgs e)
1527        {
1528            rEKLAMABindingSource.EndEdit();
1529            PrzeliczCaleZamowienie();
1530        }
1531
1532        private void rABATTextBox_Leave(object sender, EventArgs e)
1533        {
1534            rEKLAMABindingSource.EndEdit();
1535            PrzeliczCaleZamowienie();
1536        }
1537
1538        private void pVATComboBox_SelectedIndexChanged(object sender, EventArgs e)
1539        {
1540            rEKLAMABindingSource.EndEdit();
1541            PrzeliczCaleZamowienie();
1542        }
1543
1544        private void cENA_JEDNTextBox_Leave(object sender, EventArgs e)
1545        {
1546            rEKLAMABindingSource.EndEdit();
1547            PrzeliczCaleZamowienie();
1548        }
1549
1550        private void wyroznienieCheckBox_Click(object sender, EventArgs e)
1551        {
1552            this.rEKLAMABindingSource.EndEdit();
1553            PrzeliczCaleZamowienie();
1554     
1555        }
1556
1557        private void rEKLAMABindingSource_BindingComplete(object sender, BindingCompleteEventArgs e)
1558        {
1559            if (rEKLAMABindingSource.Current != null)
1560            {
1561                DataRowView row = (DataRowView)rEKLAMABindingSource.Current;
1562                REKLAMADataSet.REKLAMARow reklama = (REKLAMADataSet.REKLAMARow)row.Row;
1563                //wyliczona cena modulu
1564                double szer = reklama.SZER;
1565                double wys = reklama.WYS;
1566                int krotnosc = reklama.KROTNOŒÆ;
1567                double cenaJednostkowa = reklama.CENA_JEDN;
1568                double vatProcent = reklama.VAT;
1569                double prowizjaProcent = reklama.PROCENT_PROWIZJI;
1570                double rabatProcent = reklama.RABAT;
1571                double rabatWartosc = rabatProcent * cenaJednostkowa;
1572                double netto = (cenaJednostkowa - rabatWartosc) * krotnosc;
1573                double cenaModulu;
1574                if ((szer * wys * krotnosc) != 0)
1575                {
1576                    cenaModulu = netto / (szer * wys * krotnosc);
1577                    cenaModuluLabel.Text = String.Format("{0:C}", cenaModulu);
1578                }
1579                else
1580                {
1581                    cenaModuluLabel.Text = "---";
1582                }
1583
1584                liczbaEmisjiLabel.Text = this.rEKLAMADataSet.UKAZE_SIE_W_NR.Rows.Count.ToString();
1585
1586                this.obslugaZdarzen = false;
1587                if (!reklama.IsBrutto_Euro_MianoNull())
1588                {
1589                    walutyComboBox.SelectedItem = reklama.Brutto_Euro_Miano;
1590                }
1591                else
1592                {
1593                    walutyComboBox.SelectedIndex = 0; //PLN
1594                }
1595                this.obslugaZdarzen = true;
1596            }
1597        }
1598    }
1599}
Notatka: Zobacz TracBrowser aby uzyskać więcej informacji.