private void Reg_Form_Load(object sender, EventArgs e) { lab_title.Text = this.Text + " - " + lab_title.Text; try { SQL_Class.getcon(); //连接数据库 } catch { //当连接数据库失败时,显示错误信息 MessageBox.Show("数据库连接失败!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); //关闭窗口 } switch (Form_Type) { case 0: break; case 1: LoadInfo(); break; case 2: break; } }
private void Login_Form_Load(object sender, EventArgs e) { lab_title.Text = this.Text + " - " + lab_title.Text; try { SQL_Class.getcon(); //连接数据库 } catch { //当连接数据库失败时,显示错误信息 MessageBox.Show("数据库连接失败!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); Application.Exit(); //关闭整个工程 } }
private void txt_username_Leave(object sender, EventArgs e) { if (!Input_Regex.IsNumAndEnCh(txt_username.Text) || txt_username.Text == "") { lab_m_username.Text = "请输入正确的登陆用户名!"; lab_m_username.ForeColor = Color.Red; } else { SQL_Class SQLClass = new SQL_Class(); SqlDataReader dr = SQLClass.getcom("select * from yezhu where username = '******'"); bool ifcom = dr.Read(); if (ifcom) { lab_m_username.Text = "登陆用户名已存在!"; lab_m_username.ForeColor = Color.Red; } else { lab_m_username.Text = ""; } } }