diff --git a/CH78/Display.aspx.cs b/CH78/Display.aspx.cs
index 009654b..54a2fe8 100644
--- a/CH78/Display.aspx.cs
+++ b/CH78/Display.aspx.cs
@@ -14,30 +14,32 @@ namespace CH78
string studentID = "";
string gender;
+ string id = StudentDataTier.DecryptQueryString(Request.QueryString["ID"], "CNSAcnsa1", "salty");
+
if (!IsPostBack)
{
pageType = Request.QueryString["type"].Trim().ToUpper();
// retrieve the querystring
- if (String.IsNullOrEmpty(Request.QueryString["ID"]))
+ if (String.IsNullOrEmpty(id))
{
// not the right entry point
Response.Redirect("Home.aspx");
}
- else if (Request.QueryString["ID"].Trim().ToUpper() == "NEW")
+ else if (id.ToUpper() == "NEW")
{
BindDDL();
}
else if (Request.QueryString["type"].Trim().ToUpper() == "VIEW") // display
{
- GetStudent(Request.QueryString["ID"].Trim(), Request.QueryString["type"].Trim().ToUpper());
+ GetStudent(id, Request.QueryString["type"].Trim().ToUpper());
}
else if (Request.QueryString["type"].Trim().ToUpper() == "EDIT") // edit
{
- GetStudent(Request.QueryString["ID"].Trim(), Request.QueryString["type"].Trim().ToUpper());
+ GetStudent(id, Request.QueryString["type"].Trim().ToUpper());
}
else // anything else
@@ -138,7 +140,21 @@ namespace CH78
protected void btnCancelStu_OnClick(object sender, EventArgs e)
{
-
+ System.Text.StringBuilder cb = new System.Text.StringBuilder();
+ cb.Append(" opener.location.href = 'home.aspx';");
+ cb.Append("var ie7 = (document.all && !window.opera && window.XMLHttpRequest) ? true : false;");
+ cb.Append(" if (ie7)");
+ cb.Append(" { ");
+ cb.Append("window.open('','_parent','');");
+ cb.Append("window.close();");
+ cb.Append(" }");
+ cb.Append(" else ");
+ cb.Append(" { ");
+ cb.Append(" this.focus();");
+ cb.Append(" self.opener = this;");
+ cb.Append(" self.close();");
+ cb.Append(" }");
+ ClientScript.RegisterClientScriptBlock(this.GetType(), "CloseReloadScript", cb.ToString(), true);
}
protected void btnGoStu_OnClick(object sender, EventArgs e)
@@ -148,36 +164,97 @@ namespace CH78
{
}
else if (Request.QueryString["type"].Trim().ToUpper() == "EDIT")
- { StudentDataTier.UpdateStudents(0,
- txtStuID.Text,
- txtFNAME.Text,
- txtLNAME.Text,
- txtMidInit.Text,
- DateTime.Parse(txtDOB.Text),
- txtGender.Text,
- decimal.Parse(txtActBal.Text),
+ {
+ Decimal acct_bal = 0;
+
+ try
+ {
+ acct_bal = decimal.Parse(txtActBal.Text);
+ }
+ catch (Exception exception)
+ {
+ }
+
+ Decimal creds = 0;
+
+ try
+ {
+ creds = decimal.Parse(txtCreds.Text);
+ }
+ catch (Exception exception)
+ {
+ }
+
+ DateTime date = new DateTime(3000, 1, 1);
+ try
+ {
+ date = DateTime.Parse(txtDOB.Text);
+ }
+ catch (Exception exception)
+ {
+ }
+
+ StudentDataTier.UpdateStudents(0,
+ txtStuID.Text,
+ txtFNAME.Text,
+ txtLNAME.Text,
+ txtMidInit.Text,
+ date,
+ txtGender.Text,
+ acct_bal,
txtMajor.Text, txtCellPhone.Text,
txtAdr1.Text,
txtCity.Text,
txtState.ToString(),
txtZip.Text,
- decimal.Parse(txtCreds.Text));
+ creds);
}
else if (Request.QueryString["type"].Trim().ToUpper() == "NEW")
- { StudentDataTier.UpdateStudents(1,
+ {
+ Decimal acct_bal = 0;
+
+ try
+ {
+ acct_bal = decimal.Parse(txtActBal.Text);
+ }
+ catch (Exception exception)
+ {
+ }
+
+ Decimal creds = 0;
+
+ try
+ {
+ creds = decimal.Parse(txtCreds.Text);
+ }
+ catch (Exception exception)
+ {
+ }
+
+ DateTime date = new DateTime(3000, 1, 1);
+ try
+ {
+ date = DateTime.Parse(txtDOB.Text);
+ }
+ catch (Exception exception)
+ {
+ }
+
+
+ StudentDataTier.UpdateStudents(1,
txtStuID.Text,
txtFNAME.Text,
txtLNAME.Text,
txtMidInit.Text,
- DateTime.Parse(txtDOB.Text),
+ date,
txtGender.Text.ToString(),
- decimal.Parse(txtActBal.Text),
+ acct_bal,
txtMajor.Text, txtCellPhone.Text,
txtAdr1.Text,
txtCity.Text,
txtState.Text.ToString(),
txtZip.Text,
- decimal.Parse(txtCreds.Text));
+ creds);
}
diff --git a/CH78/Home.aspx.cs b/CH78/Home.aspx.cs
index b80e930..6df7a3e 100644
--- a/CH78/Home.aspx.cs
+++ b/CH78/Home.aspx.cs
@@ -20,6 +20,15 @@ namespace CH78
if (!IsPostBack)
{
+ Cache.Remove("StudentData");
+ BindData();
+ }
+ else
+ {
+ if (Convert.ToString(Session["GRIDREFRESH"]) != "")
+ {
+ BindData();
+ }
}
@@ -236,10 +245,12 @@ namespace CH78
// Get the record
recordToBeEdited = (e.CommandArgument.ToString().Trim());
+ recordToBeEdited = StudentDataTier.EncryptQueryString(recordToBeEdited, "CNSAcnsa1", "salty");
+
// this script will open a popup
sb.Append("");
// register with ClientScript
@@ -267,7 +278,7 @@ namespace CH78
// this script will open a popup
sb.Append("");
// register with ClientScript
diff --git a/CH78/StudentDataTier.cs b/CH78/StudentDataTier.cs
index b051d54..4ea219a 100644
--- a/CH78/StudentDataTier.cs
+++ b/CH78/StudentDataTier.cs
@@ -3,6 +3,11 @@ using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.UI.WebControls;
+using System;
+using System.IO;
+using System.Security.Cryptography;
+using System.Text;
+using System.Web;
namespace CH78
{
@@ -24,6 +29,55 @@ namespace CH78
}
+ public static string EncryptQueryString(string inputText, string key, string salt)
+{
+ byte[] plainText = Encoding.UTF8.GetBytes(inputText);
+
+ using (RijndaelManaged rijndaelCipher = new RijndaelManaged())
+ {
+ PasswordDeriveBytes secretKey = new PasswordDeriveBytes(Encoding.ASCII.GetBytes(key), Encoding.ASCII.GetBytes(salt));
+ using (ICryptoTransform encryptor = rijndaelCipher.CreateEncryptor(secretKey.GetBytes(32), secretKey.GetBytes(16)))
+ {
+ using (MemoryStream memoryStream = new MemoryStream())
+ {
+ using (CryptoStream cryptoStream = new CryptoStream(memoryStream, encryptor, CryptoStreamMode.Write))
+ {
+ cryptoStream.Write(plainText, 0, plainText.Length);
+ cryptoStream.FlushFinalBlock();
+ string base64 = Convert.ToBase64String(memoryStream.ToArray());
+
+ // Generate a string that won't get screwed up when passed as a query string.
+ string urlEncoded = HttpUtility.UrlEncode(base64);
+ return urlEncoded;
+ }
+ }
+ }
+ }
+}
+
+public static string DecryptQueryString(string inputText, string key, string salt)
+ {
+ byte[] encryptedData = Convert.FromBase64String(inputText);
+ PasswordDeriveBytes secretKey = new PasswordDeriveBytes(Encoding.ASCII.GetBytes(key), Encoding.ASCII.GetBytes(salt));
+
+ using (RijndaelManaged rijndaelCipher = new RijndaelManaged())
+ {
+ using (ICryptoTransform decryptor = rijndaelCipher.CreateDecryptor(secretKey.GetBytes(32), secretKey.GetBytes(16)))
+ {
+ using (MemoryStream memoryStream = new MemoryStream(encryptedData))
+ {
+ using (CryptoStream cryptoStream = new CryptoStream(memoryStream, decryptor, CryptoStreamMode.Read))
+ {
+ byte[] plainText = new byte[encryptedData.Length];
+ cryptoStream.Read(plainText, 0, plainText.Length);
+ string utf8 = Encoding.UTF8.GetString(plainText);
+ return utf8;
+ }
+ }
+ }
+ }
+ }
+
public DataSet GetStudents()
{