C#

xinsheng508 2009-04-29 12:59: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;

namespace myshool2
{
public partial class UseName : Form
{
public UseName()
{
InitializeComponent();
}

private void label3_Click(object sender, EventArgs e)
{

}

private void UseName3_Click(object sender, EventArgs e)
{
if (UseName3.Text == "")
{
MessageBox.Show("请输入用户姓名");
MessageBox.Show("请输入用户姓名", "输入提示", MessageBoxButtons.OKCancel);
MessageBox.Show("请输入用户姓名", "输入提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
}
}

private void Form3_Load(object sender, EventArgs e)
{

}

private void UseName3_Click_1(object sender, EventArgs e)
{
if (UseName3.Text == "")
{
DialogResult result;
result = MessageBox.Show("请输入用户名","输入提示",MessageBoxButtons.OKCancel,MessageBoxIcon.Information);
if (result == DialogResult.OK)
{
MessageBox.Show("你选择了确定");
}
else
{
MessageBox.Show("你选择了取消");
this.Close();
}
}
}

private void button2_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
}
没有输入用户名,但没任何显示。搞了一天我都无言了。。。。
...全文
86 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiaojiang2000 2009-04-29
  • 打赏
  • 举报
回复
新手路过,我把自己做毕业设计中的登陆界面代码拿来,楼主参考。
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 Dxssgl
{
public partial class Login : Form
{
public Login()
{
InitializeComponent();
}
SqlConnection conn = DBConn.Dxssgl();

private void btnLogin_Click(object sender, EventArgs e)
{
if (txtLoginNo.Text.Trim() == "")
{
MessageBox.Show("请输入账号!", "登陆提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
txtLoginNo.Focus();
}
else if (txtLoginPwd.Text == "")
{
MessageBox.Show("请输入密码!", "登陆提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
txtLoginPwd.Focus();
}
else if (cboLoginType.Text == "")
{
MessageBox.Show("请选择登陆类型!", "登陆提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
cboLoginType.Focus();
}
else
{
conn.Open();
SqlCommand cmd = new SqlCommand("select count(*) from DB_ManageInfo where loginNo='" + txtLoginNo.Text + "' and loginPwd='" +txtLoginPwd.Text + "'and loginType='" + cboLoginType.Text + "'", conn);//验证登陆信息是否在DB_ManageInfo中
int i = Convert.ToInt32(cmd.ExecuteScalar());
if (i > 0)
{
UserName.loginName = txtLoginNo.Text; //全局变量
UserName.loginType = cboLoginType.Text; //全局变量
conn.Close();
WFMain sfm = new WFMain(); //跳转到主界面
sfm.Show();
this.Hide();
}
else
{
MessageBox.Show("用户名或密码错误");
txtLoginNo.Text = "";
txtLoginPwd.Text = "";
}
}
}

private void btnCanel_Click(object sender, EventArgs e)
{
DialogResult result = MessageBox.Show("您确定要退出吗?", "操作提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
if (result == DialogResult.OK)
{
Application.Exit();
}
}
}


using System; //新建一个类文件,存放数据库的连接字符串
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
namespace Dxssgl.BaseClass
{
class DBConn
{
public static SqlConnection Dxssgl()
{
return new SqlConnection("server=.;database=Dxssgl;uid=sa;pwd=admin");
}
}
}


using System; //作为全局变量,需要时可以调用
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Dxssgl
{
class UserName
{
public static string loginName;
public static string loginType;
}
}

111,125

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