프로젝트

일반

사용자정보

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

markus / KCOM / Messenger / ConversationView.xaml.cs @ ddc223b4

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

1
using KCOM.Common;
2
using KCOM.Views;
3
using System;
4
using System.Collections.Generic;
5
using System.ComponentModel;
6
using System.Diagnostics;
7
using System.Linq;
8
using System.Text;
9
using System.Threading.Tasks;
10
using System.Windows;
11
using System.Windows.Controls;
12
using System.Windows.Data;
13
using System.Windows.Documents;
14
using System.Windows.Input;
15
using System.Windows.Media;
16
using System.Windows.Media.Imaging;
17
using System.Windows.Navigation;
18
using System.Windows.Shapes;
19
using Telerik.Windows.Controls;
20
namespace KCOM.Messenger
21
{
22
    /// <summary>
23
    /// Interaction logic for ConversationView.xaml
24
    /// </summary>
25
    public partial class ConversationView : UserControl, INotifyPropertyChanged
26
    {
27
        public Telerik.Windows.Controls.DelegateCommand ClickAnchorCommand { get; set; }
28
        MainWindow main;
29

    
30
        public ConversationView()
31
        {
32
            App.splashString(ISplashMessage.CONVERSATIONVIEW);
33
            InitializeComponent();
34
            this.DataContext = this;
35
            
36
            this.Loaded += ConversationView_Loaded;
37
            btnMark.MouseLeftButtonDown += BtnMark_Click;
38
            btnMail.MouseLeftButtonDown += BtnMail_Click;
39
            btnFile.MouseLeftButtonDown += BtnFile_Click;
40
            //강인구 추가
41
            btnSend.PreviewMouseLeftButtonDown += BtnSend_Click;
42
        }
43

    
44
        private void BtnMark_Click(object sender, RoutedEventArgs e)
45
        {
46
            if (main.dzMainMenu.SelectLayer.Children.Count > 0)
47
            {
48
                DialogParameters parameters = new DialogParameters()
49
                {
50
                    Owner = Application.Current.MainWindow,
51
                    Closed = (obj, args) => this.MarkupNameUpdatePromptClose(args),
52
                    Content = "Memo :",
53
                    Header = "Make a note About the Anchor",
54
                    Theme = new VisualStudio2013Theme(),
55
                    ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 },
56
                };
57
                RadWindow.Prompt(parameters);
58

    
59

    
60
            }
61
            else
62
            {
63
                MessageBox.Show("Please Select a comment first", "Info");
64
            }
65
        }
66

    
67
        private void BtnFile_Click(object sender, RoutedEventArgs e)
68
        {
69
            MessageBox.Show("데모 버전에서는 지원하지 않습니다", "안내");
70
        }
71

    
72
        private void BtnMail_Click(object sender, RoutedEventArgs e)
73
        {
74
            MessageBox.Show("데모 버전에서는 지원하지 않습니다", "안내");
75
        }
76

    
77
        //강인구 추가
78
        private async void BtnSend_Click(object sender, MouseButtonEventArgs e)
79
        {
80
            await AddTextAsync();
81
        }
82

    
83
        private void MarkupNameUpdatePromptClose(WindowClosedEventArgs args)
84
        {
85
            if (args.DialogResult.GetValueOrDefault())
86
            {
87
                if (String.IsNullOrWhiteSpace(args.PromptResult) || args.PromptResult == null)
88
                {
89
                    MessageBox.Show("공백으로 입력하시면 등록이 불가능합니다", "안내");
90
                }
91
                else
92
                {
93
                    Controls.AdornerFinal finalItem = main.dzMainMenu.SelectLayer.Children[0] as Controls.AdornerFinal;
94
                    Rect rect = new Rect(new Point(finalItem.BorderSize.Left - 100, finalItem.BorderSize.Top - 100), new Point(finalItem.BorderSize.Right + 100, finalItem.BorderSize.Bottom + 100));
95

    
96
                    var instanceMain = this.ParentOfType<MainWindow>();
97
                    if (instanceMain.dzMainMenu.rotate.Angle == 90)
98
                    {
99
                        rect = new Rect(new Point(finalItem.BorderSize.Top - 100, finalItem.BorderSize.Right + 100), new Point(finalItem.BorderSize.Bottom + 100, finalItem.BorderSize.Left - 100));
100
                        double y = rect.Y;
101
                        double x = rect.X;
102
                        rect.X = instanceMain.dzMainMenu.zoomAndPanCanvas.Width - x - rect.Width;
103
                        rect.Y = y;
104
                    }
105
                    else if (instanceMain.dzMainMenu.rotate.Angle == 180)
106
                    {
107
                        rect = new Rect(new Point(finalItem.BorderSize.Right + 100, finalItem.BorderSize.Bottom + 100), new Point(finalItem.BorderSize.Left - 100, finalItem.BorderSize.Top - 100));
108
                        double y = rect.Y;
109
                        double x = rect.X;
110
                        rect.X = instanceMain.dzMainMenu.zoomAndPanCanvas.Width - x - rect.Width;
111
                        rect.Y = instanceMain.dzMainMenu.zoomAndPanCanvas.Height - y - rect.Height;
112
                    }
113
                    else if (instanceMain.dzMainMenu.rotate.Angle == 270)
114
                    {
115
                        rect = new Rect(new Point(finalItem.BorderSize.Bottom + 100, finalItem.BorderSize.Left - 100), new Point(finalItem.BorderSize.Top - 100, finalItem.BorderSize.Right + 100));
116
                        double y = rect.Y;
117
                        double x = rect.X;
118
                        rect.X = x;
119
                        rect.Y = instanceMain.dzMainMenu.zoomAndPanCanvas.Height - y - rect.Height;
120
                    }
121

    
122
                    // Load 시 페이지 이동 없이 TALK 작성 시 Page값이 0으로 들어감, TALK TABLE에 PAGENUMBER가 0일 경우 Angle이 적용되지 않음.                 
123
                    if (Common.ViewerDataModel.Instance.SyncPageNumber == 0)
124
                    {
125
                        Common.ViewerDataModel.Instance.SyncPageNumber = 1;
126
                    }
127
                    //Common.ViewerDataModel.Instance.k_talkMessageSet.Clear();
128
                    KCOMDataModel.DataModel.TALK message = new KCOMDataModel.DataModel.TALK
129
                    {
130
                        TEXT = args.PromptResult,
131
                        MSGSIDE = (int)MessageSide.Me,
132
                        MEMBER_ID = App.ViewInfo.UserID,
133
                        MEMBER_NAME = App.UserName,
134
                        MSGTYPE = (int)MessageType.Anchor,
135
                        TIMESTAMP = DateTime.Now,
136
                        DOCUMENT_ID = App.ViewInfo.DocumentItemID,
137
                        RECT_X = rect.X,
138
                        RECT_Y = rect.Y,
139
                        RECT_WIDTH = rect.Width,
140
                        RECT_HEIGHT = rect.Height,
141
                        PAGENUMBER = Common.ViewerDataModel.Instance.SyncPageNumber,
142
                        ANGLE = (int)instanceMain.dzMainMenu.rotate.Angle
143
                    };
144

    
145
                    //Logger.sendReqLog("AddMessage: ", App.ViewInfo.ProjectNO + "," + message, 1);
146
                    //Logger.sendResLog("AddMessage", Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.AddMessage(App.ViewInfo.ProjectNO, message).ToString(), 1);
147
                    //Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.AddMessage(App.ViewInfo.ProjectNO, message);
148

    
149
                    //Logger.sendReqLog("GetMessage: ", App.ViewInfo.ProjectNO + "," + App.ViewInfo.DocumentItemID, 1);
150
                    List<KCOMDataModel.DataModel.TALK> messagelist = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.GetMessage(App.ViewInfo.ProjectNO, App.ViewInfo.DocumentItemID);
151
                    if (messagelist.Count() > 0)
152
                    {
153
                        //Logger.sendResLog("GetMessage", "TRUE", 1);
154
                    }
155
                    else
156
                    {
157
                        //Logger.sendResLog("GetMessage", "FALSE", 1);
158
                    }
159
                    messagelist.ForEach(a =>
160
                    {
161
                        Common.ViewerDataModel.Instance.k_talkMessageSet.Add(a);
162
                    });
163

    
164
                    tbContent.Text = "";
165
                    tbContent.Focus();
166
                    (lstMessage.Parent as ScrollViewer).ScrollToEnd();
167
                }
168
            }
169
        }
170

    
171
        protected virtual void OnPropertyChanged(String info)
172
        {
173
            if (PropertyChanged != null)
174
                PropertyChanged(this, new PropertyChangedEventArgs(info));
175
        }
176

    
177
        private void SaveAuthorization(object parameter)
178
        {
179
            KCOMDataModel.DataModel.TALK instance = parameter as KCOMDataModel.DataModel.TALK;
180
            Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.rotate.Angle = instance.ANGLE;
181
            Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.GotoPageTALK(instance.PAGENUMBER.Value, instance.ANGLE);
182
            Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.zoomAndPanControl.ZoomToTalk(new Rect { X = instance.RECT_X.Value, Y = instance.RECT_Y.Value, Width = instance.RECT_WIDTH.Value, Height = instance.RECT_HEIGHT.Value }, instance.ANGLE);
183
        }
184

    
185
        public event PropertyChangedEventHandler PropertyChanged;
186

    
187
        private async void ConversationView_Loaded(object sender, RoutedEventArgs e)
188
        {
189
            //측정
190
            //Stopwatch sw = new Stopwatch();
191
            //sw.Start();
192
            //InitializeComponent();
193
            //System.Diagnostics.Debug.WriteLine("ConversationView() : " + sw.ElapsedMilliseconds.ToString() + "ms");
194

    
195
            main = this.ParentOfType<MainWindow>();
196
            if (App.ParameterMode)
197
            {
198
                try
199
                {
200
                    var mainMenu = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu;
201

    
202
                    ClickAnchorCommand = new Telerik.Windows.Controls.DelegateCommand(SaveAuthorization);
203
                    if (string.IsNullOrEmpty(App.UserName) && mainMenu.userData == null)
204
                    {
205
                        var member = await mainMenu.BaseTaskClient.GetMemberAsync(App.ViewInfo.ProjectNO, App.ViewInfo.UserID);
206
                        if (member != null)
207
                            App.UserName = member.NAME;
208
                    }
209
                    if (Common.ViewerDataModel.Instance.k_talkMessageSet.Count() == 0)
210
                    {
211
                        //Logger.sendReqLog("GetMessage: ", App.ViewInfo.ProjectNO + "," + App.ViewInfo.DocumentItemID, 1);
212
                        List<KCOMDataModel.DataModel.TALK> messagelist = await mainMenu.BaseTaskClient.GetMessageAsync(App.ViewInfo.ProjectNO, App.ViewInfo.DocumentItemID);
213

    
214
                        //Logger.sendResLog("GetMessage", "messagelist.Count:" + messagelist.Count(), 1);
215

    
216
                        messagelist.ForEach(a =>
217
                        {
218
                            Common.ViewerDataModel.Instance.k_talkMessageSet.Add(a);
219
                        });
220
                        (lstMessage.Parent as ScrollViewer).ScrollToEnd();
221
                    }
222

    
223
                    tbContent.KeyDown += OnKeyDownHandler;
224
                }
225
                catch (Exception ex)
226
                {
227
                    Logger.sendReqLog("ConverstionView Error",Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseTaskClient.Endpoint.Address.ToString() + " " + ex.ToString(),1);
228
                    MessageBox.Show(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseTaskClient.Endpoint.Address.ToString() + ex.ToString());
229
                }
230
            }
231
        }
232

    
233
        private async void OnKeyDownHandler(object sender, KeyEventArgs e)
234
        {
235
            if (e.Key == Key.Return)
236
            {
237
                if (Keyboard.Modifiers != ModifierKeys.Shift)
238
                {
239
                    await AddTextAsync();
240
                    e.Handled = true;
241
                }
242
                else
243
                {
244
                    tbContent.Text = tbContent.Text + Environment.NewLine;
245
                    tbContent.CaretIndex = tbContent.Text.Length;
246
                    e.Handled = true;
247
                }
248
            }
249
        }
250

    
251
        private async Task AddTextAsync()
252
        {
253
            Common.ViewerDataModel.Instance.k_talkMessageSet.Clear();
254

    
255
            KCOMDataModel.DataModel.TALK message = new KCOMDataModel.DataModel.TALK
256
            {
257
                TEXT = tbContent.Text,
258
                MSGSIDE = (int)MessageSide.Me,
259
                MEMBER_ID = App.ViewInfo.UserID,
260
                MEMBER_NAME = App.UserName,
261
                MSGTYPE = (int)MessageType.Normal,
262
                TIMESTAMP = DateTime.Now,
263
                DOCUMENT_ID = App.ViewInfo.DocumentItemID
264
            };
265

    
266
            //Logger.sendReqLog("AddMessage", App.ViewInfo.ProjectNO + "," + message, 1);
267
            //Logger.sendResLog("AddMessage", Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.AddMessage(App.ViewInfo.ProjectNO, message).ToString(), 1);
268
            if(await Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseTaskClient.AddMessageAsync(App.ViewInfo.ProjectNO, message))
269
            {
270
                var messagelist = await Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseTaskClient.GetMessageAsync(App.ViewInfo.ProjectNO, App.ViewInfo.DocumentItemID);
271

    
272
                if (messagelist.Count() > 0)
273
                {
274
                    //Logger.sendResLog("GetMessage", "TRUE", 1);
275
                }
276
                else
277
                {
278
                    //Logger.sendResLog("GetMessage", "FALSE", 1);
279
                }
280

    
281
                messagelist.ForEach(a =>
282
                {
283
                    Common.ViewerDataModel.Instance.k_talkMessageSet.Add(a);
284
                });
285
                tbContent.Text = "";
286
                tbContent.Focus();
287
                (lstMessage.Parent as ScrollViewer).ScrollToEnd();
288
            }
289

    
290
            //Logger.sendReqLog("GetMessage: ", App.ViewInfo.ProjectNO + "," + App.ViewInfo.DocumentItemID, 1);
291
           
292

    
293
        }
294
    }
295
}
클립보드 이미지 추가 (최대 크기: 500 MB)