root/Baza Reklam 2 - Faktury/ProjectForm.cs @ 21

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