⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 loginform.cs

📁 利用vs2008+sql2000开发的物资管理系统
💻 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 login
{
    public partial class loginform : Form
    {
        public loginform()
        {
            InitializeComponent();
        }

        private void btn_cancel_Click(object sender, EventArgs e)
        {
           Application.Exit(); //通知所有消息泵必须终止,并且在处理了消息以后关闭所有应用程序窗口。
          
        }

        private void btn_ok_Click(object sender, EventArgs e)
        {
            SqlConnection myconnection;

            //定义DataAdapter
           // SqlDataAdapter sa;

            //定义Command对象
            SqlCommand sqlcmd;

            //定义DataSet对象;
            //DataSet ds;

            string constr = "Data Source=localhost;Initial Catalog=WZGL_20052070;Integrated Security= true;";
            myconnection = new SqlConnection(constr);

            if (txt_username .Text.Length == 0)
            {
                MessageBox.Show("用户名不能为空", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                txt_username .Focus();
            }


            //参数检查:店名是否在数据库中已存在
        //    string sqlstatement = "select count(userid) from MyTable_userverify where userid=' " + txt_username.Text.Trim() +"'"+ " and password='" + txt_password.Text.Trim()+"'";
            string sqlstatement = "select count(adName) from login where adName=@user and adPwd=@password ";
            
            sqlcmd = new SqlCommand(sqlstatement, myconnection);
            sqlcmd.Parameters.AddWithValue("@user", txt_username.Text.Trim());
            sqlcmd.Parameters.AddWithValue("@password", txt_password.Text.Trim());
            try
            {
                myconnection.Open();
                //获取对应店号的记录数,如果不为0,则表示数据库中已存在此店号。
                int rowcount = int.Parse(sqlcmd.ExecuteScalar().ToString());
                if (rowcount > 0)
                {
                    MainFrm mainform = new MainFrm();
                    mainform.Show();
                    this.Hide();
                  
                }
                else
                {
                    MessageBox.Show("用户密码不正确...", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    txt_username .Focus();
                }
                
            }
            catch (SqlException ex)
            {
                MessageBox.Show("用户身份验证出错:" + ex.Message, "出现错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                myconnection.Close();
            }
            
            
            
          
        }

        private void loginform_Load(object sender, EventArgs e)
        {

        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {

        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -