终端一体化运控平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

94 regels
3.0 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using BPASmart.Model;
  7. using Microsoft.Toolkit.Mvvm.Input;
  8. using System.Windows;
  9. using BPA.Helper;
  10. using System.Windows.Forms;
  11. using System.IO;
  12. namespace BPASmart.ConfigurationSoftware
  13. {
  14. public class NewProjectViewModel : NoticeBase
  15. {
  16. public NewProjectViewModel()
  17. {
  18. //Json<BasicInformation>.Read();
  19. NewData.ProjectPath = Json<LocalPar>.Data.ProjectDefaultPath;
  20. DefaultName();
  21. OpenBrowserDialogCommand = new RelayCommand(() =>
  22. {
  23. FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();
  24. if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
  25. {
  26. NewData.ProjectPath = folderBrowserDialog.SelectedPath;
  27. Json<LocalPar>.Data.ProjectDefaultPath = NewData.ProjectPath;
  28. //Json<LocalPar>.Save();
  29. }
  30. });
  31. CreateCommand = new RelayCommand(() =>
  32. {
  33. if (NewData.ProjectName == null || NewData.ProjectName?.Length <= 0)
  34. {
  35. ErrorInfo = "项目名不能为空";
  36. return;
  37. }
  38. if (NewData.ProjectPath == null || NewData.ProjectPath?.Length <= 0)
  39. {
  40. ErrorInfo = "项目路径不合法";
  41. return;
  42. }
  43. var res = Directory.GetDirectories(NewData.ProjectPath);
  44. if (res?.ToList()?.FirstOrDefault(p => p.Contains(NewData.ProjectName)) == null)
  45. {
  46. ActionManage.GetInstance.Send("CreateCommand", NewData);
  47. }
  48. else
  49. {
  50. ErrorInfo = "该项目已经存在";
  51. return;
  52. }
  53. });
  54. CancelCommand = new RelayCommand(() => { ActionManage.GetInstance.Send("CancelCommand"); });
  55. }
  56. private void DefaultName()
  57. {
  58. var res = Directory.GetDirectories(NewData.ProjectPath);
  59. int count = 0;
  60. while (true)
  61. {
  62. count++;
  63. if (res?.ToList()?.FirstOrDefault(p => p.Contains($"default{count}")) == null)
  64. {
  65. NewData.ProjectName = $"default{count}";
  66. break;
  67. }
  68. }
  69. }
  70. public NewProjectModel NewData { get { return _mNewData; } set { _mNewData = value; OnPropertyChanged(); } }
  71. private NewProjectModel _mNewData = new NewProjectModel();
  72. public string ErrorInfo { get { return _mErrorInfo; } set { _mErrorInfo = value; OnPropertyChanged(); } }
  73. private string _mErrorInfo;
  74. public RelayCommand CreateCommand { get; set; }
  75. public RelayCommand OpenBrowserDialogCommand { get; set; }
  76. public RelayCommand CancelCommand { get; set; }
  77. }
  78. }