프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

markus / KCOM / ViewModel / RequirementSearchViewModel.cs @ df2e7646

이력 | 보기 | 이력해설 | 다운로드 (3.2 KB)

1 df2e7646 taeseongkim
using System;
2
using System.Collections.Generic;
3
using System.Collections.ObjectModel;
4
using System.Linq;
5
using System.Text;
6
using System.Threading.Tasks;
7
using System.Windows;
8
using KCOM.Common;
9
using KCOM.Converters;
10
using KCOM.PemssService;
11
using Markus.Mvvm.ToolKit;
12
using Telerik.Windows.Controls;
13
14
namespace KCOM.ViewModel
15
{
16
    public class RequirementSearchViewModel : Markus.Mvvm.ToolKit.ViewModelBase
17
    {
18
        PemssService.PemssServiceClient pemssServiceClient;
19
20
        private System.Collections.ObjectModel.ObservableCollection<Requirement> requirementList;
21
22
        public ObservableCollection<Requirement> RequirementList
23
        {
24
            get
25
            {
26
                if (requirementList == null)
27
                {
28
                    requirementList = new ObservableCollection<Requirement>();
29
                }
30
31
                return requirementList;
32
            }
33
            set
34
            {
35
                if (requirementList != value)
36
                {
37
                    requirementList = value;
38
                    OnPropertyChanged(() => RequirementList);
39
                }
40
            }
41
        }
42
43
        #region UI에 대한 이벤트
44
45
        public RelayCommand<GridSelectMultiValues> SelectedRequirmentCommand
46
                    => new RelayCommand<GridSelectMultiValues>(x => OnSelectedRequirmentCommand(x));
47
48
        #endregion
49
50
        #region 초기화 및 종료 이벤트
51
52
        public RequirementSearchViewModel()
53
        {
54
            if (App.IsDesignMode)
55
                return;
56
57
            try
58
            {
59
                if (pemssServiceClient == null)
60
                {
61
                    pemssServiceClient = new PemssServiceClient(App._binding, App._PemssEndPoint);
62
                }
63
64
                OnGetRequirementDataAsync().ConfigureAwait(false);
65
            }
66
            catch (Exception ex)
67
            {
68
69
                System.Diagnostics.Debug.WriteLine(ex);
70
            }
71
        }
72
73
        public override void Loaded()
74
        {
75
            base.Loaded();
76
        }
77
78
        public override void Closed()
79
        {
80
            base.Closed();
81
        }
82
83
        #endregion
84
85
        #region Command
86
        private async Task OnGetRequirementDataAsync(bool IsInit = true)
87
        {
88
            var result = await pemssServiceClient.GetrequirementListAsync(App.ViewInfo.ProjectNO, App.ViewInfo.DocumentItemID);
89
            requirementList.Clear();
90
91
            result.ForEach(newItem =>
92
            {
93
                newItem.IsExpanded = true;
94
                newItem.IsExpandable = true;
95
96
                if (IsInit)
97
                {
98
                    RequirementList.Add(newItem);
99
                }
100
                else
101
                {
102
                    RequirementList.UpdateWhere(changeitem => CollectionExtensions.ChangeValues(changeitem, newItem), x => x.mdId == newItem.mdId);
103
                }
104
            });
105
        }
106
107
        private void OnSelectedRequirmentCommand(GridSelectMultiValues values)
108
        {
109
            var selectRequirement = values.SelectItem as Requirement;
110
            values.RadWindow.PromptResult = selectRequirement.mdId;
111
            values.RadWindow.DialogResult = true;
112
            values.RadWindow.Close();
113
        }
114
115
        #endregion Command
116
117
    }
118
}
클립보드 이미지 추가 (최대 크기: 500 MB)