duheng
2024-10-24 5fcc843704ca90c742b578aa5898acf0097f753b
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
namespace HStation.WinFrmUI
{
    public partial class XhsProjectSimulationSchemeMgrCtrl : DevExpress.XtraEditors.XtraUserControl
    {
        public XhsProjectSimulationSchemeMgrCtrl()
        {
            InitializeComponent();
            this.layoutControl1.SetupLayoutControl();
            this.listBoxControl1.InitialDefaultSettings(30);
        }
 
        /// <summary>
        /// 项目站选择改变事件
        /// </summary>
        public event Action<XhsProjectSiteVmo> ProjectSiteSelectedChangedEvent;
 
        private long _projectId;//项目id
        private XhsProjectVmo _project = null;//项目
        private List<XhsProjectSiteVmo> _allProjectSiteList = null;//所有项目站列表
        private List<HStation.Vmo.XhsSchemeVmo> _allSchemeList = null;//所有方案列表
 
 
        /// <summary>
        /// 绑定数据
        /// </summary>
        public async Task SetBindingData(long projectId)
        {
            _projectId = projectId;
            _project = await BLLFactory<HStation.BLL.XhsProject>.Instance.GetByID(projectId);
            await SetBindingData(_project);
        }
 
        /// <summary>
        /// 绑定数据
        /// </summary>
        public async Task SetBindingData(XhsProjectVmo project)
        {
            if (project == null)
            {
                return;
            }
            _project = project;
            _projectId = project.ID;
            _allProjectSiteList = await BLLFactory<HStation.BLL.XhsProjectSite>.Instance.GetByProjectID(_projectId);
            InitialProjectSiteList();
        }
 
        /// <summary>
        /// 添加方案
        /// </summary>
        public void AppendScheme(XhsSchemeVmo scheme)
        {
            if (_allSchemeList == null)
            {
                _allSchemeList = new List<XhsSchemeVmo>();
            }
            _allSchemeList.Add(scheme);
            this.xhsProjectSimulationSchemeMgrViewModelBindingSource.DataSource = _allSchemeList;
            this.xhsProjectSimulationSchemeMgrViewModelBindingSource.ResetBindings(false);
        }
 
        //初始化项目站列表
        private void InitialProjectSiteList()
        {
            this.imgCmbProjectSiteList.Properties.BeginUpdate();
            this.imgCmbProjectSiteList.Properties.Items.Clear();
            if (_allProjectSiteList != null && _allProjectSiteList.Count > 0)
            {
                foreach (var projectSite in _allProjectSiteList)
                {
                    var imgItem = new ImageComboBoxItem();
                    imgItem.Value = projectSite;
                    imgItem.Description = projectSite.Name;
                    this.imgCmbProjectSiteList.Properties.Items.Add(imgItem);
                }
            }
            this.imgCmbProjectSiteList.Properties.EndUpdate();
 
            if (_allProjectSiteList != null && _allProjectSiteList.Count > 0)
            {
                this.imgCmbProjectSiteList.SelectedIndex = 0;
            }
 
            if (_allProjectSiteList != null && _allProjectSiteList.Count > 1)
            {
                this.itemForProjectSiteList.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
            }
            else
            {
                this.itemForProjectSiteList.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
            }
        }
 
        //初始化项目方案
        private async Task InitalSchemeList(XhsProjectSiteVmo projectSite)
        {
            _allSchemeList = null;
            if (projectSite != null)
            {
                _allSchemeList = await BLLFactory<HStation.BLL.XhsScheme>.Instance.GetBySiteID(projectSite.ID);
            }
            this.xhsProjectSimulationSchemeMgrViewModelBindingSource.DataSource = _allSchemeList;
            this.xhsProjectSimulationSchemeMgrViewModelBindingSource.ResetBindings(false);
        }
 
        //项目站选择索引改变
        private async void imgCmbProjectSiteList_SelectedIndexChanged(object sender, EventArgs e)
        {
            var vmo = this.imgCmbProjectSiteList.EditValue as XhsProjectSiteVmo;
            await InitalSchemeList(vmo);
            this.ProjectSiteSelectedChangedEvent?.Invoke(vmo);
        }
 
 
    }
}