public static void UcitajStavkeRacuna(Racun racun, int Id_Racun)
        {
            using (SqlConnection conn = new SqlConnection(Projekat.CONNECTION_STRING))
            {
                conn.Open();
                DataSet ds = new DataSet();

                SqlCommand command = conn.CreateCommand();
                command.CommandText = $"SELECT * FROM StavkaProdajeNamestaja s WHERE s.Id_Racun=@Id_Racun ";
                command.Parameters.Add(new SqlParameter("@Id_Racun", Id_Racun));
                SqlDataAdapter daStavkaNamestaja = new SqlDataAdapter();
                daStavkaNamestaja.SelectCommand = command;
                daStavkaNamestaja.Fill(ds, "StavkaProdajeNamestaja");
                Projekat.Instance.StavkaProdajeNamestaja.Clear();
                foreach (DataRow row in ds.Tables["StavkaProdajeNamestaja"].Rows)
                {
                    StavkaProdajeNamestaja s = new StavkaProdajeNamestaja();
                    s.Id          = (int)row["Id"];
                    s.Id_Namestaj = (int)row["Id_Namestaj"];
                    s.Id_Racun    = (int)row["Id_Racun"];
                    s.Kolicina    = (int)row["Kolicina"];
                    s.Popust      = (int)(row["Popust"]);
                    s.Namestaj    = Namestaj.GetById(s.Id_Namestaj);

                    racun.listaStavkiNamestaja.Add(s);
                }
            }
        }
Esempio n. 2
0
        public static void UcitajRacune()
        {
            using (SqlConnection connection = new SqlConnection(Projekat.CONNECTION_STRING))
            {
                connection.Open();

                DataSet ds = new DataSet();

                SqlCommand namestajCommand = connection.CreateCommand();
                namestajCommand.CommandText = @"SELECT * FROM Racun ";
                SqlDataAdapter daNamestaj = new SqlDataAdapter();
                daNamestaj.SelectCommand = namestajCommand;
                daNamestaj.Fill(ds, "Racun");

                foreach (DataRow row in ds.Tables["Racun"].Rows)
                {
                    Racun n = new Racun();
                    n.Id           = (int)row["Id"];
                    n.Datum        = (DateTime)row["Datum"];
                    n.Id_Zaposleni = (int)(row["Id_Zaposleni"]);
                    n.Id_Kupac     = (int)row["Id_Kupac"];
                    n.Kupac        = Kupac.GetById(n.Id_Kupac);
                    n.Zaposleni    = Zaposleni.GetById(n.Id_Zaposleni);

                    StavkaProdajeNamestaja.UcitajStavkeRacuna(n, n.Id);
                    StavkaProdajeUsluge.UcitajStavkeRacuna(n, n.Id);
                    //DataSet ds2 = new DataSet();

                    //SqlCommand command1 = connection.CreateCommand();
                    //command1.CommandText = $"SELECT * FROM StavkaUsluge s WHERE s.Id_Racun=@Id ";
                    //SqlDataAdapter daStavkaUsluge = new SqlDataAdapter();
                    //daStavkaUsluge.SelectCommand = command1;
                    //daStavkaUsluge.Fill(ds2, "StavkaUsluge");
                    //command1.Parameters.Add(new SqlParameter("@Id", n.Id));
                    //foreach (DataRow row2 in ds2.Tables["StavkaUsluge"].Rows)
                    //{
                    //    StavkaProdajeUsluge s = new StavkaProdajeUsluge();
                    //    s.Id = (int)row2["Id"];
                    //    s.Id_Usluga = (int)row2["Id_Usluga"];
                    //    s.Usluga = Usluga.GetById(s.Id_Usluga);
                    //    s.Id_Racun = (int)row2["Id_Racun"];


                    //    n.listaStavkiUsluga.Add(s);
                    //}
                    Projekat.Instance.Racun.Add(n);
                }
            }
        }
        public static void DodajStavkuProdajeNamestaja(StavkaProdajeNamestaja stavkaProdajeNamestaja)
        {
            using (SqlConnection conn = new SqlConnection(Projekat.CONNECTION_STRING))
            {
                conn.Open();
                SqlCommand command = conn.CreateCommand();
                command.CommandText = $"INSERT INTO StavkaProdajeNamestaja (Id_Racun,Id_Namestaj,Kolicina,Popust)" +
                                      $"VALUES(@Id_Racun,@Id_Namestaj,@Kolicina,@Popust)";
                command.Parameters.Add(new SqlParameter("@Id_Racun", stavkaProdajeNamestaja.Id_Racun));
                command.Parameters.Add(new SqlParameter("@Id_Namestaj", stavkaProdajeNamestaja.Id_Namestaj));
                command.Parameters.Add(new SqlParameter("@Kolicina", stavkaProdajeNamestaja.Kolicina));
                command.Parameters.Add(new SqlParameter("@Popust", stavkaProdajeNamestaja.Popust));

                command.ExecuteNonQuery();
            }
        }