Пример #1
0
        public static ObservableCollection <ProdajaNamestaja> GetAllProdajaNamestaja()
        {
            try
            {
                var listaProdaje = new ObservableCollection <ProdajaNamestaja>();
                using (var con = new SqlConnection(ConfigurationManager.ConnectionStrings["POP"].ConnectionString))
                {
                    SqlCommand     cmd = con.CreateCommand();
                    SqlDataAdapter da  = new SqlDataAdapter();
                    DataSet        ds  = new DataSet();

                    cmd.CommandText  = "SELECT * FROM ProdajaNamestaja WHERE Obrisan=0;";
                    da.SelectCommand = cmd;
                    da.Fill(ds, "ProdajaNamestaja");

                    foreach (DataRow row in ds.Tables["ProdajaNamestaja"].Rows)
                    {
                        var p = new ProdajaNamestaja();
                        p.Id             = int.Parse(row["Id"].ToString());
                        p.DatumProdaje   = DateTime.Parse(row["DatumProdaje"].ToString());
                        p.BrojRacuna     = int.Parse(row["BrojRacuna"].ToString());
                        p.Kupac          = row["Kupac"].ToString();
                        p.UkupanIznos    = double.Parse(row["UkupanIznos"].ToString());
                        p.UkupanIznosPDV = double.Parse(row["UkupanIznosPDV"].ToString());
                        p.Obrisan        = bool.Parse(row["Obrisan"].ToString());

                        DataSet    ds2  = new DataSet();
                        SqlCommand cmd2 = con.CreateCommand();
                        ObservableCollection <Namestaj> namestajProdaja = new ObservableCollection <Namestaj>();
                        cmd2.CommandText = "SELECT NamestajZaProdajuId FROM ProdajaProzorNamestaj WHERE ProdajaNamestajaId=@ppid AND Obrisan=@obrisan";
                        cmd2.Parameters.AddWithValue("@ppid", p.Id);
                        cmd2.Parameters.AddWithValue("@obrisan", '0');
                        da.SelectCommand = cmd2;
                        da.Fill(ds2, "ProdajaProzorNamestaj");
                        foreach (DataRow row2 in ds2.Tables["ProdajaProzorNamestaj"].Rows)
                        {
                            int id = int.Parse(row2["NamestajZaProdajuId"].ToString());
                            namestajProdaja.Add(Namestaj.GetById(id));
                        }
                        p.NamestajNaProdaja = namestajProdaja;

                        DataSet    ds3  = new DataSet();
                        SqlCommand cmd3 = con.CreateCommand();
                        ObservableCollection <DodatnaUsluga> uslugaProdaja = new ObservableCollection <DodatnaUsluga>();
                        cmd3.CommandText = "SELECT DodatnaUslugaId FROM ProdajaProzorUsluga WHERE ProdajaNamestajaId=@plid AND Obrisan=@obr";
                        cmd3.Parameters.AddWithValue("@plid", p.Id);
                        cmd3.Parameters.AddWithValue("@obr", '0');
                        da.SelectCommand = cmd3;
                        da.Fill(ds3, "ProdajaProzorUsluga");
                        foreach (DataRow row3 in ds3.Tables["ProdajaProzorUsluga"].Rows)
                        {
                            int id = int.Parse(row3["DodatnaUslugaId"].ToString());
                            uslugaProdaja.Add(DodatnaUsluga.GetById(id));
                        }
                        p.DodatneUsluge = uslugaProdaja;

                        listaProdaje.Add(p);
                    }
                }
                return(listaProdaje);
            }
            catch (Exception)
            {
                MessageBox.Show("Problem prilikom ucitavanja prodaje namestaja!", "Info", MessageBoxButton.OK, MessageBoxImage.Information);
                return(null);
            }
        }
Пример #2
0
 public static void Delete(DodatnaUsluga ddd)
 {
     ddd.Obrisan = true;
     Update(ddd);
 }