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

📄 formlogin.cs

📁 kuiMsg是一款用.net C# 开发的即时消息开源软件,适合.net即时消息软件开发者用。 主要功能: 支持文件传输(p2p); 支持GIF动画表情( 彻底消除闪屏 :) );
💻 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.OracleClient;
using System.Net;
namespace LanMsg
{
    public partial class FormLogin : DevComponents.DotNetBar.Office2007Form 
    {
        public FormLogin()
        {
            InitializeComponent();
            getDBUsers();//获得用户列表
        }
        /// <summary>
        /// 设置或获取用户是否退出应用程序
        /// </summary>
        public bool isExitApp;
        /// <summary>
        /// 设置或获取用户是否登录
        /// </summary>
        private bool isLogin;

        private void butLogin_Click(object sender, EventArgs e)
        {
             if (this.textUserID.Text.Trim() == "" )
            {
                this.balloonTip1.SetBalloonCaption(this.textUserID, "提示");
                this.balloonTip1.SetBalloonText(this.textUserID, "请输入用户。");
                this.balloonTip1.ShowBalloon(this.textUserID);
                return;
            }
            if (this.textPassword.Text.Trim() == "")
            {
                this.balloonTip1.SetBalloonCaption(this.textPassword, "提示");
                this.balloonTip1.SetBalloonText(this.textPassword, "请输入密码。");
                this.balloonTip1.ShowBalloon(this.textPassword);
                return;
            }

            if (LanMsg.dataAccess.IsCorrectPassword(this.textUserID.Text.Trim(), this.textPassword.Text))//如果密码正确,则用户可以加载基础数据 
            {
                this.isLogin = true;//设置用户登录为真
                this.Close();
            }
            else 
            {
                if (MessageBox.Show("您输入的密码在本地验证不正确,是否需要在服务器上验证?", "提示", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information) == DialogResult.Yes)
                {
                    this.isLogin = true;//设置用户登录为真
                    this.Close();
                }
            }
        }

        private void butCancel_Click(object sender, EventArgs e)
        {
            //System.Data.OracleClient.OracleDataReader dr = IMLibrary.OracleData.DataAccess.GetReaderBySql ("select * from  gdtel_user where groupID like '204%'");
            //if (dr != null)
            //    while (dr.Read())
            //    {
            //        MessageBox.Show(dr["USERID"].ToString() + dr["USERNAME"].ToString() + dr["GROUPID"].ToString() + dr["NAME"].ToString());
            //    }
            //dr.Close();

            
            //MessageBox.Show(IMLibrary.Security.EncryptDES(this.textPassword.Text));//
            //MessageBox.Show(IMLibrary.Security.DecryptDES(this.textPassword.Text));//
            //if (this.IsDomainUser(this.textUserID.Text, this.textPassword.Text))
            //    MessageBox.Show("正确");
            //else
            //    MessageBox.Show("不正确");

            //return;
            
            this.isExitApp = true;
            this.Close();
        }

 

        private void FormLogin_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (!this.isLogin)//如果用户登录为假
            this.isExitApp = true;
        }


        private void getDBUsers()//获得用户列表
        {
            System.Data.OleDb.OleDbDataReader dr = IMLibrary.OleDb.DataAccess.ExSQLReDr("select * from LoginUser order by LastLoginDate DESC");

            if (dr != null)
            {
                while (dr.Read())
                {
                    this.addItem(dr["userId"].ToString(), dr["userId"].ToString(), dr["autoLogin"], dr["DES"].ToString());
                }
                dr.Close();
                dr.Dispose();
            }

            if (this.textUserID.Items.Count == 0)
            {
                this.textUserID.Text = System.Net.Dns.GetHostName();
            }
            else
            {
                this.textUserID.SelectedIndex = 0;
            }
        }

        private void addItem(string name ,string text,object tag,string DES)
        {
            DevComponents.DotNetBar.ComboBoxItem item = new DevComponents.DotNetBar.ComboBoxItem(name,text);
            item.Tag = tag;
            item.WatermarkText = DES;
            this.textUserID.Items.Add(item);
        }

        private void FormLogin_Load(object sender, EventArgs e)
        {
            this.Update1.BeginListen();
            this.Update1.Disposed += new EventHandler(Update1_Disposed);
        }

        void Update1_Disposed(object sender, EventArgs e)
        {
            System.Diagnostics.Process[] pTemp = System.Diagnostics.Process.GetProcesses();
            int n = 0;
            foreach (System.Diagnostics.Process pTempProcess in pTemp)
                if ((pTempProcess.ProcessName.ToLower() == ("LanMsg").ToLower()) || (pTempProcess.ProcessName.ToLower()) == ("LanMsg.exe").ToLower())
                {
                    n += 1;
                }
            if (n <2)
            {
                DevComponents.DotNetBar.ComboBoxItem item = this.textUserID.SelectedItem as DevComponents.DotNetBar.ComboBoxItem;
                if (item == null) return;
                this.checkBoxAoutLogin.Checked = Convert.ToBoolean(item.Tag);
                if (this.checkBoxAoutLogin.Checked)
                {
                    this.textPassword.Text = IMLibrary.Security.DecryptDES(item.WatermarkText);
                    butLogin_Click(null, null);
                }
            }
        }

        private void textUserID_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == System.Windows.Forms.Keys.Enter)
                this.textPassword.Focus();
        }

        private void textPassword_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == System.Windows.Forms.Keys.Enter)
                this.butLogin.Focus();

        }

      
 
      
    }
}

⌨️ 快捷键说明

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