root/tags/BazaReklam_1.2.9/KalendarzEmisji.cs

Wersja 764, 9.8 KB (wprowadzona przez marek, 17 years temu)

re #185

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