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
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.Data4Factory
{
    [DefaultEvent("SelectProductTypeChangedEvent")]
    public partial class SelectProductTypeCtrl : DevExpress.XtraEditors.XtraUserControl
    {
        public SelectProductTypeCtrl()
        {
            InitializeComponent();
            this.productTypeCtrl1.AddDataChanedEvent += Content_AddDataChanedEvent;
            this.productTypeCtrl1.EditDataChanedEvent += Content_EditDataChanedEvent;
            this.productTypeCtrl1.FocusedDataChangedEvent += Content_FocusedDataChangedEvent;
        }
 
        public event Action<Model.ProductStyle> FocusedDataChangedEvent = null;
        public event Action<Model.ProductStyle> AddDataChanedEvent = null;
        public event Action<Model.ProductStyle> EditDataChanedEvent = null;
 
        /// <summary>
        /// 当前选择的类别
        /// </summary>
        public Model.ProductStyle Selected { get; private set; }
 
        /// <summary>
        /// 选择的产品分类
        /// </summary>
        public Model.ProductStyle SelectProductStyle
        {
            get { return _selectProductStyle; }
            private set
            {
                var temp = _selectProductStyle;
                _selectProductStyle = value;
                this.popupContainerEdit1.Text = _selectProductStyle == null ? null : _selectProductStyle.Name;
                if (!System.Object.ReferenceEquals(_selectProductStyle, temp))
                {
                    this.FocusedDataChangedEvent?.Invoke(value);
                }
            }
        }
        private Model.ProductStyle _selectProductStyle = null;
 
 
        public void SetBindingData(Model.eProductType type) 
        {
            this.productTypeCtrl1.SetBindingData(type);
        }
 
        /// <summary>
        /// 默认值初始化
        /// </summary>
        public void SetFocused(Model.eProductType type,long ID)
        {
            var bol = this.productTypeCtrl1.SetFocused(type, ID);
            if (bol)
            {
                var obj = this.productTypeCtrl1.GetFocused();
                if (obj == null)
                    return;
                var de = obj as Model.ProductStyle;
                if (de == null)
                    return;
                if (Selected != null)
                {
                    if (Selected.ID == de.ID)
                        return;
                }
                Selected = de;
                this.popupContainerEdit1.EditValue = Selected;
                this.FocusedDataChangedEvent?.Invoke(Selected);
            }
        }
 
        private void Content_FocusedDataChangedEvent(Model.ProductStyle obj)
        {
            this.popupContainerEdit1.ClosePopup();
            if (Selected != null)
            {
                if (Selected.ID == obj.ID)
                    return;
            }
            Selected = obj;
            this.popupContainerEdit1.EditValue = Selected;
            this.FocusedDataChangedEvent?.Invoke(Selected);
        }
 
        //自定义显示
        private void popupContainerEdit1_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.ProductStyle;
            e.DisplayText = model?.Name;
        }
 
        private void Content_EditDataChanedEvent(Model.ProductStyle obj)
        {
            EditDataChanedEvent?.Invoke(obj);
        }
 
        private void Content_AddDataChanedEvent(Model.ProductStyle obj)
        {
            AddDataChanedEvent?.Invoke(obj);
        }
    }
}