C# WinForm登录窗口代码

分类:C#

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 WindowsApplication1
{
    public partial class login : Form
    {
        SqlConnection sqlConnection1;
        SqlDataAdapter sqlDataAdapter1;
        DataSet DS;
        DataTable DT;
        public login()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string st;
            st = comboBox1.Text.ToString();
            string strPwd = "";
            strPwd = textBox1.Text.ToString();
            for (int i = 0; i < DT.Rows.Count; i++)
            {
                if (st.Trim() == DT.Rows[i]["
用户姓名"].ToString().Trim())
                {
                    if (strPwd.Trim() == DT.Rows[i]["
密码
"].ToString().Trim())
                    {

                        this.DialogResult = DialogResult.OK;//成功

                        //Program.cs中写

                          // static void Main()
                          //{
                                  //Application.EnableVisualStyles();
                                  //Application.SetCompatibleTextRenderingDefault(false);
                                // login  fm = new login();
                                 //if (fm.ShowDialog() == DialogResult.OK)
                                   // {
                                     //  Application.Run(new FrmMain());
                                    // }
                        //login  form1 = new login ();
                        //form1.Close();
                        //FrmMain  form2 = new FrmMain ();
                        //form2.Show();
                    }
                    else
                    {
                        MessageBox.Show("
你的用户名或密码不正确,请重新输入!");
                        return;
                    }
                }
                //comboBox1.Items.Add(DT.Rows[i]["
用户姓名
"]);
            }

        }

        private void login_Load(object sender, EventArgs e)
        {
            string strConn = "Data Source=HOMEWELL-25A668;Initial Catalog=building;Integrated Security=True";
            string sql = " select * from
权限信息表 ";
            sqlConnection1 = new SqlConnection(strConn);
            sqlDataAdapter1 = new SqlDataAdapter(sql, sqlConnection1);
            DS = new DataSet("TableTmp");
            sqlDataAdapter1.Fill(DS, "TableTmp");
            DT = DS.Tables["TableTmp"];
            for (int i = 0; i < DT.Rows.Count; i++)
            {
                comboBox1.Items.Add(DT.Rows[i]["
用户姓名
"]);
              
            }

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }
    }
}

转载于:https://www.cnblogs.com/retopleave/archive/2008/12/29/1364266.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值