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

Wersja 31, 9.6 KB (wprowadzona przez dorota, 17 years temu)

binding w OrderDetails?

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            short nr = Emisje.MaxZafakturowanyNrWydania();
110 
111            if (nr != 0)
112            {
113                dataOstatatniejZafakturowanejEmisji = this.sLOWNIKDataSet.NR.dataWydania(Tytul, nr);
114            }
115
116            nRDataGridView.CellValueChanged += nRDataGridView_CellValueChanged;
117            nRDataGridView.CellContentClick += nRDataGridView_CellContentClicked;
118
119            nRBindingSource.ResetBindings(false);
120        }
121
122        private void dodajButton_Click(object sender, EventArgs e)
123        {
124            foreach (DataGridViewRow row in nRDataGridView.Rows)
125            {
126                if (row.Cells[3].Value != null && ((bool)row.Cells[3].Value) == true)
127                {
128                    if (row.DefaultCellStyle.BackColor == Color.LightYellow)
129                    {
130                        REKLAMADataSet.UKAZE_SIE_W_NRRow em =
131                        emisje.NewUKAZE_SIE_W_NRRow();
132
133                        em.ReklamaId = reklama.ReklamaID;
134                        em.dataDodania = DateTime.Today;
135                        em.Nr_Wydania = Convert.ToInt16(row.Cells[0].Value);
136
137                        emisje.AddUKAZE_SIE_W_NRRow(em);
138                    }
139                }
140            }
141        }
142
143        private void zmienButton_Click(object sender, EventArgs e)
144        {
145            foreach (REKLAMADataSet.UKAZE_SIE_W_NRRow r in emisje)
146            {
147                if (r.RowState != DataRowState.Deleted)
148                {
149                    if (r.Nr_Wydania == emisjaDoZmiany)
150                    {
151                        r.Nr_Wydania = nowaEmisja;
152                        r.EndEdit();
153                        break;
154                    }
155                }
156            }
157        }
158
159        private void nRDataGridView_CellContentClicked(object sender, DataGridViewCellEventArgs e)
160        {
161            if (e.RowIndex >= 0)
162            {
163                if (!nRDataGridView.Rows[e.RowIndex].ReadOnly)
164                {
165                    if (e.ColumnIndex == 3)
166                    {
167                        if (nRDataGridView.Rows[e.RowIndex].DefaultCellStyle.BackColor == Color.White)
168                        {
169                            if (emisjaDoZmiany != 0 && index != -1)
170                            {
171                                nRDataGridView.Rows[index].Cells[3].Value = false;
172                                nRDataGridView.Rows[index].DefaultCellStyle.BackColor = Color.White;
173                            }
174
175                            nowaEmisja = (short)nRDataGridView.Rows[e.RowIndex].Cells[0].Value;
176                            index = e.RowIndex;
177
178                            nRDataGridView.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.LightYellow;
179                        }
180                        else
181                        {
182                            nowaEmisja = (short)nRDataGridView.Rows[e.RowIndex].Cells[0].Value;
183                            index = e.RowIndex;
184
185                            nRDataGridView.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.White;
186                        }
187
188                    }
189                }
190            }
191            nRDataGridView.EndEdit();
192        }
193
194        private void nRDataGridView_CellValueChanged(object sender, DataGridViewCellEventArgs e)
195        {
196            if (e.ColumnIndex == 3)
197            {
198                if (((bool)nRDataGridView[e.ColumnIndex, e.RowIndex].Value) == true)
199                {
200                    iloscEmisji++;
201                }
202                else
203                {
204                    iloscEmisji--;
205                }
206
207                label2.Text = iloscEmisji.ToString();
208            }
209        }
210
211        private void nRDataGridView_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
212        {
213            if (e.ListChangedType == ListChangedType.Reset)
214            {
215                foreach (DataGridViewRow row in nRDataGridView.Rows)
216                {
217                    row.DefaultCellStyle.BackColor = Color.White;
218
219                    row.Cells[2].Value = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.DayNames
220                        [(int)Convert.ToDateTime(row.Cells[1].Value).DayOfWeek];
221
222                    DataRow[] table = emisje.Select("[Nr Wydania]=" + row.Cells[0].Value);
223
224                    if (table != null && table.Length > 0)
225                    {
226                        row.ReadOnly = true;
227                        row.Cells[3].Value = true;
228                        row.DefaultCellStyle.BackColor = Color.WhiteSmoke;
229
230                        REKLAMADataSet.UKAZE_SIE_W_NRRow em =
231                            (REKLAMADataSet.UKAZE_SIE_W_NRRow)table[0];
232
233                        if (Convert.ToDateTime(row.Cells[1].Value) < DateTime.Today)
234                        {
235                            row.DefaultCellStyle.BackColor = Color.MintCream;
236                        }
237                        else
238                        {
239                            if (em.zafakturowana)
240                            {
241                                row.DefaultCellStyle.BackColor = Color.LightGray;
242                            }
243
244                            //anulowana
245                            if (em.status == 2)
246                            {
247                                row.DefaultCellStyle.ForeColor = Color.Red;
248                            }
249
250                            if (emisjaDoZmiany == (short)row.Cells[0].Value)
251                            {
252                                row.DefaultCellStyle.BackColor = Color.MistyRose;
253                            }
254                        }
255                    }
256                    else if (emisjaDoZmiany == 0)
257                    {
258                        //emisja nie zosta³a wczeœniej wybrana, ale jej misi¹c ju¿
259                        // jest zafakturowany
260                        DateTime dataWydania = (DateTime)row.Cells[1].Value;
261                        if (dataWydania.Year <= dataOstatatniejZafakturowanejEmisji.Year
262                            &&
263                            dataWydania.Month <= dataOstatatniejZafakturowanejEmisji.Month)
264                        {
265                            row.ReadOnly = true;
266                            row.DefaultCellStyle.BackColor = Color.LightGray;
267                        }
268                    }
269                }
270            }
271        }
272    }
273}
Notatka: Zobacz TracBrowser aby uzyskać więcej informacji.