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
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
{
    [DefaultEvent("SelectProductMotorChangedEvent")]
    public partial class SelectMotorComboxCtrl : DevExpress.XtraEditors.XtraUserControl
    {
        public SelectMotorComboxCtrl()
        {
            InitializeComponent();
 
            this.productCtrl.AddDataChanedEvent += Content_AddDataChanedEvent;
            this.productCtrl.EditDataChanedEvent += Content_EditDataChanedEvent;
            this.productCtrl.FocusedDataChangedEvent += Content_FocusedDataChangedEvent;
          
            this.popupContainerEdit1.Popup += new System.EventHandler(this.popupContainerEdit_Popup);
            this.popupContainerEdit1.CustomDisplayText += new DevExpress.XtraEditors.Controls.CustomDisplayTextEventHandler(this.popupContainerEdit_CustomDisplayText);
 
        }
 
        public event Action<Model.ProductMainExMotor> FocusedDataChangedEvent = null;
        public event Action<Model.ProductMainExMotor> AddDataChanedEvent = null;
        public event Action<Model.ProductMainExMotor> EditDataChanedEvent = null;
 
        /// <summary>
        /// 选择的产品 
        /// </summary>
        public Model.ProductMainExMotor SelectMotor
        {
            get { return _selectMotor; }
            private set
            {
                long origin_id = 0;
                if (_selectMotor != null)
                {
                    origin_id = _selectMotor.ID;
                }
 
                _selectMotor = value;
                if (_selectMotor != null)
                {
                    this.popupContainerEdit1.Text = _selectMotor.Name;
                    if (_selectMotor.ID != origin_id)
                    {
                        this.FocusedDataChangedEvent?.Invoke(value);
                    }
                }
                else
                {
                    this.popupContainerEdit1.Text = null;
                }
            }
        }
        private Model.ProductMainExMotor _selectMotor = null;
       
        public void SetBindingData(long SeriesID, long ProductID)
        {
            _selectMotor = this.productCtrl.SetBindingData(SeriesID, ProductID);
            if (_selectMotor != null)
                this.popupContainerEdit1.EditValue = _selectMotor;
        }
        //是否修改了数组成员
        public bool IsChangeList { get { return productCtrl.IsChangeList; } }
 
       
        //设置为不可编辑
        public void SetReadOnly()
        {
            productCtrl.SetReadOnly();
        }
 
  
        //自定义显示
        private void popupContainerEdit_CustomDisplayText(object sender, DevExpress.XtraEditors.Controls.CustomDisplayTextEventArgs e)
        {
            var width = this.Size.Width;
            this.popupContainerControl1.Size = new Size(width, 300);
            var model = e.Value as Model.ProductMainExMotor;
            e.DisplayText = model?.Name;
        }
        /// <summary>
        /// 保证弹出时, 是 当时选择的
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void popupContainerEdit_Popup(object sender, EventArgs e)
        {
            if (_selectMotor != null)
                this.productCtrl.SetFocusedData(_selectMotor);
        }
 
        private void Content_EditDataChanedEvent(Model.ProductMainExMotor obj)
        {
            EditDataChanedEvent?.Invoke(obj);
        }
 
        private void Content_AddDataChanedEvent(Model.ProductMainExMotor obj)
        {
            AddDataChanedEvent?.Invoke(obj);
        }
        private void Content_FocusedDataChangedEvent(Model.ProductMainExMotor obj)
        {
            this.popupContainerEdit1.ClosePopup();
            if (_selectMotor != null)
            {
                if (_selectMotor.ID == obj.ID)
                    return;
            }
            _selectMotor = obj;
            this.popupContainerEdit1.EditValue = _selectMotor;
            this.FocusedDataChangedEvent?.Invoke(_selectMotor);
        }
 
    }
}