| 1 | using System;
|
|---|
| 2 | using System.Data;
|
|---|
| 3 | using System.Data.SqlClient;
|
|---|
| 4 | using System.Drawing;
|
|---|
| 5 | using System.Windows.Forms;
|
|---|
| 6 | using System.Drawing.Printing;
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 | namespace Baza_Reklam
|
|---|
| 10 | {
|
|---|
| 11 | public partial class ProjectForm : Form
|
|---|
| 12 | {
|
|---|
| 13 |
|
|---|
| 14 | private int reklamaID;
|
|---|
| 15 | private int projektID;
|
|---|
| 16 | private bool pro;
|
|---|
| 17 |
|
|---|
| 18 | public ProjectForm(int rekId)
|
|---|
| 19 | {
|
|---|
| 20 | InitializeComponent();
|
|---|
| 21 | reklamaID = rekId;
|
|---|
| 22 | }
|
|---|
| 23 |
|
|---|
| 24 | public ProjectForm(int rekId, int proId)
|
|---|
| 25 | {
|
|---|
| 26 | InitializeComponent();
|
|---|
| 27 | reklamaID = rekId;
|
|---|
| 28 | projektID = proId;
|
|---|
| 29 | pro = true;
|
|---|
| 30 | }
|
|---|
| 31 |
|
|---|
| 32 | protected REKLAMADataSet.PRODUKCJARow Projekt
|
|---|
| 33 | {
|
|---|
| 34 | get
|
|---|
| 35 | {
|
|---|
| 36 | if (pRODUKCJABindingSource.Current == null) return null;
|
|---|
| 37 |
|
|---|
| 38 | return (REKLAMADataSet.PRODUKCJARow)((DataRowView)pRODUKCJABindingSource.Current).Row;
|
|---|
| 39 | }
|
|---|
| 40 | }
|
|---|
| 41 |
|
|---|
| 42 | protected REKLAMADataSet.REKLAMARow Reklama
|
|---|
| 43 | {
|
|---|
| 44 | get
|
|---|
| 45 | {
|
|---|
| 46 | if (rEKLAMADataSet.REKLAMA.Rows.Count > 0)
|
|---|
| 47 | return (REKLAMADataSet.REKLAMARow)rEKLAMADataSet.REKLAMA.Rows[0];
|
|---|
| 48 | return null;
|
|---|
| 49 | }
|
|---|
| 50 | }
|
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 | private void ProjectForm_Load(object sender, EventArgs e)
|
|---|
| 54 | {
|
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 | pRODUKCJATableAdapter.Connection.ConnectionString = ConnString.getConnString().Value;
|
|---|
| 58 | reklamaTableAdapter1.Connection.ConnectionString = ConnString.getConnString().Value;
|
|---|
| 59 |
|
|---|
| 60 | reklamaTableAdapter1.FillByReklamaId(rEKLAMADataSet.REKLAMA, reklamaID);
|
|---|
| 61 |
|
|---|
| 62 | if (Reklama != null && Reklama.TYTU£.ToUpper() != "EXPO")
|
|---|
| 63 | {
|
|---|
| 64 | jezykComboBox.Visible = false;
|
|---|
| 65 | label1.Visible = false;
|
|---|
| 66 | }
|
|---|
| 67 | jezykComboBox.SelectedIndex = 0;
|
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 | rEKLAMADataSet.PRODUKCJA.Clear();
|
|---|
| 71 | pRODUKCJATableAdapter.FillByReklamaId(rEKLAMADataSet.PRODUKCJA, reklamaID);
|
|---|
| 72 | pRODUKCJABindingSource.DataSource = rEKLAMADataSet;
|
|---|
| 73 |
|
|---|
| 74 | if (pRODUKCJABindingSource.List.Count == 0)
|
|---|
| 75 | {
|
|---|
| 76 | dodajNowyProjekt(reklamaID);
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 | if (pro)
|
|---|
| 80 | {
|
|---|
| 81 | while (Convert.ToInt32(((DataRowView) pRODUKCJABindingSource.Current)["ID"]) != projektID)
|
|---|
| 82 | {
|
|---|
| 83 | pRODUKCJABindingSource.MoveNext();
|
|---|
| 84 | }
|
|---|
| 85 | }
|
|---|
| 86 | else
|
|---|
| 87 | {
|
|---|
| 88 | pRODUKCJABindingSource.MoveLast();
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|
| 91 | }
|
|---|
| 92 |
|
|---|
| 93 | public void dodajNowyProjekt(int rekID)
|
|---|
| 94 | {
|
|---|
| 95 | // this.reklamaID = rekID;
|
|---|
| 96 |
|
|---|
| 97 | REKLAMADataSet.REKLAMARow row = rEKLAMADataSet.REKLAMA.FindByReklamaID(reklamaID);
|
|---|
| 98 |
|
|---|
| 99 | int emisja = piewrszaEmisja(reklamaID);
|
|---|
| 100 |
|
|---|
| 101 | DataView datatable = (DataView)pRODUKCJABindingSource.List;
|
|---|
| 102 |
|
|---|
| 103 | DataRowView row2 = datatable.AddNew();
|
|---|
| 104 |
|
|---|
| 105 | //dane z zamowienia
|
|---|
| 106 | row2["NAZWA_ZAMOWIENIA"] = row["Id reklamy"];
|
|---|
| 107 | row2["modu³"] = row["MOD_TYP"];
|
|---|
| 108 | row2["reklamaId"] = reklamaID;
|
|---|
| 109 | row2["szer"] = row["SZER"];
|
|---|
| 110 | row2["wys"] = row["WYS"];
|
|---|
| 111 | row2["kolor"] = row["KOLOR"];
|
|---|
| 112 | row2["lokalizacja"] = row["strona"];
|
|---|
| 113 | row2["dataemisji"] = emisja;
|
|---|
| 114 | row2["AGENT"] = User.getUser().Login;
|
|---|
| 115 | row2["DATA_AGENT"] = DateTime.Now;
|
|---|
| 116 |
|
|---|
| 117 | if (DateTime.Today.DayOfWeek == DayOfWeek.Thursday)
|
|---|
| 118 | {
|
|---|
| 119 | row2["ZAMAWIAM_NA"] = DateTime.Today.AddDays(4);
|
|---|
| 120 | }
|
|---|
| 121 | else if (DateTime.Today.DayOfWeek == DayOfWeek.Friday)
|
|---|
| 122 | {
|
|---|
| 123 | row2["ZAMAWIAM_NA"] = DateTime.Today.AddDays(3);
|
|---|
| 124 | }
|
|---|
| 125 | else
|
|---|
| 126 | {
|
|---|
| 127 | row2["ZAMAWIAM_NA"] = DateTime.Today.AddDays(2);
|
|---|
| 128 | }
|
|---|
| 129 |
|
|---|
| 130 | dodajButton.Enabled = true;
|
|---|
| 131 |
|
|---|
| 132 | pRODUKCJABindingSource.EndEdit();
|
|---|
| 133 | pRODUKCJABindingSource.MoveLast();
|
|---|
| 134 |
|
|---|
| 135 | }
|
|---|
| 136 |
|
|---|
| 137 |
|
|---|
| 138 | private void dodajButton_Click(object sender, EventArgs e)
|
|---|
| 139 | {
|
|---|
| 140 | pRODUKCJABindingSource.EndEdit();
|
|---|
| 141 | pRODUKCJATableAdapter.Update(rEKLAMADataSet.PRODUKCJA);
|
|---|
| 142 |
|
|---|
| 143 | Close();
|
|---|
| 144 | }
|
|---|
| 145 |
|
|---|
| 146 | /// <summary>
|
|---|
| 147 | /// Blokuje pola w zale¿noci od stanu i uprawnieñ.
|
|---|
| 148 | /// </summary>
|
|---|
| 149 | private void pRODUKCJABindingSource_CurrentChanged(object sender, EventArgs e)
|
|---|
| 150 | {
|
|---|
| 151 | REKLAMADataSet.PRODUKCJARow projekt = Projekt;
|
|---|
| 152 | if (projekt == null || projekt.ID == 0) return;
|
|---|
| 153 |
|
|---|
| 154 | wymiaryLabel.Text = Utils.pobierzSzerModulu(projekt.Modu³) + " x " + Utils.pobierzWysModulu(projekt.Modu³);
|
|---|
| 155 |
|
|---|
| 156 | if (projekt.STAN == "ZAMAWIAM")
|
|---|
| 157 | {
|
|---|
| 158 | dodajButton.Enabled = true;
|
|---|
| 159 | tYP_PROJEKTUComboBox.Enabled = true;
|
|---|
| 160 | zAMAWIAM_NADateTimePicker.Enabled = true;
|
|---|
| 161 | pRIORYTETComboBox.Enabled = true;
|
|---|
| 162 |
|
|---|
| 163 | oPISTextBox.ReadOnly = false;
|
|---|
| 164 | uwagiTextBox.ReadOnly = false;
|
|---|
| 165 | path_to_materialTextBox.ReadOnly = false;
|
|---|
| 166 | dataEmisjiTextBox.ReadOnly = false;
|
|---|
| 167 | lokalizacjaTextBox.ReadOnly = false;
|
|---|
| 168 | path_to_materialTextBox.ReadOnly = false;
|
|---|
| 169 |
|
|---|
| 170 | usunButton.Enabled = (User.getUser().Symbol_agenta.ToLower() == projekt.AGENT.ToLower() ? true : false) | User.getUser().St_produkcja;
|
|---|
| 171 | }
|
|---|
| 172 | else
|
|---|
| 173 | {
|
|---|
| 174 | dodajButton.Enabled = false | User.getUser().St_produkcja;
|
|---|
| 175 | tYP_PROJEKTUComboBox.Enabled = false | User.getUser().St_produkcja;
|
|---|
| 176 | zAMAWIAM_NADateTimePicker.Enabled = false | User.getUser().St_produkcja;
|
|---|
| 177 | pRIORYTETComboBox.Enabled = false | User.getUser().St_produkcja;
|
|---|
| 178 |
|
|---|
| 179 | lokalizacjaTextBox.ReadOnly = true & !User.getUser().St_produkcja;
|
|---|
| 180 | oPISTextBox.ReadOnly = true & !User.getUser().St_produkcja;
|
|---|
| 181 | uwagiTextBox.ReadOnly = true & !User.getUser().St_produkcja;
|
|---|
| 182 | path_to_materialTextBox.ReadOnly = true & !User.getUser().St_produkcja;
|
|---|
| 183 | dataEmisjiTextBox.ReadOnly = true & !User.getUser().St_produkcja;
|
|---|
| 184 |
|
|---|
| 185 | usunButton.Enabled = User.getUser().St_kierownik;
|
|---|
| 186 | }
|
|---|
| 187 |
|
|---|
| 188 | }
|
|---|
| 189 |
|
|---|
| 190 | private void anulujButton_Click(object sender, EventArgs e)
|
|---|
| 191 | {
|
|---|
| 192 | Close();
|
|---|
| 193 | }
|
|---|
| 194 |
|
|---|
| 195 | /// <summary>
|
|---|
| 196 | /// Wyszukuje nr pierwszej emisji...
|
|---|
| 197 | /// </summary>
|
|---|
| 198 | private int piewrszaEmisja(int reklamaId) {
|
|---|
| 199 |
|
|---|
| 200 | SqlConnection conn = new SqlConnection(
|
|---|
| 201 | ConnString.getConnString().Value);
|
|---|
| 202 |
|
|---|
| 203 |
|
|---|
| 204 | SqlCommand command = new SqlCommand();
|
|---|
| 205 | command.CommandType = CommandType.Text;
|
|---|
| 206 | command.CommandText = "select min([Nr Wydania]) from dbo.[UKA¯E SIÊ W NR] where ReklamaId = @param ";
|
|---|
| 207 | command.Parameters.AddWithValue("@param",reklamaID);
|
|---|
| 208 | command.Connection = conn;
|
|---|
| 209 |
|
|---|
| 210 | int emisja = 0;
|
|---|
| 211 |
|
|---|
| 212 | conn.Open();
|
|---|
| 213 | try
|
|---|
| 214 | {
|
|---|
| 215 | emisja = Convert.ToInt16(command.ExecuteScalar());
|
|---|
| 216 | }
|
|---|
| 217 | catch (Exception e1)
|
|---|
| 218 | {
|
|---|
| 219 | MessageBox.Show("W zamówieniu nie wskazano emisji");
|
|---|
| 220 | }
|
|---|
| 221 | conn.Close();
|
|---|
| 222 |
|
|---|
| 223 | return emisja;
|
|---|
| 224 | }
|
|---|
| 225 |
|
|---|
| 226 | private void drukujProjektButton_Click(object sender, EventArgs e)
|
|---|
| 227 | {
|
|---|
| 228 | if (printDialog.ShowDialog() == DialogResult.OK)
|
|---|
| 229 | {
|
|---|
| 230 | printDoc.PrinterSettings = printDialog.PrinterSettings;
|
|---|
| 231 | printDoc.PrintPage += new PrintPageEventHandler(Renderuj2);
|
|---|
| 232 | printDoc.Print();
|
|---|
| 233 | }
|
|---|
| 234 | }
|
|---|
| 235 |
|
|---|
| 236 | /// <summary>
|
|---|
| 237 | /// Przerysowuje kontrolkê na wydruk.
|
|---|
| 238 | /// </summary>
|
|---|
| 239 | private void Renderuj2(object sender, System.Drawing.Printing.PrintPageEventArgs ev)
|
|---|
| 240 | {
|
|---|
| 241 | int leftMargin = ev.MarginBounds.Left;
|
|---|
| 242 | int topMargin = ev.MarginBounds.Left;
|
|---|
| 243 |
|
|---|
| 244 | ev.Graphics.DrawRectangle(new Pen(Color.Gray), leftMargin, topMargin, Width, Height);
|
|---|
| 245 |
|
|---|
| 246 | foreach (Control c in Controls) {
|
|---|
| 247 |
|
|---|
| 248 | string controlType = c.GetType().ToString().Substring(c.GetType().ToString().LastIndexOf(".") + 1);
|
|---|
| 249 |
|
|---|
| 250 | switch (controlType) {
|
|---|
| 251 | case "TextBox":
|
|---|
| 252 | TextBox t = (TextBox)c;
|
|---|
| 253 | ev.Graphics.DrawRectangle(new Pen(Color.Gray), t.Left + leftMargin, t.Top + topMargin, t.Width, t.Height);
|
|---|
| 254 | ev.Graphics.DrawString(t.Text, t.Font, new SolidBrush(t.ForeColor), new RectangleF(t.Left + leftMargin + 2, t.Top + topMargin + 1, t.Width + 2, t.Height - 2), new StringFormat());
|
|---|
| 255 | break;
|
|---|
| 256 | case "Label":
|
|---|
| 257 | Label l = (Label)c;
|
|---|
| 258 | ev.Graphics.DrawString(l.Text, l.Font, new SolidBrush(l.ForeColor), l.Left + leftMargin, l.Top + topMargin + l.Height / 2 - ev.Graphics.MeasureString("a", l.Font).Height / 2, new StringFormat());
|
|---|
| 259 | break;
|
|---|
| 260 | case "ComboBox":
|
|---|
| 261 | ComboBox cb = (ComboBox)c;
|
|---|
| 262 | ev.Graphics.DrawRectangle(new Pen(Color.LightGray), cb.Left + leftMargin, cb.Top + topMargin, cb.Width, cb.Height);
|
|---|
| 263 | ev.Graphics.DrawString(cb.Text, cb.Font, new SolidBrush(cb.ForeColor), cb.Left + leftMargin + 2, cb.Top + topMargin+ cb.Height / 2 - ev.Graphics.MeasureString("a", cb.Font).Height / 2, new StringFormat());
|
|---|
| 264 | break;
|
|---|
| 265 | case "DateTimePicker":
|
|---|
| 266 | DateTimePicker dp = (DateTimePicker)c;
|
|---|
| 267 | ev.Graphics.DrawRectangle(new Pen(Color.LightGray), dp.Left + leftMargin, dp.Top + topMargin, dp.Width, dp.Height);
|
|---|
| 268 | ev.Graphics.DrawString(dp.Text, dp.Font, new SolidBrush(dp.ForeColor), dp.Left + leftMargin + 2, dp.Top + topMargin + dp.Height / 2 - ev.Graphics.MeasureString("a", dp.Font).Height / 2, new StringFormat());
|
|---|
| 269 | break;
|
|---|
| 270 | default:
|
|---|
| 271 | break;
|
|---|
| 272 | }
|
|---|
| 273 | }
|
|---|
| 274 | }
|
|---|
| 275 |
|
|---|
| 276 | private void dodajNowyButton_Click(object sender, EventArgs e)
|
|---|
| 277 | {
|
|---|
| 278 | dodajNowyProjekt(reklamaID);
|
|---|
| 279 | }
|
|---|
| 280 |
|
|---|
| 281 | private void usunButton_Click(object sender, EventArgs e)
|
|---|
| 282 | {
|
|---|
| 283 | pRODUKCJABindingSource.RemoveCurrent();
|
|---|
| 284 | }
|
|---|
| 285 |
|
|---|
| 286 | private void modu³ComboBox_SelectedValueChanged(object sender, EventArgs e)
|
|---|
| 287 | {
|
|---|
| 288 | pRODUKCJABindingSource.EndEdit();
|
|---|
| 289 | DataRowView row = (DataRowView)pRODUKCJABindingSource.Current;
|
|---|
| 290 | row["modu³"] = row["modu³"];
|
|---|
| 291 | pRODUKCJABindingSource.EndEdit();
|
|---|
| 292 | }
|
|---|
| 293 |
|
|---|
| 294 | private void zAMAWIAM_NADateTimePicker_ValueChanged(object sender, EventArgs e)
|
|---|
| 295 | {
|
|---|
| 296 | if (zAMAWIAM_NADateTimePicker.Value.DayOfWeek == DayOfWeek.Saturday)
|
|---|
| 297 | {
|
|---|
| 298 | zAMAWIAM_NADateTimePicker.Value = zAMAWIAM_NADateTimePicker.Value.AddDays(-1);
|
|---|
| 299 | MessageBox.Show("WEEKEND! Wybierz inny dzieñ");
|
|---|
| 300 | return;
|
|---|
| 301 | }
|
|---|
| 302 |
|
|---|
| 303 | if (zAMAWIAM_NADateTimePicker.Value.DayOfWeek == DayOfWeek.Sunday)
|
|---|
| 304 | {
|
|---|
| 305 | zAMAWIAM_NADateTimePicker.Value = zAMAWIAM_NADateTimePicker.Value.AddDays(-2);
|
|---|
| 306 | MessageBox.Show("WEEKEND! Wybierz inny dzieñ");
|
|---|
| 307 | return;
|
|---|
| 308 | }
|
|---|
| 309 |
|
|---|
| 310 | }
|
|---|
| 311 | }
|
|---|
| 312 | } |
|---|