首页上一页 1 下一页尾页 1 条记录 1/1页
企业人事管理系统登录模块的this.Tag有问题哦??
发表在C#图书答疑
2011-11-17
是否精华
是
否
版块置顶:
是
否
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 UTEM
{
public partial class F_Login : Form
{
DataClass.MyMeans MyClass = new UTEM.DataClass.MyMeans();
public F_Login()
{
InitializeComponent();
}
private void btnClose_Click(object sender, EventArgs e)
{
//this.Close();
if ((int)(this.Tag) == 1)
{
DataClass.MyMeans.Login_n = 3;
Application.Exit();
}
else
if ((int)(this.Tag) == 2)
this.Close();
}
private void btnLogin_Click(object sender, EventArgs e)
{
if (txtUser.Text != "" & txtPass.Text != "")
{
SqlDataReader temDR = MyClass.getcom("select * from tb_Login where Name='" + txtUser.Text.Trim() + "'and Pass='" + txtPass.Text.Trim() + "'");
bool ifcom = temDR.Read();
if (ifcom)
{
DataClass.MyMeans.Login_Name = txtUser.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);
txtUser.Text = "";
txtPass.Text = "";
}
MyClass.con_close();
}
else
MessageBox.Show("请填写用户密码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private void F_Login_Load(object sender, EventArgs e)
{
try
{
MyClass.con_open();
MyClass.con_close();
txtUser.Text = "";
txtPass.Text = "";
}
catch
{
MessageBox.Show("数据库连接失败。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
Application.Exit();
}
}
private void txtUser_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == '\r')
txtPass.Focus();
}
private void txtPass_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == '\r')
btnLogin.Focus();
}
private void F_Login_Activated(object sender, EventArgs e)
{
txtUser.Focus();
}
}
}
这里出现未处理InvalidCastException指定的转换无效这个出现在哪里
提示出现在DataClass.MyMeans.Login_n = (int)(this.Tag);
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 UTEM
{
public partial class F_Login : Form
{
DataClass.MyMeans MyClass = new UTEM.DataClass.MyMeans();
public F_Login()
{
InitializeComponent();
}
private void btnClose_Click(object sender, EventArgs e)
{
//this.Close();
if ((int)(this.Tag) == 1)
{
DataClass.MyMeans.Login_n = 3;
Application.Exit();
}
else
if ((int)(this.Tag) == 2)
this.Close();
}
private void btnLogin_Click(object sender, EventArgs e)
{
if (txtUser.Text != "" & txtPass.Text != "")
{
SqlDataReader temDR = MyClass.getcom("select * from tb_Login where Name='" + txtUser.Text.Trim() + "'and Pass='" + txtPass.Text.Trim() + "'");
bool ifcom = temDR.Read();
if (ifcom)
{
DataClass.MyMeans.Login_Name = txtUser.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);
txtUser.Text = "";
txtPass.Text = "";
}
MyClass.con_close();
}
else
MessageBox.Show("请填写用户密码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private void F_Login_Load(object sender, EventArgs e)
{
try
{
MyClass.con_open();
MyClass.con_close();
txtUser.Text = "";
txtPass.Text = "";
}
catch
{
MessageBox.Show("数据库连接失败。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
Application.Exit();
}
}
private void txtUser_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == '\r')
txtPass.Focus();
}
private void txtPass_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == '\r')
btnLogin.Focus();
}
private void F_Login_Activated(object sender, EventArgs e)
{
txtUser.Focus();
}
}
}
这里出现未处理InvalidCastException指定的转换无效这个出现在哪里
提示出现在DataClass.MyMeans.Login_n = (int)(this.Tag);