This repository has been archived by the owner on Sep 11, 2023. It is now read-only.
/
Form1.cs
99 lines (86 loc) · 2.73 KB
/
Form1.cs
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Diagnostics;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
DataTable tbl;
UploadHelper helper;
public UploadedFile CurrentFile
{
get { return helper == null ? null : helper.CurrentFile; }
}
public Form1()
{
InitializeComponent();
DataTable table = CreateTable();
gridControl1.DataSource = table;
helper = new UploadHelper(table);
helper.CurrentFileChanged += helper_CurrentFileChanged;
repositoryItemButtonEdit1.ButtonClick += repositoryItemButtonEdit1_ButtonClick;
}
void helper_CurrentFileChanged(object sender, EventArgs e)
{
UpdateHyperLink();
}
public DataTable CreateTable()
{
tbl = new DataTable();
tbl.Columns.Add("FileName", typeof(string));
tbl.Columns.Add("FileSize", typeof(int));
tbl.Columns.Add("FileContent", typeof(object));
return tbl;
}
void UpdateHyperLink()
{
if (helper.CurrentFile == null)
{
hyperLinkEdit1.Enabled = false;
hyperLinkEdit1.Text = "No file chosen";
}
else
{
hyperLinkEdit1.Enabled = true;
hyperLinkEdit1.Text = String.Format("{0} ({1})", CurrentFile.FullPath, CurrentFile.FileSize);
}
}
UploadedFile GetFocusedFile()
{
DataRow dataRow =gridView1.GetFocusedDataRow();
if (dataRow == null)
{
helper.PostNewFile(-1);
return GetFocusedFile();
}
return new UploadedFile((byte[])dataRow["FileContent"], (string)dataRow["FileName"]);
}
void repositoryItemButtonEdit1_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
{
switch (e.Button.Index)
{
case 0:
GetFocusedFile().OpenFile();
break;
case 1:
helper.PostNewFile(gridView1.GetFocusedDataSourceRowIndex());
gridView1.UpdateCurrentRow();
break;
}
}
private void btOpenFile_Click(object sender, EventArgs e)
{
helper.ChooseFile();
}
private void btUploadFile_Click(object sender, EventArgs e)
{
helper.UploadFile();
}
}
}