tx
2025-04-09 fa7510e1ed63df0366787fa4ed1b3db6426d2b46
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
using DevExpress.Utils.About;
using DevExpress.XtraEditors;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms; 
 
namespace TProduct.WinFrmUI.Data4Owner
{
    public partial class SelectSeriesComboxContentCtrl : DevExpress.XtraEditors.XtraUserControl
    {
        public SelectSeriesComboxContentCtrl()
        {
            InitializeComponent();
 
            this.layoutControl1.SetupLayoutControl();
 
            this.gridViewMain.SetNormalView(30);
            this.gridViewMain.SetGridMianViewColor();
            this.gridViewMain.RegistCustomDrawRowIndicator();
            this.gridViewMain.RowClick += new DevExpress.XtraGrid.Views.Grid.RowClickEventHandler(this.GridViewMain_RowClick);
 
        }
        private bool _isChangeList = false;//是否修改了数组成员
 
        public bool IsChangeList { get => _isChangeList; set => _isChangeList = value; }
 
 
        public event Action<Model.ProductSeries> FocusedDataChangedEvent = null;
        public event Action<Model.ProductSeries> AddDataChanedEvent = null;
        public event Action<Model.ProductSeries> EditDataChanedEvent = null;
 
        private List<Model.ProductSeries> _bindList = null;
        private Model.eProductType _productType;
        List<Model.ProductStyle> _allStyles = null;
 
        public void SetReadOnly()
        {
            this.barButAdd.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
            this.barButEdit.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
        }
        /// <summary>
        /// 初始化并设置默认值
        /// </summary>
        public Model.ProductSeries SetBindingData(Model.eProductType type, long SeriesID)
        {
            _productType = type;
 
            _bindList = new BLL.ProductSeries().GetByProductType(type);
            if (_bindList == null || _bindList.Count() == 0)
                return null;
            _allStyles = new BLL.ProductStyle().GetByProductType(type);
       
            this.bindingSource1.DataSource = _bindList;
            this.bindingSource1.ResetBindings(false);
 
            Model.ProductSeries find = null;
            if (SeriesID > 0)
            {
                find = this._bindList.Find(x => x.ID == SeriesID);
            }
            if (find == null)
                find = _bindList.First();
 
            SetFocusedData(find);
 
 
 
            this.FocusedDataChangedEvent?.Invoke(find);
 
 
            return find;
        }
 
        /// <summary>
        /// 初始化并设置默认值
        /// </summary>
        /// <param name="sel"></param>
        public bool SetFocusedData(Model.ProductSeries sel)
        {
            if (sel == null) { return false; }
            var find_index = this._bindList.FindIndex(x => x.ID == sel.ID);
            this.gridViewMain.SelectRow(find_index);
 
            this.gridViewMain.FocusedRowHandle = find_index;
            return true;
        }
 
        private void GridViewMain_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
        {
            var row = this.gridViewMain.GetFocusedRow() as Model.ProductSeries;
            if (row == null)
                return;
            this.FocusedDataChangedEvent?.Invoke(row);
        }
 
        private void barButAdd_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            WaitFrmHelper.ShowWaitForm();
            var dlg = new AddProductSeriesDlg();
            dlg.Shown += delegate { WaitFrmHelper.HideWaitForm(); };
            dlg.SetBindingData(_productType);
            dlg.ReloadDataEvent += (rhs) =>
            {
                _isChangeList = true;
                _bindList.Add(rhs);
                this.bindingSource1.ResetBindings(false);
                this.AddDataChanedEvent?.Invoke(rhs);
                this.FocusedDataChangedEvent?.Invoke(rhs);
                XtraMessageBox.Show("添加成功!");
            };
            dlg.ShowDialog();
        }
 
        private void barButEdit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var row = this.gridViewMain.GetCurrentViewModel(_bindList);
            if (row == null)
            { 
                XtraMessageBox.Show("请选择一行数据!");
                return;
            }
            WaitFrmHelper.ShowWaitForm();
            var dlg = new EditProductSeriesDlg();
            dlg.Shown += delegate { WaitFrmHelper.HideWaitForm(); };
            dlg.SetBindingData(_productType,row);
            dlg.ReloadDataEvent += (rhs) =>
            {
                _isChangeList = true;
                row.Reset(rhs);
                this.bindingSource1.ResetBindings(false);
                EditDataChanedEvent?.Invoke(rhs );
                XtraMessageBox.Show("修改成功!");
            };
            dlg.ShowDialog();
        }
 
        private void barCheckFilter_CheckedChanged(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            this.gridViewMain.OptionsFind.AlwaysVisible = this.barCkSelect.Checked;
        }
 
 
        private void gridViewMain_CustomUnboundColumnData(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs e)
        {
            if (e.Column == colStyle)
            {
                var row = e.Row as Model.ProductSeries;
                if (row == null) return;
                if (_allStyles == null)
                    return;
                e.Value = _allStyles.Find(x => x.ID == row.ProductStyleID).Name;
            }
        }
    }
}