프로젝트

일반

사용자정보

통계
| 개정판:

hytos / ID2.Manager / ID2.Manager.Compare / Forms / ImageView.cs @ 4142eefa

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

1
using System;
2
using System.Collections.Generic;
3
using System.ComponentModel;
4
using System.Data;
5
using System.Drawing;
6
using System.Linq;
7
using System.Text;
8
using System.Threading.Tasks;
9
using System.Windows.Forms;
10

    
11
using System.IO;
12

    
13
using ID2.Manager.Common;
14
using ID2.Manager.Data.Models;
15
using ID2.Manager.Controller.Controllers;
16

    
17
using Telerik.WinControls;
18
using Telerik.WinControls.UI;
19

    
20
namespace ID2.Manager.Forms
21
{
22
    public partial class ImageView : RadForm
23
    {
24
        readonly Informations informations = Informations.Instance;
25

    
26
        string RefID = string.Empty;
27
        string Category = string.Empty;
28
        public OpenFileDialog ofd;
29
        
30
        public ImageView(string docID, string category)
31
        {
32
            InitializeComponent();
33

    
34
            this.RefID = docID;
35
            this.Category = category;
36

    
37
            this.Initialize();
38

    
39
            this.Load += ImageView_Load;
40
            this.radButtonSave.Click += RadButtonSave_Click;
41
        }
42

    
43
        private void Initialize()
44
        {
45
            ofd = this.radBrowseEditorFile.BrowseDialog as OpenFileDialog;
46
            ofd.Filter = "Image files (*.png)|*.png";
47
            ofd.Title = "Open an Image File";
48
        }
49

    
50
        private void ImageView_Load(object sender, EventArgs e)
51
        {
52
            //string[] files = Directory.GetFiles(@"C:\Users\yoush97\Desktop\PAP자료\SG6609 HMB\ID2\Image\img\", "*.png");
53

    
54
            //string[] files = new string[] { };
55

    
56
            //foreach (string file in files)
57
            //{
58
            //    PictureBox pic = new PictureBox();
59
            //    pic.Image = Image.FromFile(file);
60
            //    pic.SizeMode = PictureBoxSizeMode.Zoom;
61
            //    pic.Width = 150;
62
            //    pic.Height = 150;
63
            //    pic.Margin = new Padding(5);
64

    
65
            //    flowLayoutPanel1.Controls.Add(pic);
66

    
67
            //    pic.Click += Pic_Click;
68
            //}
69

    
70
            this.GetFileList();
71
        }
72

    
73
        public void GetFileList()
74
        {
75
            //var files = new FileController().GetFileList(this.RefID).ToList();
76
            var files = new AttFileController().GetFileList(this.RefID, this.Category);
77

    
78
            foreach (AttFileInfo file in files)
79
            {
80
                var arrayBinary = file.FileData.ToArray();
81

    
82
                using (MemoryStream ms = new MemoryStream(arrayBinary))
83
                {
84
                    PictureBox pic = new PictureBox();
85
                    pic.Image = Image.FromStream(ms);
86
                    pic.SizeMode = PictureBoxSizeMode.Zoom;
87
                    pic.Width = 150;
88
                    pic.Height = 150;
89
                    pic.Margin = new Padding(5);
90

    
91
                    flowLayoutPanel1.Controls.Add(pic);
92

    
93
                    pic.Click += Pic_Click;
94
                }
95
            }
96
        }
97

    
98
        private void Pic_Click(object sender, EventArgs e)
99
        {
100
            PictureBox pic = sender as PictureBox;
101
            pictureBox1.Image = pic.Image;
102
        }
103

    
104
        private void RadButtonSave_Click(object sender, EventArgs e)
105
        {
106
            string GetContentType(string filePath)
107
            {
108
                string extension = Path.GetExtension(filePath).ToLower();
109

    
110
                switch (extension)
111
                {
112
                    case ".txt":
113
                        return "text/plain";
114
                    case ".pdf":
115
                        return "application/pdf";
116
                    case ".jpg":
117
                    case ".jpeg":
118
                        return "image/jpeg";
119
                    case ".png":
120
                        return "image/png";
121
                    default:
122
                        return "application/octet-stream";
123
                }
124
            }
125

    
126
            if (string.IsNullOrEmpty(ofd.FileName) && !File.Exists(ofd.FileName))
127
            {
128
                RadMessageBox.Show($"There is no Image File selected.", "Information", MessageBoxButtons.OK, RadMessageIcon.Info);
129
                return;
130
            }
131

    
132
            System.IO.FileInfo fileInfo = new System.IO.FileInfo(ofd.FileName);
133
            if (fileInfo.Exists)
134
            {
135
                AttFileInfo attFile = new AttFileInfo()
136
                {
137
                    RefID = this.RefID,
138
                    Category = this.Category,
139
                    FileType = GetContentType(fileInfo.FullName),
140
                    FileName = fileInfo.Name,
141
                    FilePath = fileInfo.DirectoryName,
142
                    FileExtension = fileInfo.Extension
143
                };
144

    
145
                using (var stream = new FileStream(ofd.FileName, FileMode.Open, FileAccess.Read))
146
                {
147
                    using (var reader = new BinaryReader(stream))
148
                    {
149
                        attFile.FileData = reader.ReadBytes((int)stream.Length);
150
                    }
151
                }
152

    
153
                bool result = new AttFileController().SetAttFiles(new List<AttFileInfo>() { attFile }, informations.ActiveUser.ID);
154

    
155
                if (result)
156
                {
157
                    RadMessageBox.Show("Save is complete", Globals.Name, MessageBoxButtons.OK, RadMessageIcon.Info);
158
                }
159
                else
160
                {
161
                    RadMessageBox.Show("Save is not complete", Globals.Name, MessageBoxButtons.OK, RadMessageIcon.Error);
162
                }
163
            }
164
        }
165
    }
166
}
클립보드 이미지 추가 (최대 크기: 500 MB)