Exemple #1
0
 private void butLogin_Click(object sender, EventArgs e)
 {
     if (textName.Text != "" & textPass.Text != "")
     {
         OleDbDataReader temDR = MyClass.getcom("select * from tb_Login where Name='" + textName.Text.Trim() + "' and Pass='******'");
         bool            ifcom = temDR.Read();
         if (ifcom)
         {
             DataClass.MyMeans.Login_Name = textName.Text.Trim();
             DataClass.MyMeans.Login_ID   = temDR.GetString(0);
             DataClass.MyMeans.My_con.Close();
             DataClass.MyMeans.My_con.Dispose();
             DataClass.MyMeans.Login_n = (int)(this.Tag);
             this.Close();
         }
         else
         {
             MessageBox.Show("用户名或密码错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
             textName.Text = "";
             textPass.Text = "";
         }
         MyClass.con_close();
     }
     else
     {
         MessageBox.Show("请将登录信息添写完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
Exemple #2
0
        private void btn_login_Click(object sender, EventArgs e)
        {
            if (txt_name.Text != null && txt_password.Text != null)
            {
                string strName = txt_name.Text.Trim();
                string strPwd  = txt_password.Text.Trim();
                //格式化查询字符串

                //用户名和密码在数据库也有一张表,采用sqlDataReader直接查询,判断当前当前用户是否存在
                string str = string.Format("select * from tb_Login where Name='{0}' and Pass='******'", strName, strPwd);

                //向数据表中查询当前输入的用户名和密码,如果返回结果不为空,说明当前输入信息正确
                SqlDataReader sdr = MyClass.getcom(str);
                if (sdr.Read())
                {
                    DataClass.MyMeans.Login_Name = strName;
                    DataClass.MyMeans.Login_ID   = sdr.GetString(0);
                    DataClass.MyMeans.My_con.Close();
                    DataClass.MyMeans.My_con.Dispose();
                    DataClass.MyMeans.Login_n = (int)(this.Tag);
                    this.Close();
                    //当前用户在登录表中存在时,登录界面退出,进入主界面
                }
                else
                {
                    MessageBox.Show("用户名或者密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txt_name.Text     = "";
                    txt_password.Text = "";
                }
                MyClass.con_close();
            }
            else
            {
                MessageBox.Show("请将登录信息添写完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }