CreateProductPageViewModel.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. namespace TeamAAS_VP.ViewModels.Product
  13. {
  14. public class CreateProductPageViewModel : BindableBase
  15. {
  16. private string _ProductName;
  17. public string ProductName
  18. {
  19. get { return _ProductName; }
  20. set { SetProperty(ref _ProductName,value); }
  21. }
  22. private ObservableCollection<string> _Templates;
  23. public ObservableCollection<string> Templates
  24. {
  25. get { return _Templates; }
  26. set { SetProperty(ref _Templates, value); }
  27. }
  28. private string _SelectTemplate;
  29. public string SelectTemplate
  30. {
  31. get { return _SelectTemplate; }
  32. set { SetProperty(ref _SelectTemplate, value); }
  33. }
  34. private DelegateCommand _LoadedCommand;
  35. public DelegateCommand LoadedCommand =>
  36. _LoadedCommand ?? (_LoadedCommand = new DelegateCommand(ExecuteLoadedCommand));
  37. public CreateProductPageViewModel()
  38. {
  39. }
  40. void ExecuteLoadedCommand()
  41. {
  42. try
  43. {
  44. Templates = new ObservableCollection<string>();
  45. Templates.Add("空白");
  46. SelectTemplate = Templates[0];
  47. if (!Directory.Exists(FilePath.ProductTemplatePath))
  48. {
  49. Directory.CreateDirectory(FilePath.ProductTemplatePath);
  50. }
  51. DirectoryInfo dir = new DirectoryInfo(FilePath.ProductTemplatePath);
  52. DirectoryInfo[] subdirectories = dir.GetDirectories();
  53. foreach (DirectoryInfo subdir in subdirectories)
  54. {
  55. try
  56. {
  57. var product = FileHelper.ReadJsonFile<ProductModel>(FilePath.ProductTemplatePath + "//" + subdir.Name + "//" + subdir.Name + ".cfg");
  58. if (product!=null)
  59. {
  60. Templates.Add(subdir.Name);
  61. }
  62. }
  63. catch (Exception)
  64. {
  65. }
  66. }
  67. }
  68. catch (Exception)
  69. {
  70. }
  71. }
  72. }
  73. }