duheng
2025-04-08 62b7628c21e911665ce2aa7a39bf17b2e7218dca
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System.IO;
using Yw;
 
namespace PBS.WinFrmUI
{
    public class packageCurveViewModel
    {
        public long PcakageID { get; set; }
 
        public string PackageName { get; set; }
 
        public List<PumpInfo> PumpInfos { get; set; }
 
        public static async void SaveCurveFile(long facilityId, long packageId)
        {
            if (packageId < 0)
                return;
            var model = new packageCurveViewModel();
            model.PcakageID = packageId;
            model.PumpInfos = new List<PumpInfo>();
            var pumpList = await new HStation.BLL.AssetsPackagePumpMapping().GetByPackageID(packageId);
            foreach (var item in pumpList)
            {
                var allList = await BLLFactory<HStation.BLL.PhartDiagramRelation>.Instance
       .GetByObjectTypeAndObjectID(HStation.Assets.DataType.PumpMain, item.PumpMainID);
                var maxImportance = allList.OrderByDescending(x => x.Importance).FirstOrDefault();
                var vmo = await BLLFactory<Yw.BLL.PhartDiagramExtensions>.Instance.GetByID(maxImportance.DiagramID);
                model.PumpInfos.Add(new PumpInfo
                {
                    PumpID = item.ID,
                    PumpName = item.PumpOtherName,
                    phartDiagramExGraphListVmo = vmo
                });
            }
            var json = Yw.JsonHelper.Object2Json(model);
            string rootDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Package_Curve");
            if (!Directory.Exists(rootDirectory))
            {
                Directory.CreateDirectory(rootDirectory);
            }
            string filePath = Path.Combine(rootDirectory, $"{facilityId}.json");
            if (!Directory.Exists(filePath))
            {
                File.Delete(filePath);
            }
            File.WriteAllText(filePath, json);
        }
 
        public static void DeleteCurveFile(long facilityId)
        {
            string rootDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Package_Curve");
 
            string filePath = Path.Combine(rootDirectory, $"{facilityId}.json");
            if (!Directory.Exists(filePath))
            {
                File.Delete(filePath);
            }
        }
 
        public static packageCurveViewModel GetFacilityCurve(long facilityId)
        {
            string rootDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Package_Curve");
 
            string filePath = Path.Combine(rootDirectory, $"{facilityId}.json");
            if (!Directory.Exists(filePath))
            {
                var json = File.ReadAllText(filePath);
                return JsonHelper.Json2Object<packageCurveViewModel>(json);
            }
            return null;
        }
    }
 
    public class PumpInfo
    {
        public long PumpID { get; set; }
 
        public string PumpName { get; set; }
 
        public Yw.Vmo.PhartDiagramExGraphListVmo phartDiagramExGraphListVmo { get; set; }
    }
}