private void DodajNamestajUProdaju(ProdatNamestaj namestaj) { StackPanel stackPanel = new StackPanel(); ComboBox comboBox = new ComboBox(); Button button = new Button(); TextBox textBox = new TextBox(); button.Content = "-"; button.Width = 20; button.Background = (SolidColorBrush) new BrushConverter().ConvertFrom("#FF252526"); button.Foreground = Brushes.White; comboBox.Width = 200; comboBox.IsEditable = true; comboBox.ItemsSource = NamestajDataProvider.Instance.GetAll(); button.Click += new RoutedEventHandler(btnDeleteNamestaj); if (namestaj != null) { comboBox.SelectedIndex = namestaj.NamestajID - 1; textBox.Text = namestaj.Kolicina.ToString(); } textBox.Width = 50; stackPanel.Orientation = Orientation.Horizontal; stackPanel.Margin = new Thickness(5); stackPanel.Children.Add(comboBox); stackPanel.Children.Add(textBox); stackPanel.Children.Add(button); spNamestaji.Children.Add(stackPanel); }
public ObservableCollection <ProdatNamestaj> Get(int prodajaId) { ObservableCollection <ProdatNamestaj> prodatNamestaj = new ObservableCollection <ProdatNamestaj>(); using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["POP"].ConnectionString)) { SqlCommand cmd = con.CreateCommand(); cmd.CommandText = "SELECT NamestajId, Kolicina FROM ProdatNamestaj WHERE ProdajaId=@ProdajaId"; cmd.Parameters.AddWithValue("ProdajaId", prodajaId); DataSet dataSet = new DataSet(); SqlDataAdapter adapter = new SqlDataAdapter(); adapter.SelectCommand = cmd; adapter.Fill(dataSet, "IzvrsenaDodatnaUsluga"); foreach (DataRow row in dataSet.Tables["IzvrsenaDodatnaUsluga"].Rows) { ProdatNamestaj pd = new ProdatNamestaj(); pd.Kolicina = int.Parse(row["Kolicina"].ToString()); pd.NamestajID = int.Parse(row["NamestajId"].ToString()); prodatNamestaj.Add(pd); } } return(prodatNamestaj); }