Пример #1
0
        public static ProdajaNamestaja Create(ProdajaNamestaja tn)
        {
            try
            {
                using (var con = new SqlConnection(ConfigurationManager.ConnectionStrings["POP"].ConnectionString))
                {
                    con.Open();

                    SqlCommand cmd = con.CreateCommand();

                    cmd.CommandText  = "INSERT INTO Prodaja (DatumProdaje, BrojRacuna, Kupac, UkupanIznos) VALUES (@DatumProdaje, @BrojRacuna, @Kupac, @UkupanIznos);";
                    cmd.CommandText += "SELECT SCOPE_IDENTITY();";

                    cmd.Parameters.AddWithValue("DatumProdaje", tn.DatumProdaje);
                    cmd.Parameters.AddWithValue("BrojRacuna", tn.BrojRacuna);
                    cmd.Parameters.AddWithValue("Kupac", tn.Kupac);
                    cmd.Parameters.AddWithValue("UkupanIznos", tn.UkupanIznos);

                    tn.Id = int.Parse(cmd.ExecuteScalar().ToString());
                }

                Projekat.Instance.ProdajeNamestaja.Add(tn);

                return(tn);
            }
            catch (Exception)
            {
                MessageBoxResult obavestenje = MessageBox.Show("Doslo je do greske.", "Obavestenje", MessageBoxButton.OK);
                return(null);
            }
        }
Пример #2
0
        public static ObservableCollection <ProdajaNamestaja> Search(string srchtext, string sorttext)
        {
            var prodaje = new ObservableCollection <ProdajaNamestaja>();

            using (var con = new SqlConnection(ConfigurationManager.ConnectionStrings["POP"].ConnectionString))
            {
                SqlCommand     cmd = con.CreateCommand();
                SqlDataAdapter da  = new SqlDataAdapter();
                DataSet        ds  = new DataSet();

                string selectCommand = "SELECT * FROM Prodaja WHERE Kupac LIKE @srchtext OR DatumProdaje LIKE @srchtext OR UkupanIznos LIKE @srchtext ORDER BY ";
                selectCommand  += sorttext;
                cmd.CommandText = selectCommand;
                cmd.Parameters.AddWithValue("@srchtext", "%" + srchtext + "%");
                da.SelectCommand = cmd;
                da.Fill(ds, "Prodaja");

                foreach (DataRow row in ds.Tables["Prodaja"].Rows)
                {
                    var tn = new ProdajaNamestaja();
                    tn.Id           = Convert.ToInt32(row["Id"]);
                    tn.DatumProdaje = DateTime.Parse(row["DatumProdaje"].ToString());
                    tn.BrojRacuna   = Convert.ToInt32(row["BrojRacuna"]);
                    tn.Kupac        = row["Kupac"].ToString();
                    tn.UkupanIznos  = double.Parse(row["UkupanIznos"].ToString());

                    prodaje.Add(tn);
                }
                return(prodaje);
            }
        }
Пример #3
0
        public static ObservableCollection <ProdajaNamestaja> GetAll()
        {
            var prodaje = 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 Prodaja;";
                da.SelectCommand = cmd;
                da.Fill(ds, "Prodaja");

                foreach (DataRow row in ds.Tables["Prodaja"].Rows)
                {
                    var tn = new ProdajaNamestaja();
                    tn.Id           = Convert.ToInt32(row["Id"]);
                    tn.DatumProdaje = DateTime.Parse(row["DatumProdaje"].ToString());
                    tn.BrojRacuna   = Convert.ToInt32(row["BrojRacuna"]);
                    tn.Kupac        = row["Kupac"].ToString();
                    tn.UkupanIznos  = double.Parse(row["UkupanIznos"].ToString());

                    prodaje.Add(tn);
                }
            }
            return(prodaje);
        }
Пример #4
0
 private Projekat()
 {
     Namestaji        = Namestaj.GetAll();
     TipoviNamestaja  = TipNamestaja.GetAll();
     Korisnici        = Korisnik.GetAll();
     DodatneUsluge    = DodatnaUsluga.GetAll();
     ProdajeNamestaja = ProdajaNamestaja.GetAll();
     StavkeProdaje    = StavkaProdaje.GetAll();
     UslugeProdaje    = UslugaProdaje.GetAll();
     Akcije           = Akcija.GetAll();
     NaAkcijama       = NaAkciji.GetAll();
     Saloni           = Salon.GetAll();
 }
Пример #5
0
        public static void Delete(ProdajaNamestaja p)
        {
            using (var con = new SqlConnection(ConfigurationManager.ConnectionStrings["POP"].ConnectionString))
            {
                con.Open();

                SqlCommand cmd = con.CreateCommand();

                cmd.CommandText  = "DELETE FROM Prodaja WHERE Id=@Id;";
                cmd.CommandText += "SELECT SCOPE_IDENTITY();";
                cmd.Parameters.AddWithValue("Id", p.Id);

                cmd.ExecuteNonQuery();
            }
        }
Пример #6
0
        public static void Update(ProdajaNamestaja tn)
        {
            try
            {
                //azuriranje baze
                using (var con = new SqlConnection(ConfigurationManager.ConnectionStrings["POP"].ConnectionString))
                {
                    con.Open();

                    SqlCommand cmd = con.CreateCommand();

                    cmd.CommandText = "UPDATE Prodaja SET DatumProdaje = @DatumProdaje, BrojRacuna = @BrojRacuna, " +
                                      "Kupac = @Kupac, UkupanIznos = @UkupanIznos WHERE Id=@Id;";
                    cmd.CommandText += "SELECT SCOPE_IDENTITY();";
                    cmd.Parameters.AddWithValue("Id", tn.Id);
                    cmd.Parameters.AddWithValue("DatumProdaje", tn.DatumProdaje);
                    cmd.Parameters.AddWithValue("BrojRacuna", tn.BrojRacuna);
                    cmd.Parameters.AddWithValue("Kupac", tn.Kupac);
                    cmd.Parameters.AddWithValue("UkupanIznos", tn.UkupanIznos);

                    cmd.ExecuteNonQuery();
                }
                //azuriranje modela
                foreach (var tip in Projekat.Instance.ProdajeNamestaja)
                {
                    if (tn.Id == tip.Id)
                    {
                        tip.DatumProdaje = tn.DatumProdaje;
                        tip.BrojRacuna   = tn.BrojRacuna;
                        tip.Kupac        = tn.Kupac;
                        tip.UkupanIznos  = tn.UkupanIznos;
                    }
                }
            }
            catch (Exception)
            {
            }
        }