//wyświetlenie danych w oknie edycji materiału private void CableSelectEditCB_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (CableSelectEditCB.SelectedValue != null) { var a = Convert.ToInt32(CableSelectEditCB.SelectedValue.ToString()); Cable cable = db.Cables.FirstOrDefault(x => x.CableId == a); CableImageNew.Source = LoadImage(cable.Image); cableNameTextBox.Text = cable.CableName; cablePNTextBox.Text = cable.CablePN; stockTextBox.Text = cable.Stock.ToString(); minStockTextBox.Text = cable.MinStock.ToString(); orderedQtyTextBox.Text = cable.OrderedQty.ToString(); priceTextBox.Text = cable.Price.ToString(); descTextBox.Text = cable.Desc; } }
//zapis edycji/nowego materiału w bd private async void Button_Click_SaveItem(object sender, RoutedEventArgs e) { try { if (CableSelectEditCB.SelectedValue != null) { int num = Convert.ToInt32(CableSelectEditCB.SelectedValue.ToString()); var cable = db.Cables.Where(w => w.CableId == num).FirstOrDefault(); cable.Image = GetJPGFromImageControl((BitmapImage)CableImageNew.Source); cable.CableName = cableNameTextBox.Text; cable.CablePN = cablePNTextBox.Text; cable.Stock = Convert.ToInt32(stockTextBox.Text); cable.MinStock = Convert.ToInt32(minStockTextBox.Text); cable.OrderedQty = Convert.ToInt32(orderedQtyTextBox.Text); cable.Price = Convert.ToDecimal(priceTextBox.Text); cable.Desc = descTextBox.Text; } else { Cable cable = new Cable { Image = GetJPGFromImageControl((BitmapImage)CableImageNew.Source), CableName = cableNameTextBox.Text, CablePN = cablePNTextBox.Text, Stock = Convert.ToInt32(stockTextBox.Text), MinStock = Convert.ToInt32(minStockTextBox.Text), OrderedQty = Convert.ToInt32(orderedQtyTextBox.Text), Price = Convert.ToDecimal(priceTextBox.Text), Desc = descTextBox.Text }; db.Cables.Add(cable); } await db.SaveChangesAsync(); await ReloadDataAsync(); MessageBox.Show("Zapisano poprawnie"); } catch (Exception error) { MessageBox.Show(error.Message); } }