-
-
Notifications
You must be signed in to change notification settings - Fork 110
Expand file tree
/
Copy pathDatabaseRecordList.aspx.cs
More file actions
157 lines (140 loc) · 5.05 KB
/
Copy pathDatabaseRecordList.aspx.cs
File metadata and controls
157 lines (140 loc) · 5.05 KB
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace System.pages
{
public partial class DatabaseRecordList : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
LoadRecords();
}
else
{
string action = Request["hiddenPostbackAction"] + "";
if (action == "delete")
{
DeleteRecords();
}
}
}
protected void btnLoadFiles_Click(object sender, EventArgs e)
{
LoadRecords();
}
private void LoadRecords()
{
var records = BackupFilesManager.GetRecordList(0, null, null);
StringBuilder sb = new StringBuilder();
sb.Append($@"
<div class='records-container'>
<div class='summary-info'>Total Records: {records.Count}</div>
<table class='records-table'>
<thead>
<tr>
<th><input type='checkbox' id='chkSelectAll' onclick='toggleSelectAll()' /></th>
<th>ID</th>
<th>Operation</th>
<th>Original Filename</th>
<th>Size</th>
<th>Database</th>
<th>Date Created</th>
<th>Remarks</th>
<th>Action</th>
</tr>
</thead>
<tbody>");
foreach (var record in records)
{
string elapsedTime = GetElapsedTime(record.DateCreated);
sb.Append($@"
<tr>
<td><input type='checkbox' class='record-checkbox' name='del_{record.Id}' /></td>
<td>{record.Id}</td>
<td>{HttpUtility.HtmlEncode(record.Operation)}</td>
<td><span class='label-filename'>{HttpUtility.HtmlEncode(record.Filename)}</span><br />
<span class='label-sha'>SHA256:</span><span class='value-sha'>{record.Sha256}</span>
</td>
<td>{FormatFileSize(record.Filesize)}</td>
<td>{HttpUtility.HtmlEncode(record.DatabaseName)}</td>
<td>{record.DateCreated:yyyy-MM-dd HH:mm:ss}<br />{elapsedTime}</td>
<td>{HttpUtility.HtmlEncode(record.Remarks)}</td>
<td>
<a class='view-link' href='/DisplayFileContent?id={record.Id}' target='_blank'>View</a><br />
<a class='view-link' href='/DisplayFileContent?id={record.Id}&action=download' target='frame1' onclick='showBigLoading();'>Download</a><br />
<a class='view-link' href='#' onclick='event.preventDefault(); restoreFileId({record.Id});'>Restore</a>
</td>
</tr>");
}
sb.Append($@"
</tbody>
</table>
</div>");
ltlRecords.Text = sb.ToString();
}
private string GetElapsedTime(DateTime dateCreated)
{
TimeSpan elapsed = DateTime.Now - dateCreated;
if (elapsed.TotalDays >= 1)
{
int days = (int)elapsed.TotalDays;
return $"{days} day{(days == 1 ? "" : "s")} ago";
}
else if (elapsed.TotalHours >= 1)
{
int hours = (int)elapsed.TotalHours;
return $"{hours} hour{(hours == 1 ? "" : "s")} ago";
}
else if (elapsed.TotalMinutes >= 1)
{
int minutes = (int)elapsed.TotalMinutes;
return $"{minutes} minute{(minutes == 1 ? "" : "s")} ago";
}
else
{
int seconds = (int)elapsed.TotalSeconds;
return $"{seconds} second{(seconds == 1 ? "" : "s")} ago";
}
}
void DeleteRecords()
{
List<int> lstDelId = new List<int>();
// Collect all form keys that start with "del_"
foreach (string key in Request.Form.AllKeys)
{
if (key != null && key.StartsWith("del_"))
{
// Extract ID from the key name (del_123 -> 123)
string idStr = key.Substring(4); // Remove "del_" prefix
if (int.TryParse(idStr, out int id))
{
lstDelId.Add(id);
}
}
}
if (lstDelId.Count > 0)
{
BackupFilesManager.DeleteRecords(lstDelId);
}
LoadRecords();
}
private string FormatFileSize(long bytes)
{
string[] sizes = { "B", "KB", "MB", "GB", "TB" };
double len = bytes;
int order = 0;
while (len >= 1024 && order < sizes.Length - 1)
{
order++;
len = len / 1024;
}
return string.Format("{0:0.###} {1}", len, sizes[order]);
}
}
}