loading.cs
上传用户:zhongfine
上传日期:2022-08-01
资源大小:2860k
文件大小:5k
源码类别:

企业管理

开发平台:

C#

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Data.SqlClient;
  10. namespace 人事管理系统
  11. {
  12.     public partial class loading : Form
  13.     {
  14.         Datacon mydatacon = new Datacon();
  15.         password mypassword = new password();
  16.         public loading()
  17.         {
  18.             InitializeComponent();
  19.         }
  20.         private void button2_Click(object sender, EventArgs e)
  21.         {
  22.             this.HideForm1.Start();
  23.             
  24.             
  25.         }
  26.         private void Form1_Load(object sender, EventArgs e)
  27.         {
  28.             //timer控件ShowForm1
  29.             this.ShowForm1.Enabled = true; //控件是否激活
  30.             this.ShowForm1.Interval = 50; //Elapsed 事件的频率
  31.             //timer控件HideForm1
  32.             this.HideForm1.Enabled = false;
  33.             this.HideForm1.Interval = 30;
  34.             this.Opacity = 0.0;  //设置窗体透明度
  35.             ShowForm1.Start();  //timer控件 ShowForm1开始
  36.         }
  37.         private void ShowForm1_Tick(object sender, EventArgs e)
  38.         {
  39.             if (this.Opacity == 1)  //如果窗体透明度达到 1
  40.             {
  41.                 this.ShowForm1.Stop();
  42.             }
  43.             else  //透明度小于 1
  44.             {
  45.                 this.Opacity = this.Opacity + 0.1; //透明度递增
  46.             }
  47.         }
  48.         private void HideForm1_Tick(object sender, EventArgs e)
  49.         {
  50.             this.Opacity = this.Opacity - 0.1; //透明度不等于 0
  51.             if (this.Opacity == 0) //透明度等于 0
  52.             {
  53.                 this.HideForm1.Stop();
  54.                 Application.Exit();//退出系统,程序结束
  55.             }
  56.         }
  57.         private void button1_Click(object sender, EventArgs e)
  58.         {
  59.             if (user.Text == "")
  60.             {
  61.                 MessageBox.Show("用户名不能为空!");
  62.                 return;
  63.             }
  64.             else
  65.                 if (password.Text == "")
  66.                 {
  67.                     MessageBox.Show("密码不能为空!");
  68.                     return;
  69.                 }
  70.                 else
  71.                     if (login_style.Text == "")
  72.                     {
  73.                         MessageBox.Show("请选择登陆方式!");
  74.                         return;
  75.                     }
  76.            
  77.             
  78.             if (user.Text != "" && password.Text != "" && login_style.Text!= "")//如果三者都不为空,继续
  79.             {
  80.                 SqlConnection sqlcn = mydatacon.getcon();//调用类mydatacon里面的连接字符串函数getcon()
  81.                
  82.                 
  83.                 sqlcn.Open();//连接打开
  84.                 SqlCommand cmd = new SqlCommand("SELECT COUNT(*) FROM [PERSON] WHERE ID='" + this.user.Text + "'", sqlcn);
  85.                 string q = cmd.ExecuteScalar().ToString();//用q来记录表PERSON中有没有该用户名存在
  86.                 SqlCommand hcmd = new SqlCommand("SELECT COUNT(*) FROM [PERSON] WHERE ID='" + this.user.Text + "'and PASSWD='" +mypassword.OUT(this.password.Text)+ "'and AUTHORITY='"+this.login_style.Text+"'", sqlcn);
  87.                 string t = hcmd.ExecuteScalar().ToString();//用t来记录表PERSON中有没有满足用户登陆方式的与之相对应的帐号与密码
  88.                 cmd.Connection.Close();
  89.                 if (q == "0")//q为0表示不存在这样的情况
  90.                 {
  91.                     MessageBox.Show("用户名不存在!");
  92.                     return;
  93.                 }
  94.                 else
  95.                     if (t == "1")//t为1表示这样的情况存在,且只有一种
  96.                     {
  97.                         sqlcn.Open();
  98.                         major mymajor = new major();
  99.                         String mysql = "SELECT NAME FROM [PERSON] where ID='" + this.user.Text + "' ;";
  100.                         SqlCommand sqlcm = new SqlCommand(mysql, sqlcn);
  101.                         SqlDataReader dr = sqlcm.ExecuteReader();
  102.                         dr.Read();//读取当前登陆用户的姓名
  103.                         mymajor.label9.Text = dr["NAME"].ToString();
  104.                         mymajor.label10.Text = this.login_style.Text;//将该用户的姓名与登陆方式传递给主界面上的lable控件
  105.                         mymajor.label14.Text = this.user.Text;
  106.                         this.Hide();
  107.                         mymajor.Show();//主窗口显示
  108.                         sqlcn.Close();
  109.                     }
  110.                     else
  111.                     {
  112.                         MessageBox.Show("密码不正确!");
  113.                         return;
  114.                     }
  115.             }
  116.          
  117.         }
  118.     }
  119. }