我有两个表经销商和客户。管理员将添加经销商字段并为客户提供参考编号。客户必须在网站注册时获取该参考编号和类型。在后端,客户编写的参考编号应与他提供的参考编号相匹配。如果它是相同的,那么他可以登录。否则,他将看到错误消息。
在这里,我无法比较参考编号。价值没有过去。
protected void SignInButton_Click(object sender, EventArgs e)
{
int customerID;
Customer customer = new Customer();
customer.CustomerName = CustomerNameTextBox.Text;
customer.ShopName = ShopNameTextBox.Text;
customer.Address = AddressTextBox.Text;
customer.Mobile1 = Mobile1TextBox.Text;
customer.Mobile2 = Mobile2TextBox.Text;
customer.ReferenceNumber = ReferenceNumberTextBox.Text;
customer.LoginID = Mobile1TextBox.Text;
customer.Password = RandomNoGenerator.GenerateRandomNo();
customer.SignUpDate = DateTime.Now;
customer.Enabled = true;
try
{
Reseller reseller = new Reseller();
if (customer.ReferenceNumber == reseller.ReferenceNumber)
{
//MessageLabel.Text = "Customer successfully added";
customerID = CustomerBL.AddCustomer(customer);
MessageLabel.Text = "You've successfully signed up!";
Response.Redirect("UserSignUpSuccess.aspx?CustomerID=" + customerID);
}
else
{
MessageLabel.Text = "Please Provide Same Reference Number";
}
//customerID = CustomerBL.AddCustomer(customer);
//MessageLabel.Text = "You've successfully signed up!";
//Response.Redirect("UserSignUpSuccess.aspx?CustomerID=" + customerID);
}
catch (Exception ex)
{
MessageLabel.Text = "Some error occured while processing the request. Error Description <br/>" + ex.Message;
}
业务逻辑层代码
public class CustomerBL
{
public static int AddCustomer(Customer customer)
{
int customerID;
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "INSERT INTO [Customers] ([LoginID], [Password], [CustomerName], [ShopName], [Address], [Mobile1], [Mobile2], [ReferenceNumber], [SignUpDate], [Enabled]) " +
"VALUES (@LoginID, @Password, @CustomerName, @ShopName, @Address, @Mobile1, @Mobile2, @ReferenceNumber, @SignUpDate, @Enabled); SELECT @@IDENTITY";
cmd.Parameters.AddWithValue("@LoginID", SqlDbType.Text).Value = customer.LoginID;
cmd.Parameters.AddWithValue("@Password", SqlDbType.Text).Value = customer.Password;
cmd.Parameters.AddWithValue("@CustomerName", SqlDbType.Text).Value = customer.CustomerName;
cmd.Parameters.AddWithValue("@ShopName", SqlDbType.Text).Value = customer.ShopName;
cmd.Parameters.AddWithValue("@Address", SqlDbType.Text).Value = customer.Address;
cmd.Parameters.AddWithValue("@Mobile1", SqlDbType.Text).Value = customer.Mobile1;
cmd.Parameters.AddWithValue("@Mobile2", SqlDbType.Text).Value = customer.Mobile2;
cmd.Parameters.AddWithValue("@ReferenceNumber", SqlDbType.Text).Value = customer.ReferenceNumber;
cmd.Parameters.AddWithValue("@SignUpDate", SqlDbType.DateTime2).Value = customer.SignUpDate;
cmd.Parameters.AddWithValue("@Enabled", SqlDbType.Bit).Value = customer.Enabled;
customerID = DbUtility.UpdateDbGetIdentity(cmd);
return customerID;
}
答案 0 :(得分:0)
您正在创建Reseller
个实例,但在使用它之前不进行初始化
Reseller reseller = new Reseller();
if (customer.ReferenceNumber == reseller.ReferenceNumber)
{
假设默认构造函数没有为ReferenceNumber
实例设置Reseller
,您可能希望在使用它之前对其进行初始化。