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
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("_selectProductSeriestProductSeriesChangedEvent")]
    public partial class SelectSeriesComboxCtrl : DevExpress.XtraEditors.XtraUserControl
    {
        public SelectSeriesComboxCtrl()
        {
            InitializeComponent();
            this.popupContainerEdit1.Popup += new System.EventHandler(this.popupContainerEdit_Popup);
            this.popupContainerEdit1.CustomDisplayText += new DevExpress.XtraEditors.Controls.CustomDisplayTextEventHandler(this.popupContainerEdit_CustomDisplayText);
 
            this.productSeriesCtrl1.AddDataChanedEvent += ProductSeriesCtrl1_AddDataChanedEvent;
            this.productSeriesCtrl1.EditDataChanedEvent += ProductSeriesCtrl1_EditDataChanedEvent;
            this.productSeriesCtrl1.FocusedDataChangedEvent += ProductSeriesCtrl1_FocusedDataChangedEvent;
        }
 
        public event Action<Model.ProductSeries> FocusedDataChangedEvent = null;
        public event Action<Model.ProductSeries> AddDataChanedEvent = null;
        public event Action<Model.ProductSeries> EditDataChanedEvent = null;
        //是否修改了数组成员
        public bool IsChangeList { get { return productSeriesCtrl1.IsChangeList; } }
        /// <summary>
        /// 选择的产品 
        /// </summary>
        public Model.ProductSeries SelectProductSeries
        {
            get { return _selectProductSeries; }
            private set
            {
                long origin_id = 0;
                if(_selectProductSeries != null)
                {
                    origin_id = _selectProductSeries.ID;
                }
                _selectProductSeries = value;
                if(_selectProductSeries != null)
                {
                    this.popupContainerEdit1.Text = _selectProductSeries.Name;
                    if (_selectProductSeries.ID != origin_id)
                    {
                        this.FocusedDataChangedEvent?.Invoke(value);
                    }
                }
                else
                {
                    this.popupContainerEdit1.Text = null;
                }
            }
        }
        private Model.ProductSeries _selectProductSeries = null;
 
        /// <summary>
        /// 
        /// </summary>
        /// <param name="height"></param>
        public void SetHeight(int height)
        {
            //this.popupContainerEdit1.MaximumSize = new System.Drawing.Size(0, height);
            this.popupContainerEdit1.MinimumSize = new System.Drawing.Size(0, height);
        }
        /// <summary>
        /// 默认值初始化
        /// </summary>
        public void SetBindingData(Model.eProductType type,long ID)
        {
            _selectProductSeries = this.productSeriesCtrl1.SetBindingData(type, ID);
            if (_selectProductSeries != null)
                this.popupContainerEdit1.EditValue = _selectProductSeries;
        }
 
        /// <summary>
        /// 保证弹出时, 是 当时选择的
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void popupContainerEdit_Popup(object sender, EventArgs e)
        {
            if (_selectProductSeries != null)
                this.productSeriesCtrl1.SetFocusedData(_selectProductSeries);
        }
        //自定义显示
        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.ProductSeries;
            e.DisplayText = model?.Name;
        }
 
        private void ProductSeriesCtrl1_FocusedDataChangedEvent(Model.ProductSeries obj)
        {
            this.popupContainerEdit1.ClosePopup();
            if (_selectProductSeries != null)
            {
                if (_selectProductSeries.ID == obj.ID)
                    return;
            }
            _selectProductSeries = obj;
            this.popupContainerEdit1.EditValue = _selectProductSeries;
            this.FocusedDataChangedEvent?.Invoke(_selectProductSeries);
        }
 
        private void ProductSeriesCtrl1_EditDataChanedEvent(Model.ProductSeries obj)
        {
            EditDataChanedEvent?.Invoke(obj);
        }
 
        private void ProductSeriesCtrl1_AddDataChanedEvent(Model.ProductSeries obj)
        {
            AddDataChanedEvent?.Invoke(obj);
        }
 
        //设置为不可编辑
        public void SetReadOnly()
        {
            productSeriesCtrl1.SetReadOnly();
        }
    }
}