using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class CAPTION : Form
{
public string ww = string.Empty;
public CAPTION()
{
InitializeComponent();
}
private void CAPTION_Load(object sender, EventArgs e)
{
this.textBox1.Text = ww;
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Data;
namespace WindowsFormsApplication2
{
class Tool
{
public string MM = "Data Source=.;User ID=bdqn;Password=123";
private SqlConnection connection;
public SqlConnection Connection {
get {
if(connection==null)
{
connection = new SqlConnection(MM);
}
return connection;
}
}
public void OpenConnection() {
if(Connection.State==ConnectionState.Closed){
Connection.Open();
}
else if( Connection.State==ConnectionState.Broken)
{
Connection.Close();
Connection.Open();
}
}
public void CloseConnection()
{
if(Connection.State==ConnectionState.Open||Connection.State==ConnectionState.Broken)
{
Connection.Close();
}
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void label2_Click(object sender, EventArgs e)
{
DialogResult result = MessageBox.Show("确认取消登陆吗?", "操作提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
this.Close();
}
}
//登录按钮事件
public bool checkInput()
{
if (this.textBox1.Text.Trim().Equals(string.Empty))
{
MessageBox.Show("请输入您名字:", "请输入提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.name.Focus();
return false;
}
else if (this.textBox2.Text.Trim().Equals(string.Empty))
{
MessageBox.Show("请输入您密码:", "请输入提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.name.Focus();
return false;
}
else if (this.comboBox1.Text.Trim().Equals(string.Empty))
{
MessageBox.Show("请输入登录类型:", "请输入提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.name.Focus();
return false;
}
else
{
return true;
}
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
public bool CheckUser(ref string message)
{
bool isValidUser = false;
string userName = textBox1.Text.Trim();
string userpwd = textBox2.Text.Trim();
StringBuilder sb = new StringBuilder();
if (comboBox1.Equals("管理员"))
{
sb.AppendFormat("select count(1) from Table_1" + "where name='{0}'and pwd='{1}'", userName, userpwd);
}
int count = 0;
Tool db = new Tool();
try
{
SqlCommand com = new SqlCommand(sb.ToString(), db.Connection);
db.OpenConnection();
count = (int)com.ExecuteScalar();
if (count > 0)
{
isValidUser = true;
}
else
{
MessageBox.Show("用户和密码不存在");
isValidUser = false;
}
}
catch (Exception)
{
message = "系统发生错误,请稍后再试!";
isValidUser = false;
}
finally
{
db.CloseConnection();
}
return isValidUser;
}
private void button1_Click_1(object sender, EventArgs e)
{
//if (checkInput())
//{
// string message = string.Empty;
// if (CheckUser(ref message))
// {
// if (this.comboBox1.Text.Equals("管理员"))
// {
// CAPTION s = new CAPTION();
// s.Show();
// }
// this.Hide();
// }
CAPTION s = new CAPTION();
s.Show();
}
}
}