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 StavkaUsluge 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, "StavkaUsluge");
                Projekat.Instance.StavkaProdajeUsluge.Clear();
                foreach (DataRow row in ds.Tables["StavkaUsluge"].Rows)
                {
                    StavkaProdajeUsluge s = new StavkaProdajeUsluge();
                    s.Id        = (int)row["Id"];
                    s.Id_Usluga = (int)row["Id_Usluga"];
                    s.Usluga    = Usluga.GetById(s.Id_Usluga);
                    s.Id_Racun  = (int)row["Id_Racun"];

                    racun.listaStavkiUsluga.Add(s);
                }
            }
        }
        public static void DodajStavkuProdajeUsluga(StavkaProdajeUsluge stavkaProdajeUsluge)
        {
            using (SqlConnection conn = new SqlConnection(Projekat.CONNECTION_STRING))
            {
                conn.Open();
                SqlCommand command = conn.CreateCommand();
                command.CommandText = $"INSERT INTO StavkaUsluge (Id_Racun,Id_Usluga)" +
                                      $"VALUES(@Id_Racun,@Id_Usluga)";
                command.Parameters.Add(new SqlParameter("@Id_Racun", stavkaProdajeUsluge.Id_Racun));
                command.Parameters.Add(new SqlParameter("@Id_Usluga", stavkaProdajeUsluge.Id_Usluga));

                command.ExecuteNonQuery();
            }
        }
示例#3
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);
                }
            }
        }