Esempio n. 1
0
 public void ucitajKupce()
 {
     try
     {
         Kupci = new List <Kupac>();
         String             query = "SELECT * FROM Kupac;";
         DBConnectionString s     = new DBConnectionString();
         using (SqlConnection con = new SqlConnection(s.GetString()))
         {
             con.Open();
             if (con.State == System.Data.ConnectionState.Open)
             {
                 SqlCommand cmd = con.CreateCommand();
                 cmd.CommandText = query;
                 SqlDataReader reader = cmd.ExecuteReader();
                 while (reader.Read())
                 {
                     Kupac      a = new Kupac(Convert.ToInt32(reader.GetString(0)), reader.GetString(1), reader.GetString(2), reader.GetString(3), reader.GetString(4), reader.GetString(5), reader.GetString(6), reader.GetString(7), reader.GetString(8));
                     DBNarudzba n = new DBNarudzba();
                     n.ucitajNarudzbeKupca(Convert.ToInt32(reader.GetString(0)));
                     a.narudzbe = n.narudzbeKupca;
                     Kupci.Add(a);
                 }
             }
             con.Close();
         }
     }
     catch (Exception e)
     {
         Debug.WriteLine("Exception: " + e.Message);
     }
 }
Esempio n. 2
0
 public int brisiKupca(Kupac a)
 {
     try
     {
         String             query = "DELETE FROM Kupac WHERE id = @id;";
         DBConnectionString s     = new DBConnectionString();
         using (SqlConnection con = new SqlConnection(s.GetString()))
         {
             SqlCommand cmd = con.CreateCommand();
             cmd.CommandText = query;
             SqlParameter id = new SqlParameter();
             id.Value         = Convert.ToString(a.id);
             id.ParameterName = "id";
             cmd.Parameters.Add(id);
             con.Open();
             int r = 0;
             if (con.State == System.Data.ConnectionState.Open)
             {
                 r = cmd.ExecuteNonQuery();
             }
             con.Close();
             return(r);
         }
     }
     catch (Exception e)
     {
         Debug.WriteLine("Exception: " + e.Message);
         return(0);
     }
 }
Esempio n. 3
0
 public void ucitajNarudzbe()
 {
     try
     {
         Narudzbe = new List <NarudzbaHrane>();
         String             query = "SELECT * FROM NarudzbaHrane;";
         DBConnectionString s     = new DBConnectionString();
         using (SqlConnection con = new SqlConnection(s.GetString()))
         {
             con.Open();
             if (con.State == System.Data.ConnectionState.Open)
             {
                 SqlCommand cmd = con.CreateCommand();
                 cmd.CommandText = query;
                 SqlDataReader reader = cmd.ExecuteReader();
                 while (reader.Read())
                 {
                     NarudzbaHrane a = new NarudzbaHrane(Convert.ToInt32(reader.GetString(0)), reader.GetInt32(1));
                     Narudzbe.Add(a);
                 }
             }
             con.Close();
         }
     }
     catch (Exception e)
     {
         Debug.WriteLine("Exception: " + e.Message);
     }
 }
Esempio n. 4
0
 public void ucitajNarudzbeKupca(int idKupca)
 {
     try
     {
         narudzbeKupca = new List <int>();
         String             query = "SELECT * FROM Narudzba WHERE idKupca = @idObj;";
         DBConnectionString s     = new DBConnectionString();
         using (SqlConnection con = new SqlConnection(s.GetString()))
         {
             con.Open();
             if (con.State == System.Data.ConnectionState.Open)
             {
                 SqlCommand cmd = con.CreateCommand();
                 cmd.CommandText = query;
                 SqlParameter id = new SqlParameter();
                 id.Value         = idKupca;
                 id.ParameterName = "idObj";
                 cmd.Parameters.Add(id);
                 SqlDataReader reader = cmd.ExecuteReader();
                 while (reader.Read())
                 {
                     narudzbeKupca.Add(Convert.ToInt32(reader.GetString(0)));
                 }
             }
             con.Close();
         }
     }
     catch (Exception e)
     {
         Debug.WriteLine("Exception: " + e.Message);
     }
 }
