using System.Linq;
using System.Windows;
using Comal.Classes;
using InABox.Configuration;
using InABox.DynamicGrid;
using InABox.Wpf;
namespace PRSDesktop
{
///
/// Interaction logic for ScheduleSettings.xaml
///
public partial class FactorySettings : ThemableWindow
{
private readonly GlobalConfiguration config = new();
private readonly FactorySetup settings;
public FactorySettings()
{
InitializeComponent();
settings = config.Load();
Groups.OnSelectItem += Groups_OnSelectItem;
Groups.Groups = settings.Groups;
Groups.Refresh(true, true);
Sections.Sections = settings.Sections;
Sections.Refresh(true, true);
//Stages.Model.RowHeights.DefaultLineSize = 20;
//Stages.Model.ColumnCount = 8;
//Stages.Model.ColumnWidths[0] = 20;
//Stages.Model.ColumnWidths[1] = 20;
//Stages.Model.ColumnWidths[2] = 0;
//Stages.Model.ColumnWidths[3] = 0;
//Stages.Model.ColumnWidths[4] = 0;
//Stages.Model.ColumnWidths[5] = 50;
//Stages.Model.ColumnWidths[6] = 20;
//Stages.Model.ColumnWidths[7] = 20;
//Stages.Model.HeaderColumns = 0;
//Stages.Model.RowCount = 0;
//Stages.Model.RowCount = settings.Sections.Count + 2;
}
private void Groups_OnSelectItem(object sender, DynamicGridSelectionEventArgs e)
{
Sections.CurrentGroup = e.Rows?.FirstOrDefault()?.Get(x => x.Group) ?? "";
Sections.Refresh(false, true);
}
//private void Stages_SizeChanged(object sender, SizeChangedEventArgs e)
//{
// Stages.Model.ColumnWidths[3] = (e.NewSize.Width - 130) / 3;
// Stages.Model.ColumnWidths[4] = (e.NewSize.Width - 130) * 2 / 3;
//}
//private void Stages_QueryCellInfo(object sender, Syncfusion.Windows.Controls.Grid.GridQueryCellInfoEventArgs e)
//{
// try
// {
// int row = e.Cell.RowIndex - 1;
// int col = e.Cell.ColumnIndex;
// switch (col)
// {
// case 0:
// if ((row == -1) || ((row > 0) && (row < settings.Sections.Count)))
// GridUtils.SetButtonImage(e.Style, PRSDesktop.Resources.uparrow, Stages.Model, col);
// else
// GridUtils.SetButtonImage(e.Style, null, Stages.Model, col);
// break;
// case 1:
// if (row < settings.Sections.Count - 1)
// GridUtils.SetButtonImage(e.Style, PRSDesktop.Resources.downarrow, Stages.Model, col);
// else
// GridUtils.SetButtonImage(e.Style, null, Stages.Model, col);
// break;
// case 2:
// if (row == -1)
// e.Style.CellValue = "Guid";
// else if (row < settings.Sections.Count)
// e.Style.CellValue = settings.Sections[row].ID.ToString();
// else
// e.Style.CellValue = "";
// break;
// case 3:
// if (row == -1)
// e.Style.CellValue = "Group";
// else if (row < settings.Sections.Count)
// e.Style.CellValue = settings.Sections[row].Group;
// else
// e.Style.CellValue = "";
// e.Style.VerticalAlignment = VerticalAlignment.Center;
// break;
// case 4:
// if (row == -1)
// e.Style.CellValue = "Section Name";
// else if (row < settings.Sections.Count)
// e.Style.CellValue = settings.Sections[row].Name;
// else
// e.Style.CellValue = "";
// e.Style.VerticalAlignment = VerticalAlignment.Center;
// break;
// case 5:
// if (row == -1)
// e.Style.CellValue = "Stations";
// else if (row < settings.Sections.Count)
// e.Style.CellValue = settings.Sections[row].Stations.ToString();
// else
// e.Style.CellValue = "";
// e.Style.HorizontalAlignment = HorizontalAlignment.Center;
// e.Style.VerticalAlignment = VerticalAlignment.Center;
// break;
// case 6:
// if (row == -1)
// GridUtils.SetButtonImage(e.Style, PRSDesktop.Resources.shared, Stages.Model, col);
// else if (row < settings.Sections.Count)
// GridUtils.SetButtonImage(e.Style, settings.Sections[row].Shared ? PRSDesktop.Resources.shared : null, Stages.Model, col);
// else
// GridUtils.SetButtonImage(e.Style, null, Stages.Model, col);
// break;
// case 7:
// if (row < settings.Sections.Count)
// GridUtils.SetButtonImage(e.Style, PRSDesktop.Resources.delete, Stages.Model, col);
// else
// GridUtils.SetButtonImage(e.Style, null, Stages.Model, col);
// break;
// }
// } catch (Exception err)
// {
// MessageBox.Show(err.Message);
// }
//}
//private void Stages_CommitCellInfo(object sender, Syncfusion.Windows.Controls.Grid.GridCommitCellInfoEventArgs e)
//{
// FactorySection section;
// if (e.Style.RowIndex > settings.Sections.Count)
// {
// section = new FactorySection() { ID = Guid.NewGuid(), Stations = 1 };
// settings.Sections.Add(section);
// }
// else
// section = settings.Sections[e.Style.RowIndex - 1];
// switch (e.Cell.ColumnIndex)
// {
// case 3:
// section.Group = e.Style.CellValue.ToString();
// break;
// case 4:
// section.Name = e.Style.CellValue.ToString();
// break;
// case 5:
// section.Stations = Convert.ToInt32(e.Style.CellValue.ToString());
// break;
// }
// Stages.Model.RowCount = 0;
// Stages.Model.RowCount = settings.Sections.Count + 2;
//}
//private void Stages_CellClick(object sender, GridCellClickEventArgs e)
//{
// int index = e.RowIndex - 1;
// if ((index < 0) || (index >= settings.Sections.Count))
// return;
// FactorySection section = settings.Sections[index];
// switch (e.ColumnIndex)
// {
// case 0:
// if (index > 0)
// {
// settings.Sections.Remove(section);
// settings.Sections.Insert(index - 1, section);
// e.Handled = true;
// }
// break;
// case 1:
// if (e.RowIndex < settings.Sections.Count - 1)
// {
// settings.Sections.Remove(section);
// settings.Sections.Insert(index+1, section);
// e.Handled = true;
// }
// break;
// case 6:
// if (index > -1)
// {
// section.Shared = !section.Shared;
// e.Handled = true;
// }
// break;
// case 7:
// settings.Sections.Remove(section);
// e.Handled = true;
// break;
// }
// if (e.Handled)
// {
// Stages.Model.RowCount = 0;
// Stages.Model.RowCount = settings.Sections.Count + 2;
// }
//}
private void Button_Click(object sender, RoutedEventArgs e)
{
Sections.CurrentGroup = "";
config.Save(settings);
DialogResult = true;
Close();
}
private void CancelButton_Click(object sender, RoutedEventArgs e)
{
DialogResult = false;
Close();
}
}
}