您现在的位置是:首页 >

国家指南 ASP.NET项目开发指南:个人信息的修改(2)[1]

火烧 2021-10-16 21:27:10 1064
ASP.NET项目开发指南:个人信息的修改(2)[1]    个人信息的修改( )   ST_U erAdd a x c 的主要代码及其解释  在此主要是读取用户信息 显示到每个We 控件 主要代码如

ASP.NET项目开发指南:个人信息的修改(2)[1]  

     个人信息的修改( )

   ST_UserAdd aspx cs的主要代码及其解释

  在此主要是读取用户信息 显示到每个Web控件 主要代码如程序 所示

  程序   ST_UserAdd aspx cs

     protected void Page_Load(object sender System EventArgs e)

     {

         Response Cache SetCacheability(HttpCacheability NoCache)

         //判断是否是第一次加载

         if(!IsPostBack)

         {

             //初始化用户信息

             ST_BookBiz ST_User st_user = new STGROUP ST_BookBiz ST_User()

              //编辑操作

             if(Request[ Action ]== edit )

             {

                  ST_BookBiz ST_Identity identity = new

                 ST_BookBiz ST_Identity(User Identity Name)

                  int userid = identity UserID;

                  if (userid == )

                      Response Redirect( /ST_Login aspx )

                  st_entity = st_user GetUserInfo(userid)

                 txtNumber Text = userid ToString()

                  txtName Text = st_entity ST_Name;

                  txtAddress Text = st_entity ST_Address;

                  txtEmail Text = st_entity ST_Email;

                  txtPhone Text = st_entity ST_Telephone;

                  txtPostCode Text = st_entity ST_Postcode;

                  txtTrueName Text = st_entity ST_TrueName;

                 txtPass Text = st_entity ST_Pass;

                  RadioButtonList SelectedIndex =

             RadioButtonList Items IndexOf(RadioButtonList Items

                 FindByText(st_entity ST_Gender))

                 txtName ReadOnly = true;

             }

         }

     }

  【代码说明】代码第 ~ 行根据用户ID读取用户信息 代码第 ~ 行显示这些信息 在此要提醒读者的是代码第 ~ 行 注意读取值如何与RadioButtonList控件进行绑定

  说明 Items IndexOf()方法用来获取所选择项的索引

  触发btnOK_Click事件后 即可进行个人信息的添加或修改操作 主要代码如程序 所示

  程序   ST_UserAdd aspx cs

     protected void btnOK_Click(object sender System EventArgs e)

     {

国家指南 ASP.NET项目开发指南:个人信息的修改(2)[1]

          ST_BookBiz ST_User st_user = new STGROUP ST_BookBiz ST_User()

          //判断条件 名称不允许为空

         if(txtName Text== )

             Response Write( <script defer>alert( 名称不允许为空! )

                 </script> )

         else if(txtPass Text== )

             Response Write( <script defer>alert( 密码不允许为空! )

                 </script> )

         else if(txtPass Text != txtPass Text)

         {

             Response Write( <script defer>alert( 密码不一致! )

                 </script> )

         }

         else if (st_user ST_IsUserExist(txtName Text Trim()) &&

                 Request[ Action ] == add )

         {

               Response Write( <script defer>alert( 用户名已经存在! )

                     </script> )

         }

         else

         {

               ST_BookBiz ST_Identity identity = new

                     ST_BookBiz ST_Identity(User Identity Name)

               int userid = identity UserID;

               //用户信息的添加或删除操作

               if (Request[ Action ] == add )

               {

                   userid = ;

                   st_entity ST_Name = txtName Text;

                   st_entity ST_Address = txtAddress Text;

                   st_entity ST_Email = txtEmail Text;

                   st_entity ST_Telephone = txtPhone Text;

                   st_entity ST_Postcode = txtPostCode Text ;

                   st_entity ST_TrueName = txtTrueName Text;

                   st_entity ST_Pass = txtPass Text;

                   st_entity ST_Gender = RadioButtonList SelectedValue;

                   userid = st_user InsertUser(st_entity)

                   identity = new ST_BookBiz ST_

  Identity(txtName Text Trim()

                     userid)

                   Context User = new ST_BookBiz

  ST_Principal(identity new

                     string[] { User })

                   identity Name = txtName Text;

                   identity Roles = User ;

                   identity Save()

                 //身份验证票

                   FormsAuthentication SetAuthCookie(txtName Text false)

                   Response Redirect( /ST_Common/ST_Main aspx )

               }

               else if (Request[ Action ] == edit && userid!= )

               {

                   //修改信息

                   st_entity ST_Name = txtName Text;

                   st_entity ST_Address = txtAddress Text;

                   st_entity ST_Email = txtEmail Text;

                   st_entity ST_Telephone = txtPhone Text;

                   st_entity ST_Postcode = txtPostCode Text;

                   st_entity ST_TrueName = txtTrueName Text;

                   st_entity ST_Pass = txtPass Text;

                   st_entity ST_Gender = RadioButtonList SelectedValue;

                   st_entity ST_UserID = userid;

                   st_user UpdateUser(st_entity)

                   string str = <script language=

  javascript>alert( 更新成功! )

                     </script> ;

                   Response Write(str)

               }

         }

     }

  【代码说明】代码第 ~ 行首先判断用户的用户名和密码输入是否正确 代码第 ~ 行实现用户信息的添加 代码第 ~ 实现用户信息的修改

lishixinzhi/Article/program/net/201311/15818  
永远跟党走
  • 如果你觉得本站很棒,可以通过扫码支付打赏哦!

    • 微信收款码
    • 支付宝收款码