After I found out who is logged in and gave proper query for it and fill the datatable dt with return value of query. (Edited by idea of Derek Smyth) :
for (int i = 0; i < dt.Rows.Count; i++) //dt is the datatable that was filled with data depending on the role of user that is logged in
{
//query that returns how many times an employee logged in in that month of a year
komanda = "begin;select count(*) from radni_sati where zaposlenik_id=@zaposlenik_id and " +
" extract(month from datum)=@mjesec_broj and extract(year from datum)=@godina ;commit;";
listaParametara.Add(new NpgsqlParameter { ParameterName = "@mjesec_broj", Value = mjesec_broj }); //month we are making report on
listaParametara.Add(new NpgsqlParameter { ParameterName = "@godina", Value = godina }); //year we are making report on
listaParametara.Add(new NpgsqlParameter { ParameterName = "@zaposlenik_id", Value = dt.Rows[i][0] }); //employee id
long ZapisUMjesecu = instanca.ExecuteScalar<long>(komanda, CommandType.Text, listaParametara);
listaParametara.Clear();
//returns the department_id from current employee
komanda = "begin;select odjel_id from zaposlenici where zaposlenik_id=@zaposlenik_id ;commit;";
listaParametara.Add(new NpgsqlParameter { ParameterName = "@zaposlenik_id", Value = dt.Rows[i][0] });
int OdjelID = instanca.ExecuteScalar<int>(komanda, CommandType.Text, listaParametara);
listaParametara.Clear();
//if that employee has atlest 1 day of work
ifbool (radio = ZapisUMjesecu > 00; //ako postoje zapisi, tj. ako se zaposlenik bar jednom prijavio u mjesecu
if (radio)
{
//return number of sick days he had
komanda = "begin;select count(*) from bolovanje where extract(month from bolovanje.datum)" +
"=@mjesec_broj and extract(year from bolovanje.datum)=@godina and zaposlenik_id=@zaposlenik_id ;commit;";
listaParametara.Add(new NpgsqlParameter { ParameterName = "@mjesec_broj", Value = mjesec_broj });
listaParametara.Add(new NpgsqlParameter { ParameterName = "@godina", Value = godina });
listaParametara.Add(new NpgsqlParameter { ParameterName = "@zaposlenik_id", Value = dt.Rows[i][0] });
longTask<long> iskoristeno_bolovanjeiskoristeno_bolovanje_tsk = Task.Run(() => instanca.ExecuteScalar<long>(komanda,
CommandType "begin;select count(*) from bolovanje where extract(month from bolovanje.Text,datum)" listaParametara+
"=@mjesec_broj and extract(year from bolovanje.datum);=@godina and zaposlenik_id=@zaposlenik_id ;commit;",
listaParametaraCommandType.Clear(Text, listaParametara));
//returns all the dates that employee was sick
komanda = "begin;select datum fromTask<DataTable> bolovanjeDatumiBolovanja_tsk where= extractTask.Run(month() from=> bolovanjeinstanca.datum)" +FillDataTable(
"begin;select datum from "=@mjesec_brojbolovanje andwhere extract(yearmonth from bolovanje.datum)=@godina and zaposlenik_id=@zaposlenik_id" ;commit;";+
listaParametara.Add(new NpgsqlParameter { ParameterName = "@zaposlenik_id", Value = dt.Rows[i][0] });
"=@mjesec_broj and listaParametara.Addextract(new NpgsqlParameter { ParameterName = "@mjesec_broj", Value = mjesec_broj });
year from listaParametarabolovanje.Add(new NpgsqlParameter {datum)=@godina ParameterNameand =zaposlenik_id=@zaposlenik_id "@godina";commit;", Value = godina });
DataTable DatumiBolovanja = instanca.FillDataTable(komanda, CommandType.Text, listaParametara);
listaParametara.Clear();
//return number of holidays he had
komanda = "begin;select count(*) from godisnji where extract(month from godisnji.datum)" +
"=@mjesec_broj and extract(year from godisnji.datum)=@godina and zaposlenik_id=@zaposlenik_id;commit;";
listaParametara.Add(new NpgsqlParameter { ParameterName = "@mjesec_broj", Value = mjesec_broj });
listaParametara.Add(new NpgsqlParameter { ParameterName = "@godina", Value = godina });
listaParametara.Add(new NpgsqlParameter { ParameterName = "@zaposlenik_id", Value = dt.Rows[i][0] });
long iskoristeni_godisnji = instanca.ExecuteScalar<long>(komanda, CommandType.Text, listaParametara);
listaParametara.Clear();
//returns allreturn thenumber datesof thatholidays employee was on holidayhad
komanda = "begin;select datum fromTask<long> godisnjiiskoristeni_godisnji_tsk where= extractTask.Run(month() from=> godisnjiinstanca.datum)" +ExecuteScalar<long>(
"begin;select count(*) from "=@mjesec_brojgodisnji andwhere extract(yearmonth from godisnji.datum)=@godina and zaposlenik_id=@zaposlenik_id" ;commit;";+
listaParametara.Add(new NpgsqlParameter { ParameterName = "@zaposlenik_id", Value = dt.Rows[i][0] });
"=@mjesec_broj and listaParametara.Addextract(new NpgsqlParameter { ParameterName = "@mjesec_broj", Value = mjesec_broj });
year from listaParametaragodisnji.Add(new NpgsqlParameter { ParameterNamedatum)=@godina =and "@godina"zaposlenik_id=@zaposlenik_id;commit;", Value = godina });
DataTable DatumiGodisnjeg = instanca.FillDataTable(komanda, CommandType.Text, listaParametara);
listaParametara.Clear();
//returns all the dates that employee was on holiday
Task<DataTable> DatumiGodisnjeg_tsk = Task.Run(() => instanca.FillDataTable(
"begin;select datum from godisnji where extract(month from godisnji.datum)" +
"=@mjesec_broj and extract(year from godisnji.datum)=@godina and zaposlenik_id=@zaposlenik_id ;commit;",
CommandType.Text, listaParametara));
//returns a number of days that employee was working
komandaTask<long> redovi_tsk = Task.Run(() => instanca.ExecuteScalar<long>(
"begin;select count(*) from radni_sati where zaposlenik_id=@zaposlenik_id" +
" and (dolazak is not null and odlazak is not null and sati_rada is not null) and extract(month from radni_sati.datum)" +
"=@mjesec_broj and extract(year from radni_sati.datum)=@godina group by zaposlenik_id order by zaposlenik_id;commit;";
listaParametara.Add(new NpgsqlParameter { ParameterName = "@mjesec_broj", Value = mjesec_broj });
listaParametara.Add(new NpgsqlParameter { ParameterName = "@godina", Value = godina });
listaParametara.Add(new NpgsqlParameter { ParameterName = "@zaposlenik_id"zaposlenik_id;commit;", Value = dt.Rows[i][0] });
long redovi = instanca.ExecuteScalar<long>(komanda, CommandType.Text, listaParametara);
listaParametara.Clear();
//calculate number of hours that employee was working in that month
//calculate number of hours that employee was working in that month Task<DataTable> UkupnoSati_tsk = Task.Run(() => instanca.FillDataTable(
komanda = "begin;select cast(radni_sati.sati_rada as time) from radni_sati where zaposlenik_id=@zaposlenik_id " +
" and extract(month from radni_sati.datum)=@mjesec_broj and extract(year from radni_sati.datum)=@godina;commit;";=@godina;commit;",
listaParametara CommandType.Add(newText, NpgsqlParameterlistaParametara));
{ ParameterName = "@zaposlenik_id", Value = dt.Rows[i][0] }); // wait for all the tasks above to complete
listaParametaraTask.AddWaitAll(new
NpgsqlParameter { ParameterName = "@mjesec_broj" iskoristeno_bolovanje_tsk, ValueDatumiBolovanja_tsk,
= mjesec_broj } iskoristeni_godisnji_tsk, DatumiGodisnjeg_tsk,
redovi_tsk, UkupnoSati_tsk);
listaParametara.Add(new// NpgsqlParameterget {the ParameterNamevalues after each of these return
long iskoristeno_bolovanje = "@godina",iskoristeno_bolovanje_tsk.Result;
Value DataTable DatumiBolovanja = godinaDatumiBolovanja_tsk.Result;
}); long iskoristeni_godisnji = iskoristeni_godisnji_tsk.Result;
DataTable UkupnoSatiDatumiGodisnjeg = instancaDatumiGodisnjeg_tsk.FillDataTable(komanda,Result;
CommandType long redovi = redovi_tsk.Text,Result;
listaParametara); DataTable UkupnoSati = UkupnoSati_tsk.Result;
listaParametara.Clear();