Esempio n. 5
0
        public int unesiNarudzbu(NarudzbaHrane a)
        {
            try
            {
                String query = "insert into NarudzbaHrane " +
                               "values (@id,@idKupca)";
                DBConnectionString s = new DBConnectionString();
                using (SqlConnection con = new SqlConnection(s.GetString()))
                {
                    SqlCommand cmd = con.CreateCommand();
                    cmd.CommandText = query;

                    SqlParameter id = new SqlParameter();
                    id.Value         = Convert.ToString(a.idNarudzbe);
                    id.ParameterName = "id";

                    SqlParameter idKupca = new SqlParameter();
                    idKupca.Value         = a.idKupca;
                    idKupca.ParameterName = "idKupca";


                    cmd.Parameters.Add(id);
                    cmd.Parameters.Add(idKupca);

                    int k = cmd.ExecuteNonQuery();
                    cmd.Dispose();
                    return(k);
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine("Exception: " + e.Message);
                return(0);
            }
        }
Esempio n. 6
0
 public void ucitajObjekte()
 {
     try
     {
         Objekti = new List <Objekat>();
         String             query = "SELECT * FROM Objekat;";
         DBConnectionString s     = new DBConnectionString();
         using (SqlConnection con = new SqlConnection(s.GetString()))
         {
             con.Open();
             if (con.State == System.Data.ConnectionState.Open)
             {
                 SqlCommand cmd = con.CreateCommand();
                 cmd.CommandText = query;
                 SqlDataReader reader = cmd.ExecuteReader();
                 while (reader.Read())
                 {
                     Objekat a   = new Objekat(Convert.ToInt32(reader.GetString(0)), reader.GetString(1), reader.GetString(2), reader.GetString(3), reader.GetString(4), reader.GetString(5), reader.GetString(6), reader.GetString(7), reader.GetString(8));
                     DBJelo  dbj = new DBJelo();
                     dbj.ucitajJelaObjekta(a.id);
                     a.jela = dbj.jelaObjekta;
                     Objekti.Add(a);
                 }
             }
             con.Close();
         }
     }
     catch (Exception e)
     {
         Debug.WriteLine("Exception: " + e.Message);
     }
 }
Esempio n. 7
0
 public void ucitajAdministratore()
 {
     try
     {
         Administratori = new List <Administrator>();
         String             query = "SELECT * FROM Administrator;";
         DBConnectionString s     = new DBConnectionString();
         using (SqlConnection con = new SqlConnection(s.GetString()))
         {
             con.Open();
             if (con.State == System.Data.ConnectionState.Open)
             {
                 SqlCommand cmd = con.CreateCommand();
                 cmd.CommandText = query;
                 SqlDataReader reader = cmd.ExecuteReader();
                 while (reader.Read())
                 {
                     Administrator a = new Administrator(Convert.ToInt32(reader.GetString(0)), reader.GetString(1), reader.GetString(2), reader.GetString(3), reader.GetString(4));
                     Administratori.Add(a);
                 }
             }
             con.Close();
         }
     }
     catch (Exception e)
     {
         Debug.WriteLine("Exception: " + e.Message);
     }
 }
Esempio n. 8
0
        public int unesiAdministratora(Administrator a)
        {
            try
            {
                String query = "insert into Administrator " +
                               "values (@id,@Ime,@Prezime,@Username,@Password)";
                DBConnectionString s = new DBConnectionString();
                using (SqlConnection con = new SqlConnection(s.GetString()))
                {
                    SqlCommand cmd = con.CreateCommand();
                    cmd.CommandText = query;

                    SqlParameter id = new SqlParameter();
                    id.Value         = Convert.ToString(a.ID);
                    id.ParameterName = "id";

                    SqlParameter Ime = new SqlParameter();
                    Ime.Value         = a.Ime;
                    Ime.ParameterName = "Ime";

                    SqlParameter Prezime = new SqlParameter();
                    Prezime.Value         = a.Prezime;
                    Prezime.ParameterName = "Prezime";

                    SqlParameter Username = new SqlParameter();
                    Username.Value         = a.Username;
                    Username.ParameterName = "Username";

                    SqlParameter Password = new SqlParameter();
                    Password.Value         = a.Password;
                    Password.ParameterName = "Password";

                    cmd.Parameters.Add(id);
                    cmd.Parameters.Add(Ime);
                    cmd.Parameters.Add(Prezime);
                    cmd.Parameters.Add(Username);
                    cmd.Parameters.Add(Password);

                    int k = cmd.ExecuteNonQuery();
                    cmd.Dispose();
                    return(k);
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine("Exception: " + e.Message);
                return(0);
            }
        }
Esempio n. 9
0
        public int unesiJelo(Jelo a)
        {
            try
            {
                String query = "insert into Jelo " +
                               "values (@id,@nazivJela,@vrsta,@cijena,@idObjekta)";
                DBConnectionString s = new DBConnectionString();
                using (SqlConnection con = new SqlConnection(s.GetString()))
                {
                    SqlCommand cmd = con.CreateCommand();
                    cmd.CommandText = query;

                    SqlParameter id = new SqlParameter();
                    id.Value         = Convert.ToString(a.idJela);
                    id.ParameterName = "id";

                    SqlParameter nazivJela = new SqlParameter();
                    nazivJela.Value         = a.nazivJela;
                    nazivJela.ParameterName = "nazivJela";

                    SqlParameter vrsta = new SqlParameter();
                    vrsta.Value         = a.vrsta;
                    vrsta.ParameterName = "vrsta";

                    SqlParameter cijena = new SqlParameter();
                    cijena.Value         = a.cijena;
                    cijena.ParameterName = "cijena";

                    SqlParameter idObjekta = new SqlParameter();
                    idObjekta.Value         = a.cijena;
                    idObjekta.ParameterName = "idObjekta";

                    cmd.Parameters.Add(id);
                    cmd.Parameters.Add(nazivJela);
                    cmd.Parameters.Add(vrsta);
                    cmd.Parameters.Add(cijena);
                    cmd.Parameters.Add(idObjekta);

                    int k = cmd.ExecuteNonQuery();
                    cmd.Dispose();
                    return(k);
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine("Exception: " + e.Message);
                return(0);
            }
        }
Esempio n. 10
0
        public int unesiKupca(Kupac a)
        {
            try
            {
                String query = "insert into Kupac " +
                               "values (@id,@Ime,@Prezime,@Adresa,@Telefon,@Username,@Password,@Mail,@Grad)";
                DBConnectionString s = new DBConnectionString();
                using (SqlConnection con = new SqlConnection(s.GetString()))
                {
                    SqlCommand cmd = con.CreateCommand();
                    cmd.CommandText = query;

                    SqlParameter id = new SqlParameter();
                    id.Value         = Convert.ToString(a.id);
                    id.ParameterName = "id";

                    SqlParameter Ime = new SqlParameter();
                    Ime.Value         = a.ime;
                    Ime.ParameterName = "Ime";

                    SqlParameter Prezime = new SqlParameter();
                    Prezime.Value         = a.prezime;
                    Prezime.ParameterName = "Prezime";

                    SqlParameter Adresa = new SqlParameter();
                    Adresa.Value         = a.adresa;
                    Adresa.ParameterName = "Adresa";

                    SqlParameter Telefon = new SqlParameter();
                    Telefon.Value         = a.telefon;
                    Telefon.ParameterName = "Telefon";

                    SqlParameter Username = new SqlParameter();
                    Username.Value         = a.username;
                    Username.ParameterName = "Username";

                    SqlParameter Password = new SqlParameter();
                    Password.Value         = a.password;
                    Password.ParameterName = "Password";

                    SqlParameter Mail = new SqlParameter();
                    Mail.Value         = a.email;
                    Mail.ParameterName = "Mail";

                    SqlParameter Grad = new SqlParameter();
                    Grad.Value         = a.grad;
                    Grad.ParameterName = "Grad";

                    cmd.Parameters.Add(id);
                    cmd.Parameters.Add(Ime);
                    cmd.Parameters.Add(Prezime);
                    cmd.Parameters.Add(Adresa);
                    cmd.Parameters.Add(Telefon);
                    cmd.Parameters.Add(Username);
                    cmd.Parameters.Add(Password);
                    cmd.Parameters.Add(Mail);
                    cmd.Parameters.Add(Grad);

                    int k = cmd.ExecuteNonQuery();
                    cmd.Dispose();
                    return(k);
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine("Exception: " + e.Message);
                return(0);
            }
        }