CreateProductPageViewModel.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using Prism.Commands;
  2. using Prism.Mvvm;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Collections.ObjectModel;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Web.UI;
  9. using System.Windows.Shapes;
  10. using TeamAAS_VP.Core;
  11. using TeamAAS_VP.Models;
  12. using TeamAAS_VP.Resources.Languages;
  13. namespace TeamAAS_VP.ViewModels.Product
  14. {
  15. public class CreateProductPageViewModel : BindableBase
  16. {
  17. private string _ProductName;
  18. public string ProductName
  19. {
  20. get { return _ProductName; }
  21. set { SetProperty(ref _ProductName,value); }
  22. }
  23. private ObservableCollection<string> _Templates;
  24. public ObservableCollection<string> Templates
  25. {
  26. get { return _Templates; }
  27. set { SetProperty(ref _Templates, value); }
  28. }
  29. private string _SelectTemplate;
  30. public string SelectTemplate
  31. {
  32. get { return _SelectTemplate; }
  33. set { SetProperty(ref _SelectTemplate, value); }
  34. }
  35. private DelegateCommand _LoadedCommand;
  36. public DelegateCommand LoadedCommand =>
  37. _LoadedCommand ?? (_LoadedCommand = new DelegateCommand(ExecuteLoadedCommand));
  38. public CreateProductPageViewModel()
  39. {
  40. }
  41. void ExecuteLoadedCommand()
  42. {
  43. try
  44. {
  45. Templates = new ObservableCollection<string>();
  46. Templates.Add(Lang.空白);
  47. SelectTemplate = Templates[0];
  48. if (!Directory.Exists(FilePath.ProductTemplatePath))
  49. {
  50. Directory.CreateDirectory(FilePath.ProductTemplatePath);
  51. }
  52. DirectoryInfo dir = new DirectoryInfo(FilePath.ProductTemplatePath);
  53. DirectoryInfo[] subdirectories = dir.GetDirectories();
  54. foreach (DirectoryInfo subdir in subdirectories)
  55. {
  56. try
  57. {
  58. var product = FileHelper.ReadJsonFile<ProductModel>(FilePath.ProductTemplatePath + "//" + subdir.Name + "//" + subdir.Name + ".cfg");
  59. if (product!=null)
  60. {
  61. Templates.Add(subdir.Name);
  62. }
  63. }
  64. catch (Exception)
  65. {
  66. }
  67. }
  68. }
  69. catch (Exception)
  70. {
  71. }
  72. }
  73. }
  74. }