终端一体化运控平台
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.
 
 
 

78 lines
2.5 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<BasicInformation>.Data.ProjectDefaultPath;
  20. OpenBrowserDialogCommand = new RelayCommand(() =>
  21. {
  22. FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();
  23. if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
  24. {
  25. NewData.ProjectPath = folderBrowserDialog.SelectedPath;
  26. Json<BasicInformation>.Data.ProjectDefaultPath = NewData.ProjectPath;
  27. Json<BasicInformation>.Save();
  28. }
  29. });
  30. CreateCommand = new RelayCommand(() =>
  31. {
  32. if (NewData.ProjectName == null || NewData.ProjectName?.Length <= 0)
  33. {
  34. ErrorInfo = "项目名不能为空";
  35. return;
  36. }
  37. if (NewData.ProjectPath == null || NewData.ProjectPath?.Length <= 0)
  38. {
  39. ErrorInfo = "项目路径不合法";
  40. return;
  41. }
  42. var res = Directory.GetDirectories(NewData.ProjectPath);
  43. if (res?.ToList()?.FirstOrDefault(p => p.Contains(NewData.ProjectName)) == null)
  44. {
  45. ActionManage.GetInstance.Send("CreateCommand", NewData);
  46. }
  47. else
  48. {
  49. ErrorInfo = "该项目已经存在";
  50. return;
  51. }
  52. });
  53. CancelCommand = new RelayCommand(() => { ActionManage.GetInstance.Send("CancelCommand"); });
  54. }
  55. public NewProjectModel NewData { get { return _mNewData; } set { _mNewData = value; OnPropertyChanged(); } }
  56. private NewProjectModel _mNewData = new NewProjectModel();
  57. public string ErrorInfo { get { return _mErrorInfo; } set { _mErrorInfo = value; OnPropertyChanged(); } }
  58. private string _mErrorInfo;
  59. public RelayCommand CreateCommand { get; set; }
  60. public RelayCommand OpenBrowserDialogCommand { get; set; }
  61. public RelayCommand CancelCommand { get; set; }
  62. }
  63. }