我是靠谱客的博主 傲娇长颈鹿,最近开发中收集的这篇文章主要介绍数据库 第一章Windows程序,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
//
public Form1()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
MessageBox.Show("确定取消登陆吗");
this.Close();
}
private void Form1_Click(object sender, EventArgs e)
{
if (this.BackColor == Color.Red)
{
this.BackColor = Color.Yellow;
}
else if (this.BackColor == Color.Yellow)
{
this.BackColor = Color.Green;
}
else
{
this.BackColor = Color.Red;
}
}
public const string CAPTION = "输入提示";
public const string ADMIN = "管理员";
private void button1_Click(object sender, EventArgs e)
{
//用户名 密码和用户类型都不为空
if (CheckInput())
{
if (this.comboBox1.Text.Equals(ADMIN))
{
guanliyuan d = new guanliyuan();
d.name = textBox1.Text;
d.Show();
}
this.Hide();
}
}
//用户名为空
public bool CheckInput()
{
if (this.textBox1.Text.Trim().Equals(string.Empty))
{
MessageBox.Show("请输入用户名", CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Information);
this.label1.Focus();
return false;
}
//密码为空
else if (this.textBox2.Text.Trim().Equals(string.Empty))
{
MessageBox.Show("请输入密码", CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Information);
this.txtpwd.Focus();
return false;
}
//用户类型为空
else if (this.comboBox1.Text.Trim().Equals(string.Empty))
{
MessageBox.Show("请选择登录类型", CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Information);
this.cboLoginType.Focus();
return false;
}
else
{
guanliyuan d = new guanliyuan();
d.name = textBox1.Text;
return true;
}
}
public bool CheckUser(ref string message)
{
bool i = false;
string name = this.textBox1.Text.Trim();
string mima = textBox2.Text.Trim();
StringBuilder sb = new StringBuilder();
if (txtpwd.Equals(ADMIN))
{
sb.AppendFormat("SELECT COUNT(*) FROM [Table_1]" + " WHERE [name]= '" + name + "' AND [mima]='" + mima + "'");
}
int count = 0;
DEHelper dbhelper = new DEHelper();
try
{
SqlCommand comm = new SqlCommand(sb.ToString(), dbhelper.Connection);
dbhelper.OpenConnection();
count = (int)comm.ExecuteScalar();
if (count > 0)
{
i = true;
}
else
{
message = "用户名或密码不存在";
i = false;
}
}
catch (Exception)
{
message = "系统发生错误,请稍后再试";
i = false;
}
finally
{
dbhelper.CloseConnection();
}
return i;
}
}
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Data;
namespace WindowsFormsApplication2
{
class DEHelper
{
private string connString = "Data Source=.;Initial Catalog=MySchool;Integrated Security=True";
private SqlConnection connection;
public SqlConnection Connection
{
get
{
if (connection == null)
{
connection = new SqlConnection(connString);
}
return connection;
}
}
public void OpenConnection()
{
if (Connection.State == ConnectionState.Closed
)
{
Connection.Open();
}
else if (Connection.State == ConnectionState.Broken)
{
Connection.Close();
Connection.Open();
}
}
public void CloseConnection()
{
if (Connection.State == ConnectionState.Open || Connection.State == ConnectionState.Broken)
{
Connection.Close();
}
}
}
}

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class guanliyuan : Form
{
public
string name = "";
public guanliyuan()
{
InitializeComponent();
}
private void guanliyuan_Load(object sender, EventArgs e)
{
this.aa.Text = name;
}
}
}

最后

以上就是傲娇长颈鹿为你收集整理的数据库 第一章Windows程序的全部内容,希望文章能够帮你解决数据库 第一章Windows程序所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(54)

评论列表共有 0 条评论

立即
投稿
返回
顶部