lixiaojun
2024-07-25 8b2f98400842e022aefd5f2f935ca62239a75228
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
using DevExpress.XtraLayout.Utils;
 
namespace HStation.WinFrmUI
{
    public partial class ImportXhsProjectDlg : DevExpress.XtraEditors.XtraForm
    {
        public ImportXhsProjectDlg()
        {
            InitializeComponent();
        }
 
 
        private readonly ImportXhsProjectViewModel _vm = new();
        private ImportXhsProjectManager _wizard;
 
        /// <summary>
        /// 
        /// </summary>
        public ImportXhsProjectViewModel ViewModel
        {
            get { return _vm; }
        }
 
        /// <summary>
        /// 
        /// </summary>
        public void SetBindingData()
        {
            _wizard = new ImportXhsProjectManager(_vm);
            _wizard.SelectedPageChangedEvent += _wizard_SelectedPageChangedEvent;
            _wizard.SelectedPageStateChangedEvent += _wizard_SelectedPageStateChangedEvent; ;
            _wizard.InitialManager(new IWizardPage<ImportXhsProjectViewModel>[] {
                this.selectXhsProjectModelFileWizardPage,
                this.inputXhsProjectInfoWizardPage,
                this.setXhsProjectMapLocationWizardPage,
                this.generateXhsProjectWizardPage,
                this.importXhsProjectCompletedWizardPage
            });
        }
 
        //选择页面改变
        private void _wizard_SelectedPageChangedEvent(IWizardPage<ImportXhsProjectViewModel> page, int index)
        {
            this.itemForPrev.Visibility = page.AllowPrev ? LayoutVisibility.Always : LayoutVisibility.Never;
            this.itemForNext.Visibility = page.AllowNext ? LayoutVisibility.Always : LayoutVisibility.Never;
            this.itemForCancel.Visibility = page.AllowCancel ? LayoutVisibility.Always : LayoutVisibility.Never;
            this.itemForComplete.Visibility = page.AllowComplete ? LayoutVisibility.Always : LayoutVisibility.Never;
            this.navigationFrame1.SelectedPageIndex = index;
            this.stepProgressBar1.SelectedItemIndex = index;
        }
 
        //选择页面状态改变
        private void _wizard_SelectedPageStateChangedEvent(IWizardPage<ImportXhsProjectViewModel> page, int index)
        {
            this.itemForPrev.Visibility = page.AllowPrev ? LayoutVisibility.Always : LayoutVisibility.Never;
            this.itemForNext.Visibility = page.AllowNext ? LayoutVisibility.Always : LayoutVisibility.Never;
            this.itemForCancel.Visibility = page.AllowCancel ? LayoutVisibility.Always : LayoutVisibility.Never;
            this.itemForComplete.Visibility = page.AllowComplete ? LayoutVisibility.Always : LayoutVisibility.Never;
        }
 
        //上一步
        private void btnPrev_Click(object sender, EventArgs e)
        {
            if (_wizard != null)
            {
                _wizard.Prev();
            }
        }
 
        //下一步
        private void btnNext_Click(object sender, EventArgs e)
        {
            if (_wizard != null)
            {
                _wizard.Next();
            }
        }
 
        //取消
        private void btnCancel_Click(object sender, EventArgs e)
        {
            if (_wizard != null)
            {
                var bol = _wizard.Cancel();
                if (bol)
                {
                    this.DialogResult = DialogResult.Cancel;
                    this.Close();
                }
            }
        }
 
        //完成
        private void btnComplete_Click(object sender, EventArgs e)
        {
            if (_wizard != null)
            {
                var bol = _wizard.Complete();
                if (bol)
                {
                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
            }
        }
 
        //正在关闭
        private void ImportXhsProjectDlg_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (_wizard != null)
            {
                if (this.DialogResult == DialogResult.OK)
                {
                    if (!_wizard.Complete())
                    {
                        e.Cancel = true;
                    }
                }
                else if (this.DialogResult == DialogResult.Cancel)
                {
                    if (!_wizard.Cancel())
                    {
                        e.Cancel = true;
                    }
                }
                else
                {
                    e.Cancel = true;
                }
 
            }
        }
    }
}