-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAddEvidance.aspx.cs
113 lines (87 loc) · 4.23 KB
/
AddEvidance.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
namespace SmartSystems_NS
{
public partial class AddEvidance : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
}
}
protected void UploadFile(object sender, EventArgs e)
{
string caseno = TextBox1.Text.ToString();
string Evddetails = TextBox2.Text.ToString();
string strsql;
string fileName = caseno+"_"+Path.GetFileName(FileUpload1.PostedFile.FileName);
FileUpload1.PostedFile.SaveAs(Server.MapPath("~/Uploads/") + fileName);
strsql = "Insert into [tbl_EvidanceFiles] values ('" + caseno + "','" + fileName + "','" + Evddetails + "' ) ";
string ConnectionString = ConfigurationManager.ConnectionStrings["Database_ConnectionString"].ConnectionString;
SqlConnection conn = new SqlConnection(ConnectionString);
conn.Open();
SqlCommand cmd = new SqlCommand(strsql, conn);
cmd.ExecuteNonQuery();
Session["ViewState"] = null;
this.ClientScript.RegisterStartupScript(this.GetType(), "Evidance updated.", "<script language=\"javaScript\">" + "alert('Evidance attached successfully. ');" + "/script>");
//Response.Redirect(Request.Url.AbsoluteUri);
Bindgrid(caseno);
}
protected void DownloadFile(object sender, EventArgs e)
{
string filePath = (sender as LinkButton).CommandArgument;
filePath = Server.MapPath("~/Uploads/") + filePath;
Response.ContentType = ContentType;
Response.AppendHeader("Content-Disposition", "attachment; filename="+ Path.GetFileName(filePath));
Response.WriteFile(filePath);
Response.End();
}
protected void DeleteFile(object sender, EventArgs e)
{
//Determine the RowIndex of the Row whose Button was clicked.
int rowIndex = ((sender as LinkButton).NamingContainer as GridViewRow).RowIndex;
//Get the value of column from the DataKeys using the RowIndex.
string caseno = GridView1.DataKeys[rowIndex].Values[0].ToString();
string Evddetails = TextBox2.Text.ToString();
string strsql;
string filePath = (sender as LinkButton).CommandArgument;
strsql = "Delete from [tbl_EvidanceFiles] where CaseNo='" + caseno + "' and filename='" + filePath + "' ";
string ConnectionString = ConfigurationManager.ConnectionStrings["Database_ConnectionString"].ConnectionString;
SqlConnection conn = new SqlConnection(ConnectionString);
conn.Open();
SqlCommand cmd = new SqlCommand(strsql, conn);
cmd.ExecuteNonQuery();
Session["ViewState"] = null;
this.ClientScript.RegisterStartupScript(this.GetType(), "Evidance updated.", "<script language=\"javaScript\">"
+ "alert('Evidance Deleted successfully. ');" + "/script>");
File.Delete(filePath);
//Response.Redirect(Request.Url.AbsoluteUri);
Bindgrid(caseno);
}
protected void Bindgrid(string caseno)
{
string ConnectionString = ConfigurationManager.ConnectionStrings["Database_ConnectionString"].ConnectionString;
SqlConnection conn = new SqlConnection(ConnectionString);
conn.Open();
SqlDataAdapter adaptor = new SqlDataAdapter("select * from tbl_EvidanceFiles where caseno='" + caseno + "'", conn);
DataSet ds = new DataSet();
adaptor.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
string caseno = TextBox1.Text.ToString();
Bindgrid(caseno);
}
}
}