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

85 line
2.4 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Collections.ObjectModel;
  7. using System.Windows;
  8. using System.IO;
  9. using BPASmartClient.Helper;
  10. namespace BPASmartClient.CustomResource.Pages.Model
  11. {
  12. public class ProductionDataHelper<TProductionData> where TProductionData : class, new()
  13. {
  14. public static string SavePath { get; set; }
  15. private static string FileName = string.Empty;
  16. private static string FilePath = string.Empty;
  17. public static string Alias { get; set; } = string.Empty;
  18. private static string _path
  19. {
  20. get
  21. {
  22. Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"AccessFile\\ProductionData\\{FilePath}"));
  23. return $"{AppDomain.CurrentDomain.BaseDirectory}AccessFile\\ProductionData\\{ FilePath}";
  24. }
  25. }
  26. public static ObservableCollection<TProductionData> productionDatas { get; set; } = new ObservableCollection<TProductionData>();
  27. //public static TProductionData Data { get; set; } = new TProductionData();
  28. public static void Add(TProductionData production)
  29. {
  30. if (FilePath.Length <= 0)
  31. {
  32. if (Alias.Length <= 0)
  33. FilePath = $"{DateTime.Now.ToString("yyy-MM-dd")}";
  34. else
  35. FilePath = $"{DateTime.Now.ToString("yyy-MM-dd")}\\{Alias}";
  36. }
  37. if (FileName.Length <= 0) FileName = $"{DateTime.Now.ToString("HH-mm-ss")}.pry";
  38. Application.Current.Dispatcher.Invoke(new Action(() =>
  39. {
  40. productionDatas.Add(production);
  41. }));
  42. }
  43. public static bool Save(string path = "")
  44. {
  45. DataRecord dr = new DataRecord();
  46. if (File.Exists(path))
  47. {
  48. dr.Save(productionDatas, FileName);
  49. return true;
  50. }
  51. if (SavePath != null && File.Exists(SavePath))
  52. {
  53. dr.Save(productionDatas, FileName);
  54. return true;
  55. }
  56. dr.Save(productionDatas, FileName);
  57. return true;
  58. }
  59. public static void End()
  60. {
  61. FileName = string.Empty;
  62. FilePath = string.Empty;
  63. Alias = string.Empty;
  64. }
  65. }
  66. }