IBuySpy Store购物例子中注册时的疑问?是在哪一步验证同名email是否存在
提交信息中如果email已经有了,则会注册失败提示:Registration failed: That email address is already registered.
但我看不清楚程序是在哪一步验证同名email是否已经存在的?谁能告诉我?
在AddCustomer中没看到哪句是验证重名的,存储过程也看不出。。
**************************
//RegisterBtn_Click是报单提交处理函数
private void RegisterBtn_Click(object sender, System.Web.UI.ImageClickEventArgs e) {
// Only attempt a login if all form fields on the page are valid
if (Page.IsValid == true) {
// Store off old temporary shopping cart ID
IBuySpy.ShoppingCartDB shoppingCart = new IBuySpy.ShoppingCartDB();
String tempCartId = shoppingCart.GetShoppingCartId();
// Add New Customer to CustomerDB database
IBuySpy.CustomersDB accountSystem = new IBuySpy.CustomersDB();
String customerId = accountSystem.AddCustomer(Name.Text, Email.Text, Password.Text);//此处添加新用户
if (customerId != "") {
// Set the user's authentication name to the customerId
FormsAuthentication.SetAuthCookie(customerId, false);
// Migrate any existing shopping cart items into the permanent shopping cart
shoppingCart.MigrateCart(tempCartId, customerId);
// Store the user's fullname in a cookie for personalization purposes
Response.Cookies["IBuySpy_FullName"].Value = Server.HtmlEncode(Name.Text);
// Redirect browser back to shopping cart page
Response.Redirect("ShoppingCart.aspx");
}
else {
MyError.Text = "Registration failed: That email address is already registered.";
}
}
}
//AddCustomer是添加用户函数
public String AddCustomer(string fullName, string email, string password)
{
// Create Instance of Connection and Command Object
SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
SqlCommand myCommand = new SqlCommand("CustomerAdd", myConnection);
// Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure;
// Add Parameters to SPROC
SqlParameter parameterFullName = new SqlParameter("@FullName", SqlDbType.NVarChar, 50);
parameterFullName.Value = fullName;
myCommand.Parameters.Add(parameterFullName);
SqlParameter parameterEmail = new SqlParameter("@Email", SqlDbType.NVarChar, 50);
parameterEmail.Value = email;
myCommand.Parameters.Add(parameterEmail);
SqlParameter parameterPassword = new SqlParameter("@Password", SqlDbType.NVarChar, 50);
parameterPassword.Value = password;
myCommand.Parameters.Add(parameterPassword);
SqlParameter parameterCustomerID = new SqlParameter("@CustomerID", SqlDbType.Int, 4);
parameterCustomerID.Direction = ParameterDirection.Output;
myCommand.Parameters.Add(parameterCustomerID);
try {
myConnection.Open();
myCommand.ExecuteNonQuery();
myConnection.Close();
// Calculate the CustomerID using Output Param from SPROC
int customerId = (int)parameterCustomerID.Value;
return customerId.ToString();
}
catch {
return String.Empty;
}
}
//添加用户调用的存储过程
CREATE Procedure CustomerAdd
(
@FullName nvarchar(50),
@Email nvarchar(50),
@Password nvarchar(50),
@CustomerID int OUTPUT
)
AS
INSERT INTO Customers
(
FullName,
EMailAddress,
Password
)
VALUES
(
@FullName,
@Email,
@Password
)
SELECT
@CustomerID = @@Identity