using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Windows.Controls;
using com.healthmarketscience.jackcess.impl;
using Comal.Classes;
using InABox.Clients;
using InABox.Configuration;
using InABox.Core;
using InABox.DynamicGrid;
using InABox.Wpf;
using Syncfusion.Pdf.Parsing;
namespace PRSDesktop;
public class JobRequisitionPanelSettings : IUserConfigurationSettings, ISplitPanelSettings
{
public DynamicSplitPanelView ViewType { get; set; } = DynamicSplitPanelView.Combined;
public double AnchorWidth { get; set; } = 500;
}
///
/// Interaction logic for JobMaterialPanel.xaml
///
public partial class JobRequisitionPanel : UserControl, IPanel, IMasterDetailControl
{
private JobRequisitionPanelSettings Settings;
public JobRequisitionPanel()
{
InitializeComponent();
}
private void LoadSettings()
{
Settings = new UserConfiguration().Load();
SplitPanel.AnchorWidth = Settings.AnchorWidth;
SplitPanel.View = Settings.ViewType;
}
protected void SaveSettings()
{
Settings.AnchorWidth = SplitPanel.AnchorWidth;
Settings.ViewType = SplitPanel.View;
Settings.SaveUser();
}
public Job? Master
{
get => Requisitions.Master;
set => Requisitions.Master = value;
}
public bool IsReady { get; set; }
public event DataModelUpdateEvent? OnUpdateDataModel;
public void CreateToolbarButtons(IPanelHost host)
{
}
public void Setup()
{
LoadSettings();
Requisitions.Refresh(true, false);
Items.Refresh(true, false);
}
public void Shutdown(CancelEventArgs? cancel)
{
}
public void Refresh()
{
if(Settings.ViewType == DynamicSplitPanelView.Detail)
{
Items.Master = null;
Items.Job = Master;
Items.Refresh(false, true);
}
else
{
Requisitions.Refresh(false, true);
}
}
public string SectionName => "Job Requisitions";
public DataModel DataModel(Selection selection)
{
var ids = Requisitions.ExtractValues(x => x.ID, selection).ToArray();
return new AutoDataModel(new Filter(c => c.ID).InList(ids));
}
public Dictionary Selected()
{
return new Dictionary
{
{ typeof(JobRequisition).EntityName(), Requisitions.SelectedRows }
};
}
public void Heartbeat(TimeSpan time)
{
}
private void Requisitions_OnSelectItem(object sender, DynamicGridSelectionEventArgs e)
{
Items.Master = e.Rows?.FirstOrDefault()?.ToObject();
Items.Refresh(false, true);
}
private void SplitPanel_OnChanged(object sender, DynamicSplitPanelSettings e)
{
var changedView = e.View != Settings.ViewType;
SaveSettings();
if (changedView)
{
Refresh();
}
}
}