using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Collections.ObjectModel; using System.Windows; using System.IO; using BPASmartClient.Helper; namespace BPASmartClient.CustomResource.Pages.Model { public class ProductionDataHelper where TProductionData : class, new() { public static string SavePath { get; set; } private static string FileName = string.Empty; private static string FilePath = string.Empty; public static string Alias { get; set; } = string.Empty; private static string _path { get { Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"AccessFile\\ProductionData\\{FilePath}")); return $"{AppDomain.CurrentDomain.BaseDirectory}AccessFile\\ProductionData\\{ FilePath}"; } } public static ObservableCollection productionDatas { get; set; } = new ObservableCollection(); //public static TProductionData Data { get; set; } = new TProductionData(); public static void Add(TProductionData production) { if (FilePath.Length <= 0) { if (Alias.Length <= 0) FilePath = $"{DateTime.Now.ToString("yyy-MM-dd")}"; else FilePath = $"{DateTime.Now.ToString("yyy-MM-dd")}\\{Alias}"; } if (FileName.Length <= 0) FileName = $"{DateTime.Now.ToString("HH-mm-ss")}.pry"; Application.Current.Dispatcher.Invoke(new Action(() => { productionDatas.Add(production); })); } public static bool Save(string path = "") { DataRecord dr = new DataRecord(); if (File.Exists(path)) { dr.Save(productionDatas, FileName); return true; } if (SavePath != null && File.Exists(SavePath)) { dr.Save(productionDatas, FileName); return true; } dr.Save(productionDatas, FileName); return true; } public static void End() { FileName = string.Empty; FilePath = string.Empty; Alias = string.Empty; } } }