Shuxia Ning
2025-01-14 0f99d4d12f2eae29bbe343f4b3131f2faeccda5d
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
using DevExpress.XtraEditors;
using HStation.Vmo;
using Yw;
 
namespace HStation.WinFrmUI
{
    public partial class ImportPumpPerform2dByExcelDlg : XtraForm
    {
        public ImportPumpPerform2dByExcelDlg()
        {
            InitializeComponent();
            this.IconOptions.Icon = Yw.WinFrmUI.GlobalParas.AppIcon;
            this.generalOkAndCancelCtrl1.OkEvent += GeneralOkAndCancelCtrl1_OkEvent;
        }
 
        private AssetsPumpMainVmo _pump;
 
        private PhartDiagramRelationVmo _vmo;
 
        /// <summary>
        /// 回调事件
        /// </summary>
        public event Action<PhartDiagramRelationVmo> ReloadDataEvent;
 
        public void SetBindingData(AssetsPumpMainVmo pump)
        {
            if (pump == null)
            {
                return;
            }
            _pump = pump;
            this.textEditName.Text = pump.Name;
            _vmo = new PhartDiagramRelationVmo();
            _vmo.ObjectType = HStation.Assets.DataType.PumpMain;
            _vmo.ObjectID = _pump.ID;
            _vmo.Importance = 0;
            this.textEditImportance.EditValue = 0;
        }
 
        //验证
        private bool Valid()
        {
            this.dxErrorProvider1.ClearErrors();
            if (string.IsNullOrEmpty(this.textEditName.Text.Trim()))
            {
                this.dxErrorProvider1.SetError(this.textEditName, "必选项");
                return false;
            }
            if (string.IsNullOrEmpty(this.btnExcelFilePath.Text.Trim()))
            {
                this.dxErrorProvider1.SetError(this.btnExcelFilePath, "必填项");
                return false;
            }
            return true;
        }
 
        //确定
        private async void GeneralOkAndCancelCtrl1_OkEvent()
        {
            if (!Valid())
            {
                return;
            }
            var diagram = this.pumpChartExcelImportCtrl1.Get();
            var diagramId = await BLLFactory<Yw.BLL.PhartDiagramExtensions>.Instance.Insert(diagram);
            if (diagramId < 1)
            {
                TipFormHelper.ShowError("图表信息保存失败!");
                return;
            }
            _vmo.DiagramID = diagramId;
            _vmo.OtherName = this.textEditName.Text.Trim();
            _vmo.Importance = int.Parse(this.textEditImportance.EditValue.ToString());
            _vmo.ID = await BLLFactory<HStation.BLL.PhartDiagramRelation>.Instance.Insert(_vmo);
            if (_vmo.ID < 1)
            {
                TipFormHelper.ShowError("图表关联信息保存失败!");
                return;
            }
            var vmo = await BLLFactory<HStation.BLL.PhartDiagramRelation>.Instance.GetByID(_vmo.ID);
            this.ReloadDataEvent?.Invoke(vmo);
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
 
        private void btnExcelFilePath_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            if (e.Button.Tag.ToString() == "Import")
            {
                var dlg = new System.Windows.Forms.OpenFileDialog();
                dlg.Filter = "EXCEL 文件(*.xls)|*.xls";
                dlg.CheckFileExists = true;
                if (dlg.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                    return;
                this.btnExcelFilePath.Text = dlg.FileName;
                this.pumpChartExcelImportCtrl1.SetBindingData(btnExcelFilePath.Text);
            }
            else if (e.Button.Tag.ToString() == "Download")
            {
                var dlg = new SaveFileDialog();
                dlg.Title = "模板导出路径";
                dlg.Filter = "Excel文件|*.xls";
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    var fileName = dlg.FileName;
                    Yw.WinFrmUI.PhartExcelHelper.ExportPumpTemplate(fileName);
                    TipFormHelper.ShowSucceed("导出成功!");
                }
            }
        }
    }
}