-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheditImage.aspx.cs
More file actions
95 lines (80 loc) · 2.38 KB
/
editImage.aspx.cs
File metadata and controls
95 lines (80 loc) · 2.38 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
public partial class editImage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["admin"] == null)
{
Response.Redirect("home.aspx");
}
if (!IsPostBack)
{
int imageID = Convert.ToInt32(Request.QueryString["ImageID"]);
if (imageID != 0)
{
GetImage(imageID);
}
}
}
protected void GetImage(int imageID)
{
DataTable results = ImageDB.GetImage(imageID);
if (results.Rows.Count == 1)
{
imgEdit.ImageUrl = results.Rows[0]["ImageURL"].ToString();
txtCaption.Text = results.Rows[0]["ImageCaption"].ToString();
if (Convert.ToInt32(results.Rows[0]["ImagePrimary"].ToString()) == 1)
{
cbPrimaryPhoto.Checked = true;
}
else
{
cbPrimaryPhoto.Checked = false;
}
hfRegistrantID.Value = results.Rows[0]["RegistrantID"].ToString();
hfImageID.Value = imageID.ToString();
}
}
protected void btnSave_Click(object sender, EventArgs e)
{
RegImages image = new RegImages();
image.ImageCaption = txtCaption.Text;
if (cbPrimaryPhoto.Checked == true)
{
image.Primary = 1;
}
else
{
image.Primary = 0;
}
image.ImageID = Convert.ToInt32(hfImageID.Value.ToString());
int registrantID = Convert.ToInt32(hfRegistrantID.Value.ToString());
image.RegistrantID = registrantID;
ImageDB.UpdateImage(image);
Response.Redirect("profileEdit.aspx?registrantID=" + registrantID);
}
protected void btnCancel_Click(object sender, EventArgs e)
{
int registrantID = Convert.ToInt32(hfRegistrantID.Value.ToString());
Response.Redirect("profileEdit.aspx?registrantID=" + registrantID);
}
protected void btnDelete_Click(object sender, EventArgs e)
{
int imageID = Convert.ToInt32(hfImageID.Value.ToString());
int registrantID = Convert.ToInt32(hfRegistrantID.Value.ToString());
string filePath = Server.MapPath("~/" + imgEdit.ImageUrl);
if (System.IO.File.Exists(filePath))
{
System.IO.File.Delete(filePath);
}
ImageDB.DeleteImage(imageID);
Response.Redirect("profileEdit.aspx?registrantID=" + registrantID);
}
}