tx
8 天以前 e0b138b3e057de6f57021e6c8963868f5c5acc5a
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
using DevExpress.XtraEditors;
using System.Collections.Generic;
using System.Windows.Forms;
 
namespace TProduct.WinFrmUI.TestBench
{
    public partial class MgrWorkBenchMonitorPointPanel : DocumentPage
    {
        public MgrWorkBenchMonitorPointPanel()
        {
            InitializeComponent();
            this.PageTitle.Caption = "测点信息";
            this._pageOperateInfo = "测点信息列表";
 
            this.gridView1.SetNormalView();
            this.gridView1.SetGridMianViewColor();
            this.gridView1.CustomUnboundColumnData += GridView1_CustomUnboundColumnData;
        }
        public override void InitialDataSource()
        {
            base.InitialDataSource();
 
            /// <summary>
            /// 初始化
            /// </summary>
            /// <param name="paras"></param>
            _bindList = new BLL.WorkBenchMonitorPoint().GetAll();
            if (_bindList == null)
                _bindList = new List<Model.WorkBenchMonitorPoint>();
            this.bindingSource1.DataSource = _bindList;
            this.bindingSource1.ResetBindings(false);
        }
 
        private void GridView1_CustomUnboundColumnData(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs e)
        {
            if (e.Column == this.colSourceType)
            {
                var pt = e.Row as Model.WorkBenchMonitorPoint;
                if (pt != null)
                {
                    if (pt.SourceType == Model.eMonitorPointSourceType.未知)
                    {
                        e.Value = "还未设置,请尽快确认";
                    }
                    if (pt.SourceType == Model.eMonitorPointSourceType.模拟量)
                    {
                        e.Value = "模拟量,需要确认量程";
                    }
                    if (pt.SourceType == Model.eMonitorPointSourceType.数字量)
                    {
                        e.Value = "数字量,需要确认寄存器地址";
                    }
                    if (pt.SourceType == Model.eMonitorPointSourceType.额定参数)
                    {
                        e.Value = "额定参数";
                    }
                }
            }
        }
 
 
        private List<Model.WorkBenchMonitorPoint> _bindList = null;
 
 
 
        //添加
        private void barBtnAdd_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (  _bindList == null)
                return;
            WaitFrmHelper.ShowWaitForm();
            var dlg = new SetSingleBenchMonitorPointInfoDlg();
            dlg.Shown += delegate { WaitFrmHelper.HideWaitForm(); };
            dlg.SetBindingData( );
            dlg.ReloadDataEvent += rhs =>
            {
                _bindList.Add(rhs);
                this.bindingSource1.ResetBindings(false);
            };
            dlg.ShowDialog();
        }
        //
        private void barBtnCopy_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (_bindList == null)
                return;
            var source = this.gridView1.GetCurrentViewModel(_bindList);
            if (source == null)
            {
                XtraMessageBox.Show("未选择数据!");
                return;
            }
            var bll = new BLL.WorkBenchMonitorPoint();
            var copy_pt = new TProduct.Model.WorkBenchMonitorPoint(source);
            copy_pt.ID = 0;
            copy_pt.Name = copy_pt.Name + "(复制)";
            copy_pt.Code = bll.CreateNO();
            copy_pt.ID = bll.Insert(copy_pt);
 
            WaitFrmHelper.ShowWaitForm();
            var dlg = new SetSingleBenchMonitorPointInfoDlg();
            dlg.Shown += delegate { WaitFrmHelper.HideWaitForm(); };
            dlg.SetBindingData(copy_pt);
            dlg.ReloadDataEvent += rhs =>
            {
                _bindList.Add(rhs);
                this.gridView1.RefreshData();
            };
            dlg.ShowDialog();
        }
 
        //编辑
        private void barBtnEdit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (_bindList == null)
                return;
            var row = this.gridView1.GetCurrentViewModel(_bindList);
            if (row == null)
            {
                XtraMessageBox.Show("未选择数据!");
                return;
            }
            WaitFrmHelper.ShowWaitForm();
            var dlg = new SetSingleBenchMonitorPointInfoDlg();
            dlg.Shown += delegate { WaitFrmHelper.HideWaitForm(); };
            dlg.SetBindingData(row);
            dlg.ReloadDataEvent += rhs =>
            {
                row.Reset(rhs);
                this.gridView1.RefreshData();
            };
            dlg.ShowDialog();
        }
 
 
 
        private void barBtnDel_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var row = this.gridView1.GetCurrentViewModel(_bindList);
            if (row == null)
                return;
 
            DialogResult dr = XtraMessageBox.Show("是否删除此测点?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
            if (dr != DialogResult.Yes)
                return;
 
            var result = new BLL.WorkBenchMonitorPoint().DeleteByID(row.ID);
 
            if (result)
            {
                _bindList.Remove(row);
                this.bindingSource1.ResetBindings(false);
                XtraMessageBox.Show("删除成功!");
            }
            else
            {
                XtraMessageBox.Show("删除失败!");
            }
        }
 
        private void bbi导出EXCEL_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var path = ExcelSaveFilePathHelper.SaveFilePathName();
            if (string.IsNullOrEmpty(path)) return;
            DevExpress.XtraPrinting.XlsExportOptions options = new DevExpress.XtraPrinting.XlsExportOptions();
            options.RawDataMode = true;//所见即所得
            options.TextExportMode = DevExpress.XtraPrinting.TextExportMode.Text;
            this.colID.DisplayFormat.FormatString = "\t{0}";
            this.colID.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Custom;
            this.gridView1.OptionsPrint.AutoWidth = false;
            this.gridView1.ExportToXls(path, options);
            DialogResult dr = XtraMessageBox.Show("导出成功!是否打开刚刚保存的Excel文件?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
            if (dr != DialogResult.OK)
                return;
            System.Diagnostics.Process.Start(path);
        }
 
        private void barBtnView_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
 
        }
    }
}