Skip to content

Commit

Permalink
<feat: add reload function to refresh data in Add Product page>
Browse files Browse the repository at this point in the history
  • Loading branch information
eben4ya committed Nov 18, 2024
1 parent 1fc4b50 commit a610316
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions Appview/Views/AddProducts.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
}
}
}

0 comments on commit a610316

Please sign in to comment.