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 qizhongtu
{
public partial class MainFrm : Form
{
private bool isLogined = false;
private Login orm;
public object Login { get; private set; }
public MainFrm()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void btnYes_Click(object sender, EventArgs e)
{
string userName = txtName.Text;
string password = txtPwd.Text;
string connString = @"Data Source=.\ sqlexpress; Initial Catalog=qizhongtu;Integrated Security=true";
SqlConnection conn = new SqlConnection(connString);
string sql = String.Format("select count (*) from [User] where UserName = ' (0)' and password = ' (1)'", userName, password);
try
{
conn.Open();
SqlCommand comm = new SqlCommand(sql, conn);
//创建Command对象
int n = (int)comm.ExecuteScalar();
//执行查询语句,返回匹配的行数
if (n == 1)
{
this.DialogResult = DialogResult.OK;
this.Tag = true;//登录成功并记录
}
else
{
MessageBox.Show("您输人的用户名或密码错误!请重试", "登录失败", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
this.Tag = false; // 登录失败并记录
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "操作数据库出错!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
this.Tag = false;
}
finally
{