|  | @@ -12,7 +12,8 @@ public partial class MainWindowViewModel : ObservableObject
 | 
	
		
			
				|  |  |  {
 | 
	
		
			
				|  |  |      private readonly IClientService _clientService;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    private readonly string jsonFilePath= $"{Environment.CurrentDirectory}/DeviceInformation.json";
 | 
	
		
			
				|  |  | +    private readonly string jsonFilePath = $"{Environment.CurrentDirectory}/DeviceInformation.json";
 | 
	
		
			
				|  |  | +    private bool _isInitialized = false;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      [ObservableProperty]
 | 
	
		
			
				|  |  |      private string _ipAddress = string.Empty;
 | 
	
	
		
			
				|  | @@ -96,18 +97,22 @@ public partial class MainWindowViewModel : ObservableObject
 | 
	
		
			
				|  |  |              MessageBox.Show("存在未被填写的项目!");
 | 
	
		
			
				|  |  |              return;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |          try
 | 
	
		
			
				|  |  |          {
 | 
	
		
			
				|  |  |              _ = Enum.TryParse<DeviceModel>(DeviceModel, out var deviceModel);
 | 
	
		
			
				|  |  | -            var guid = _clientService.RegisterDevice(new Models.DeviceInfo
 | 
	
		
			
				|  |  | +            var deviceInfo = new Models.DeviceInfo
 | 
	
		
			
				|  |  |              {
 | 
	
		
			
				|  |  |                  DeviceModel = deviceModel,
 | 
	
		
			
				|  |  |                  DeviceSubModel = DeviceSubModel,
 | 
	
		
			
				|  |  |                  DeviceName = DeviceName,
 | 
	
		
			
				|  |  |                  Position = Position,
 | 
	
		
			
				|  |  | +                Guid = _isInitialized ? Guid.Parse(GuidStr) : null,
 | 
	
		
			
				|  |  |                  SoftwareVersion = SoftwareVersion,
 | 
	
		
			
				|  |  |                  DBConnectionString = DBConnectionString
 | 
	
		
			
				|  |  | -            });
 | 
	
		
			
				|  |  | +            };
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            var guid = _clientService.RegisterDevice(deviceInfo);
 | 
	
		
			
				|  |  |              if (guid == Guid.Empty)
 | 
	
		
			
				|  |  |              {
 | 
	
		
			
				|  |  |                  MessageBox.Show("未能获取Guid,设备注册失败!");
 | 
	
	
		
			
				|  | @@ -116,34 +121,7 @@ public partial class MainWindowViewModel : ObservableObject
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |              GuidStr = guid.ToString();
 | 
	
		
			
				|  |  |              MessageBox.Show("设备注册成功。");
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        catch (Exception ex)
 | 
	
		
			
				|  |  | -        {
 | 
	
		
			
				|  |  | -            MessageBox.Show($"遭遇异常:{ex.Message}");
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  | -    [RelayCommand]
 | 
	
		
			
				|  |  | -    private void Save()
 | 
	
		
			
				|  |  | -    {
 | 
	
		
			
				|  |  | -        if(string.IsNullOrWhiteSpace(GuidStr) || !Guid.TryParse(GuidStr,out var guidStr))
 | 
	
		
			
				|  |  | -        {
 | 
	
		
			
				|  |  | -            MessageBox.Show("Guid错误!");
 | 
	
		
			
				|  |  | -            return;
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        try
 | 
	
		
			
				|  |  | -        {
 | 
	
		
			
				|  |  | -            _ = Enum.TryParse<DeviceModel>(DeviceModel, out var deviceModel);
 | 
	
		
			
				|  |  | -            var deviceInfo = new Models.DeviceInfo
 | 
	
		
			
				|  |  | -            {
 | 
	
		
			
				|  |  | -                DeviceModel = deviceModel,
 | 
	
		
			
				|  |  | -                DeviceSubModel = DeviceSubModel,
 | 
	
		
			
				|  |  | -                DeviceName = DeviceName,
 | 
	
		
			
				|  |  | -                Position = Position,
 | 
	
		
			
				|  |  | -                SoftwareVersion = SoftwareVersion,
 | 
	
		
			
				|  |  | -                Guid = guidStr,
 | 
	
		
			
				|  |  | -                DBConnectionString = DBConnectionString
 | 
	
		
			
				|  |  | -            };
 | 
	
		
			
				|  |  |              string jsonString = JsonSerializer.Serialize(deviceInfo);
 | 
	
		
			
				|  |  |              File.WriteAllText(jsonFilePath, jsonString);
 | 
	
		
			
				|  |  |          }
 | 
	
	
		
			
				|  | @@ -162,18 +140,21 @@ public partial class MainWindowViewModel : ObservableObject
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          string jsonFromFile = File.ReadAllText(jsonFilePath);
 | 
	
		
			
				|  |  |          var deserializedDeviceInfo = JsonSerializer.Deserialize<Models.DeviceInfo>(jsonFromFile);
 | 
	
		
			
				|  |  | -        if(deserializedDeviceInfo is null)
 | 
	
		
			
				|  |  | +        if (deserializedDeviceInfo is null)
 | 
	
		
			
				|  |  |          {
 | 
	
		
			
				|  |  |              return;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |          DeviceModelIndex = (int)deserializedDeviceInfo.DeviceModel!;
 | 
	
		
			
				|  |  | -        DeviceModel = deserializedDeviceInfo.DeviceModel.ToString()??string.Empty;
 | 
	
		
			
				|  |  | +        DeviceModel = deserializedDeviceInfo.DeviceModel.ToString() ?? string.Empty;
 | 
	
		
			
				|  |  |          DeviceSubModel = deserializedDeviceInfo.DeviceSubModel ?? string.Empty;
 | 
	
		
			
				|  |  |          DeviceName = deserializedDeviceInfo.DeviceName ?? string.Empty;
 | 
	
		
			
				|  |  |          Position = deserializedDeviceInfo.Position ?? string.Empty;
 | 
	
		
			
				|  |  |          SoftwareVersion = deserializedDeviceInfo.SoftwareVersion ?? string.Empty;
 | 
	
		
			
				|  |  |          GuidStr = deserializedDeviceInfo.Guid.ToString() ?? string.Empty;
 | 
	
		
			
				|  |  |          DBConnectionString = deserializedDeviceInfo.DBConnectionString ?? string.Empty;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        _isInitialized = true;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      private void OnRequestFileReceived(object? sender, (Guid guid, ServiceBase.FileType fileType) e)
 |