using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using Comal.Classes;
using InABox.Configuration;
using InABox.Core;
using InABox.DynamicGrid;
using InABox.Wpf;
namespace PRSDesktop
{
public class ReadyToGoGlobalSettings : BaseObject, IGlobalConfigurationSettings
{
public int PageSize { get; set; } = 5000;
}
///
/// Interaction logic for ItemsPanel.xaml
///
public partial class ReadyToGoPanel : UserControl, IPanel
{
private ReadyToGoGlobalSettings _globalSettings = new();
public ReadyToGoPanel()
{
_globalSettings = new GlobalConfiguration().Load();
InitializeComponent();
}
public bool IsReady { get; set; }
public event DataModelUpdateEvent? OnUpdateDataModel;
public Dictionary Selected()
{
return new Dictionary(); // { { typeof(DeliveryItem).EntityName(), Items.SelectedRows } };
}
public void Setup()
{
Items.Options.PageSize = _globalSettings.PageSize;
Items.Refresh(true, false);
}
public void Shutdown(CancelEventArgs? cancel)
{
}
public void CreateToolbarButtons(IPanelHost host)
{
host.CreateSetupAction(new PanelAction() { Caption = "Delivered On Site Settings", Image = PRSDesktop.Resources.product, OnExecute =
(obj) =>
{
var grid = new DynamicItemsListGrid();
if (grid.EditItems(new ReadyToGoGlobalSettings[] { _globalSettings }))
{
new GlobalConfiguration().Save(_globalSettings);
Items.Options.PageSize = _globalSettings.PageSize;
Refresh();
}
}
});
}
public void Refresh()
{
Items.Refresh(false, true);
}
public string SectionName => "Ready To Go";
public DataModel DataModel(Selection selection)
{
var ids = Items.ExtractValues(x => x.ID, selection).ToArray();
return new DeliveryItemDataModel(new Filter(x => x.ID).InList(ids));
}
public void Heartbeat(TimeSpan time)
{
}
public Type DataType()
{
return typeof(DeliveryItem);
}
private void SearchBox_KeyUp(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
Items.Search = SearchBox.Text;
Items.Refresh(false, true);
}
}
private void ClearSearchButton_Click(object sender, RoutedEventArgs e)
{
Items.Search = "";
Items.Refresh(false, true);
}
}
}