-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathManageProduct.aspx.cs
149 lines (125 loc) · 4.26 KB
/
ManageProduct.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
//ID#: 1401375
//Developer: Lomar Lilly
//Module: Enterprise Computing
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class ManageProduct : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void getAntiMalwareSoftware(object sender, EventArgs e)
{
txtCategory.Text = "1";
}
protected void getBusinessAntivirusSoftware(object sender, EventArgs e)
{
txtCategory.Text = "2";
}
protected void getBackupSoftware(object sender, EventArgs e)
{
txtCategory.Text = "3";
}
protected void getDeveloperSoftware(object sender, EventArgs e)
{
txtCategory.Text = "4";
}
protected void getDriverSoftware(object sender, EventArgs e)
{
txtCategory.Text = "5";
}
protected void getFileTransferSoftware(object sender, EventArgs e)
{
txtCategory.Text = "6";
}
protected void getMultimediaSoftware(object sender, EventArgs e)
{
txtCategory.Text = "7";
}
protected void getOfficeNewsSoftware(object sender, EventArgs e)
{
txtCategory.Text = "8";
}
protected void getNetworkingSoftware(object sender, EventArgs e)
{
txtCategory.Text = "9";
}
protected void getSecuritySoftware(object sender, EventArgs e)
{
txtCategory.Text = "10";
}
protected void getSystemTuningSoftware(object sender, EventArgs e)
{
txtCategory.Text = "11";
}
protected void getVPNsSoftware(object sender, EventArgs e)
{
txtCategory.Text = "12";
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
// Read the file and convert it to Byte Array
string filePath = fuImagePath.PostedFile.FileName;
string filename = Path.GetFileName(filePath);
string ext = Path.GetExtension(filename);
string contenttype = String.Empty;
//Set the contenttype based on File Extension
switch (ext)
{
case ".jpg":
contenttype = "image/jpg";
break;
case ".png":
contenttype = "image/png";
break;
case ".gif":
contenttype = "image/gif";
break;
case ".jpeg":
contenttype = "image/jpeg";
break;
}
if (contenttype != String.Empty)
{
String strConnString = ConfigurationManager.ConnectionStrings["1401375ConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(strConnString);
SqlCommand cmd = new SqlCommand("spSoftware_UploadImage", con);
cmd.CommandType = System.Data.CommandType.StoredProcedure;
try
{
Stream fs = fuImagePath.PostedFile.InputStream;
BinaryReader br = new BinaryReader(fs);
Byte[] bytes = br.ReadBytes((Int32)fs.Length);
//INSERT IMAGE FILE AND DATA IN DB
cmd.Parameters.AddWithValue("@softwareID", Convert.ToInt32(txtSoftwareID.Text));
cmd.Parameters.AddWithValue("@softwareImage", bytes);
con.Open();
int result = cmd.ExecuteNonQuery();
con.Close();
lblmessage.ForeColor = System.Drawing.Color.Green;
lblmessage.Text = "File Uploaded Successfully";
}
catch (Exception ex)
{
lblmessage.ForeColor = System.Drawing.Color.Red;
lblmessage.Text = "Oops!! Something went wrong";
//lblmessage.Text = Convert.ToString(ex);
}
}
else
{
lblmessage.ForeColor = System.Drawing.Color.Red;
lblmessage.Text = "File format not recognised." +
" Please select a Image format .png .jpg OR .gif";
}
Response.Redirect("ManageProduct.aspx", false);
}
}