root/Baza Reklam 2 - Faktury/ProvisionForm.cs @ 692

Wersja 114, 27.7 KB (wprowadzona przez dorota, 17 years temu)

dodanie liczenia prowizji po staremu (dla grudnia 2008)

Line 
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Data;
5using System.Data.SqlClient;
6using System.Drawing;
7using System.Text;
8using System.Windows.Forms;
9
10namespace Baza_Reklam
11{
12    public partial class ProvisionForm : Form
13    {
14
15        private short rok = 0;
16        private short miesiac = 0;
17        private int agencja = 0;
18
19
20
21        /// <summary>
22        /// Klasa pomocnicza do wyœwietlania w 0 - 2 w gridzie
23        /// </summary>
24        class Ocena
25        {
26            private int label;
27
28            public int Label
29            {
30                get { return label; }
31                set { label = value; }
32            }
33            private Single value;
34
35            public Single Value
36            {
37                get { return this.value; }
38                set { this.value = value; }
39            }
40
41            public Ocena(int l, Single v)
42            {
43                label = l;
44                value = v;
45            }
46        }
47
48        /// <summary>
49        /// List do databindings
50        /// </summary>
51        List<Ocena> oceny = new List<Ocena>();
52
53
54        private static ProvisionForm provisionForm;
55
56        public static ProvisionForm getProvisionForm(MDIBazaReklam parent)
57        {
58            if (provisionForm == null)
59            {
60                provisionForm = new ProvisionForm(parent);
61            }
62            return provisionForm;
63        }
64
65        public ProvisionForm(MDIBazaReklam parent)
66        {
67            InitializeComponent();
68
69            this.MdiParent = parent;
70
71            pLANTableAdapter.Connection.ConnectionString = ConnString.getConnString().Value;
72            aGENCITableAdapter.Connection.ConnectionString = ConnString.getConnString().Value;
73            agencjeTableAdapter1.Connection.ConnectionString = ConnString.getConnString().Value;
74
75            //bindowanie ocen z comboBoxColumn
76            oceny.Add(new Ocena(0, 0));
77            oceny.Add(new Ocena(1, 50));
78            oceny.Add(new Ocena(2, 100));
79
80            OCENAComboCoxColumn.DataSource = oceny;
81            OCENAComboCoxColumn.DisplayMember = "label";
82            OCENAComboCoxColumn.ValueMember = "value";
83
84            dodajPlanToolStripButton.Enabled = User.getUser().St_kierownik;
85            usunToolStripButton.Enabled = User.getUser().St_kierownik;
86        }
87
88        private void ProvisionForm_Load(object sender, EventArgs e)
89        {
90            rokToolStripTextBox.Text = DateTime.Today.Year.ToString();
91            msToolStripTextBox.Text = DateTime.Today.Month.ToString();
92
93            ((ComboBox)agencjaToolStripComboBox.Control).DataSource = agencjeTableAdapter1.GetData();
94            ((ComboBox)agencjaToolStripComboBox.Control).DisplayMember = "Symbol";
95            ((ComboBox)agencjaToolStripComboBox.Control).ValueMember = "ID_Agencji";
96
97            ((ComboBox)agencjaToolStripComboBox.Control).SelectedValue = User.getUser().IdAgencji;
98
99            if (!User.getUser().St_kierownik)
100            {
101                agencjaToolStripComboBox.Enabled = false;
102            }
103
104        }
105
106        private void treeView1_AfterExpand(object sender, TreeViewEventArgs e)
107        {
108            SqlCommand command = new SqlCommand();
109            command.Connection = new SqlConnection(ConnString.getConnString().Value);
110
111            if (e.Node != null)
112            {
113                switch (e.Node.Level)
114                {
115                    case 0:
116                        e.Node.Nodes.Clear();
117
118                        TreeNode node;
119
120                        command.CommandText = "select distinct datepart(year,DATA_W) as rok from dbo.NR where datepart(year,DATA_W) is not null and datepart(year,DATA_W)>= 2003 order by rok desc";
121                        command.Connection.Open();
122                        SqlDataReader reader = command.ExecuteReader();
123
124                        while (reader.Read())
125                        {
126                            node = new TreeNode(reader.GetValue(0).ToString());
127                            node.Name = reader.GetValue(0).ToString();
128
129                            for (int i = 12; i >= 1; i--)
130                            {
131                                TreeNode node2 = new TreeNode(i.ToString());
132                                node2.Name = i.ToString();
133                                //  node2.Nodes.Add(new TreeNode());
134                                node.Nodes.Add(node2);
135                            }
136                            e.Node.Nodes.Add(node);
137                        }
138                        command.Connection.Close();
139
140                        break;
141                    case 1:
142                        break;
143                    case 2:
144                        break;
145                }
146            }
147        }
148
149        /// <summary>
150        ///  Pobiera dane o kontaktach i bud¿ecie.
151        /// </summary>
152        private void pobierzDaneToolStripButton_Click(object sender, EventArgs e)
153        {
154            this.Cursor = Cursors.WaitCursor;
155
156            SqlCommand command = new SqlCommand();
157            command.Connection = new SqlConnection(ConnString.getConnString().Value);
158            command.CommandType = CommandType.StoredProcedure;
159
160            command.CommandText = "PROC_WYLICZ_I_ZAPISZ_DANE_O_KONTAKTACH_I_BUDZECIE";
161            command.Parameters.AddWithValue("@rok", rok);
162            command.Parameters.AddWithValue("@ms", miesiac);
163
164            command.Connection.Open();
165
166            SqlTransaction transaction = command.Connection.BeginTransaction();
167
168            command.Transaction = transaction;
169
170            try
171            {
172                command.ExecuteNonQuery();
173                transaction.Commit();
174                MessageBox.Show("Dane pobrano!");
175            }
176            catch (Exception ex)
177            {
178                MessageBox.Show(ex.GetType() + ex.Message);
179
180                try
181                {
182                    transaction.Rollback();
183                }
184                catch (Exception ex2)
185                {
186                    MessageBox.Show("ROLLBACK:" + ex2.GetType() + ex2.Message);
187                }
188            }
189
190            command.Connection.Close();
191
192            this.rEKLAMADataSet.PLAN.Clear();
193            this.pLANTableAdapter.FillByAgencja(this.rEKLAMADataSet.PLAN, rok, miesiac, agencja);
194            this.Cursor = Cursors.Default;
195        }
196
197        /// <summary>
198        /// Wylicza i zapisuje prowizjê agenta do planu
199        /// </summary>
200        private void zapiszToolStripButton_Click(object sender, EventArgs e)
201        {
202            this.Cursor = Cursors.WaitCursor;
203
204            SqlCommand command = new SqlCommand();
205
206            command.Connection = new SqlConnection(ConnString.getConnString().Value);
207
208            command.CommandType = CommandType.StoredProcedure;
209
210            command.CommandText = "PROC_WYLICZ_I_ZAPISZ_PROWIZJE_AGENTA_DO_PLANU";
211            command.Parameters.AddWithValue("@rok", rok);
212            command.Parameters.AddWithValue("@ms", miesiac);
213            command.Parameters.AddWithValue("@id_Agencji", agencja);
214            command.Connection.Open();
215
216            SqlTransaction transaction = command.Connection.BeginTransaction();
217
218            command.Transaction = transaction;
219
220            try
221            {
222                command.ExecuteNonQuery();
223                transaction.Commit();
224                MessageBox.Show("Prowizja zosta³a zapisana!");
225            }
226            catch (Exception ex)
227            {
228                MessageBox.Show(ex.GetType() + ex.Message);
229
230                try
231                {
232                    transaction.Rollback();
233                }
234                catch (Exception ex2)
235                {
236                    MessageBox.Show("ROLLBACK:" + ex2.GetType() + ex2.Message);
237                }
238            }
239
240            command.Connection.Close();
241
242            this.rEKLAMADataSet.PLAN.Clear();
243
244            this.pLANTableAdapter.FillByAgencja(this.rEKLAMADataSet.PLAN, rok, miesiac, agencja);
245
246            this.Cursor = Cursors.Default;
247        }
248
249        private void naniesNaReklamyToolStripButton_Click(object sender, EventArgs e)
250        {
251            this.Cursor = Cursors.WaitCursor;
252
253            SqlCommand command = new SqlCommand();
254
255            command.Connection = new SqlConnection(ConnString.getConnString().Value);
256
257            command.CommandType = CommandType.StoredProcedure;
258
259            // command.CommandText = "PROC_WYLICZ_I_ZAPISZ_PROWIZJE_DO_REKLAM";
260            command.CommandText = "PROC_WYLICZ_I_ZAPISZ_PROWIZJE";
261            command.Parameters.AddWithValue("@rok", this.rok);
262            command.Parameters.AddWithValue("@ms", this.miesiac);
263            command.Parameters.AddWithValue("@idAgencji", agencja);
264
265            command.Connection.Open();
266
267            SqlTransaction transaction = command.Connection.BeginTransaction();
268
269            command.Transaction = transaction;
270
271            try
272            {
273                command.ExecuteNonQuery();
274                transaction.Commit();
275                MessageBox.Show("Prowizja zosta³a naniesiona na zlecenia");
276            }
277            catch (Exception ex)
278            {
279                MessageBox.Show(ex.GetType() + ex.Message);
280
281                try
282                {
283                    transaction.Rollback();
284                }
285                catch (Exception ex2)
286                {
287                    MessageBox.Show("ROLLBACK:" + ex2.GetType() + ex.Message);
288                }
289            }
290
291            command.Connection.Close();
292
293            this.Cursor = Cursors.Default;
294
295            MessageBox.Show("Prowizja naniesiona na zlecenia");
296        }
297
298        /*
299        private void przeliczStripButton_Click(object sender, EventArgs e)
300        {
301            if (pLANBindingSource.List.Count != 0)
302            {
303                foreach (DataRowView r in pLANBindingSource.List)
304                {
305                    REKLAMADataSet.PLANRow row = (REKLAMADataSet.PLANRow)r.Row;
306                    przelicz(row);
307                    pLANBindingSource.EndEdit();
308                }
309            }
310
311        }*/
312
313        /*
314        private void przelicz(REKLAMADataSet.PLANRow row)
315        {
316
317            row.ECP = 0;
318            row.ESP = 0;
319            row.ELK = 0;
320            row.EP = 0;
321            row.EPK = 0;
322            row.EPR = 0;
323            row.WH = 0;
324            row.QO = 0;
325            row.OCENA = 0;
326
327            if (row.IsNull("BUDZET")) { row.BUDZET = 0; }
328            if (row.IsNull("REKLAMY")) { row.REKLAMY = 0; }
329            if (row.IsNull("W_REKLAMY")) { row.W_REKLAMY = 0; }
330            if (row.IsNull("W_BUDZET")) { row.W_BUDZET = 0; }
331            if (row.IsNull("N_KLIENCI")) { row.N_KLIENCI = 0; }
332            if (row.IsNull("W_N_KLIENCI")) { row.W_N_KLIENCI = 0; }
333            if (row.IsNull("W_SPOTKANIA")) { row.W_SPOTKANIA = 0; }
334            if (row.IsNull("W_TEL")) { row.W_TEL = 0; }
335            if (row.IsNull("W_EMAIL")) { row.W_EMAIL = 0; }
336            if (row.IsNull("W_FAX")) { row.W_FAX = 0; }
337            if (row.IsNull("W_LIST")) { row.W_LIST = 0; }
338            if (row.IsNull("KONTAKTY")) { row.KONTAKTY = 0; }
339
340
341            float W_BUDZET = Convert.ToSingle(row.W_BUDZET);
342            float BUDZET = Convert.ToSingle(row.BUDZET);
343            float W_REKLAMY = Convert.ToSingle(row.W_REKLAMY);
344            float REKLAMY = Convert.ToSingle(row.REKLAMY);
345            float W_N_KLIENCI = Convert.ToSingle(row.W_N_KLIENCI);
346            float N_KLIENCI = Convert.ToSingle(row.N_KLIENCI);
347            float W_SPOTKANIA = Convert.ToSingle(row.W_SPOTKANIA);
348            float W_TEL = Convert.ToSingle(row.W_TEL);
349            float W_EMAIL = Convert.ToSingle(row.W_EMAIL);
350            float W_FAX = Convert.ToSingle(row.W_FAX);
351            float W_LIST = Convert.ToSingle(row.W_LIST);
352            float KONTAKTY = Convert.ToSingle(row.KONTAKTY);
353            float JAKOSC_KORESPONDENCJI = Convert.ToSingle(row.JAKOSC_KORESPONDENCJI);
354            float JAKOSC_OFERT = Convert.ToSingle(row.JAKOSC_OFERT);
355            float JAKOSC_ROZMOWY_TEL = Convert.ToSingle(row.JAKOSC_ROZMOWY_TEL);
356            float JAKOSC_SPOTKAN = Convert.ToSingle(row.JAKOSC_SPOTKAN);
357            float WIEDZA_O_FIRMIE = Convert.ToSingle(row.WIEDZA_O_FIRMIE);
358            float WIEDZA_O_PRODUKCIE = Convert.ToSingle(row.WIEDZA_O_PRODUKCIE);
359            float WIEDZA_O_RYNKU = Convert.ToSingle(row.WIEDZA_O_RYNKU);
360            float WIEDZA_OGOLNO_HANDLOWA = Convert.ToSingle(row.WIEDZA_OGOLNO_HANDLOWA);
361
362            if (BUDZET != 0)
363            {
364                row.EP = 100 * W_BUDZET / BUDZET;
365            }
366
367            if (REKLAMY != 0)
368            {
369                row.ESP = 100 * W_REKLAMY / REKLAMY;
370            }
371
372            if ((REKLAMY != 0) && (W_REKLAMY != 0))
373            {
374                row.EPR = 100 * (W_BUDZET/W_REKLAMY)/(BUDZET/REKLAMY);
375            }
376
377            if (N_KLIENCI != 0)
378            {
379                row.EPK = 100 * (W_N_KLIENCI/N_KLIENCI);
380            }
381
382            row.ECP = 100 * ((120 * W_SPOTKANIA + 5 * W_TEL + 30 * W_EMAIL + 30 * W_FAX + 30 * W_LIST) / (20 * 7 * 60));
383
384            if (KONTAKTY != 0)
385            {
386                row.ELK = 100 * ((W_SPOTKANIA + W_TEL + W_EMAIL + W_FAX + W_LIST) / KONTAKTY);
387            }
388
389            row.QO = 100 * (JAKOSC_KORESPONDENCJI / 10 + JAKOSC_OFERT / 10 + JAKOSC_ROZMOWY_TEL / 10 + JAKOSC_SPOTKAN / 10) / 4;
390            row.WH = 100 * (WIEDZA_O_FIRMIE / 10 + WIEDZA_O_PRODUKCIE / 10 + WIEDZA_O_RYNKU / 10 + WIEDZA_OGOLNO_HANDLOWA / 10) / 4;
391            row.OCENA = (float)Math.Round(((row.WH + row.QO + row.ELK + row.ECP + row.EPK + 1 * row.EPR + 1 * row.ESP + 1 * row.EP) / 8), 2);
392        }
393        */
394
395        private void dodajPlanToolStripButton_Click(object sender, EventArgs e)
396        {
397            OcenaAddForm oaf = new OcenaAddForm();
398            oaf.Show();
399        }
400
401        private void usunToolStripButton_Click(object sender, EventArgs e)
402        {
403            if (pLANBindingSource.Current != null)
404            {
405                if (MessageBox.Show("Czy na pewno usun¹æ rekord?", "", MessageBoxButtons.YesNo) == DialogResult.Yes)
406                {
407                    pLANBindingSource.RemoveCurrent();
408                    pLANBindingSource.EndEdit();
409                    pLANTableAdapter.Update(this.rEKLAMADataSet.PLAN);
410                }
411            }
412        }
413
414        private void zapiszDaneToolStripButton_Click(object sender, EventArgs e)
415        {
416            this.Cursor = Cursors.WaitCursor;
417
418            if (Validate())
419            {
420                pLANBindingSource.EndEdit();
421                pLANTableAdapter.Update(this.rEKLAMADataSet.PLAN);
422            }
423            this.Cursor = Cursors.Default;
424
425            MessageBox.Show("Zmiany zapisane");
426        }
427
428        private void ukryjKolumnyToolStripButton_Click(object sender, EventArgs e)
429        {
430            rOKDataGridViewTextBoxColumn.Visible = rOKDataGridViewTextBoxColumn.Visible ? false : true;
431
432            mSDataGridViewTextBoxColumn.Visible = mSDataGridViewTextBoxColumn.Visible ? false : true;
433        }
434
435        private void prowizjeDataGridView_Leave(object sender, EventArgs e)
436        {
437            //ukrytyLabel.Select();
438            prowizjeDataGridView.EndEdit();
439            //pLANBindingSource.EndEdit();
440
441            REKLAMADataSet.PLANDataTable changes = rEKLAMADataSet.PLAN.GetChanges(DataRowState.Modified) as
442                REKLAMADataSet.PLANDataTable;
443
444            if (changes != null)
445            {
446                if (Validate())
447                {
448                    pLANBindingSource.EndEdit();
449                    pLANTableAdapter.Update(this.rEKLAMADataSet.PLAN);
450                }
451            }
452        }
453
454        /// <summary>
455        /// Podsumowuje bud¿et do wykonania
456        /// </summary>
457        private void uzupelnijBDsuma()
458        {
459            int kasa = 0;
460            foreach (DataRowView r in pLANBindingSource.List)
461            {
462                kasa += Convert.ToInt32(r["BUDZET"]);
463            }
464            BDsumaTextBox.Text = String.Format("{0:C}", kasa);
465        }
466
467        /// <summary>
468        /// Podsumowuje bud¿et wykonany
469        /// </summary>
470        private void uzupelnijBDWykonanySuma()
471        {
472            int kasa = 0;
473            foreach (DataRowView r in pLANBindingSource.List)
474            {
475                kasa += Convert.ToInt32(r["W_BUDZET"]);
476            }
477            BDWykonanySumaTextBox.Text = String.Format("{0:C}", kasa);
478        }
479
480        /// <summary>
481        /// Zamienia wpisan¹ liczbê do decimal
482        /// </summary>
483        private void prowizjeDataGridView_CellLeave(object sender, DataGridViewCellEventArgs e)
484        {
485            ukrytyLabel.Select();
486            prowizjeDataGridView.EndEdit();
487            pLANBindingSource.EndEdit();
488
489            if (prowizjeDataGridView.Columns[e.ColumnIndex].Name == "PR_PROWIZJI")
490            {
491
492                if (Convert.ToDecimal(prowizjeDataGridView[e.ColumnIndex, e.RowIndex].Value) >= 1)
493                {
494                    prowizjeDataGridView[e.ColumnIndex, e.RowIndex].Value = Convert.ToDecimal(prowizjeDataGridView[e.ColumnIndex, e.RowIndex].Value) / 100;
495                }
496            }
497
498            REKLAMADataSet.PLANDataTable changes = rEKLAMADataSet.PLAN.GetChanges(DataRowState.Modified) as
499                 REKLAMADataSet.PLANDataTable;
500
501            if (changes != null)
502            {
503                pLANBindingSource.EndEdit();
504                pLANTableAdapter.Update(this.rEKLAMADataSet.PLAN);
505            }
506        }
507
508        private void pLANBindingSource_ListChanged(object sender, ListChangedEventArgs e)
509        {
510            uzupelnijBDsuma();
511            uzupelnijBDWykonanySuma();
512        }
513
514
515        private void szukajToolStripButton_Click(object sender, EventArgs e)
516        {
517            if (rokToolStripTextBox.Text != "")
518            {
519                short i;
520                if (!Int16.TryParse(rokToolStripTextBox.Text, out i))
521                {
522                    MessageBox.Show("Podaj prawid³owy rok.");
523                    this.Cursor = Cursors.Default;
524                    return;
525                }
526            }
527            else
528            {
529                MessageBox.Show("Podaj prawid³owy rok.");
530                this.Cursor = Cursors.Default;
531                return;
532            }
533
534            if (msToolStripTextBox.Text != "")
535            {
536                short i;
537                if (!Int16.TryParse(msToolStripTextBox.Text, out i))
538                {
539                    MessageBox.Show("Podaj prawid³owy miesi¹c.");
540                    this.Cursor = Cursors.Default;
541                    return;
542                }
543            }
544            else
545            {
546                MessageBox.Show("Podaj prawid³owy miesi¹c.");
547                this.Cursor = Cursors.Default;
548                return;
549            }
550
551            if (((ComboBox)agencjaToolStripComboBox.Control).SelectedValue == null)
552            {
553                MessageBox.Show("Wybierz agencjê");
554                return;
555            }
556
557            this.rok = Convert.ToInt16(rokToolStripTextBox.Text);
558            this.miesiac = Convert.ToInt16(msToolStripTextBox.Text);
559            this.agencja = Convert.ToInt32(((ComboBox)agencjaToolStripComboBox.Control).SelectedValue);
560
561            uprawnienia();
562
563            this.sLOWNIKDataSet.AGENCI.Clear();
564            this.rEKLAMADataSet.PLAN.Clear();
565
566            this.aGENCITableAdapter.FillByIdAgencji(this.sLOWNIKDataSet.AGENCI, this.agencja);
567            this.pLANTableAdapter.FillByAgencja(this.rEKLAMADataSet.PLAN, this.rok, this.miesiac, this.agencja);
568        }
569
570        /*
571        private void szukajToolStripButton_Click(object sender, EventArgs e)
572        {           
573            this.Cursor = Cursors.WaitCursor;
574
575            string query = "SELECT   top 1000 [PLAN].* FROM AGENCJE INNER JOIN AGENCI ON AGENCJE.Id_agencji = AGENCI.ID_AGENCJI " +
576                " INNER JOIN [PLAN] ON AGENCI.Symbol = [PLAN].SYMBOL WHERE  1 = 1 ";
577
578            SqlCommand command = new SqlCommand();
579            command.CommandText = query;
580
581            if (rokToolStripTextBox.Text != "")
582            {
583                short i;
584                if (!Int16.TryParse(rokToolStripTextBox.Text, out i))
585                {
586                    MessageBox.Show("Podaj prawid³owy rok.");
587                    this.Cursor = Cursors.Default;
588                    return;
589                }
590                command.CommandText += " AND [PLAN].rok = @rok ";
591                command.Parameters.AddWithValue("@rok", rokToolStripTextBox.Text);
592                this.rok = Convert.ToInt16(rokToolStripTextBox.Text);
593            }           
594
595            if (msToolStripTextBox.Text != "")
596            {
597                short i;
598                if (!Int16.TryParse(msToolStripTextBox.Text, out i))
599                {
600                    MessageBox.Show("Podaj prawid³owy miesi¹c.");
601                    this.Cursor = Cursors.Default;
602                    return;
603                }
604                command.CommandText += " AND [PLAN].ms = @ms ";
605                command.Parameters.AddWithValue("ms", msToolStripTextBox.Text);
606                this.miesiac = Convert.ToInt16(msToolStripTextBox.Text);
607            }
608
609            if (((ComboBox)agencjaToolStripComboBox.Control).SelectedValue == null)
610            {
611                MessageBox.Show("Wybierz agencjê");
612                return;
613            }
614            else
615            {
616                command.CommandText += " AND AGENCJE.Id_Agencji=@agencja";
617                command.Parameters.AddWithValue("@agencja", ((ComboBox)agencjaToolStripComboBox.Control).SelectedValue);
618                this.agencja = Convert.ToInt32(((ComboBox)agencjaToolStripComboBox.Control).SelectedValue);
619            }
620
621          //  uprawnienia();   
622            poblokujWiersze();
623                     
624           
625            this.sLOWNIKDataSet.AGENCI.Clear();
626            this.aGENCITableAdapter.FillByIdAgencji(this.sLOWNIKDataSet.AGENCI, this.agencja);
627
628            this.rEKLAMADataSet.PLAN.Clear();
629           // this.pLANTableAdapter.FillByAgencja(this.rEKLAMADataSet.PLAN, this.rok, this.miesiac, this.agencja);
630
631            command.Connection = new SqlConnection(ConnString.getConnString().Value);
632            SqlDataAdapter adapter = new SqlDataAdapter();
633            adapter.SelectCommand = command;
634
635            adapter.Fill(rEKLAMADataSet.PLAN);
636
637            this.Cursor = Cursors.Default;   
638        }
639
640        private void poblokujWiersze()
641        {
642            if (User.getUser().St_kierownik)
643            {
644                prowizjeDataGridView.ReadOnly = false;
645                foreach (DataGridViewRow r in prowizjeDataGridView.Rows)
646                {
647                    if (!((Convert.ToInt32(r.Cells["rOKDataGridViewTextBoxColumn"].Value) > DateTime.Today.Year) |
648                        ((Convert.ToInt32(r.Cells["rOKDataGridViewTextBoxColumn"].Value) == DateTime.Today.Year) & (Convert.ToInt32(r.Cells["mSDataGridViewTextBoxColumn"].Value) >= DateTime.Today.Month - 1)) |
649                        ((Convert.ToInt32(r.Cells["rOKDataGridViewTextBoxColumn"].Value) == DateTime.Today.Year - 1) & (Convert.ToInt32(r.Cells["mSDataGridViewTextBoxColumn"].Value) == 12) & (DateTime.Today.Month == 1))))
650                    {
651                        r.ReadOnly = true;
652                    }
653                }
654            }
655        }
656        */
657
658        private void uprawnienia()
659        {
660            if (User.getUser().St_kierownik)
661            {
662
663                if (!((this.rok > DateTime.Today.Year) |
664                    ((this.rok == DateTime.Today.Year) & (this.miesiac >= DateTime.Today.Month - 1)) |
665                    ((this.rok == DateTime.Today.Year - 1) & (this.miesiac == 12) & (DateTime.Today.Month == 1))))
666                {
667                    OCENAComboCoxColumn.Visible = false;
668                    oCENADataGridViewTextBoxColumn.Visible = true;
669
670                    prowizjeDataGridView.ReadOnly = true;
671                    usunToolStripButton.Enabled = false;
672                    pobierzDaneToolStripButton.Enabled = false;
673                    naniesNaReklamyToolStripButton.Enabled = false;
674                    zapiszDaneToolStripButton.Enabled = false;
675                    zapiszToolStripButton.Enabled = false;
676
677                }
678                else
679                {
680                    OCENAComboCoxColumn.Visible = true;
681                    oCENADataGridViewTextBoxColumn.Visible = false;
682                    prowizjeDataGridView.ReadOnly = false;
683
684                    usunToolStripButton.Enabled = true;
685                    pobierzDaneToolStripButton.Enabled = true;
686                    naniesNaReklamyToolStripButton.Enabled = true;
687                    zapiszDaneToolStripButton.Enabled = true;
688                    zapiszToolStripButton.Enabled = true;
689
690                    stareProwizjeToolStripButton.Enabled = true;
691                }
692            }
693        }
694
695        private void prowizjeDataGridView_DataError_1(object sender, DataGridViewDataErrorEventArgs e)
696        {
697            MessageBox.Show("WprowadŸ poprawne dane");
698        }
699
700        private void ProvisionForm_Leave(object sender, EventArgs e)
701        {
702            prowizjeDataGridView.EndEdit();
703            //pLANBindingSource.EndEdit();
704
705            REKLAMADataSet.PLANDataTable changes = rEKLAMADataSet.PLAN.GetChanges(DataRowState.Modified) as
706                REKLAMADataSet.PLANDataTable;
707
708            if (changes != null)
709            {
710                if (Validate())
711                {
712                    pLANBindingSource.EndEdit();
713                    pLANTableAdapter.Update(this.rEKLAMADataSet.PLAN);
714                }
715            }
716        }
717
718        private void printToolStripButton_Click(object sender, EventArgs e)
719        {
720            PrintDGV.Print_DataGridView(prowizjeDataGridView, 50);
721        }
722
723        private void wyczyscToolStripButton_Click(object sender, EventArgs e)
724        {
725
726        }
727
728        private void przeliczStripButton_Click(object sender, EventArgs e)
729        {
730
731        }
732
733        private void stareProwizjeToolStripButton_Click(object sender, EventArgs e)
734        {
735            this.Cursor = Cursors.WaitCursor;
736
737            SqlCommand command = new SqlCommand();
738
739            command.Connection = new SqlConnection(ConnString.getConnString().Value);
740
741            command.CommandType = CommandType.StoredProcedure;
742
743            command.CommandText = "PROC_WYLICZ_I_ZAPISZ_PROWIZJE_DO_REKLAM";
744            command.Parameters.AddWithValue("@rok", this.rok);
745            command.Parameters.AddWithValue("@ms", this.miesiac);
746
747            command.Connection.Open();
748
749            SqlTransaction transaction = command.Connection.BeginTransaction();
750
751            command.Transaction = transaction;
752
753            try
754            {
755                command.ExecuteNonQuery();
756                transaction.Commit();
757                MessageBox.Show("Prowizja zosta³a naniesiona na zlecenia");
758            }
759            catch (Exception ex)
760            {
761                MessageBox.Show(ex.GetType() + ex.Message);
762
763                try
764                {
765                    transaction.Rollback();
766                }
767                catch (Exception ex2)
768                {
769                    MessageBox.Show("ROLLBACK:" + ex2.GetType() + ex.Message);
770                }
771            }
772
773            command.Connection.Close();
774
775            this.Cursor = Cursors.Default;
776
777            MessageBox.Show("Prowizja naniesiona na zlecenia");
778        }
779    }
780}
Notatka: Zobacz TracBrowser aby uzyskać więcej informacji.