ee67bedc31
Implementato il calcolo del valore reale dei prodotti in asta, includendo il prezzo "Compra Subito", spese di spedizione e risparmio stimato. Aggiunta una nuova sezione "Info Prodotto" nella UI per visualizzare i dettagli estratti e i calcoli. - **AuctionMonitorControl.xaml**: Aggiunta sezione fissa per mostrare informazioni prodotto e calcolo valore. - **AuctionMonitorControl.xaml.cs**: Gestiti eventi per il caricamento e aggiornamento delle informazioni prodotto. - **MainWindow**: Integrati handler per il calcolo e refresh delle informazioni prodotto. - **AuctionInfo.cs**: Aggiunte proprietà per gestire prezzo "Compra Subito", spese di spedizione e limiti di vincita. - **ProductValueCalculator.cs**: Nuova utility per calcolare il valore del prodotto e parsare informazioni dall'HTML. - **AuctionViewModel.cs**: Binding per visualizzare risparmio, costo totale e convenienza nella UI. - **Documentazione**: Aggiornata con dettagli sull'algoritmo di calcolo e layout UI. Fix: - Risolto problema di encoding UTF-8 per emoji nella UI. - Migliorato parsing HTML per prezzi e limiti di vincita. TODO: - Testare parsing su più aste e gestire edge cases. - Implementare caricamento automatico delle informazioni.
383 lines
16 KiB
C#
383 lines
16 KiB
C#
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Input;
|
|
|
|
namespace AutoBidder.Controls
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for AuctionMonitorControl.xaml
|
|
/// </summary>
|
|
public partial class AuctionMonitorControl : UserControl
|
|
{
|
|
public AuctionMonitorControl()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
// Dependency Properties per Commands (da bindare al MainWindow)
|
|
public static readonly DependencyProperty GridStartCommandProperty =
|
|
DependencyProperty.Register(nameof(GridStartCommand), typeof(ICommand), typeof(AuctionMonitorControl));
|
|
|
|
public static readonly DependencyProperty GridPauseCommandProperty =
|
|
DependencyProperty.Register(nameof(GridPauseCommand), typeof(ICommand), typeof(AuctionMonitorControl));
|
|
|
|
public static readonly DependencyProperty GridStopCommandProperty =
|
|
DependencyProperty.Register(nameof(GridStopCommand), typeof(ICommand), typeof(AuctionMonitorControl));
|
|
|
|
public static readonly DependencyProperty GridBidCommandProperty =
|
|
DependencyProperty.Register(nameof(GridBidCommand), typeof(ICommand), typeof(AuctionMonitorControl));
|
|
|
|
public ICommand? GridStartCommand
|
|
{
|
|
get => (ICommand?)GetValue(GridStartCommandProperty);
|
|
set => SetValue(GridStartCommandProperty, value);
|
|
}
|
|
|
|
public ICommand? GridPauseCommand
|
|
{
|
|
get => (ICommand?)GetValue(GridPauseCommandProperty);
|
|
set => SetValue(GridPauseCommandProperty, value);
|
|
}
|
|
|
|
public ICommand? GridStopCommand
|
|
{
|
|
get => (ICommand?)GetValue(GridStopCommandProperty);
|
|
set => SetValue(GridStopCommandProperty, value);
|
|
}
|
|
|
|
public ICommand? GridBidCommand
|
|
{
|
|
get => (ICommand?)GetValue(GridBidCommandProperty);
|
|
set => SetValue(GridBidCommandProperty, value);
|
|
}
|
|
|
|
// Event handlers - these will bubble up to MainWindow
|
|
private void StartButton_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
RaiseEvent(new RoutedEventArgs(StartClickedEvent, this));
|
|
}
|
|
|
|
private void PauseAllButton_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
RaiseEvent(new RoutedEventArgs(PauseAllClickedEvent, this));
|
|
}
|
|
|
|
private void StopButton_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
RaiseEvent(new RoutedEventArgs(StopClickedEvent, this));
|
|
}
|
|
|
|
private void AddUrlButton_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
RaiseEvent(new RoutedEventArgs(AddUrlClickedEvent, this));
|
|
}
|
|
|
|
private void RemoveUrlButton_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
RaiseEvent(new RoutedEventArgs(RemoveUrlClickedEvent, this));
|
|
}
|
|
|
|
private void ExportButton_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
RaiseEvent(new RoutedEventArgs(ExportClickedEvent, this));
|
|
}
|
|
|
|
private void MultiAuctionsGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
{
|
|
// Forza il focus sul DataGrid quando viene selezionata una riga
|
|
// Questo assicura che il tasto Canc venga catturato
|
|
if (sender is DataGrid grid && grid.SelectedItem != null)
|
|
{
|
|
// Attende che il rendering sia completo prima di dare il focus
|
|
grid.Dispatcher.BeginInvoke(new Action(() =>
|
|
{
|
|
if (!grid.IsFocused)
|
|
{
|
|
grid.Focus();
|
|
System.Diagnostics.Debug.WriteLine("[FOCUS] DataGrid ora ha il focus keyboard");
|
|
}
|
|
}), System.Windows.Threading.DispatcherPriority.Background);
|
|
}
|
|
|
|
RaiseEvent(new RoutedEventArgs(AuctionSelectionChangedEvent, this));
|
|
}
|
|
|
|
// Usato PreviewKeyDown invece di KeyDown per catturare l'evento prima che venga consumato
|
|
private void MultiAuctionsGrid_PreviewKeyDown(object sender, KeyEventArgs e)
|
|
{
|
|
if (e.Key == Key.Delete && MultiAuctionsGrid.SelectedItem != null)
|
|
{
|
|
System.Diagnostics.Debug.WriteLine("[DELETE KEY] Tasto Canc premuto su asta selezionata");
|
|
|
|
// Lancia direttamente l'evento senza chiedere conferma
|
|
// La conferma verrà mostrata dal gestore RemoveUrlButton_Click
|
|
System.Diagnostics.Debug.WriteLine("[DELETE KEY] Lancio evento RemoveUrlClicked");
|
|
RaiseEvent(new RoutedEventArgs(RemoveUrlClickedEvent, this));
|
|
|
|
// Previeni che l'evento venga gestito da altri controlli
|
|
e.Handled = true;
|
|
}
|
|
}
|
|
|
|
private void CopyAuctionUrlButton_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
RaiseEvent(new RoutedEventArgs(CopyUrlClickedEvent, this));
|
|
}
|
|
|
|
private void ResetSettingsButton_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
RaiseEvent(new RoutedEventArgs(ResetSettingsClickedEvent, this));
|
|
}
|
|
|
|
private void ClearBiddersButton_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
RaiseEvent(new RoutedEventArgs(ClearBiddersClickedEvent, this));
|
|
}
|
|
|
|
private void ClearLogButton_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
RaiseEvent(new RoutedEventArgs(ClearLogClickedEvent, this));
|
|
}
|
|
|
|
private void ClearGlobalLogButton_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
RaiseEvent(new RoutedEventArgs(ClearGlobalLogClickedEvent, this));
|
|
}
|
|
|
|
private void OpenAuctionInternalButton_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
RaiseEvent(new RoutedEventArgs(OpenAuctionInternalClickedEvent, this));
|
|
}
|
|
|
|
private void OpenAuctionExternalButton_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
RaiseEvent(new RoutedEventArgs(OpenAuctionExternalClickedEvent, this));
|
|
}
|
|
|
|
private void ExportAuctionButton_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
RaiseEvent(new RoutedEventArgs(ExportAuctionClickedEvent, this));
|
|
}
|
|
|
|
private void RefreshProductInfoButton_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
RaiseEvent(new RoutedEventArgs(RefreshProductInfoClickedEvent, this));
|
|
}
|
|
|
|
private void SelectedBidBeforeDeadlineMs_TextChanged(object sender, TextChangedEventArgs e)
|
|
{
|
|
RaiseEvent(new RoutedEventArgs(BidBeforeDeadlineMsChangedEvent, this));
|
|
}
|
|
|
|
private void SelectedCheckAuctionOpen_Changed(object sender, RoutedEventArgs e)
|
|
{
|
|
RaiseEvent(new RoutedEventArgs(CheckAuctionOpenChangedEvent, this));
|
|
}
|
|
|
|
private void SelectedMinPrice_TextChanged(object sender, TextChangedEventArgs e)
|
|
{
|
|
RaiseEvent(new RoutedEventArgs(MinPriceChangedEvent, this));
|
|
}
|
|
|
|
private void SelectedMaxPrice_TextChanged(object sender, TextChangedEventArgs e)
|
|
{
|
|
RaiseEvent(new RoutedEventArgs(MaxPriceChangedEvent, this));
|
|
}
|
|
|
|
private void SelectedMaxClicks_TextChanged(object sender, TextChangedEventArgs e)
|
|
{
|
|
RaiseEvent(new RoutedEventArgs(MaxClicksChangedEvent, this));
|
|
}
|
|
|
|
// Routed Events
|
|
public static readonly RoutedEvent StartClickedEvent = EventManager.RegisterRoutedEvent(
|
|
"StartClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(AuctionMonitorControl));
|
|
|
|
public static readonly RoutedEvent PauseAllClickedEvent = EventManager.RegisterRoutedEvent(
|
|
"PauseAllClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(AuctionMonitorControl));
|
|
|
|
public static readonly RoutedEvent StopClickedEvent = EventManager.RegisterRoutedEvent(
|
|
"StopClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(AuctionMonitorControl));
|
|
|
|
public static readonly RoutedEvent AddUrlClickedEvent = EventManager.RegisterRoutedEvent(
|
|
"AddUrlClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(AuctionMonitorControl));
|
|
|
|
public static readonly RoutedEvent RemoveUrlClickedEvent = EventManager.RegisterRoutedEvent(
|
|
"RemoveUrlClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(AuctionMonitorControl));
|
|
|
|
public static readonly RoutedEvent ExportClickedEvent = EventManager.RegisterRoutedEvent(
|
|
"ExportClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(AuctionMonitorControl));
|
|
|
|
public static readonly RoutedEvent AuctionSelectionChangedEvent = EventManager.RegisterRoutedEvent(
|
|
"AuctionSelectionChanged", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(AuctionMonitorControl));
|
|
|
|
public static readonly RoutedEvent CopyUrlClickedEvent = EventManager.RegisterRoutedEvent(
|
|
"CopyUrlClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(AuctionMonitorControl));
|
|
|
|
public static readonly RoutedEvent ResetSettingsClickedEvent = EventManager.RegisterRoutedEvent(
|
|
"ResetSettingsClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(AuctionMonitorControl));
|
|
|
|
public static readonly RoutedEvent ClearBiddersClickedEvent = EventManager.RegisterRoutedEvent(
|
|
"ClearBiddersClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(AuctionMonitorControl));
|
|
|
|
public static readonly RoutedEvent ClearLogClickedEvent = EventManager.RegisterRoutedEvent(
|
|
"ClearLogClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(AuctionMonitorControl));
|
|
|
|
public static readonly RoutedEvent ClearGlobalLogClickedEvent = EventManager.RegisterRoutedEvent(
|
|
"ClearGlobalLogClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(AuctionMonitorControl));
|
|
|
|
public static readonly RoutedEvent BidBeforeDeadlineMsChangedEvent = EventManager.RegisterRoutedEvent(
|
|
"BidBeforeDeadlineMsChanged", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(AuctionMonitorControl));
|
|
|
|
public static readonly RoutedEvent CheckAuctionOpenChangedEvent = EventManager.RegisterRoutedEvent(
|
|
"CheckAuctionOpenChanged", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(AuctionMonitorControl));
|
|
|
|
public static readonly RoutedEvent MinPriceChangedEvent = EventManager.RegisterRoutedEvent(
|
|
"MinPriceChanged", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(AuctionMonitorControl));
|
|
|
|
public static readonly RoutedEvent MaxPriceChangedEvent = EventManager.RegisterRoutedEvent(
|
|
"MaxPriceChanged", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(AuctionMonitorControl));
|
|
|
|
public static readonly RoutedEvent MaxClicksChangedEvent = EventManager.RegisterRoutedEvent(
|
|
"MaxClicksChanged", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(AuctionMonitorControl));
|
|
|
|
public static readonly RoutedEvent OpenAuctionInternalClickedEvent = EventManager.RegisterRoutedEvent(
|
|
"OpenAuctionInternalClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(AuctionMonitorControl));
|
|
|
|
public static readonly RoutedEvent OpenAuctionExternalClickedEvent = EventManager.RegisterRoutedEvent(
|
|
"OpenAuctionExternalClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(AuctionMonitorControl));
|
|
|
|
public static readonly RoutedEvent ExportAuctionClickedEvent = EventManager.RegisterRoutedEvent(
|
|
"ExportAuctionClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(AuctionMonitorControl));
|
|
|
|
public static readonly RoutedEvent RefreshProductInfoClickedEvent = EventManager.RegisterRoutedEvent(
|
|
"RefreshProductInfoClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(AuctionMonitorControl));
|
|
|
|
public event RoutedEventHandler StartClicked
|
|
{
|
|
add { AddHandler(StartClickedEvent, value); }
|
|
remove { RemoveHandler(StartClickedEvent, value); }
|
|
}
|
|
|
|
public event RoutedEventHandler PauseAllClicked
|
|
{
|
|
add { AddHandler(PauseAllClickedEvent, value); }
|
|
remove { RemoveHandler(PauseAllClickedEvent, value); }
|
|
}
|
|
|
|
public event RoutedEventHandler StopClicked
|
|
{
|
|
add { AddHandler(StopClickedEvent, value); }
|
|
remove { RemoveHandler(StopClickedEvent, value); }
|
|
}
|
|
|
|
public event RoutedEventHandler AddUrlClicked
|
|
{
|
|
add { AddHandler(AddUrlClickedEvent, value); }
|
|
remove { RemoveHandler(AddUrlClickedEvent, value); }
|
|
}
|
|
|
|
public event RoutedEventHandler RemoveUrlClicked
|
|
{
|
|
add { AddHandler(RemoveUrlClickedEvent, value); }
|
|
remove { RemoveHandler(RemoveUrlClickedEvent, value); }
|
|
}
|
|
|
|
public event RoutedEventHandler ExportClicked
|
|
{
|
|
add { AddHandler(ExportClickedEvent, value); }
|
|
remove { RemoveHandler(ExportClickedEvent, value); }
|
|
}
|
|
|
|
public event RoutedEventHandler AuctionSelectionChanged
|
|
{
|
|
add { AddHandler(AuctionSelectionChangedEvent, value); }
|
|
remove { RemoveHandler(AuctionSelectionChangedEvent, value); }
|
|
}
|
|
|
|
public event RoutedEventHandler CopyUrlClicked
|
|
{
|
|
add { AddHandler(CopyUrlClickedEvent, value); }
|
|
remove { RemoveHandler(CopyUrlClickedEvent, value); }
|
|
}
|
|
|
|
public event RoutedEventHandler ResetSettingsClicked
|
|
{
|
|
add { AddHandler(ResetSettingsClickedEvent, value); }
|
|
remove { RemoveHandler(ResetSettingsClickedEvent, value); }
|
|
}
|
|
|
|
public event RoutedEventHandler ClearBiddersClicked
|
|
{
|
|
add { AddHandler(ClearBiddersClickedEvent, value); }
|
|
remove { RemoveHandler(ClearBiddersClickedEvent, value); }
|
|
}
|
|
|
|
public event RoutedEventHandler ClearLogClicked
|
|
{
|
|
add { AddHandler(ClearLogClickedEvent, value); }
|
|
remove { RemoveHandler(ClearLogClickedEvent, value); }
|
|
}
|
|
|
|
public event RoutedEventHandler ClearGlobalLogClicked
|
|
{
|
|
add { AddHandler(ClearGlobalLogClickedEvent, value); }
|
|
remove { RemoveHandler(ClearGlobalLogClickedEvent, value); }
|
|
}
|
|
|
|
public event RoutedEventHandler BidBeforeDeadlineMsChanged
|
|
{
|
|
add { AddHandler(BidBeforeDeadlineMsChangedEvent, value); }
|
|
remove { RemoveHandler(BidBeforeDeadlineMsChangedEvent, value); }
|
|
}
|
|
|
|
public event RoutedEventHandler CheckAuctionOpenChanged
|
|
{
|
|
add { AddHandler(CheckAuctionOpenChangedEvent, value); }
|
|
remove { RemoveHandler(CheckAuctionOpenChangedEvent, value); }
|
|
}
|
|
|
|
public event RoutedEventHandler MinPriceChanged
|
|
{
|
|
add { AddHandler(MinPriceChangedEvent, value); }
|
|
remove { RemoveHandler(MinPriceChangedEvent, value); }
|
|
}
|
|
|
|
public event RoutedEventHandler MaxPriceChanged
|
|
{
|
|
add { AddHandler(MaxPriceChangedEvent, value); }
|
|
remove { RemoveHandler(MaxPriceChangedEvent, value); }
|
|
}
|
|
|
|
public event RoutedEventHandler MaxClicksChanged
|
|
{
|
|
add { AddHandler(MaxClicksChangedEvent, value); }
|
|
remove { RemoveHandler(MaxClicksChangedEvent, value); }
|
|
}
|
|
|
|
public event RoutedEventHandler OpenAuctionInternalClicked
|
|
{
|
|
add { AddHandler(OpenAuctionInternalClickedEvent, value); }
|
|
remove { RemoveHandler(OpenAuctionInternalClickedEvent, value); }
|
|
}
|
|
|
|
public event RoutedEventHandler OpenAuctionExternalClicked
|
|
{
|
|
add { AddHandler(OpenAuctionExternalClickedEvent, value); }
|
|
remove { RemoveHandler(OpenAuctionExternalClickedEvent, value); }
|
|
}
|
|
|
|
public event RoutedEventHandler ExportAuctionClicked
|
|
{
|
|
add { AddHandler(ExportAuctionClickedEvent, value); }
|
|
remove { RemoveHandler(ExportAuctionClickedEvent, value); }
|
|
}
|
|
|
|
public event RoutedEventHandler RefreshProductInfoClicked
|
|
{
|
|
add { AddHandler(RefreshProductInfoClickedEvent, value); }
|
|
remove { RemoveHandler(RefreshProductInfoClickedEvent, value); }
|
|
}
|
|
}
|
|
}
|