root/Baza Reklam 2 - Faktury/KalendarzEmisji.cs @ 28

Wersja 23, 9.7 KB (wprowadzona przez dorota, 17 years temu)
Line 
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Data;
5using System.Drawing;
6using System.Text;
7using System.Windows.Forms;
8
9namespace Baza_Reklam
10{
11    public partial class KalendarzEmisji : Form
12    {
13        //emisja, która ukazala sie w gazecie
14        public readonly string WYDANA = "wydana";
15        //emisja, ktora sie dopiero ukaze
16        public readonly string NIEWYDANA = "niewydana";
17        //emisja zafakturowana
18        public readonly string ZAFAKTUROWANA = "zafakturowana";
19        //emisja zafakturowana i wydana
20        public readonly string ZAFAKTUROWANA_WYDANA = "zafakturowana_wydana";
21        //emisja siê nie ukazala, ale jest w miesiacu, ktory jest juz zafakturowany
22        public readonly string MS_ZAFAKTUROWANY_NIEWYDANA = "zafakturowana_wydana";
23        //emisja do zmiany
24        public readonly string DO_ZMIANY = "do_zmiany";
25        //emisja do zmiany
26        public readonly string NOWA = "nowa";
27
28        string tytul;
29
30        REKLAMADataSet.REKLAMARow reklama;
31
32        REKLAMADataSet.UKAZE_SIE_W_NRDataTable emisje;
33
34        public REKLAMADataSet.UKAZE_SIE_W_NRDataTable Emisje
35        {
36            get { return emisje; }
37            set { emisje = value; }
38        }
39
40        short emisjaDoZmiany;
41        short nowaEmisja;
42
43        int iloscEmisji;
44        int index = -1;
45
46        public DateTime dataOstatatniejZafakturowanejEmisji = DateTime.Today;
47
48        #region properties
49
50        public short NowaEmisja
51        {
52            get { return nowaEmisja; }
53            set { nowaEmisja = value; }
54        }
55
56        public string Tytul
57        {
58            get { return tytul; }
59            set { tytul = value; }
60        }
61
62        #endregion properties
63
64        public KalendarzEmisji(string tytul, REKLAMADataSet.REKLAMARow reklama, REKLAMADataSet.UKAZE_SIE_W_NRDataTable emisje)
65        {
66            InitializeComponent();
67            Tytul = tytul;
68            label1.Text = tytul;
69            this.reklama = reklama;
70            this.emisje = emisje;
71
72            foreach (DataRow r in emisje.Rows)
73            {
74                if (r.RowState != DataRowState.Deleted)
75                {
76                    iloscEmisji++;
77                }
78            }
79
80            label2.Text = iloscEmisji.ToString();
81
82            dodajButton.Click += dodajButton_Click;
83        }
84
85
86        public KalendarzEmisji(string tytul, REKLAMADataSet.REKLAMARow reklama, REKLAMADataSet.UKAZE_SIE_W_NRDataTable emisje, short emisjaDoZmiany)
87        {
88            InitializeComponent();
89            Tytul = tytul;
90            label1.Text = tytul;
91            dodajButton.Text = "Zmieñ";
92
93            this.reklama = reklama;
94            this.emisje = emisje;
95
96            this.emisjaDoZmiany = emisjaDoZmiany;
97
98            dodajButton.Click += zmienButton_Click;
99        }
100
101
102        private void KalendarzEmisji_Load(object sender, EventArgs e)
103        {
104            nRTableAdapter.Connection.ConnectionString = ConnString.getConnString().Value;
105            DateTime startDay = DateTime.Today;
106
107            this.nRTableAdapter.FillByTytulData(this.sLOWNIKDataSet.NR, Tytul, startDay);
108
109            foreach (DataGridViewRow row in nRDataGridView.Rows)
110            {
111                row.Cells[2].Value = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.DayNames
112                    [(int)Convert.ToDateTime(row.Cells[1].Value).DayOfWeek];
113            }
114
115            short nr = Emisje.MaxZafakturowanyNrWydania();
116 
117            if (nr != 0)
118            {
119                dataOstatatniejZafakturowanejEmisji = this.sLOWNIKDataSet.NR.dataWydania(Tytul, nr);
120            }
121
122            nRDataGridView.CellValueChanged += nRDataGridView_CellValueChanged;
123            nRDataGridView.CellContentClick += nRDataGridView_CellContentClicked;
124
125            nRBindingSource.ResetBindings(false);
126        }
127
128        private void dodajButton_Click(object sender, EventArgs e)
129        {
130            foreach (DataGridViewRow row in nRDataGridView.Rows)
131            {
132                if (row.Cells[3].Value != null && ((bool)row.Cells[3].Value) == true)
133                {
134                    if (row.DefaultCellStyle.BackColor == Color.LightYellow)
135                    {
136                        REKLAMADataSet.UKAZE_SIE_W_NRRow em =
137                        emisje.NewUKAZE_SIE_W_NRRow();
138
139                        em.ReklamaId = reklama.ReklamaID;
140                        em.dataDodania = DateTime.Today;
141                        em.Nr_Wydania = Convert.ToInt16(row.Cells[0].Value);
142
143                        emisje.AddUKAZE_SIE_W_NRRow(em);
144                    }
145                }
146            }
147        }
148
149        private void zmienButton_Click(object sender, EventArgs e)
150        {
151            foreach (REKLAMADataSet.UKAZE_SIE_W_NRRow r in emisje)
152            {
153                if (r.RowState != DataRowState.Deleted)
154                {
155                    if (r.Nr_Wydania == emisjaDoZmiany)
156                    {
157                        r.Nr_Wydania = nowaEmisja;
158                        r.EndEdit();
159                        break;
160                    }
161                }
162            }
163        }
164
165        private void nRDataGridView_CellContentClicked(object sender, DataGridViewCellEventArgs e)
166        {
167            if (e.RowIndex >= 0)
168            {
169                if (!nRDataGridView.Rows[e.RowIndex].ReadOnly)
170                {
171                    if (e.ColumnIndex == 3)
172                    {
173                        if (nRDataGridView.Rows[e.RowIndex].DefaultCellStyle.BackColor == Color.White)
174                        {
175                            if (emisjaDoZmiany != 0 && index != -1)
176                            {
177                                nRDataGridView.Rows[index].Cells[3].Value = false;
178                                nRDataGridView.Rows[index].DefaultCellStyle.BackColor = Color.White;
179                            }
180
181                            nowaEmisja = (short)nRDataGridView.Rows[e.RowIndex].Cells[0].Value;
182                            index = e.RowIndex;
183
184                            nRDataGridView.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.LightYellow;
185                        }
186                        else
187                        {
188                            nowaEmisja = (short)nRDataGridView.Rows[e.RowIndex].Cells[0].Value;
189                            index = e.RowIndex;
190
191                            nRDataGridView.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.White;
192                        }
193
194                    }
195                }
196            }
197            nRDataGridView.EndEdit();
198        }
199
200        private void nRDataGridView_CellValueChanged(object sender, DataGridViewCellEventArgs e)
201        {
202            if (e.ColumnIndex == 3)
203            {
204                if (((bool)nRDataGridView[e.ColumnIndex, e.RowIndex].Value) == true)
205                {
206                    iloscEmisji++;
207                }
208                else
209                {
210                    iloscEmisji--;
211                }
212
213                label2.Text = iloscEmisji.ToString();
214            }
215        }
216
217        private void nRDataGridView_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
218        {
219            if (e.ListChangedType == ListChangedType.Reset)
220            {
221                foreach (DataGridViewRow row in nRDataGridView.Rows)
222                {
223                    row.DefaultCellStyle.BackColor = Color.White;
224
225                    DataRow[] table = emisje.Select("[Nr Wydania]=" + row.Cells[0].Value);
226
227                    if (table != null && table.Length > 0)
228                    {
229                        row.ReadOnly = true;
230                        row.Cells[3].Value = true;
231                        row.DefaultCellStyle.BackColor = Color.WhiteSmoke;
232
233                        REKLAMADataSet.UKAZE_SIE_W_NRRow em =
234                            (REKLAMADataSet.UKAZE_SIE_W_NRRow)table[0];
235
236                        if (Convert.ToDateTime(row.Cells[1].Value) < DateTime.Today)
237                        {
238                            row.DefaultCellStyle.BackColor = Color.MintCream;
239                        }
240                        else
241                        {
242                            if (em.zafakturowana)
243                            {
244                                row.DefaultCellStyle.BackColor = Color.LightGray;
245                            }
246
247                            //anulowana
248                            if (em.status == 2)
249                            {
250                                row.DefaultCellStyle.ForeColor = Color.Red;
251                            }
252
253                            if (emisjaDoZmiany == (short)row.Cells[0].Value)
254                            {
255                                row.DefaultCellStyle.BackColor = Color.MistyRose;
256                            }
257                        }
258                    }
259                    else if (emisjaDoZmiany == 0)
260                    {
261                        //emisja nie zosta³a wczeœniej wybrana, ale jej misi¹c ju¿
262                        // jest zafakturowany
263                        DateTime dataWydania = (DateTime)row.Cells[1].Value;
264                        if (dataWydania.Year <= dataOstatatniejZafakturowanejEmisji.Year
265                            &&
266                            dataWydania.Month <= dataOstatatniejZafakturowanejEmisji.Month)
267                        {
268                            row.ReadOnly = true;
269                            row.DefaultCellStyle.BackColor = Color.LightGray;
270                        }
271                    }
272                }
273            }
274        }
275    }
276}
Notatka: Zobacz TracBrowser aby uzyskać więcej informacji.