C#_會員管理系統:開發五(使用者註冊)

來源:互聯網
上載者:User

標籤:

建立一個新的使用者註冊表單(VIPRegistration.cs):

使用者註冊表單(VIPRegistration.cs)詳細代碼如下:

 1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.Linq; 7 using System.Text; 8 using System.Threading.Tasks; 9 using System.Windows.Forms;10 using System.Data.SqlClient;11 using System.Configuration;12 13 namespace 會員管理系統14 {15     public partial class VIPRegistration : Form16     {17         public VIPRegistration()18         {19             InitializeComponent();20         }21 22 23         //提交按鈕24         private void btnOK_Click(object sender, EventArgs e)25         {26             27             string connstr = ConfigurationManager.ConnectionStrings["str"].ConnectionString;28             SqlConnection conn = new SqlConnection(connstr);29             string sql = string.Format("select vusername from VipAccount where vUserName=‘{0}‘ ",txtName.Text);30             SqlCommand cmd = new SqlCommand(sql, conn);31             conn.Open();32             SqlDataReader sda=cmd.ExecuteReader();33 34             if (txtName.Text.Trim() == "")35             {36                 lblName.Text="使用者名稱不可為空";37                 return;38             }39             else if (txtPwd.Text.Trim() == ""|| txtPwdConfirm.Text.Trim()=="")40             {41                 lblPwd.Text = "密碼不可為空";42                 return;43             }44             else if (txtPwdConfirm.Text.Trim()!= txtPwd.Text.Trim())45             {46                 lblPwdConfirm.Text = "兩次密碼輸入不同,請確認後再輸";47                 return;48             }49             else if (sda.Read())50             {51                 lblName.Text = "使用者名稱已存在,請重新輸入";52                 return;53             }54             else55             {56                 conn.Close();57                 SqlConnection conninsert = new SqlConnection(connstr);58                 string insertsql = string.Format("insert into VipAccount(vUserName,vUserPwd) values(‘{0}‘,‘{1}‘)",txtName.Text,txtPwd.Text);59                 SqlCommand cmdinsert = new SqlCommand(insertsql, conninsert);60                 conninsert.Open();61                 int n = cmdinsert.ExecuteNonQuery();62                 if (n == 0)63                 {64                     MessageBox.Show("註冊失敗,請重新輸入");65                 }66                 else67                 {68                     MessageBox.Show("註冊成功");69                 }70                 conninsert.Close();71 72             }73             //conn.Close();74         }75 76         //返回主菜單77         private void btnBack_Click(object sender, EventArgs e)78         {79             VIPMain vm = new VIPMain();80             vm.Show();81             this.Hide();82         }83 84         private void VIPRegistration_Load(object sender, EventArgs e)85         {86             lblName.Text = "";87             lblPwd.Text = "";88             lblPwdConfirm.Text = "";89         }90         91     }92 }

主介面表單(VIPMain.cs)添加一個新的按鈕:

使用者註冊按鈕代碼:

1         private void btnRegistration_Click(object sender, EventArgs e)2         {3             VIPRegistration vrn = new VIPRegistration();4             vrn.Show();5             this.Hide();6         }

 

C#_會員管理系統:開發五(使用者註冊)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.