📄 myinformation.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 web.Code;
namespace web.Customer
{
/// <summary>
/// MyInformation 的摘要说明。
/// </summary>
public partial class MyInformation : System.Web.UI.Page
{
static string Name = null;
protected void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if( !Page.IsPostBack )
{
if( Session["LoginName"] == null )
{
if( Request.Params["CustomerId"] != null )
{
int id = Convert.ToInt32( Request.Params["CustomerId"].ToString() );
CustomerDAO customerDAO = new CustomerDAO();
DataGrid1.DataSource = customerDAO.getMyInformation( id );
DataGrid1.DataBind();
}
else
{
Response.Redirect("../Login.aspx?Return=" + Request.Url.ToString());
}
}
else
{
Name = Session["LoginName"].ToString();
BindData();
}
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.DataGrid1.CancelCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_CancelCommand);
this.DataGrid1.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_EditCommand);
this.DataGrid1.UpdateCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_UpdateCommand);
}
#endregion
private void BindData()
{
CustomerDAO customerDAO = new CustomerDAO();
DataGrid1.DataSource = customerDAO.getMyInformation( Name );
DataGrid1.DataBind();
}
private void DataGrid1_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
DataGrid1.EditItemIndex=(int)e.Item.ItemIndex;
BindData();
}
public string getSex( string virtualSex )
{
string Sex = null;
switch( virtualSex )
{
case "0":
Sex = "男";
break;
case "1":
Sex = "女";
break;
}
return Sex;
}
private void DataGrid1_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
DataGrid1.EditItemIndex = -1;
BindData();
}
private void DataGrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string realName = ((TextBox)(e.Item.FindControl("TextBox2"))).Text;
string address = ((TextBox)(e.Item.FindControl("TextBox3"))).Text;
string sex = ((RadioButtonList)(e.Item.FindControl("RadioButtonList1"))).SelectedValue;
string phone = ((TextBox)(e.Item.FindControl("TextBox4"))).Text;
string email = ((TextBox)(e.Item.FindControl("TextBox5"))).Text;
string qq = ((TextBox)(e.Item.FindControl("TextBox6"))).Text;
CustomerVO customerVO = new CustomerVO();
customerVO.RealName = realName;
customerVO.Address = address;
customerVO.Sex = sex;
customerVO.Phone = phone;
customerVO.Email = email;
customerVO.QQ = qq;
CustomerDAO customerDAO = new CustomerDAO();
customerVO.CustomerId = customerDAO.getUserId( Name );
if( customerDAO.updateMyInformation( customerVO ) != 0 )
{
Response.Write("<script>alert('修改成功!')</script>");
DataGrid1.EditItemIndex=-1;
BindData();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -