📄 editaccountinfomation.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
namespace MobileShop
{
/// <summary>
/// EditAccountInfomation 的摘要说明。
/// </summary>
public class EditAccountInfomation : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label lblAccount;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label lblEmail;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Label Label4;
protected System.Web.UI.WebControls.RequiredFieldValidator valFirstName;
protected System.Web.UI.WebControls.Label Label5;
protected System.Web.UI.WebControls.RequiredFieldValidator valLastName;
protected System.Web.UI.WebControls.Label Label6;
protected System.Web.UI.WebControls.TextBox txtAddress1;
protected System.Web.UI.WebControls.RequiredFieldValidator valAddress1;
protected System.Web.UI.WebControls.Label Label11;
protected System.Web.UI.WebControls.TextBox txtAddress2;
protected System.Web.UI.WebControls.Label Label7;
protected System.Web.UI.WebControls.TextBox txtCity;
protected System.Web.UI.WebControls.RequiredFieldValidator valCity;
protected System.Web.UI.WebControls.Label Label8;
protected System.Web.UI.WebControls.TextBox txtPostalCode;
protected System.Web.UI.WebControls.RegularExpressionValidator rvalPostalCode;
protected System.Web.UI.WebControls.Label Label12;
protected System.Web.UI.WebControls.TextBox txtTelephoneNumber;
protected System.Web.UI.WebControls.TextBox txtFirstName;
protected System.Web.UI.WebControls.TextBox txtLastName;
protected System.Web.UI.WebControls.RegularExpressionValidator rvalTelephoneNunber;
protected System.Web.UI.WebControls.DropDownList dlistState;
protected System.Web.UI.WebControls.Label Label9;
protected System.Web.UI.WebControls.Label lblOldPassword;
protected System.Web.UI.WebControls.TextBox txtOldPassword;
protected System.Web.UI.WebControls.Label Label10;
protected System.Web.UI.WebControls.Label Label13;
protected System.Web.UI.WebControls.TextBox Textbox2;
protected System.Web.UI.WebControls.Button btnChangePassword;
protected System.Web.UI.WebControls.TextBox txtNewPassword;
protected System.Web.UI.WebControls.Button btnSubmit;
protected System.Web.UI.WebControls.HyperLink hplReturn;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.CompareValidator cvalPassword;
protected System.Web.UI.WebControls.RegularExpressionValidator rvalPassword;
protected string ConnectionString;
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
DropDownListBind();
this.lblAccount.Text = Request.QueryString["ID"].ToString();
getAccountInfo();
}
}
private void getAccountInfo()
{
OleDbConnection conn = new OleDbConnection(ConnectionString);
OleDbCommand cmd = new OleDbCommand("Select Email,FirstName,LastName,Addr1,Addr2,City,PostalCode,State,TelephoneNumber From UserInfo where Account='"
+ Request.QueryString["ID"].ToString() + "'", conn);
try
{
conn.Open();
OleDbDataReader dr = cmd.ExecuteReader();
dr.Read();
lblEmail.Text = dr.GetString(0);
txtFirstName.Text = dr.GetString(1);
txtLastName.Text = dr.GetString(2);
txtAddress1.Text = dr.GetString(3);
txtAddress2.Text = dr.GetString(4);
txtCity.Text = dr.GetString(5);
txtPostalCode.Text = dr.GetString(6);
dlistState.SelectedValue = dr.GetString(7);
//dlistCountry.SelectedValue = dr.GetString(8);
txtTelephoneNumber.Text = dr.GetString(8);
dr.Close();
}
catch(Exception err)
{
MessageBox(err.Message);
}
finally
{
conn.Close();
}
}
public void DropDownListBind()
{
OleDbConnection conn = new OleDbConnection(ConnectionString);
OleDbCommand cmd = new OleDbCommand("Select name from Province", conn);
conn.Open();
try
{
OleDbDataReader dr = cmd.ExecuteReader();
while(dr.Read())
{
ListItem ls = new ListItem(dr.GetString(0), dr.GetString(0));
this.dlistState.Items.Add(ls);
}
dr.Close();
}
catch(Exception err)
{
Response.Write(err.Message);
}
finally
{
conn.Close();
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
ConnectionString = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=";
ConnectionString += Server.MapPath("MobileShop.mdb");
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.btnChangePassword.Click += new System.EventHandler(this.btnChangePassword_Click);
this.btnSubmit.Click += new System.EventHandler(this.btnSubmit_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void btnChangePassword_Click(object sender, System.EventArgs e)
{
if(txtNewPassword.Text == "")
{
MessageBox("新密码不能为空!");
}
else
{
OleDbConnection conn = new OleDbConnection(ConnectionString);
string SqlString = "Select Account,Pwd from UserInfo Where Account='" + Request.QueryString["ID"] + "' And Pwd='" + txtOldPassword.Text.Trim() + "'";
OleDbCommand SqlCmd = new OleDbCommand(SqlString, conn);
try
{
conn.Open();
if(SqlCmd.ExecuteScalar() != null)
{
SqlString = "Update UserInfo Set Pwd='" + txtNewPassword.Text.Trim() + "' where Account='" + Request.QueryString["ID"] + "'";
SqlCmd.CommandText = SqlString;
SqlCmd.ExecuteNonQuery();
}
else
{
MessageBox("原始密码错误,请确认后重试!");
}
}
catch(Exception err)
{
Response.Write(err.Message);
}
finally
{
conn.Close();
}
}
}
private void btnSubmit_Click(object sender, System.EventArgs e)
{
OleDbConnection conn = new OleDbConnection(ConnectionString);
string SqlString = "Update UserInfo Set FirstName='" + txtFirstName.Text.Trim() + "',";
SqlString += "LastName='" + txtLastName.Text.Trim() + "',";
SqlString += "Addr1='" + txtAddress1.Text.Trim() + "',";
SqlString += "Addr2='" + txtAddress2.Text.Trim() + "',";
SqlString += "City='" + txtCity.Text.Trim() + "',";
SqlString += "PostalCode='" + txtPostalCode.Text.Trim() + "',";
SqlString += "State='" + dlistState.SelectedItem.Text.Trim() + "',";
SqlString += "TelephoneNumber='" + txtTelephoneNumber.Text.Trim() + "'";
OleDbCommand SqlCmd = new OleDbCommand(SqlString, conn);
try
{
conn.Open();
SqlCmd.ExecuteNonQuery();
}
catch(Exception err)
{
Response.Write(err.Message);
}
finally
{
conn.Close();
}
}
public void MessageBox(string strMessage)
{
Response.Write("<"+"SCRIPT language=javascript>");
Response.Write("alert(\""+strMessage+"\");");
Response.Write("<"+"/SCRIPT>\n");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -