/
Administration.aspx.cs
226 lines (218 loc) · 9.48 KB
/
Administration.aspx.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
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.IO;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using Magazine;
public partial class Administration : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
StatusLabel.Text = string.Empty;
}
Panel1.Visible = false;
UploadPanel.Visible = false;
btnPreview.Attributes.Add("OnClick", "window.open('magazine.html');");
}
protected string UploadPdfFile()
{
string status;
string path = Server.MapPath("~/PDF/");
if (FileUpload.HasFile)
{
String fileExtension = Path.GetExtension(FileUpload.FileName).ToLower();
if (fileExtension == ".pdf")
{
try
{
FileUpload.SaveAs(path + "temp.pdf");
status = "File uploaded!";
}
catch (Exception ex)
{
status = ex.ToString();
}
}
else
{
status = "You can upload only *.pdf files";
}
}
else
status = "Select file to upload!";
return status;
}
protected void btnCreate_Click(object sender, EventArgs e)
{
string temp2 = UploadPdfFile();
if (temp2 == "File uploaded!")
{
string temp1 = NameTextBox.Text;
int chk = temp1.IndexOf(" ");
if ((IsAlphaNumeric(NameTextBox.Text)) && chk == -1)
{
Issue newIssue = new Issue();
newIssue.IssueId = NameTextBox.Text;
newIssue.IssueDirectory = ConfigurationManager.AppSettings["imagepath"] + NameTextBox.Text;
if (Directory.Exists(newIssue.IssueDirectory))
StatusLabel.Text = "Folder already exists!";
else
{
if (!File.Exists(HttpContext.Current.Server.MapPath("~/pdf") + @"\temp.pdf"))
StatusLabel.Text = "Please upload PDF file first!";
else
{
Directory.CreateDirectory(newIssue.IssueDirectory);
newIssue.Resolution = ResolutionDropDownList.SelectedValue;
newIssue.Quality = QualityTextBox.Text;
newIssue.TextAntialiasing = TxtAliasingDropDownList.SelectedValue;
newIssue.GraphicsAntialiasing = GraphAliasingDropDownList.SelectedValue;
//StatusLabel.Text = CreateImages.CreateImagesGhostScript(newIssue);
string pdfpath = HttpContext.Current.Server.MapPath("~/pdf");
string sourcePDF = pdfpath + @"\temp.pdf";
List<string> fileList;
GhostScript.DeviceOption[] options = GhostScript.DeviceOptions.jpg(int.Parse(newIssue.Quality), int.Parse(newIssue.TextAntialiasing), int.Parse(newIssue.GraphicsAntialiasing));
GhostScript gs = new GhostScript(ConfigurationManager.AppSettings["gspath"]);
fileList = gs.Convert(GhostScript.OutputDevice.jpeg, options, sourcePDF, newIssue.IssueDirectory, "%d.jpg", pdfpath, int.Parse(newIssue.Resolution));
gs.Dispose();
string destinationPDF = newIssue.IssueDirectory + @"\" + newIssue.IssueId + ".pdf";
File.Move(sourcePDF, destinationPDF);
if (fileList.Count == 0)
{
MagazineData.CreateIssue(newIssue);
CreateXML.CreatePagesXMLFile(newIssue.IssueId);
btnPreview.Visible = true;
btnUploadOnServer.Visible = true;
StatusLabel.Text = "Image files created!";
}
else
StatusLabel.Text = "Error!";
}
}
}
else StatusLabel.Text = "Enter valid Issue name";
}
else
StatusLabel.Text = temp2;
}
protected void btnNew_Click(object sender, EventArgs e)
{
TitleLabel.Text = "New Issue";
NameTextBox.Text = string.Empty;
ResolutionDropDownList.SelectedIndex = 0;
QualityTextBox.Text = string.Empty;
TxtAliasingDropDownList.SelectedIndex = 0;
GraphAliasingDropDownList.SelectedIndex = 0;
IssuePanel.Visible = true;
Panel1.Visible = false;
NameTextBox.Visible = true;
btnUpdate.Visible = false;
btnCreate.Visible = true;
btnPreview.Visible = false;
btnUploadOnServer.Visible = false;
IssueNameLabel.Visible = true;
IssueNameLabel.Text = "Issue name: ";
}
protected void btnOpen_Click(object sender, EventArgs e)
{
TitleLabel.Text = "Open Issue";
IssuePanel.Visible = false;
Panel1.Visible = true;
OpenDropDownList.DataBind();
}
protected void btnUpdate_Click(object sender, EventArgs e)
{
if (FileUpload.HasFile)
UploadPdfFile();
string[] pdfFiles = Directory.GetFiles(Server.MapPath("~/pdf"));
string[] orgPdfFiles = Directory.GetFiles(Server.MapPath("~/content/" + OpenDropDownList.SelectedValue), "*.pdf");
if (pdfFiles.Length == 0)
File.Copy(orgPdfFiles[0], Server.MapPath("~/pdf/") + "temp.pdf");
string[] jpgFiles = Directory.GetFiles(Server.MapPath("~/content/" + OpenDropDownList.SelectedValue), "*.jpg");
foreach (string file in jpgFiles)
File.Delete(file);
Issue newIssue = new Issue();
newIssue.IssueId = OpenDropDownList.SelectedValue;
newIssue.IssueDirectory = ConfigurationManager.AppSettings["imagepath"] + OpenDropDownList.SelectedValue;
newIssue.Resolution = ResolutionDropDownList.SelectedValue;
newIssue.Quality = QualityTextBox.Text;
newIssue.TextAntialiasing = TxtAliasingDropDownList.SelectedValue;
newIssue.GraphicsAntialiasing = GraphAliasingDropDownList.SelectedValue;
StatusLabel.Text = CreateImages.CreateImagesGhostScript(newIssue);
string pdfpath = HttpContext.Current.Server.MapPath("~/pdf");
string sourcePDF = pdfpath + @"\temp.pdf";
string destinationPDF = newIssue.IssueDirectory + @"\" + newIssue.IssueId + ".pdf";
File.Copy(sourcePDF, destinationPDF, true);
File.Delete(sourcePDF);
MagazineData.UpdateIssue(newIssue);
CreateXML.CreatePagesXMLFile(newIssue.IssueId);
Panel1.Visible = true;
btnPreview.Visible = true;
RequiredFieldValidator4.Visible = false;
}
protected void btnUploadOnServer_Click(object sender, EventArgs e)
{
IssuePanel.Visible = false;
UploadPanel.Visible = true;
TitleLabel.Text = "Upload issue";
}
protected void btnUploadOnWebServer_Click(object sender, EventArgs e)
{
StatusLabel.Text = Upload.UploadUsingClient(IssuesDropDownList.SelectedValue, HostTextBox.Text, UserTextBox.Text, PasswordTextBox.Text);
}
public static bool IsAlphaNumeric(string strToCheck)
{
Regex objAlphaNumericPattern = new Regex("[^a-zA-Z0-9 ]");
return !objAlphaNumericPattern.IsMatch(strToCheck);
}
protected void btnSelect_Click(object sender, EventArgs e)
{
if (OpenDropDownList.SelectedValue == string.Empty)
StatusLabel.Text = "There are no current issues!";
else
{
Issue existingIssue = MagazineData.OpenIssue(OpenDropDownList.SelectedValue);
ResolutionDropDownList.Text = existingIssue.Resolution;
QualityTextBox.Text = existingIssue.Quality;
TxtAliasingDropDownList.Text = existingIssue.TextAntialiasing;
GraphAliasingDropDownList.Text = existingIssue.GraphicsAntialiasing;
CreateXML.CreatePagesXMLFile(existingIssue.IssueId);
btnPreview.Visible = true;
btnUploadOnServer.Visible = true;
IssuePanel.Visible = true;
Panel1.Visible = true;
IssueNameLabel.Visible = true;
NameTextBox.Visible = false;
btnCreate.Visible = false;
btnUpdate.Visible = true;
IssueNameLabel.Text = "Issue name: " + existingIssue.IssueId.ToUpper();
}
}
protected void btnDelete_Click(object sender, EventArgs e)
{
if (OpenDropDownList.SelectedValue == string.Empty)
StatusLabel.Text = "There are no current issues!";
else
{
CreateImages.DeleteImages(OpenDropDownList.SelectedValue);
StatusLabel.Text = MagazineData.DeleteIssue(OpenDropDownList.SelectedValue);
OpenDropDownList.DataBind();
Panel1.Visible = true;
IssuePanel.Visible = false;
}
}
protected void btnPreview_Click(object sender, EventArgs e)
{
Panel1.Visible = true;
}
}