using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace BazaZamowien.Classes
{
    class PremieUtils
    {

        public static object ExecuteQuery(string query)
        {
            SqlConnection conn = new SqlConnection(ConnString.getConnString().PremieConnStr);

            SqlCommand command = new SqlCommand(query);
            command.Connection = conn;

            object result = null;

            conn.Open();
            result = command.ExecuteScalar();
            conn.Close();

            return result;
            
        }
        
        /// <summary>
        /// 
        /// </summary>
        public static int pobierzeIDE_CT(string login)
        {
            string query = " select IDEPracownicy from dbo.Interface_Pracownicy where SQLLogins='" + login + "'";

            return (int)ExecuteQuery(query);
        }

        public static int pobierzeIDEDzialuCT(int IDEPracownika)
        {
            string query = " select IDEDzial from dbo.PODWLADNOSC where IDEPracownik=" + IDEPracownika;

            return (int)ExecuteQuery(query);
        }

        public static int pobierzeIDEOdzialuCT(int IDEPracownika)
        {
            string query = " select IDEOddzial from dbo.PODWLADNOSC where IDEPracownik=" + IDEPracownika;

            return (int)ExecuteQuery(query);
        }

        public static int pobierzeIDEGrupy(string login)
        {
            string query = " select IDEGrupa from dbo.Users where Login='" + login + "'";

            return (int)ExecuteQuery(query);
        }

        public static int iloscDzialowWGrupie(int IDEGrupy)
        {
            string query = "select count(*) from dbo.GrupaDzial where IDEGrupy = " + IDEGrupy;

            return (int)ExecuteQuery(query);
        }

        public static int iloscUzytkownikowWGrupie(int IDEGrupy)
        {
            string query = "select count(*) from dbo.Users where IDEGrupa = " + IDEGrupy;

            return (int)ExecuteQuery(query);
        }

        public static string podajMailaPracownika(int IDEPracownik)
        {
            string query = "select EMail from dbo.Interface_Pracownicy where IDEPracownicy=" + IDEPracownik;

            return (string)ExecuteQuery(query);
        }

    }
}
