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

Wersja 2, 15.7 KB (wprowadzona przez dorota, 17 years temu)
Line 
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Data;
5using System.Data.SqlClient;
6using System.Drawing;
7using System.Text;
8using System.Windows.Forms;
9using System.IO;
10using Baza_Reklam.Classes;
11
12namespace Baza_Reklam
13{
14    public partial class ListaReklamNaWydanieForm : Form
15    {
16        private static ListaReklamNaWydanieForm lrnwForm;
17
18        public static ListaReklamNaWydanieForm getListaReklamNaWydanieForm(MDIBazaReklam parent)
19        {
20            if (lrnwForm == null)
21            {
22                lrnwForm = new ListaReklamNaWydanieForm(parent);
23            }
24            return lrnwForm;       
25        }
26
27        private ListaReklamNaWydanieForm(MDIBazaReklam parent)
28        {
29            InitializeComponent();
30
31            this.MdiParent = parent;
32            listaReklamNaWydanie2TableAdapter.Connection.ConnectionString = ConnString.getConnString().Value;
33         
34            bindingNavigator1.Items.Insert(17, new ToolStripLabel("DR"));
35            bindingNavigator1.Items.Insert(18, new ToolStripControlHost(new CheckBox(), "DRCheckBox"));
36            ((CheckBox)((ToolStripControlHost)bindingNavigator1.Items["DRCheckBox"]).Control).Checked = true;
37
38            bindingNavigator1.Items.Insert(19, new ToolStripLabel("A"));
39            bindingNavigator1.Items.Insert(20, new ToolStripControlHost(new CheckBox(), "AktywneCheckBox"));
40            ((CheckBox)((ToolStripControlHost)bindingNavigator1.Items["AktywneCheckBox"]).Control).Checked = true;
41       
42            bindingNavigator1.Items.Insert(21, new ToolStripLabel("W"));
43            bindingNavigator1.Items.Insert(22, new ToolStripControlHost(new CheckBox(), "WyrCheckBox"));
44            ((CheckBox)((ToolStripControlHost)bindingNavigator1.Items["WyrCheckBox"]).Control).Checked = false;
45
46        }
47
48        private void ListaReklamNaWydanieForm_Load(object sender, EventArgs e)
49        {
50            DBBindings.bindujTytuly(tytulToolStripComboBox);
51            DBBindings.bindujTytuly(tytToolStripComboBox2);
52            DBBindings.bindujGrzbiety2(grzbietToolStripComboBox);
53            DBBindings.bindujAgencje(agencjaToolStripComboBox);
54            DBBindings.bindujAgentow(agentToolStripComboBox);
55            DBBindings.bindujModuly(modToolStripComboBox);
56           
57            ((ComboBox)this.tytToolStripComboBox2.Control).SelectedValueChanged += new EventHandler(
58                tytToolStripComboBox2_SelectedIndexChanged);
59        }
60
61        private void toolStripButton1_Click(object sender, EventArgs e)
62        {
63            rEKLAMADataSet.LISTA_REKLAM_NA_WYDANIE.Clear();
64
65            if (tytulToolStripComboBox.Text.Trim() == "")
66            {
67                MessageBox.Show("Wybierz tytu³.");
68                return;
69            }
70
71            if (nrToolStripTextBox.Text.Trim() != "")
72            {
73                int i;
74                if (!Int32.TryParse(nrToolStripTextBox.Text.Trim(), out i))
75                {
76                    MessageBox.Show("Podaj prawid³owy nr wydania.");
77                    return;
78                }
79            }
80            else
81            {
82                MessageBox.Show("Wybierz nr wydania.");
83                return;
84            }
85
86            this.Cursor = Cursors.WaitCursor;
87
88            SqlConnection conn = new SqlConnection();
89            conn.ConnectionString = ConnString.getConnString().Value;
90
91            SqlCommand command = new SqlCommand();
92            command.Connection = conn;
93            command.CommandText = "SELECT TOP 1000 * FROM LISTA_REKLAM_NA_WYDANIE " +
94                        " WHERE (TYTU£ = @tytul) AND (NR = @nrwydania) ";
95                       
96
97            command.Parameters.AddWithValue("@tytul", tytulToolStripComboBox.Text.Trim());
98            command.Parameters.AddWithValue("@nrwydania", nrToolStripTextBox.Text.Trim());
99
100            if (((CheckBox)((ToolStripControlHost)bindingNavigator1.Items["DRCheckBox"]).Control).CheckState == CheckState.Checked)
101            {
102                command.CommandText += " AND ([ZATWIERDZONO DO DRUKU] = 1) ";
103            }
104
105            if (((CheckBox)((ToolStripControlHost)bindingNavigator1.Items["AktywneCheckBox"]).Control).CheckState == CheckState.Checked)
106            {
107                command.CommandText += " AND ([status] <> 2) ";
108            }
109
110            if (((CheckBox)((ToolStripControlHost)bindingNavigator1.Items["DRCheckBox"]).Control).CheckState == CheckState.Checked)
111            {
112                command.CommandText += " AND ([ZATWIERDZONO DO DRUKU] = 1) ";
113            }
114
115            if (agencjaToolStripComboBox.Text.Trim() != "")
116            {
117                command.CommandText += " AND (agencja = @agencja) ";
118                command.Parameters.AddWithValue("@agencja", agencjaToolStripComboBox.Text.Trim());
119            }
120
121            if (agentToolStripComboBox.Text.Trim() != "")
122            {
123                command.CommandText += " AND ([symbol akwizytora] = @agent) ";
124                command.Parameters.AddWithValue("@agent", agentToolStripComboBox.Text.Trim());
125            }
126
127            if (grzbietToolStripComboBox.SelectedItem != null)
128            {
129                command.CommandText += " AND (GRZBIET = @grzbiet) ";
130                command.Parameters.AddWithValue("@grzbiet", ((BoundItem)grzbietToolStripComboBox.SelectedItem).IDEvalue1);
131            }
132
133          //  ((CheckBox)((ToolStripControlHost)bindingNavigator1.Items["DRCheckBox"]).Control).Checked = true;
134
135         
136
137            SqlDataAdapter adapter = new SqlDataAdapter();
138            adapter.SelectCommand = command;
139
140            adapter.Fill(rEKLAMADataSet.LISTA_REKLAM_NA_WYDANIE);
141           
142            this.Cursor = Cursors.Default;
143           
144        }
145
146        private void klientToolStripButton_Click(object sender, EventArgs e)
147        {
148            if (listaReklamNaWydanie2BindingSource.Current != null)
149            {
150                DataRowView row = (DataRowView)listaReklamNaWydanie2BindingSource.Current;
151                int idRek = Convert.ToInt32(row["ReklamaId"]);
152
153                int custId = Utils.customerId(idRek);
154
155                ClientsForm.getClientsForm((MDIBazaReklam)this.MdiParent).pokazKlienta(custId);
156
157                this.Hide();
158
159                ClientsForm.getClientsForm((MDIBazaReklam)this.MdiParent).Show();
160            } 
161        }
162
163        private void zamToolStripButton_Click(object sender, EventArgs e)
164        {
165            if (listaReklamNaWydanie2BindingSource.Current != null)
166            {
167                DataRowView row = (DataRowView)listaReklamNaWydanie2BindingSource.Current;
168                int idRek = Convert.ToInt32(row["ReklamaId"]);
169               // this.reklamaTableAdapter.FillByReklamaId(this.rEKLAMADataSet.REKLAMA, idRek);
170
171                OrderDetails.getOrderDetails().pokazSzczegolyZamowienia(idRek);
172                OrderDetails.getOrderDetails().ShowDialog();
173                /*
174                OrderDetails od = new OrderDetails();
175                od.pokazSzczegolyZamowienia(idRek);
176                od.ShowDialog(); */
177            }     
178        }
179
180        private void tytToolStripComboBox2_SelectedIndexChanged(object sender, EventArgs e)
181        {
182            if (((ComboBox)this.tytToolStripComboBox2.Control).SelectedItem != null)
183            {
184                ((BindingSource)((ComboBox)this.modToolStripComboBox.Control).DataSource).Filter = "tytul = '" + ((ComboBox)this.tytToolStripComboBox2.Control).Text.ToString() + "'";
185                this.modToolStripComboBox.SelectedIndex = -1;
186                this.modToolStripComboBox.SelectedIndex = -1;
187            }
188        }
189
190
191        private void wyczyscFiltrToolStripButton_Click(object sender, EventArgs e)
192        {           
193            tytulToolStripComboBox.Text = "";
194            nrToolStripTextBox.Text = "";
195            agencjaToolStripComboBox.SelectedIndex = -1;
196            agencjaToolStripComboBox.Text = "";
197
198            agentToolStripComboBox.SelectedIndex = -1;
199            agentToolStripComboBox.Text = "";
200
201            grzbietToolStripComboBox.SelectedIndex = -1;
202            grzbietToolStripComboBox.Text = "";
203
204            ((CheckBox)((ToolStripControlHost)bindingNavigator1.Items["DRCheckBox"]).Control).CheckState = CheckState.Indeterminate;
205            ((CheckBox)((ToolStripControlHost)bindingNavigator1.Items["WyrCheckBox"]).Control).CheckState = CheckState.Indeterminate;         
206
207        }
208
209        private void szukajRezerToolStripButton_Click(object sender, EventArgs e)
210        {
211            this.Cursor = Cursors.WaitCursor;
212
213            SqlConnection conn = new SqlConnection();
214            conn.ConnectionString = ConnString.getConnString().Value;
215
216            SqlCommand command = new SqlCommand();
217            command.Connection = conn;
218
219            command.CommandText = "SELECT TOP 1000 * FROM LISTA_REKLAM_NA_WYDANIE WHERE 1=1 ";
220
221            this.rEKLAMADataSet.LISTA_REKLAM_NA_WYDANIE.Clear();       
222
223            command.Parameters.Clear();
224
225
226            if (odToolStripTextBox.Text.Trim() != "")
227            {
228                int i;
229                if (!Int32.TryParse(odToolStripTextBox.Text.Trim(), out i))
230                {
231                    MessageBox.Show("Podaj prawid³ow¹ wartoœæ.");
232                    this.Cursor = Cursors.Default;
233                    return;
234                }
235
236                command.CommandText += " AND NR >=@od ";
237                command.Parameters.AddWithValue("@od", odToolStripTextBox.Text.Trim());
238            }
239
240
241            if (doToolStripTextBox.Text.Trim() != "")
242            {
243                int i;
244                if (!Int32.TryParse(doToolStripTextBox.Text.Trim(), out i))
245                {
246                    MessageBox.Show("Podaj prawid³ow¹ wartoœæ.");
247                    this.Cursor = Cursors.Default;
248                    return;
249                }
250
251                command.CommandText += " AND NR <=@do ";
252                command.Parameters.AddWithValue("@do", doToolStripTextBox.Text.Trim());
253            }
254
255            if (modToolStripComboBox.Text.Trim() != "")
256            {
257                command.CommandText += " AND MOD_TYP=@modul ";
258                command.Parameters.AddWithValue("@modul", modToolStripComboBox.Text.Trim());
259            }
260
261            if (tytToolStripComboBox2.Text.Trim() != "")
262            {
263                command.CommandText += " AND TYTU£=@tyt ";
264                command.Parameters.AddWithValue("@tyt", tytToolStripComboBox2.Text.Trim());
265
266            }
267         
268           
269            SqlDataAdapter adapter = new SqlDataAdapter();
270            adapter.SelectCommand = command;
271
272            adapter.Fill(rEKLAMADataSet.LISTA_REKLAM_NA_WYDANIE);
273                       
274            this.Cursor = Cursors.Default;
275        }
276
277        private void wyczyscToolStripButton2_Click(object sender, EventArgs e)
278        {
279            odToolStripTextBox.Clear();
280            doToolStripTextBox.Clear();
281            ((BindingSource)((ComboBox)this.modToolStripComboBox.Control).DataSource).Filter = "";         
282            modToolStripComboBox.SelectedIndex = -1;
283            modToolStripComboBox.SelectedIndex = -1;
284            modToolStripComboBox.Text = "";
285            tytToolStripComboBox2.SelectedIndex = -1;
286            tytToolStripComboBox2.SelectedIndex = -1;
287            tytToolStripComboBox2.Text = "";
288        }
289
290        private void drukujToolStripButton_Click(object sender, EventArgs e)
291        {
292            PrintDGV.Print_DataGridView(listaReklamDataGridView,50);
293        }
294
295        private void podgladJPGToolStripButton_Click(object sender, EventArgs e)
296        {
297            if (listaReklamNaWydanie2BindingSource.Current != null)
298            {
299                this.Cursor = Cursors.WaitCursor;
300
301                DataRowView row = (DataRowView)listaReklamNaWydanie2BindingSource.Current;
302
303                int reklamaId = Convert.ToInt32(row["reklamaId"]);
304                string idReklamy = row["id reklamy"].ToString();
305
306                string tytul;
307                int grzbiet;
308                string miasto;
309                byte staryNowyArchiwum;
310
311                Produkcja.argumentyDoSciezki(reklamaId,idReklamy, out tytul, out grzbiet, out miasto, out staryNowyArchiwum);
312
313                string sciezka = Produkcja.GetReklamaFileName(idReklamy, tytul, grzbiet, miasto, staryNowyArchiwum, "jpg");
314
315                if (File.Exists(sciezka))
316                {
317                    System.Diagnostics.Process.Start(sciezka);
318                }
319                else
320                {
321                    MessageBox.Show("Nie znaleziono pliku: " + sciezka);
322                }
323
324                this.Cursor = Cursors.Default;
325            }
326        }
327
328        private void podgladToolStripButton_Click(object sender, EventArgs e)
329        {
330            if (listaReklamNaWydanie2BindingSource.Current != null)
331            {
332                this.Cursor = Cursors.WaitCursor;
333
334                DataRowView row = (DataRowView)listaReklamNaWydanie2BindingSource.Current;
335
336                int reklamaId = Convert.ToInt32(row["reklamaId"]);
337                string idReklamy = row["id reklamy"].ToString();
338
339                string tytul;
340                int grzbiet;
341                string miasto;
342                byte staryNowyArchiwum;
343
344                Produkcja.argumentyDoSciezki(reklamaId,idReklamy, out tytul, out grzbiet, out miasto, out staryNowyArchiwum);
345
346                string sciezka = Produkcja.GetReklamaFileName(idReklamy, tytul, grzbiet, miasto, staryNowyArchiwum, "pdf");
347
348                if (File.Exists(sciezka))
349                {
350                    System.Diagnostics.Process.Start(sciezka);
351                }
352                else
353                {
354                    MessageBox.Show("Nie znaleziono pliku: " + sciezka);
355                }
356
357                this.Cursor = Cursors.Default;
358            }
359        }
360
361        private void dodajLogoToolStripButton_Click(object sender, EventArgs e)
362        {
363            if (listaReklamNaWydanie2BindingSource.Current != null)
364            {             
365                DataRowView row = (DataRowView)listaReklamNaWydanie2BindingSource.Current;
366
367                int reklamaId = Convert.ToInt32(row["reklamaId"]);
368                LogoWReklamieForm lwrf = new LogoWReklamieForm(reklamaId);
369
370                lwrf.ShowDialog();
371            }
372        }
373
374        private void toolStripButton2_Click(object sender, EventArgs e)
375        {
376            if (listaReklamNaWydanie2BindingSource.Current != null)
377            {
378                DataRowView row = (DataRowView)listaReklamNaWydanie2BindingSource.Current;
379                int reklamaId = Convert.ToInt32(row["reklamaId"]);
380                int custId = Utils.customerId(reklamaId);
381
382                LogaKlientowForm logaForm = new LogaKlientowForm(custId);
383                logaForm.ShowDialog();
384            }
385        }
386
387        private void listaReklamDataGridView_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
388        {
389            if (e.ListChangedType == ListChangedType.Reset)
390            {
391                foreach (DataGridViewRow r in listaReklamDataGridView.Rows)
392                {
393                    if (
394                        !((REKLAMADataSet.LISTA_REKLAM_NA_WYDANIERow)
395                        ((DataRowView)r.DataBoundItem).Row).ZATWIERDZONO_DO_DRUKU
396                        ||
397                        ((REKLAMADataSet.LISTA_REKLAM_NA_WYDANIERow)
398                        ((DataRowView)r.DataBoundItem).Row).sTATUS == 2)
399                    {
400
401                        r.DefaultCellStyle.ForeColor = Color.Red;
402                    }
403                }
404            }
405        }
406
407    }
408}
Notatka: Zobacz TracBrowser aby uzyskać więcej informacji.