c#登录界面

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.Sql;
using System.Data.SqlClient;
using System.IO;
using System.Data.OleDb;


namespace login
{
    public partial class login : Form
    {
        string connS = "Data Source=.;Initial Catalog=Student;User ID=sa;Password=123456789";//连接数据库

        public login()
        {
            InitializeComponent();//窗体设计
        }
        public bool User()//判断用户名和密码是否匹配
        {
            using (SqlConnection conn = new SqlConnection(connS))//实例连接对象
            {
                conn.Open();//打开数据库连接
                using (SqlCommand cmd = conn.CreateCommand())//通过连接对象创建数据库命令对象
                {
                    cmd.CommandText = "select * from Suser where Uname='" + textBoxU.Text + "' and Upassw='" + textBoxP.Text + "'";//查询数据库的SQL语句
                    using (SqlDataReader reader = cmd.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                              return true;
                          
                        }
                        else
                        {
                            return false;
                        }
                    }
                }
            }
        }



        private void Form1_Load(object sender, EventArgs e)//加载
        {
            timer1.Start();
        }

        
        private void timer1_Tick(object sender, EventArgs e)//时间组件
        {
            labeltime.Text = System.DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss", System.Globalization.DateTimeFormatInfo.InvariantInfo);//获取当前时间
        }

        private void buttonlogin_Click(object sender, EventArgs e)//登录按钮
        {
            try
            {
                if (textBoxU.Text != "" && textBoxP.Text != "")
                {
                    if (User())
                    {
                        //this.Hide();
                        Smassage fm1 = new Smassage();
                        fm1.GetStudentMessageEvent += new Smassage.GetStudentMessage(getSMessage);
                        fm1.ShowDialog();
                    }
                    else
                    {
                        MessageBox.Show("账号或密码错误!");
                    }
                }
                else
                {
                    MessageBox.Show("用户名和密码不能为空!");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        public string getSMessage()
        {
            return textBoxU.Text + "#" + labeltime.Text;//返回用户名和时间
        }

        private void buttonregiste_Click(object sender, EventArgs e)//注册按钮
        {
            registe re1 = new registe();

            re1.ShowDialog();
        }

        

        


    }
}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值