已有56人关注
企业人事管理系统登录模块的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);
分享到:
精彩评论 1
东方_mrkj
学分:0 LV1
2011-11-18
沙发
读者你好:
    你可以在登录窗体的属性对话框中设置一下该窗体的Tag属性,要求是整数类型,比如设置为2,然后再运行程序就可以了。
首页上一页 1 下一页尾页 1 条记录 1/1页
手机同步功能介绍
友情提示:以下图书配套资源能够实现手机同步功能
明日微信公众号
明日之星 明日之星编程特训营
客服热线(每日9:00-17:00)
400 675 1066
mingrisoft@mingrisoft.com
吉林省明日科技有限公司Copyright ©2007-2022,mingrisoft.com, All Rights Reserved长春市北湖科技开发区盛北大街3333号长春北湖科技园项目一期A10号楼四、五层
吉ICP备10002740号-2吉公网安备22010202000132经营性网站备案信息 营业执照