duheng
2024-12-20 3d69e0e8d953690b588c8a868bcf090f6119186b
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
using DevExpress.XtraEditors;
using HStation.Vmo;
using Yw;
 
namespace HStation.WinFrmUI
{
    public partial class AssetsValveCurveQLMgrPage : DocumentPage
    {
        public AssetsValveCurveQLMgrPage(string title, Yw.Ahart.eCurveType eCurveType)
        {
            InitializeComponent();
            _title = title;
            _eCurveType = eCurveType;
            this.PageTitle.Caption = title;
            this.PageTitle.HeaderSvgImage = AssetsMainSvgImageHelper.Curve;
            this.PageTitle.SvgImageSize = new Size(24, 24);
            this.phartDiagramRelationListCtrl1.SelectedChangedEvent += PhartDiagramRelationListCtrl1_SelectedChangedEvent;
        }
 
        private string _title;
        private Yw.Ahart.eCurveType _eCurveType;
        private AssetsValveMainVmo _vmo = null;
 
        private List<PhartDiagramRelationVmo> _allBindingList = null;
        private PhartDiagramRelationVmo _relation = null;
 
        /// <summary>
        ///
        /// </summary>
        public async void SetBindingData(AssetsValveMainVmo vmo)
        {
            if (vmo == null)
            {
                return;
            }
            _vmo = vmo;
            this.PageTitle.Caption = $"{vmo.Name}\r\n{_title}";
            _allBindingList = new List<PhartDiagramRelationVmo>();
            var allList = await BLLFactory<HStation.BLL.PhartDiagramRelation>.Instance
               .GetByObjectTypeAndObjectID(HStation.Assets.DataType.ValveMain, vmo.ID);
            allList?.ForEach(x => _allBindingList.Add(x));
            this.phartDiagramRelationListCtrl1.SetBindingData(_allBindingList);
        }
 
        //excel
        private void Excel()
        {
            if (_vmo == null)
            {
                return;
            }
            var dlg = new ImportAssetsValveCurveQLByExcelDlg(_eCurveType);
            dlg.ReloadDataEvent += (rhs) =>
            {
                _allBindingList.Add(rhs);
                this.phartDiagramRelationListCtrl1.SetBindingData(_allBindingList);
            };
            dlg.SetBindingData(_vmo);
            dlg.ShowDialog();
        }
 
        //图片
        private void Picture()
        {
            if (_vmo == null)
            {
                return;
            }
            var vm = GetCurrentViewModel();
            if (vm == null)
            {
                return;
            }
            var dlg = new ImportAssetsValveCurveQLByPictureDlg(_eCurveType);
            dlg.ReloadDataEvent += (rhs) =>
            {
                _allBindingList.Add(rhs);
                this.phartDiagramRelationListCtrl1.SetBindingData(_allBindingList);
            };
            dlg.SetBindingData(_vmo);
            dlg.ShowDialog();
        }
 
        //基本信息
        private void Info()
        {
            var vm = GetCurrentViewModel();
            if (vm == null)
            {
                return;
            }
            var dlg = new EditPhartDiagramRelationDlg();
            dlg.ReloadDataEvent += (rhs) =>
            {
                var item = _allBindingList?.Find(x => x.ID == rhs.ID);
                if (item == null)
                {
                    return;
                }
                item.Reset(rhs);
                this.phartDiagramRelationListCtrl1.SetBindingData(_allBindingList);
            };
            dlg.SetBindingData(vm);
            dlg.ShowDialog();
        }
 
        //曲线
        private async void Curve()
        {
            var vm = GetCurrentViewModel();
            if (vm == null)
            {
                return;
            }
            var vmo = await BLLFactory<Yw.BLL.PhartDiagramExtensions>.Instance.GetByID(vm.DiagramID);
            var dlg = new EditAssetsValveCurveQLDlg();
            dlg.ReloadDataEvent += (rhs) =>
            {
                this.universalChartViewCtrl1.SetBindingData(rhs);
            };
            dlg.SetBindingData(vmo);
            dlg.ShowDialog();
        }
 
        //删除
        private async void Delete()
        {
            var vm = GetCurrentViewModel();
            if (vm == null)
            {
                return;
            }
            var result = XtraMessageBox.Show("请问确认删除当前数据吗?", "询问", MessageBoxButtons.YesNo) == DialogResult.Yes;
            if (!result)
            {
                return;
            }
            var bol = await BLLFactory<HStation.BLL.PhartDiagramRelation>.Instance.DeleteByID(vm.ID);
            if (!bol)
            {
                TipFormHelper.ShowError("删除失败!");
                return;
            }
            _allBindingList.Remove(vm);
            this.phartDiagramRelationListCtrl1.SetBindingData(_allBindingList);
            TipFormHelper.ShowSucceed("删除成功!");
        }
 
        #region 当前
 
        //获取当前
        private PhartDiagramRelationVmo GetCurrentViewModel()
        {
            if (_allBindingList == null)
            {
                TipFormHelper.ShowError("数据初始化错误!");
                return null;
            }
            if (_allBindingList.Count < 1)
            {
                TipFormHelper.ShowInfo("无数据!");
                return null;
            }
            if (_relation == null)
            {
                TipFormHelper.ShowWarn("请选择数据行!");
                return null;
            }
            return _relation;
        }
 
        #endregion 当前
 
        //Excel导入
        private void barBtnImportByExcel_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Excel();
        }
 
        //图片导入
        private void barBtnImportByPicture_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Picture();
        }
 
        //基本信息
        private void barBtnInfo_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Info();
        }
 
        //曲线
        private void barBtnCurve_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Curve();
        }
 
        //删除
        private void barBtnDelete_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Delete();
        }
 
        //选择改变
        private void PhartDiagramRelationListCtrl1_SelectedChangedEvent(PhartDiagramRelationVmo obj)
        {
            _relation = obj;
            LoadPhart(_relation);
        }
 
        //加载图表
        private async void LoadPhart(PhartDiagramRelationVmo relation)
        {
            if (relation == null)
            {
                this.universalChartViewCtrl1.SetBindingData(null);
                return;
            }
            var vmo = await BLLFactory<Yw.BLL.PhartDiagramExtensions>.Instance.GetByID(relation.DiagramID);
            this.universalChartViewCtrl1.SetBindingData(vmo);
        }
    }
}