📄 registerform.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace 通讯录
{
public partial class RegisterForm : Form
{
private DataSet myDataSet;
public RegisterForm(DataSet ds)
{
InitializeComponent();
myDataSet = ds;
}
private void btnRegister_Click(object sender, EventArgs e)
{
string username = txtUsername.Text.Trim();
string password = txtPassword.Text.Trim();
string confirmPwd = txtConfirmPwd.Text.Trim();
string pwdClew = txtPwdClew.Text.Trim();
if (username == "")
{
lblValidate.Text = "用户名不能为空";
lblValidate.Visible = true;
return;
}
if (password == "")
{
lblValidate.Text = "密码不能为空";
lblValidate.Visible = true;
return;
}
if (pwdClew == "")
{
lblValidate.Text = "密码提示不能为空";
lblValidate.Visible = true;
return;
}
if (password != confirmPwd)
{
lblValidate.Text = "前后密码输入不一致";
lblValidate.Visible = true;
txtPassword.Text = "";
txtPwdClew.Text = "";
return;
}
foreach (DataRow row in myDataSet.Tables[0].Rows)
{
if (row["用户名"].ToString()==username)
{
lblValidate.Text = "此用户名已被使用";
lblValidate.Visible = true;
txtUsername.Text = "";
txtPassword.Text = "";
txtPwdClew.Text = "";
return;
}
}
int rowCount = myDataSet.Tables[0].Rows.Count + 1;
DateTime now=DateTime.Now;
string str = now.Year.ToString() + now.Month.ToString() + now.Day.ToString() + now.Hour.ToString() + now.Minute.ToString() + now.Second.ToString();
string xFileName = "Data\\" + str + ".xml";
string demo = "Data\\Demo.xml";
File.Copy(demo,xFileName);
DataRow newRow = myDataSet.Tables[0].NewRow();
newRow["用户编号"] = rowCount.ToString();
newRow["用户名"] = username;
newRow["用户密码"] = password;
newRow["密码提示"] = pwdClew;
newRow["资料路径"] = xFileName;
myDataSet.Tables[0].Rows.Add(newRow);
myDataSet.WriteXml("Data\\User.xml");
MessageBox.Show("注册成功!", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.Close();
}
private void Cancel_Click(object sender, EventArgs e)
{
this.Close();
}
private void txtUsername_KeyDown(object sender, KeyEventArgs e)
{
lblValidate.Visible = false;
}
private void txtPassword_KeyDown(object sender, KeyEventArgs e)
{
lblValidate.Visible = false;
}
private void txtConfirmPwd_KeyDown(object sender, KeyEventArgs e)
{
lblValidate.Visible = false;
}
private void txtPwdClew_TextChanged(object sender, EventArgs e)
{
lblValidate.Visible = false;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -