示例#1
0
        public static void UpdateForRacun(Racun r, Stavka s)
        {
            using (var con = new SqlConnection(ConfigurationManager.ConnectionStrings["POP"].ConnectionString))
            {
                con.Open();
                SqlCommand cmd = con.CreateCommand();
                if (s.BrojKomada == 0)
                {
                    Console.WriteLine("Poziva se delete metoda");
                    cmd.CommandText = "DELETE FROM StavkeRacuna WHERE RacunId=@RacunId AND NamestajId=@NamestajId";
                    cmd.Parameters.AddWithValue("RacunId", r.Id);
                    cmd.Parameters.AddWithValue("NamestajId", s.Namestaj.Id);
                }
                else
                {
                    Console.WriteLine("Poziva se update metoda");
                    cmd.CommandText = "UPDATE StavkeRacuna SET BrojKomada=@BrojKomada WHERE RacunId=@RacunId AND NamestajId=@NamestajId";
                    cmd.Parameters.AddWithValue("NamestajId", s.Namestaj.Id);
                    cmd.Parameters.AddWithValue("BrojKomada", s.BrojKomada);
                    cmd.Parameters.AddWithValue("RacunId", r.Id);
                }

                cmd.ExecuteNonQuery();
            }
        }
示例#2
0
 public static void AddForRacun(Racun r, Stavka s)
 {
     Console.WriteLine("Dosao do add metode racuna");
     Console.WriteLine("Id ovog racuna: " + r.Id);
     using (var con = new SqlConnection(ConfigurationManager.ConnectionStrings["POP"].ConnectionString))
     {
         r.Stavke.Add(s);
         con.Open();
         SqlCommand cmd = con.CreateCommand();
         cmd.CommandText = "INSERT INTO StavkeRacuna(RacunId, NamestajId, BrojKomada) VALUES (@RacunId, @NamestajId, @BrojKomada)";
         cmd.Parameters.AddWithValue("RacunId", r.Id);
         cmd.Parameters.AddWithValue("NamestajId", s.Namestaj.Id);
         cmd.Parameters.AddWithValue("BrojKomada", s.BrojKomada);
         cmd.ExecuteNonQuery();
     }
 }
示例#3
0
        public static ObservableCollection <Stavka> GetForRacun(int id)
        {
            ObservableCollection <Stavka> stavke = new ObservableCollection <Stavka>();

            using (var con = new SqlConnection(ConfigurationManager.ConnectionStrings["POP"].ConnectionString))
            {
                SqlCommand cmd = con.CreateCommand();
                cmd.CommandText = "SELECT * FROM StavkeRacuna WHERE RacunId=@RacunId";
                cmd.Parameters.AddWithValue("RacunId", id);
                SqlDataAdapter DataAdapter = new SqlDataAdapter();
                DataAdapter.SelectCommand = cmd;
                DataSet ds = new DataSet();
                DataAdapter.Fill(ds, "StavkeRacuna");

                foreach (DataRow row in ds.Tables["StavkeRacuna"].Rows)
                {
                    Stavka stavka = new Stavka();
                    stavka.namestajId = int.Parse(row["NamestajId"].ToString());
                    stavka.BrojKomada = int.Parse(row["BrojKomada"].ToString());
                    stavke.Add(stavka);
                }
                return(stavke);
            }
        }