终端一体化运控平台
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GLobal.cs 2.1 KiB

2 년 전
2 년 전
2 년 전
2 년 전
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using BPASmartClient.Model;
  2. using Model;
  3. using Newtonsoft.Json;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Collections.ObjectModel;
  7. using System.IO;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. namespace BPASmartClient.MilkWithTea
  12. {
  13. public class GLobal
  14. {
  15. //路径
  16. public static string recipePath = string.Empty;
  17. public static string posionPath = string.Empty;
  18. public static bool makeEnable = false;
  19. public static ObservableCollection<LocalTeaWithMilkConfig> MaterialRecipes { get; set; } = new ObservableCollection<LocalTeaWithMilkConfig>();
  20. /// <summary>
  21. /// 设备信息列表
  22. /// </summary>
  23. public static ObservableCollection<DeviceConfigModelJson> deviceConfig { get; set; } = new ObservableCollection<DeviceConfigModelJson>();
  24. /// <summary>
  25. /// 获取Json文件内容,转换成ObservableCollection
  26. /// </summary>
  27. /// <typeparam name="T"></typeparam>
  28. /// <param name="path"></param>
  29. /// <returns></returns>
  30. public static ObservableCollection<T> GetJsonToT<T>(string path)
  31. {
  32. if (!File.Exists(path))
  33. {
  34. //创建该文件
  35. File.Create(path);
  36. return default;
  37. }
  38. else
  39. {
  40. using (StreamReader recipeReader = new StreamReader(path))//读取json文件
  41. {
  42. string datacache = "";
  43. string line;
  44. while ((line = recipeReader.ReadLine()) != null) //循环将每一行数据拼接为一个完整的字符串
  45. {
  46. datacache = datacache + line;
  47. }
  48. var res = JsonConvert.DeserializeObject<ObservableCollection<T>>(datacache); //将string转换为class类,从而达到json文件转换的目的
  49. if (res != null)
  50. return res;
  51. else return new ObservableCollection<T> { };
  52. }
  53. }
  54. }
  55. }
  56. }