From a6103166a2de8a7f2a56158dbf6729b4b3ce58b0 Mon Sep 17 00:00:00 2001 From: eben4ya Date: Mon, 18 Nov 2024 07:46:31 +0700 Subject: [PATCH] --- Appview/Views/AddProducts.xaml.cs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Appview/Views/AddProducts.xaml.cs b/Appview/Views/AddProducts.xaml.cs index fe06741..2527c3f 100644 --- a/Appview/Views/AddProducts.xaml.cs +++ b/Appview/Views/AddProducts.xaml.cs @@ -29,6 +29,22 @@ public AddProducts() DataContext = new GetProductFromDB(); } + private void ReloadData() + { + // Function to reload data from database + var mainWindow = Application.Current.MainWindow as MainWindow; + + if (mainWindow != null) + { + // Make instance from this page + var newPage = new AddProducts(); + + // Set main window content to this page + mainWindow.Content = newPage; + } + } + + private void Button_Click(object sender, RoutedEventArgs e) { var loginPage = new TodayOrder(); @@ -95,9 +111,19 @@ private void Button_Click_1(object sender, RoutedEventArgs e) MessageBox.Show("Stok harus berupa angka bulat yang valid.", "Kesalahan Input", MessageBoxButton.OK, MessageBoxImage.Error); return; // Kembali jika parsing gagal } + + if (datePickerTanggalKadaluarsa.SelectedDate == null) + { + MessageBox.Show("Silakan pilih tanggal kadaluarsa yang valid.", "Kesalahan Input", MessageBoxButton.OK, MessageBoxImage.Error); + return; // Kembali jika tidak ada tanggal yang dipilih + } + DateTime expiryDate = datePickerTanggalKadaluarsa.SelectedDate.Value; AddProductToDatabase(productName, price, quantity, expiryDate, description); + + // Reload page to refresh data + ReloadData(); } } }