CoreAttributeGrid.cs 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. namespace PRSDesktop
  2. {
  3. }
  4. //class CoreAttributeGrid<T> : DynamicEnclosedListGrid<T,CoreAttribute> where T : Entity, IRemotable, IPersistent, new()
  5. //{
  6. // public CoreTable Schedules { get; set; }
  7. // public CoreAttributeGrid(PropertyInfo prop) : base(prop)
  8. // {
  9. // Options = new DynamicGridOptions[] { DynamicGridOptions.RecordCount, DynamicGridOptions.AddRows, DynamicGridOptions.EditRows, DynamicGridOptions.DeleteRows, DynamicGridOptions.SelectColumns, DynamicGridOptions.MultiSelect };
  10. // HiddenColumns.Add(x => x.Name);
  11. // HiddenColumns.Add(x => x.Value);
  12. // AddButton("Export", PRSDesktop.Resources.download.AsBitmapImage(), SaveAttributes);
  13. // AddButton("Import", PRSDesktop.Resources.upload.AsBitmapImage(), LoadAttributes);
  14. // }
  15. // private bool LoadAttributes(Button sender, CoreRow[] rows)
  16. // {
  17. // var dlg = new Microsoft.Win32.OpenFileDialog();
  18. // dlg.Filter = "PRS Attribute Files (*.attributes)|*.attributes";
  19. // if (dlg.ShowDialog() == true)
  20. // {
  21. // Items.Clear();
  22. // Progress.Show("");
  23. // String json = File.ReadAllText(dlg.FileName);
  24. // List<CoreAttribute> attributes = new List<CoreAttribute> { };
  25. // try
  26. // {
  27. // attributes = Serialization.Deserialize<List<CoreAttribute>>(json);
  28. // }
  29. // catch (Exception e)
  30. // {
  31. // Progress.Close();
  32. // MessageBox.Show("[" + Path.GetFileName(dlg.FileName) + "] is not a valid attributes file!");
  33. // return false;
  34. // }
  35. // if (!attributes.Any())
  36. // {
  37. // Progress.Close();
  38. // MessageBox.Show("[" + Path.GetFileName(dlg.FileName) + "] does not contain any attributes!");
  39. // return false;
  40. // }
  41. // Items.AddRange(attributes);
  42. // Progress.Close();
  43. // MessageBox.Show(String.Format("{0} attributes loaded from [{1}]", attributes.Count, Path.GetFileName(dlg.FileName)));
  44. // }
  45. // return true;
  46. // }
  47. // /// <summary>
  48. // /// Strip illegal chars and reserved words from a candidate filename (should not include the directory path)
  49. // /// </summary>
  50. // /// <remarks>
  51. // /// http://stackoverflow.com/questions/309485/c-sharp-sanitize-file-name
  52. // /// </remarks>
  53. // private string CoerceValidFileName(string filename)
  54. // {
  55. // var invalidChars = Regex.Escape(new string(Path.GetInvalidFileNameChars()));
  56. // var invalidReStr = string.Format(@"[{0}]+", invalidChars);
  57. // var reservedWords = new[]
  58. // {
  59. // "CON", "PRN", "AUX", "CLOCK$", "NUL", "COM0", "COM1", "COM2", "COM3", "COM4",
  60. // "COM5", "COM6", "COM7", "COM8", "COM9", "LPT0", "LPT1", "LPT2", "LPT3", "LPT4",
  61. // "LPT5", "LPT6", "LPT7", "LPT8", "LPT9"
  62. // };
  63. // var sanitisedNamePart = Regex.Replace(filename, invalidReStr, "_");
  64. // foreach (var reservedWord in reservedWords)
  65. // {
  66. // var reservedWordPattern = string.Format("^{0}\\.", reservedWord);
  67. // sanitisedNamePart = Regex.Replace(sanitisedNamePart, reservedWordPattern, "_reservedWord_.", RegexOptions.IgnoreCase);
  68. // }
  69. // return sanitisedNamePart;
  70. // }
  71. // private bool SaveAttributes(Button sender, CoreRow[] rows)
  72. // {
  73. // String filename = CoerceValidFileName(String.Format("{0} ({1})",typeof(T).EntityName().Split('.').Last(),Entity.ToString()));
  74. // var dlg = new Microsoft.Win32.SaveFileDialog();
  75. // dlg.Filter = "PRS Schedule Files (*.attributes)|*.attributes";
  76. // dlg.FileName = filename + ".attributes";
  77. // dlg.AddExtension = false;
  78. // if (dlg.ShowDialog() == true)
  79. // {
  80. // string json = Serialization.Serialize(Items);
  81. // File.WriteAllText(dlg.FileName, json);
  82. // MessageBox.Show(String.Format("{0} attributes saved to [{1}]", Items.Count, Path.GetFileName(dlg.FileName)));
  83. // }
  84. // return false;
  85. // }
  86. //}