📄 mainopenform.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.Data.SqlClient;
namespace Bank
{
public partial class MainOpenform : Form
{
public MainOpenform()
{
InitializeComponent();
}
private void btnOpenOpen_Click(object sender, EventArgs e)
{
string id = txtOpenID.Text;
string pwd = txtOpenPwd.Text;
int money = int.Parse(MaintxtOpenMoney.Text) ;
string free = "true";
int result = 0;
bool Pwd = this.txtOpenPwd.Text == this.txtOpenRePwd.Text && this.txtOpenID.Text != "";
bool RePwd = this.txtOpenPwd.Text == this.txtOpenRePwd.Text;
if (Pwd && RePwd)
{//成功
if (money >= 10)
{
string sql = string.Format("insert into users (id,pwd,money,free) values ('{0}','{1}',{2},'{3}')", id, pwd, money, free);
bool i = false;
try
{
SqlCommand command = new SqlCommand(sql, DBHelper.connection);
DBHelper.connection.Close();
DBHelper.connection.Open();
SqlDataReader dataReader = command.ExecuteReader();
/*
验证部分
*/
if (dataReader.HasRows)
{
i = true;
result = command.ExecuteNonQuery();
}
}
catch (Exception ex)
{
MessageBox.Show("数据库出错了!\n\n" + ex, "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
}
finally
{
DBHelper.connection.Close();
}
if (result > 0)
{
MessageBox.Show("对不起,用户创建失败!");
}
else
{
MessageBox.Show("恭喜你,用户创建成功!");
this.Close();
}
while (i)
{
MessageBox.Show("对不起,您输入的用户名或密码错误 !请重新输入..");
this.txtOpenRePwd.Focus();
i = false;
}
}
else
{
MessageBox.Show("对不起,您的金额不足!");
}
}//out if
}
private void btnOpenExit_Click(object sender, EventArgs e)
{
DialogResult result = MessageBox.Show("是否返回主界面吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Hand);
if (result == DialogResult.Yes)
{
this.Close();
}
}
private void MainOpenform_Load(object sender, EventArgs e)
{
}
private void linOpenValidate_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -