/
FriendDetails.aspx.cs
226 lines (189 loc) · 7.84 KB
/
FriendDetails.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.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Oracle.DataAccess.Client;
using System.Data;
/*
Name: Keshav Sridhara
Student No: 300948195
*/
public partial class FriendDetails : System.Web.UI.Page
{
protected void Page_PreInit(object sender, EventArgs e)
{
System.Diagnostics.Debug.WriteLine("Inside Page_PreInit: " + Session["ThemeSessionValue"].ToString());
if (Session["ThemeSessionValue"] != null)
{
Page.Theme = (String)Session["ThemeSessionValue"];
}
else
{
Session["ThemeSessionValue"] = "DarkTheme";
Page.Theme = (string)Session["ThemeSessionValue"];
}
}
private OracleConnection GetConnection()
{
var conString = System.Configuration.ConfigurationManager.ConnectionStrings["LibCollectionOracleCenCol"];
string strConnString = conString.ConnectionString;
return new OracleConnection(strConnString);
}
protected void Page_Load(object sender, EventArgs e)
{
System.Diagnostics.Debug.WriteLine("*****INSIDE FRIENDDETAILS:Page_Load*****");
if (!IsPostBack)
{
BindDetails();
}
}
private void BindDetails()
{
System.Diagnostics.Debug.WriteLine("*****INSIDE FRIENDDETAILS:BindDetails*****");
int bookId = Convert.ToInt32(Request.QueryString["FRIEND_ID"]);
OracleConnection oConn = GetConnection();
OracleCommand oCmd = new OracleCommand(" SELECT NAME, COMMENTS FROM FRIEND WHERE FRIEND_ID =:Friend_ID ", oConn);
oCmd.Parameters.Add(new OracleParameter("Friend_ID", bookId));
try
{
oConn.Open();
OracleDataReader reader = oCmd.ExecuteReader();
friendDetailsGrid.DataSource = reader;
friendDetailsGrid.DataKeyNames = new string[] { "Name" };
friendDetailsGrid.DataBind();
reader.Close();
}
finally
{
oConn.Close();
}
}
protected void friendDetailsGrid_ModeChanging(object sender, DetailsViewModeEventArgs e)
{
System.Diagnostics.Debug.WriteLine("*****INSIDE FRIENDDETAILS:friendDetailsGrid_ModeChanging*****");
friendDetailsGrid.ChangeMode(e.NewMode);
BindDetails();
}
protected void friendDetailsGrid_ItemDeleting(object sender, DetailsViewDeleteEventArgs e)
{
System.Diagnostics.Debug.WriteLine("*****INSIDE FRIENDDETAILS:friendDetailsGrid_ItemDeleting*****");
int bookId = Convert.ToInt32(Request.QueryString["Friend_ID"]);
OracleConnection oConn = GetConnection();
OracleCommand oCmd = oConn.CreateCommand();
oCmd.CommandText = "DELETE_FRIENDS_PRC";
oCmd.CommandType = CommandType.StoredProcedure;
OracleParameter param1 = oCmd.Parameters.Add("P_FRIEND_ID", OracleDbType.Int32, ParameterDirection.Input);
param1.Value = bookId;
oCmd.Parameters.Add("OUT_ERR_MSG", OracleDbType.Varchar2, ParameterDirection.Output);
oCmd.Parameters.Add("OUT_ERR_CODE", OracleDbType.Varchar2, ParameterDirection.Output);
oCmd.Parameters["OUT_ERR_CODE"].Size = 500;
oCmd.Parameters["OUT_ERR_MSG"].Size = 500;
System.Diagnostics.Debug.WriteLine("*****INSIDE friendDetailsGrid_ItemDeleting:*****" + (oCmd.Parameters["OUT_ERR_MSG"].Value));
try
{
oConn.Open();
oCmd.ExecuteNonQuery();
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine("*****Exception***** " + ex.Message);
dbErrorMessage.Text =
"Error while deleting friend!" +
"Error Code: {0}" + oCmd.Parameters["OUT_ERR_CODE"].Value.ToString() +
"Error Msg: {1}" + oCmd.Parameters["OUT_ERR_MSG"].Value.ToString();
}
finally
{
oConn.Close();
}
deletedLabel.Text = "The friend is deleted successfully!";
friendDetailsGrid.ChangeMode(DetailsViewMode.ReadOnly);
BindDetails();
//Response.Redirect("Books.aspx");
}
protected void friendDetailsGrid_ItemUpdating(object sender, DetailsViewUpdateEventArgs e)
{
int bookId = Convert.ToInt32(Request.QueryString["Friend_ID"]);
TextBox newNameTextBox =
(TextBox)friendDetailsGrid.FindControl("editNameTextBox");
TextBox newCommentsTextBox =
(TextBox)friendDetailsGrid.FindControl("editCommentsTextBox");
string newName = newNameTextBox.Text;
string newComments = newCommentsTextBox.Text;
OracleConnection oConn = GetConnection();
OracleCommand oCmd = oConn.CreateCommand();
oCmd.CommandText = "UPDATE_FRIENDS_PRC";
oCmd.CommandType = CommandType.StoredProcedure;
OracleParameter param0 = oCmd.Parameters.Add("P_FRIEND_ID", OracleDbType.Int32, ParameterDirection.Input);
param0.Value = bookId;
OracleParameter param1 = oCmd.Parameters.Add("P_NAME", OracleDbType.Varchar2, ParameterDirection.Input);
param1.Value = newName;
OracleParameter param7 = oCmd.Parameters.Add("P_COMMENTS", OracleDbType.Varchar2, ParameterDirection.Input);
param7.Value = newComments;
oCmd.Parameters.Add("OUT_ERR_MSG", OracleDbType.Varchar2, ParameterDirection.Output);
oCmd.Parameters.Add("OUT_ERR_CODE", OracleDbType.Varchar2, ParameterDirection.Output);
oCmd.Parameters["OUT_ERR_CODE"].Size = 500;
oCmd.Parameters["OUT_ERR_MSG"].Size = 500;
System.Diagnostics.Debug.WriteLine("*****INSIDE friendDetailsGrid_ItemUpdating:*****" + (oCmd.Parameters["OUT_ERR_MSG"].Value));
try
{
oConn.Open();
oCmd.ExecuteNonQuery();
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine("*****Exception***** " + ex.Message);
dbErrorMessage.Text =
"Error while updating the friend!" +
"Please try again later, and/or change the entered data!" +
"Error Code: {0}" + oCmd.Parameters["OUT_ERR_CODE"].Value.ToString() +
"Error Msg: {1}" + oCmd.Parameters["OUT_ERR_MSG"].Value.ToString();
}
finally
{
oConn.Close();
}
deletedLabel.Text = "The friend details are updated successfully!";
friendDetailsGrid.ChangeMode(DetailsViewMode.ReadOnly);
BindDetails();
}
protected void btnBack_Click(object sender, EventArgs e)
{
if (Session["ThemeSessionValue"] != null)
{
Session["ThemeSessionValue"] = Page.Theme;
Response.Redirect("Friends.aspx");
Server.Transfer(Request.Path);
}
}
protected void friendDetailsGrid_ItemCreated(object sender, EventArgs e)
{
// Test FooterRow to make sure all rows have been created
if (friendDetailsGrid.FooterRow != null && friendDetailsGrid.Rows.Count > 0)
{
// The command bar is the last element in the Rows collection
int commandRowIndex = friendDetailsGrid.Rows.Count - 1;
DetailsViewRow commandRow = friendDetailsGrid.Rows[commandRowIndex];
// Look for the DELETE button
DataControlFieldCell cell = (DataControlFieldCell)commandRow.Controls[0];
foreach (Control ctl in cell.Controls)
{
Button button = ctl as Button;
if (button != null)
{
if (button.CommandName == "Delete")
{
button.ToolTip = "Click here to delete this record";
button.OnClientClick = "if (!confirm('Do you want to delete this record?')) return false;";
}
}
}
}
}
}
/*
Name: Keshav Sridhara
Student No: 300948195
*/