Exemple #1
0
      public static ObservableCollection <StavkaProdajeDU> GetAll()
      {
          var spn = new ObservableCollection <StavkaProdajeDU>();

          using (var con = new SqlConnection(ConfigurationManager.ConnectionStrings["POP"].ConnectionString))
          {
              SqlCommand cmd = con.CreateCommand();
              cmd.CommandText = "SELECT * FROM  StavkaDUsluge ";

              DataSet        ds = new DataSet();
              SqlDataAdapter da = new SqlDataAdapter();

              da.SelectCommand = cmd;
              da.Fill(ds, "StavkaDUsluge");   // Query se izvrsava
              foreach (DataRow row in ds.Tables["StavkaDUsluge"].Rows)
              {
                  var s = new StavkaProdajeDU();
                  s.Id      = int.Parse(row["Id"].ToString());
                  s.RacunId = int.Parse(row["RacunId"].ToString());
                  s.DUId    = int.Parse(row["DUId"].ToString());


                  spn.Add(s);
              }
              return(spn);
          }
      }
Exemple #2
0
      public static void Update(StavkaProdajeDU s)
      {
          using (var con = new SqlConnection(ConfigurationManager.ConnectionStrings["POP"].ConnectionString))
          {
              con.Open();
              SqlCommand cmd = con.CreateCommand();
              cmd.CommandText = "Update  StavkaDUsluge set RacunId=@RacunId,DUId=@DUId, where Id=@Id";
              cmd.Parameters.AddWithValue("Id", s.Id);
              cmd.Parameters.AddWithValue("DUId", s.DUId);
              cmd.Parameters.AddWithValue("RacunId", s.RacunId);

              cmd.ExecuteNonQuery();

              foreach (var spn in Projekat.Instance.spdu)
              {
                  if (spn.Id == s.Id)
                  {
                      spn.RacunId = s.RacunId;
                      spn.DUId    = s.DUId;

                      break;
                  }
              }
          }
      }
Exemple #3
0
      public static StavkaProdajeDU Create(StavkaProdajeDU s)
      {
          using (var con = new SqlConnection(ConfigurationManager.ConnectionStrings["POP"].ConnectionString))
          {
              con.Open();
              SqlCommand cmd = con.CreateCommand();
              cmd.CommandText  = $"Insert into  StavkaDUsluge (RacunId,DUId) Values(@RacunId,@DUId);"; //razmisli o ne unosenju obrisan pri dodavanju vec to u bazi
              cmd.CommandText += "Select scope_identity();";
              cmd.Parameters.AddWithValue("RacunId", s.RacunId);
              cmd.Parameters.AddWithValue("DUId", s.DUId);

              int newId = int.Parse(cmd.ExecuteScalar().ToString());   //es izvrsava query
              s.Id = newId;
          }
          Projekat.Instance.spdu.Add(s);  //obrati paznju {azurira i stanje modela}
          return(s);
      }
Exemple #4
0
 public static void Delete(StavkaProdajeDU n)
 {
     using (var con = new SqlConnection(ConfigurationManager.ConnectionStrings["POP"].ConnectionString))
     {
         con.Open();
         SqlCommand cmd = con.CreateCommand();
         cmd.CommandText = "Delete  StavkaDUsluge where Id=@Id";
         cmd.Parameters.AddWithValue("Id", n.Id);
         cmd.ExecuteNonQuery();
         foreach (var spdu in Projekat.Instance.spdu)
         {
             if (spdu.Id == n.Id)
             {
                 Projekat.Instance.spdu.Remove(spdu);
                 break;
             }
         }
     }
 }
 private Projekat()
 {
     TN = TipNamestaja.GetAll();
     //Console.WriteLine("1");
     namestaj = Namestaj.GetAll();
     // Console.WriteLine("2");
     korisnik = Korisnik.GetAll();
     // Console.WriteLine("3");
     DU = DodatnaUsluga.GetAll();
     //  Console.WriteLine("4");
     pn = Racun.GetAll();
     //  Console.WriteLine("5");
     akcija = AkcijskaProdaja.GetAll();
     //  Console.WriteLine("6");
     spn = StavkaProdajeNamestaj.GetAll();
     // Console.WriteLine("7");
     spdu = StavkaProdajeDU.GetAll();
     //  Console.WriteLine("8");
 }