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.
|
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using BPASmart.Model;
- using Microsoft.Toolkit.Mvvm.Input;
- using System.Windows;
- using BPA.Helper;
- using System.Windows.Forms;
- using System.IO;
-
- namespace BPASmart.ConfigurationSoftware
- {
- public class NewProjectViewModel : NoticeBase
- {
- public NewProjectViewModel()
- {
- //Json<BasicInformation>.Read();
- NewData.ProjectPath = Json<LocalPar>.Data.ProjectDefaultPath;
- DefaultName();
- OpenBrowserDialogCommand = new RelayCommand(() =>
- {
- FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();
- if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
- {
- NewData.ProjectPath = folderBrowserDialog.SelectedPath;
- Json<LocalPar>.Data.ProjectDefaultPath = NewData.ProjectPath;
- //Json<LocalPar>.Save();
- }
- });
-
- CreateCommand = new RelayCommand(() =>
- {
- if (NewData.ProjectName == null || NewData.ProjectName?.Length <= 0)
- {
- ErrorInfo = "项目名不能为空";
- return;
- }
-
- if (NewData.ProjectPath == null || NewData.ProjectPath?.Length <= 0)
- {
- ErrorInfo = "项目路径不合法";
- return;
- }
- var res = Directory.GetDirectories(NewData.ProjectPath);
- if (res?.ToList()?.FirstOrDefault(p => p.Contains(NewData.ProjectName)) == null)
- {
- ActionManage.GetInstance.Send("CreateCommand", NewData);
- }
- else
- {
- ErrorInfo = "该项目已经存在";
- return;
- }
-
- });
-
- CancelCommand = new RelayCommand(() => { ActionManage.GetInstance.Send("CancelCommand"); });
-
- }
-
- private void DefaultName()
- {
- var res = Directory.GetDirectories(NewData.ProjectPath);
- int count = 0;
- while (true)
- {
- count++;
- if (res?.ToList()?.FirstOrDefault(p => p.Contains($"default{count}")) == null)
- {
- NewData.ProjectName = $"default{count}";
- break;
- }
- }
- }
-
- public NewProjectModel NewData { get { return _mNewData; } set { _mNewData = value; OnPropertyChanged(); } }
- private NewProjectModel _mNewData = new NewProjectModel();
-
-
- public string ErrorInfo { get { return _mErrorInfo; } set { _mErrorInfo = value; OnPropertyChanged(); } }
- private string _mErrorInfo;
-
-
- public RelayCommand CreateCommand { get; set; }
-
- public RelayCommand OpenBrowserDialogCommand { get; set; }
-
- public RelayCommand CancelCommand { get; set; }
-
- }
- }
|