Indeks članaka


4.  Izvorni kod programa

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.IO;
 
namespace WindowsFormsApplication1
{
 public partial class Form1 : Form
 {
 public Form1()
 {
 InitializeComponent();
 }
 //bool ok = false;
 string output_path,inport_path;
 bool promene = false;
 string conection_string, comand_string;
 
 private void Form1_Load(object sender, EventArgs e)
 {
 txbIMe.Enabled = false;
 txbKomentar.Enabled = false;
 txbLogin.Enabled = false;
 txbPassword.Enabled = false;
 promene = true;
 try
 {
 StreamReader read = new StreamReader("lastset.txt");
 inport_path =read.ReadLine();
 output_path = read.ReadLine();
 read.Close();
 if (inport_path != "" && output_path != "")
 {
 
 IMPORT_PATH_LABEL.Text = inport_path;
 EXPORT_PATH_LABEL.Text = output_path;
 btnEXPORT.Enabled = true;
 txbIMe.Enabled = true;
 txbKomentar.Enabled = true;
 txbLogin.Enabled = true;
 txbPassword.Enabled = true;
 cmbODELJENJE.Enabled = true;
 cmbPeriod.Enabled = true;
 cmbPREDMET.Enabled = true;
 {
 try
 {
 conection_string = String.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0}", inport_path);
 // OleDbConnection Konekcija = new OleDbConnection();
 Konekcija.ConnectionString = conection_string;
 label_status.Text = "Program pristupa podataka! ";
 Konekcija.Open();
 //komanda
 //OleDbCommand Komanda = new OleDbCommand();
 Komanda.Connection = Konekcija;
 comand_string = "SELECT * FROM Predmeti;";
 Komanda.CommandText = comand_string;
 
 //data set
 // DataSet DS = new DataSet();
 
 //data adapter
 //OleDbDataAdapter DA = new OleDbDataAdapter();
 DA.SelectCommand = Komanda;
 
 DA.Fill(DS);
 
 //data reader
 // OleDbDataReader DR;
 
 DR = Komanda.ExecuteReader();
 //punjenje combo boxa-a
 while (DR.Read() == true)
 {
 cmbPREDMET.Items.Add(DR["Sifra_Predmeta"].ToString());
 
 }
 Konekcija.Close();
 
 comand_string = "SELECT ID FROM Razredi";
 Konekcija.ConnectionString = conection_string;
 Konekcija.Open();
 Komanda.CommandText = comand_string;
 DA.SelectCommand = Komanda;
 DA.Fill(DS);
 DR = Komanda.ExecuteReader();
 //punjenje combo boxa-a
 while (DR.Read() == true)
 {
 cmbODELJENJE.Items.Add(DR["ID"].ToString());
 
 }
 btnEXPORT.Enabled = true;
 button1.Enabled = true;
 
 //}
 Konekcija.Close();
 label_status.Text = "Program uspesno okoncao pristup bazi podataka. ";
 btnEXPORT.Enabled = true;
 button1.Enabled = true;
 }
 catch (FileNotFoundException)
 {
 MessageBox.Show("DATA BAZA NIJE PRONADJENA ILI SA NJOM NIJE MOGUCE USPOSTAVITI KONTAKT!", "OBAVESTENJE!");
 }
 }
 
 }
 
 
 
 else MessageBox.Show("Poslednja podesavanja programa nisu pronadjena.\nMoracete rucno da pronadjete bazu podataka!", "Obavestenje", MessageBoxButtons.OK);
 
 }
 catch (FileNotFoundException)
 {
 MessageBox.Show("Poslednja podesavanja programa nisu pronadjena.\nMoracete rucno da pronadjete bazu podataka!", "Obavestenje", MessageBoxButtons.OK);
 
 }
 
 label_status.Text = "Program uspesno pokrenut,ocekuje unos podataka! ";
 }
 OleDbConnection Konekcija = new OleDbConnection();
 OleDbCommand Komanda = new OleDbCommand();
 DataSet DS = new DataSet();
 OleDbDataAdapter DA = new OleDbDataAdapter();
 OleDbDataReader DR;
 
