windows窗体
来源:互联网 发布:邮箱绑域名有什么用 编辑:程序博客网 时间:2024/06/01 07:23
sing System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace 第一章
{
public partial class frmMain : Form
{
//连接字符串
private const string sqlcon = "Data Source=.;Initial Catalog=MySchool;User ID=sa;Pwd=.";
//用于打开/关闭数据库连接
SqlConnection con = new SqlConnection(sqlcon);
//构造方法:用来做初始化工作
public frmMain()
{
InitializeComponent();
}
//取消按钮的单击事件
private void btnexit_Click(object sender, EventArgs e)
{
DialogResult result= MessageBox.Show("是否取消?","提示",MessageBoxButtons.YesNo);
if (result == DialogResult.Yes)
{
//关闭窗体
this.Close();
}
else
{
//清空窗体中所有信息
this.txtName.Clear();
this.txtPwd.Clear();
this.cborow.SelectedIndex = -1 ;
}
}
//登录按钮的单击事件
private void btnOK_Click(object sender, EventArgs e)
{
if (CheckInput())
{
try
{
con.Open();
string sql = "select count(*) from Student where StudentNo='" + this.txtName.Text + "' and LoginPwd='" + this.txtPwd.Text + "'";
SqlCommand com = new SqlCommand(sql, con);
int count = (int)com.ExecuteScalar();
if (count > 0)
{
MessageBox.Show("登陆成功!", "提示");
//创建出FrmTest窗体
FrmTest test = new FrmTest();
//test代表的就是FrmTest窗体 .Test就是标题
test.txtshow.Text = "欢迎您:" + this.txtName.Text;
test.Show();
{
public partial class frmMain : Form
{
//连接字符串
private const string sqlcon = "Data Source=.;Initial Catalog=MySchool;User ID=sa;Pwd=.";
//用于打开/关闭数据库连接
SqlConnection con = new SqlConnection(sqlcon);
//构造方法:用来做初始化工作
public frmMain()
{
InitializeComponent();
}
//取消按钮的单击事件
private void btnexit_Click(object sender, EventArgs e)
{
DialogResult result= MessageBox.Show("是否取消?","提示",MessageBoxButtons.YesNo);
if (result == DialogResult.Yes)
{
//关闭窗体
this.Close();
}
else
{
//清空窗体中所有信息
this.txtName.Clear();
this.txtPwd.Clear();
this.cborow.SelectedIndex = -1 ;
}
}
//登录按钮的单击事件
private void btnOK_Click(object sender, EventArgs e)
{
if (CheckInput())
{
try
{
con.Open();
string sql = "select count(*) from Student where StudentNo='" + this.txtName.Text + "' and LoginPwd='" + this.txtPwd.Text + "'";
SqlCommand com = new SqlCommand(sql, con);
int count = (int)com.ExecuteScalar();
if (count > 0)
{
MessageBox.Show("登陆成功!", "提示");
//创建出FrmTest窗体
FrmTest test = new FrmTest();
//test代表的就是FrmTest窗体 .Test就是标题
test.txtshow.Text = "欢迎您:" + this.txtName.Text;
test.Show();
}
else
{
MessageBox.Show("登陆失败!", "提示");
this.txtName.Clear();
this.txtPwd.Clear();
this.cborow.SelectedIndex = -1;
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
finally
{
con.Close();
}
}
}
//在点击登录按钮的时候验证文本框内容是否为空
private bool CheckInput()
{
bool flag = true;
//判断文本框是否输入值了?
//判断txtName是否输入值了
if (this.txtName.Text.Trim()== null||this.txtName.Text.Trim() =="")
{
//提示信息
MessageBox.Show("请输入登录账号!","登录验证");
flag = false;
}else if (this.txtPwd.Text.Trim() == null || this.txtPwd.Text.Trim() == "")
{
//提示信息
MessageBox.Show("请输入登录密码!", "登录验证");
flag = false;
}
else if (this.cborow.Text.Trim() == null || this.cborow.Text.Trim() == "")
{
MessageBox.Show("请选择登录角色!", "登录验证");
flag = false;
}
return flag;
}
}
}
阅读全文
0 0
- Windows 窗体
- Windows窗体
- windows窗体
- 自动化 Windows 窗体
- 再谈 Windows 窗体多线程
- Windows 窗体 CheckBox 控件
- 图形和 Windows 窗体
- c# 本地化 Windows 窗体
- Windows SDK 创建窗体
- 创建透明 Windows 窗体
- 弹出windows窗体(js)
- Windows 不规则窗体
- 设计关闭Windows窗体
- Windows窗体总结
- windows窗体高级控件
- Windows 窗体的坐标系
- Windows窗体Paint()事件
- Windows API 激活窗体
- Angular 5.0 来了,有这些大变化
- 简单工厂模式(思想)
- 【第1099期】Eruda: 手机网页调试利器
- 小程序内嵌网页能力开放
- oracle的DML,DCL,DDL区别
- windows窗体
- Ajax 的全面总结
- Firefox 58 将增强防御能力,保护用户隐私
- 为什么我不喜欢联想的笔记本
- UDP协议相关解释
- 执行应用程序或者加载动态库时出现: No such file or directory
- two sum
- 安装httpd服务器
- 深入理解java虚拟机—编译