프로젝트

일반

사용자정보

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

hytos / ID2.Manager / ID2.Manager / Controls / BriefAndImages.cs @ 3b7f9db8

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

1
using ID2.Manager.Data.Models;
2
using System;
3
using System.Collections.Generic;
4
using System.ComponentModel;
5
using System.Data;
6
using System.Drawing;
7
using System.IO;
8
using System.Linq;
9
using System.Text;
10
using System.Threading.Tasks;
11
using System.Windows.Forms;
12
using Telerik.WinControls;
13
using Telerik.WinControls.UI;
14

    
15
using ID2.Manager.Common;
16

    
17
namespace ID2.Manager.Controls
18
{
19

    
20
    public partial class BriefAndImages : UserControl
21
    {
22
        readonly Informations informations = Informations.Instance;
23
        const int TextMinHeight = 30;
24
        public event EventHandler<AttImageInfo> RemoveImage;
25
        bool IsClient = false;
26

    
27
        public BriefAndImages()
28
        {
29
            InitializeComponent();
30
            
31
            txtBriefDoftech.DataBindings.Add(new Binding("Text", this, "BriefDoftech",false,DataSourceUpdateMode.OnPropertyChanged));
32
            txtBriefSec.DataBindings.Add(new Binding("Text", this, "BriefSec", false, DataSourceUpdateMode.OnPropertyChanged));
33
            txtBriefDoftech.TextBoxElement.TextBoxItem.MouseDown += TextBoxItemDoftech_MouseDown;
34
            txtBriefDoftech.TextBoxElement.TextBoxItem.LostFocus += TextBoxItemDoftech_LostFocus;
35

    
36
            txtBriefSec.TextBoxElement.TextBoxItem.MouseDown += TextBoxItemSec_MouseDown;
37
            txtBriefSec.TextBoxElement.TextBoxItem.LostFocus += TextBoxItemSec_LostFocus;
38

    
39
            lstToImages.ListViewElement.ViewElement.Orientation = Orientation.Horizontal;
40
            lstFrImages.ListViewElement.ViewElement.Orientation = Orientation.Horizontal;
41

    
42
            selectImage.ContextMenuOpened += SelectImage_ContextMenuOpened;
43
            selectImage.MouseWheel += SelectImage_MouseWheel;
44

    
45
            lstToImages.SelectedItemChanged += LstImages_SelectedItemChanged;
46
            lstToImages.ItemRemoving += LstToImages_ItemRemoving;
47
            lstToImages.ItemRemoved += LstToImages_ItemRemoved;
48
            lstToImages.VisualItemFormatting += LstImages_VisualItemFormatting;
49
            lstToImages.EditorInitialized += LstToImages_EditorInitialized;
50
            lstFrImages.SelectedItemChanged += LstImages_SelectedItemChanged;
51
            lstFrImages.ItemRemoving += LstFrImages_ItemRemoving;
52
            lstFrImages.ItemRemoved += LstFrImages_ItemRemoved;
53
            lstFrImages.VisualItemFormatting += LstImages_VisualItemFormatting;
54
            lstFrImages.EditorInitialized += LstFrImages_EditorInitialized;
55

    
56
            this.IsClient = !string.IsNullOrEmpty(informations.ActiveUser.RefProjectID);
57
            txtBriefDoftech.ReadOnly = this.IsClient;
58
            txtBriefSec.ReadOnly = !this.IsClient;
59
        }
60

    
61
        private void LstToImages_EditorInitialized(object sender, ListViewItemEditorInitializedEventArgs e)
62
        {
63
        }
64

    
65
        private void LstFrImages_EditorInitialized(object sender, ListViewItemEditorInitializedEventArgs e)
66
        {
67
        }
68

    
69
        private void LstToImages_ItemRemoving(object sender, ListViewItemCancelEventArgs e)
70
        {
71
            if (RemoveImage != null)
72
            {
73
                e.Cancel = this.IsClient;
74
            }
75
        }
76

    
77
        private void LstToImages_ItemRemoved(object sender, ListViewItemEventArgs e)
78
        {
79
            if (RemoveImage != null)
80
            {
81
                RemoveImage(this, e.Item.DataBoundItem as AttImageInfo);
82
            }
83
        }
84

    
85
        private void LstFrImages_ItemRemoving(object sender, ListViewItemCancelEventArgs e)
86
        {
87
            if (RemoveImage != null)
88
            {
89
                e.Cancel = !this.IsClient;
90
            }
91
        }
92

    
93
        private void LstFrImages_ItemRemoved(object sender, ListViewItemEventArgs e)
94
        {
95
            if (RemoveImage != null)
96
            {
97
                RemoveImage(this, e.Item.DataBoundItem as AttImageInfo);
98
            }
99
        }
100

    
101
        private void TextBoxItemDoftech_LostFocus(object sender, EventArgs e)
102
        {
103
            txtBriefDoftech.MinimumSize = new Size(0, TextMinHeight);
104

    
105
            LayoutDoftech.RowStyles[1].Height = 100;
106
            LayoutDoftech.RowStyles[1].SizeType = SizeType.Percent;
107
        }
108

    
109
        private void TextBoxItemDoftech_MouseDown(object sender, MouseEventArgs e)
110
        {
111
            txtBriefDoftech.MinimumSize = new Size(0, 100);
112

    
113
            LayoutDoftech.RowStyles[1].Height = 100;
114
            LayoutDoftech.RowStyles[1].SizeType = SizeType.Absolute;
115
        }
116

    
117
        private void TextBoxItemSec_LostFocus(object sender, EventArgs e)
118
        {
119

    
120
            txtBriefSec.MinimumSize = new Size(0, TextMinHeight);
121

    
122
            LayoutSec.RowStyles[1].Height = 100;
123
            LayoutSec.RowStyles[1].SizeType = SizeType.Percent;
124
        }
125

    
126
        private void TextBoxItemSec_MouseDown(object sender, MouseEventArgs e)
127
        {
128
            txtBriefSec.MinimumSize = new Size(0, 100);
129

    
130
            LayoutSec.RowStyles[1].Height = 100;
131
            LayoutSec.RowStyles[1].SizeType = SizeType.Absolute;
132
        }
133

    
134
        public event PropertyChangedEventHandler PropertyChanged;
135

    
136
        private void LstImages_VisualItemFormatting(object sender, ListViewVisualItemEventArgs e)
137
        {
138
            e.VisualItem.ImageLayout = ImageLayout.Stretch;
139
        }
140

    
141
        private void LstImages_SelectedItemChanged(object sender, EventArgs e)
142
        {
143
            var lstImages = sender as RadListViewElement;
144

    
145
            if (lstImages.SelectedItem?.Image != null)
146
            {
147
                selectImage.Image = lstImages.SelectedItem.Image;
148
            }
149
        }
150

    
151
        private void SelectImage_MouseWheel(object sender, MouseEventArgs e)
152
        {
153
            if (e.Delta < 0)
154
            {
155
                selectImage.ZoomProperties.ZoomOut();
156
            }
157
            else
158
            {
159
                selectImage.ZoomProperties.ZoomIn();
160
            }
161

    
162
        }
163

    
164
        private void SelectImage_ContextMenuOpened(object sender, EventArgs e)
165
        {
166
            selectImage.ContextMenuProperties.OpenItem.Visibility = ElementVisibility.Collapsed;
167
            selectImage.ContextMenuProperties.RemoveItem.Visibility = ElementVisibility.Collapsed;
168
            selectImage.ContextMenuProperties.CutItem.Visibility = ElementVisibility.Collapsed;
169
            selectImage.ContextMenuProperties.PasteItem.Visibility = ElementVisibility.Collapsed;
170
            
171
            //selectImage.ContextMenuProperties.EditItem.Visibility = ElementVisibility.Collapsed;
172
        }
173

    
174
        public void SetToImages(List<AttImageInfo> images)
175
        {
176
            foreach (var image in images)
177
            {
178
                AddToImage(image);
179
            }
180

    
181
            if (images?.Count() > 0)
182
            {
183
                lstToImages.SelectedIndex = 0;
184
            }
185
        }
186

    
187
        public void AddToImage(AttImageInfo image,bool SelectItem = false)
188
        {
189
            ListViewDataItem item = new ListViewDataItem("");
190
            item.DataBoundItem = image;
191
            item.ImageAlignment = ContentAlignment.MiddleCenter;
192
            item.Image = GetImage(image.Data);
193
            item.TextImageRelation = TextImageRelation.ImageBeforeText;
194
            lstToImages.Items.Add(item);
195

    
196
            if (SelectItem)
197
            {
198
                lstToImages.SelectedItem = item; 
199
            }
200
        }
201

    
202
        public void SetFrImages(List<AttImageInfo> images)
203
        {
204
            foreach (var image in images)
205
            {
206
                AddFrImage(image);
207
            }
208

    
209
            if (images?.Count() > 0)
210
            {
211
                lstFrImages.SelectedIndex = 0;
212
            }
213
        }
214

    
215

    
216
        public void AddFrImage(AttImageInfo image, bool SelectItem = false)
217
        {
218
            ListViewDataItem item = new ListViewDataItem(image);
219
            item.ImageAlignment = ContentAlignment.MiddleCenter;
220
            item.Text = "";
221
            item.Image = GetImage(image.Data);
222
            item.TextImageRelation = TextImageRelation.Overlay;
223
            lstFrImages.Items.Add(item);
224

    
225
            if (SelectItem)
226
            {
227
                lstFrImages.SelectedItem = item;
228
            }
229
        }
230

    
231

    
232
        public void Clear()
233
        {
234
            this.DataBindings.Clear();
235
            lstFrImages.Items.Clear();
236
            lstToImages.Items.Clear();
237
            selectImage.Image = null;
238
            briefDoftech = "";
239
            BriefSec = "";
240
        }
241

    
242
        private string briefDoftech;
243
        public string BriefDoftech
244
        {
245
            get { return briefDoftech; }
246
            set
247
            {
248
                if (briefDoftech != value)
249
                {
250
                    briefDoftech = value;
251
                    var propArg = new PropertyChangedEventArgs(nameof(BriefDoftech));
252
                    PropertyChanged?.Invoke(this, propArg);
253
                }
254
            }
255
        }
256

    
257
        private string briefSec;
258
        public string BriefSec
259
        {
260
            get { return briefSec; }
261
            set
262
            {
263
                if (briefSec != value)
264
                {
265
                    briefSec = value;
266
                    var propArg = new PropertyChangedEventArgs(nameof(BriefSec));
267
                    PropertyChanged?.Invoke(this, propArg);
268
                }
269
            }
270
        }
271

    
272
        private System.Drawing.Image GetImage(byte[] data)
273
        {
274
            System.Drawing.Image result = null;
275

    
276
            using (MemoryStream ms = new MemoryStream(data))
277
            {
278
                result = System.Drawing.Image.FromStream(ms);
279
            }
280

    
281
            return result;
282
        }
283

    
284
        private void txtBrief_TextChanged(object sender, EventArgs e)
285
        {
286
           BriefDoftech = txtBriefDoftech.Text;
287
        }
288

    
289
        private void txtBriefSec_TextChanged(object sender, EventArgs e)
290
        {
291
            BriefSec = txtBriefSec.Text;
292
        }
293

    
294
    }
295

    
296
}
297

    
298
public class AttImageInfo
299
{
300
    public string ID { get; set; }
301
    public string Category { get; set; }
302
    public byte[] Data { get; set; }
303
}
클립보드 이미지 추가 (최대 크기: 500 MB)