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