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.SqlClient;namespace Dxssgl
{
    public partial class Login : Form
    {
        public Login()
        {
            InitializeComponent();
        }
        SqlConnection conn = DBConn.Dxssgl();        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (txtLoginNo.Text.Trim() == "")
            {
                MessageBox.Show("请输入账号!", "登陆提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtLoginNo.Focus();
            }
            else if (txtLoginPwd.Text == "")
            {
                MessageBox.Show("请输入密码!", "登陆提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtLoginPwd.Focus();
            }
            else if (cboLoginType.Text == "")
            {
                MessageBox.Show("请选择登陆类型!", "登陆提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                cboLoginType.Focus();
            }
            else
                {                                                           
                    conn.Open();
                    SqlCommand cmd = new SqlCommand("select count(*) from DB_ManageInfo where loginNo='" + txtLoginNo.Text + "' and loginPwd='" +txtLoginPwd.Text + "'and loginType='" + cboLoginType.Text + "'", conn);//验证登陆信息是否在DB_ManageInfo中
                    int i = Convert.ToInt32(cmd.ExecuteScalar());
                    if (i > 0)
                    {
                        UserName.loginName = txtLoginNo.Text;       //全局变量
                        UserName.loginType = cboLoginType.Text;     //全局变量
                        conn.Close();
                        WFMain sfm = new WFMain(); //跳转到主界面
                        sfm.Show();
                        this.Hide();
                    }
                    else
                    {
                        MessageBox.Show("用户名或密码错误");
                        txtLoginNo.Text = "";
                        txtLoginPwd.Text = "";
                    }
                }
        }        private void btnCanel_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("您确定要退出吗?", "操作提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
            if (result == DialogResult.OK)
            {
                Application.Exit();
            }
        }
    }
using System;                 //新建一个类文件,存放数据库的连接字符串
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
namespace Dxssgl.BaseClass
{
    class DBConn
    {
        public static SqlConnection Dxssgl()
        {
            return new SqlConnection("server=.;database=Dxssgl;uid=sa;pwd=admin");
        }
    }

using System;                        //作为全局变量,需要时可以调用
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace Dxssgl
{
    class UserName
    {
        public static string loginName;
        public static string loginType;
    }
}