 private void btnIMPORT_Click(object sender, EventArgs e)
 {
 openFileDialog1.InitialDirectory = inport_path;
 try{
 
 if (openFileDialog1.ShowDialog() == DialogResult.OK)
 {
 //malo kozmetike
 {
 btnEXPORT.Enabled = true;
 txbIMe.Enabled = true;
 txbKomentar.Enabled = true;
 txbLogin.Enabled = true;
 txbPassword.Enabled = true;
 
 inport_path = openFileDialog1.FileName;
 IMPORT_PATH_LABEL.Text = inport_path;
 cmbODELJENJE.Enabled = true;
 cmbPeriod.Enabled = true;
 cmbPREDMET.Enabled = true;
 cmbODELJENJE.Items.Clear();
 cmbPREDMET.Items.Clear();
 }
 
 //konekcija 
 conection_string = String.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0}", Convert.ToString(openFileDialog1.FileName));
 // OleDbConnection Konekcija = new OleDbConnection();
 Konekcija.ConnectionString = conection_string;
 label_status.Text = "Program pristupa podataka! ";
 Konekcija.Open();
 //komanda
 //OleDbCommand Komanda = new OleDbCommand();
 Komanda.Connection = Konekcija;
 comand_string = "SELECT * FROM Predmeti;";
 Komanda.CommandText = comand_string;
 
 //data set
 // DataSet DS = new DataSet();
 
 //data adapter
 //OleDbDataAdapter DA = new OleDbDataAdapter();
 DA.SelectCommand = Komanda;
 
 DA.Fill(DS);
 
 //data reader
 // OleDbDataReader DR;
 
 DR = Komanda.ExecuteReader();
 //punjenje combo boxa-a
 while (DR.Read() == true)
 {
 cmbPREDMET.Items.Add(DR["Sifra_Predmeta"].ToString());
 
 }
 Konekcija.Close();
 
 comand_string = "SELECT ID FROM Razredi";
 Konekcija.ConnectionString = conection_string;
 Konekcija.Open();
 Komanda.CommandText = comand_string;
 DA.SelectCommand = Komanda;
 DA.Fill(DS);
 DR = Komanda.ExecuteReader();
 //punjenje combo boxa-a
 while (DR.Read() == true)
 {
 cmbODELJENJE.Items.Add(DR["ID"].ToString());
 
 }
 
 
 }
 Konekcija.Close();
 label_status.Text = "Program uspesno okoncao pristup bazi podataka. ";
 }
 
catch (FileNotFoundException )
 {
 
 MessageBox.Show("DATA BAZA NIJE PRONADJENA ILI SA NJOM NIJE MOGUCE USPOSTAVITI KONTAKT!","OBAVESTENJE!");
 label_status.Text = "Program nije uspesno pristupio bazi podataka. ";
 }
 
 
 
 //
 // Komanda.Dispose();
 // Konekcija.Dispose();
 // DR.Dispose();
 }
 
 private void textBox4_TextChanged(object sender, EventArgs e)
 {
 
 }
 
 private void button3_Click(object sender, EventArgs e)
 {
 if (promene == false)
 {
 this.Close();
 }
 else
 {
 if(MessageBox.Show("Da li ste sigurni da zelite da prekinete rad?","Upozorenje!",MessageBoxButtons.YesNoCancel,MessageBoxIcon.Question)==DialogResult.Yes)
 {
 this.Close();
 }
 
 
 }
 }
 
 private void cmbPeriod_SelectedIndexChanged(object sender, EventArgs e)
 {
 
 
 }
 
 private void button1_Click(object sender, EventArgs e)
 {
 string tempString,tmp1,tmp2=" ";
 string period = Convert.ToString(cmbPeriod.SelectedItem);
 string odeljenje = Convert.ToString(cmbODELJENJE.SelectedItem);
 string predmet = Convert.ToString(cmbPREDMET.SelectedItem);
 string loggin = Convert.ToString(txbLogin.Text);
 string pass = Convert.ToString(txbPassword.Text);
 string ime = Convert.ToString(txbIMe.Text);
 string komentar = Convert.ToString(txbKomentar.Text);
 string temstring2;
 StreamWriter sr = new StreamWriter(output_path);
 
 //StreamReader sr3=new StreamReader("temp.txt");
 //set za konekciju sa ucenicima
 OleDbConnection Konekcija2 = new OleDbConnection();
 OleDbCommand Komanda2 = new OleDbCommand();
 DataSet DS2 = new DataSet();
 OleDbDataAdapter DA2 = new OleDbDataAdapter();
 OleDbDataReader DR2;
 //pocetak eksporta
 
 label_status.Text = "Program pristupa obradi .xml datoteke; ";
sr.WriteLine(" ");
 
//definicija odeljenja
sr.WriteLine(" ");
temstring2 = String.Format(" {0}  ",odeljenje);
sr.WriteLine(temstring2);
sr.WriteLine(" 01 ");
 Konekcija.Open();
 Komanda.Connection=Konekcija;
 tempString=string.Format("SELECT * FROM Predmeti WHERE Predmeti.Sifra_Predmeta='{0}';",predmet);
 Komanda.CommandText=tempString;
 DA.SelectCommand=Komanda;
 DA.Fill(DS);
 DR=Komanda.ExecuteReader();
 DR.Read(); 
sr.WriteLine(" {0}  ",DR["Naziv_Predmeta"].ToString());
sr.WriteLine(" {0} ",loggin);
sr.WriteLine(" ");
sr.WriteLine(" ");
sr.WriteLine(" ");
sr.WriteLine(" {0} ",pass);
sr.WriteLine(" {0} ",ime);
sr.WriteLine(" {0} ",period);
sr.WriteLine(" {0} ",komentar);
sr.WriteLine(" ");
Konekcija.Close();
//DR.Dispose();
//definicija zadataka
 comand_string = String.Format("SELECT * FROM Zadaci,Predmeti WHERE Zadaci.Predmet_kome_zadatak_pripada=Predmeti.Sifra_Predmeta AND Predmeti.Sifra_predmeta='{0}' ORDER BY Datum_izrade_zadatka ;", predmet);
 Konekcija.Open();
 Komanda.Connection = Konekcija;
 Komanda.CommandText = comand_string;
 
 DA.SelectCommand = Komanda;
 DA.Fill(DS);
 DR = Komanda.ExecuteReader();
//petlja za popunu tabele zadataka
while(DR.Read()==true)
 {
sr.WriteLine(" ");
sr.WriteLine(" {0} ", DR["Datum_izrade_zadatka"].ToString());
sr.WriteLine(" {0} ",DR["Naziv_zadatka"].ToString());
sr.WriteLine(" {0} ",DR["MAX_bodova"].ToString());
sr.WriteLine(" {0} ",DR["Komentar"].ToString());
sr.WriteLine("");
 
};
 Konekcija.Close();
//definicaja ucenika u while petlji
 comand_string = String.Format("SELECT * FROM Ucenici,Razredi WHERE Ucenici.Razred=Razredi.ID AND Razredi.ID='{0}';", odeljenje);
 
 Konekcija.Open();
 Komanda.Connection = Konekcija;
 Komanda.CommandText = comand_string;
 
 DA.SelectCommand = Komanda;
 DA.Fill(DS);
 DR = Komanda.ExecuteReader();
 
while (DR.Read() == true)
{
 sr.WriteLine(" ");
 temstring2=DR["Sifra_ucenika"].ToString();
 sr.WriteLine(" {0} ",temstring2 );
 //sr.WriteLine(" ");
 //popuna ocena
 
 // ce mora da se deklarise jos jedan set objekata za konekciju sa bazom da bi se popunilie ocene!
 tempString = String.Format("SELECT * FROM Tabela_ocena,Zadaci,Ucenici WHERE Tabela_ocena.SIFRA_ZADATKA=Zadaci.ID_zadatka AND Tabela_ocena.SIFRA_UCENIKA=Ucenici.Sifra_ucenika AND Zadaci.Predmet_kome_zadatak_pripada='{0}' AND Tabela_ocena.SIFRA_UCENIKA='{1}';",predmet ,temstring2);
 Konekcija2.ConnectionString =conection_string;
 Konekcija2.Open();
 Komanda2.Connection = Konekcija2;
 Komanda2.CommandText = tempString;
 DA2.SelectCommand = Komanda2;
 DA2.Fill(DS2);
 DR2 = Komanda2.ExecuteReader();
 string tmp3="";
 while (DR2.Read() == true)
 {
 tmp1=String.Format("{0}" , DR2["Ocena_na_zadatku"].ToString());
 tmp2=String.Format("{0},{1}", tmp2 , tmp1);
 tmp3 = tmp2;
 };
 
 Konekcija2.Close();
 sr.WriteLine(" {0} ", tmp3);
 
 //sr.WriteLine("");
 sr.WriteLine(" ");
 sr.WriteLine(" {0} ", DR["Srednja_ocena"]);
 sr.WriteLine(",,,");
 //for(int x=0;x=i;i++)
 //{
 //temp_string2=string.Format(",{0}",temp_string);
 //temp_string=tempstring2;
 //};
 //sr.WriteLine("");
 sr.WriteLine(" ");
 sr.WriteLine("");
 
};
sr.WriteLine("");
Konekcija.Close();
sr.Close();
label_status.Text = "Program uspesno okoncao pristup bazi podataka i formirao .xml datoteku. ";
 
if (inport_path != "" || output_path != "")
{
 StreamWriter sr2 = new StreamWriter("lastset.txt");
 
 sr2.WriteLine("{0}", inport_path);
 sr2.WriteLine("{0}", output_path);
 sr2.Close();
 
}
 }
 
 private void btnEXPORT_Click(object sender, EventArgs e)
 {
 saveFileDialog1.InitialDirectory = output_path;
 if (saveFileDialog1.ShowDialog() == DialogResult.OK)
 {
 output_path = Convert.ToString(saveFileDialog1.FileName);
 EXPORT_PATH_LABEL.Text = output_path;
 button1.Enabled = true;
 
 }
 if (inport_path != "" || output_path != "")
 {
 StreamWriter sr2 = new StreamWriter("lastset.txt");
 
 sr2.WriteLine("{0}", inport_path);
 sr2.WriteLine("{0}", output_path);
 sr2.Close();
 
 }
 }
 
 private void Form1_FormClosing(object sender, FormClosingEventArgs e)
 {
 if (inport_path != "" || output_path != "")
 {
 StreamWriter sr2 = new StreamWriter("lastset.txt");
 
 sr2.WriteLine("{0}", inport_path);
 sr2.WriteLine("{0}", output_path);
 sr2.Close();
 
 }
 //
 Komanda.Dispose();
 Konekcija.Dispose();
 //DR.Dispose();
 }
 
 private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
 {
 try
 {
 VisitLink();
 }
 catch (Exception ex )
 {
 MessageBox.Show("Aplikacija ne moze da pokrene/pronadje index.htm .");
 }
}
 
private void VisitLink()
{
 
 linkLabel1.LinkVisited = true;
 
 System.Diagnostics.Process.Start("index.htm");
}
 
 }
 }