FactorySettings.xaml.cs 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. using System.Linq;
  2. using System.Windows;
  3. using Comal.Classes;
  4. using InABox.Configuration;
  5. using InABox.DynamicGrid;
  6. using InABox.Wpf;
  7. namespace PRSDesktop
  8. {
  9. /// <summary>
  10. /// Interaction logic for ScheduleSettings.xaml
  11. /// </summary>
  12. public partial class FactorySettings : ThemableWindow
  13. {
  14. private readonly GlobalConfiguration<FactorySetup> config = new();
  15. private readonly FactorySetup settings;
  16. public FactorySettings()
  17. {
  18. InitializeComponent();
  19. settings = config.Load();
  20. Groups.OnSelectItem += Groups_OnSelectItem;
  21. Groups.Groups = settings.Groups;
  22. Groups.Refresh(true, true);
  23. Sections.Sections = settings.Sections;
  24. Sections.Refresh(true, true);
  25. //Stages.Model.RowHeights.DefaultLineSize = 20;
  26. //Stages.Model.ColumnCount = 8;
  27. //Stages.Model.ColumnWidths[0] = 20;
  28. //Stages.Model.ColumnWidths[1] = 20;
  29. //Stages.Model.ColumnWidths[2] = 0;
  30. //Stages.Model.ColumnWidths[3] = 0;
  31. //Stages.Model.ColumnWidths[4] = 0;
  32. //Stages.Model.ColumnWidths[5] = 50;
  33. //Stages.Model.ColumnWidths[6] = 20;
  34. //Stages.Model.ColumnWidths[7] = 20;
  35. //Stages.Model.HeaderColumns = 0;
  36. //Stages.Model.RowCount = 0;
  37. //Stages.Model.RowCount = settings.Sections.Count + 2;
  38. }
  39. private void Groups_OnSelectItem(object sender, DynamicGridSelectionEventArgs e)
  40. {
  41. Sections.CurrentGroup = e.Rows?.FirstOrDefault()?.Get<FactoryGroup, string>(x => x.Group) ?? "";
  42. Sections.Refresh(false, true);
  43. }
  44. //private void Stages_SizeChanged(object sender, SizeChangedEventArgs e)
  45. //{
  46. // Stages.Model.ColumnWidths[3] = (e.NewSize.Width - 130) / 3;
  47. // Stages.Model.ColumnWidths[4] = (e.NewSize.Width - 130) * 2 / 3;
  48. //}
  49. //private void Stages_QueryCellInfo(object sender, Syncfusion.Windows.Controls.Grid.GridQueryCellInfoEventArgs e)
  50. //{
  51. // try
  52. // {
  53. // int row = e.Cell.RowIndex - 1;
  54. // int col = e.Cell.ColumnIndex;
  55. // switch (col)
  56. // {
  57. // case 0:
  58. // if ((row == -1) || ((row > 0) && (row < settings.Sections.Count)))
  59. // GridUtils.SetButtonImage(e.Style, PRSDesktop.Resources.uparrow, Stages.Model, col);
  60. // else
  61. // GridUtils.SetButtonImage(e.Style, null, Stages.Model, col);
  62. // break;
  63. // case 1:
  64. // if (row < settings.Sections.Count - 1)
  65. // GridUtils.SetButtonImage(e.Style, PRSDesktop.Resources.downarrow, Stages.Model, col);
  66. // else
  67. // GridUtils.SetButtonImage(e.Style, null, Stages.Model, col);
  68. // break;
  69. // case 2:
  70. // if (row == -1)
  71. // e.Style.CellValue = "Guid";
  72. // else if (row < settings.Sections.Count)
  73. // e.Style.CellValue = settings.Sections[row].ID.ToString();
  74. // else
  75. // e.Style.CellValue = "";
  76. // break;
  77. // case 3:
  78. // if (row == -1)
  79. // e.Style.CellValue = "Group";
  80. // else if (row < settings.Sections.Count)
  81. // e.Style.CellValue = settings.Sections[row].Group;
  82. // else
  83. // e.Style.CellValue = "";
  84. // e.Style.VerticalAlignment = VerticalAlignment.Center;
  85. // break;
  86. // case 4:
  87. // if (row == -1)
  88. // e.Style.CellValue = "Section Name";
  89. // else if (row < settings.Sections.Count)
  90. // e.Style.CellValue = settings.Sections[row].Name;
  91. // else
  92. // e.Style.CellValue = "";
  93. // e.Style.VerticalAlignment = VerticalAlignment.Center;
  94. // break;
  95. // case 5:
  96. // if (row == -1)
  97. // e.Style.CellValue = "Stations";
  98. // else if (row < settings.Sections.Count)
  99. // e.Style.CellValue = settings.Sections[row].Stations.ToString();
  100. // else
  101. // e.Style.CellValue = "";
  102. // e.Style.HorizontalAlignment = HorizontalAlignment.Center;
  103. // e.Style.VerticalAlignment = VerticalAlignment.Center;
  104. // break;
  105. // case 6:
  106. // if (row == -1)
  107. // GridUtils.SetButtonImage(e.Style, PRSDesktop.Resources.shared, Stages.Model, col);
  108. // else if (row < settings.Sections.Count)
  109. // GridUtils.SetButtonImage(e.Style, settings.Sections[row].Shared ? PRSDesktop.Resources.shared : null, Stages.Model, col);
  110. // else
  111. // GridUtils.SetButtonImage(e.Style, null, Stages.Model, col);
  112. // break;
  113. // case 7:
  114. // if (row < settings.Sections.Count)
  115. // GridUtils.SetButtonImage(e.Style, PRSDesktop.Resources.delete, Stages.Model, col);
  116. // else
  117. // GridUtils.SetButtonImage(e.Style, null, Stages.Model, col);
  118. // break;
  119. // }
  120. // } catch (Exception err)
  121. // {
  122. // MessageBox.Show(err.Message);
  123. // }
  124. //}
  125. //private void Stages_CommitCellInfo(object sender, Syncfusion.Windows.Controls.Grid.GridCommitCellInfoEventArgs e)
  126. //{
  127. // FactorySection section;
  128. // if (e.Style.RowIndex > settings.Sections.Count)
  129. // {
  130. // section = new FactorySection() { ID = Guid.NewGuid(), Stations = 1 };
  131. // settings.Sections.Add(section);
  132. // }
  133. // else
  134. // section = settings.Sections[e.Style.RowIndex - 1];
  135. // switch (e.Cell.ColumnIndex)
  136. // {
  137. // case 3:
  138. // section.Group = e.Style.CellValue.ToString();
  139. // break;
  140. // case 4:
  141. // section.Name = e.Style.CellValue.ToString();
  142. // break;
  143. // case 5:
  144. // section.Stations = Convert.ToInt32(e.Style.CellValue.ToString());
  145. // break;
  146. // }
  147. // Stages.Model.RowCount = 0;
  148. // Stages.Model.RowCount = settings.Sections.Count + 2;
  149. //}
  150. //private void Stages_CellClick(object sender, GridCellClickEventArgs e)
  151. //{
  152. // int index = e.RowIndex - 1;
  153. // if ((index < 0) || (index >= settings.Sections.Count))
  154. // return;
  155. // FactorySection section = settings.Sections[index];
  156. // switch (e.ColumnIndex)
  157. // {
  158. // case 0:
  159. // if (index > 0)
  160. // {
  161. // settings.Sections.Remove(section);
  162. // settings.Sections.Insert(index - 1, section);
  163. // e.Handled = true;
  164. // }
  165. // break;
  166. // case 1:
  167. // if (e.RowIndex < settings.Sections.Count - 1)
  168. // {
  169. // settings.Sections.Remove(section);
  170. // settings.Sections.Insert(index+1, section);
  171. // e.Handled = true;
  172. // }
  173. // break;
  174. // case 6:
  175. // if (index > -1)
  176. // {
  177. // section.Shared = !section.Shared;
  178. // e.Handled = true;
  179. // }
  180. // break;
  181. // case 7:
  182. // settings.Sections.Remove(section);
  183. // e.Handled = true;
  184. // break;
  185. // }
  186. // if (e.Handled)
  187. // {
  188. // Stages.Model.RowCount = 0;
  189. // Stages.Model.RowCount = settings.Sections.Count + 2;
  190. // }
  191. //}
  192. private void Button_Click(object sender, RoutedEventArgs e)
  193. {
  194. Sections.CurrentGroup = "";
  195. config.Save(settings);
  196. DialogResult = true;
  197. Close();
  198. }
  199. private void CancelButton_Click(object sender, RoutedEventArgs e)
  200. {
  201. DialogResult = false;
  202. Close();
  203. }
  204. }
  205. }