第一章 所有上机练习
来源:互联网 发布:pk10软件下载 编辑:程序博客网 时间:2024/06/07 12:06
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Data;using System.Data.SqlClient;namespace MySchool{ public class DBHelper { private string connString = @"Data Source=.;Initital Catalog = MySchool; User ID=sa;Pwd=bdqn"; 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;using System.Data.SqlClient;namespace MySchool{ public partial class FrmAdminMainin : Form { public string userId = string.Empty; public FrmAdminMainin() { InitializeComponent(); } private void FrmAdminMainin_Load(object sender, EventArgs e) { textBox1.Text = userId; } public const string ADMIN = "系统管理员"; private void textBox1_TextChanged(object sender, EventArgs e) { if (CheckInput()) { string message = string.Empty; if (CheckUser(ref message)) { if (this.cboLoginType.Text.Equals(ADMIN)) { FrmAdminMainin frmAdmin = new FrmAdminMainin(); frmAdmin.Show(); } this.Hide(); } } } public bool CheckUser(ref string message) { bool isValidUser = false; string userName = textBox1.Text.Trim(); string userPwd = textBox2.Text.Trim(); StringBuilder sb = new StringBuilder(); if (cboLoginType.Equals(ADMIN)) { sb.AppendFormat("SELECT COUNT(*) FROM [Admin]" + " WHERE [LoginId] = '{0}' AND [LoginPwd]='{1}'", userName, userPwd); } int count = 0; DBHelper dbhelper = new DBHelper(); try { SqlCommand command = new SqlCommand(sb.ToString(), dbhelper.Connection); dbhelper.OpenConnection(); count = (int)command.ExecuteScalar(); if (count > 0) { isValidUser = true; } else { message = "用户名或密码不存在!"; isValidUser = false; } } catch (Exeception ex) { message = "系统发生错误,请稍后再试!"; isValidUser = false; } finally { dbhelper.CloseConnection(); } return isValidUser; } }}
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 MySchool{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void checkBox2_CheckedChanged(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; } } private void checkBox4_CheckedChanged(object sender, EventArgs e) { } public const string CAPTION = "输入提示"; private void denglu_Click(object sender, EventArgs e) { if (CheckInput()) { } } public bool CheckInput() { if (this.textBox1.Text.Trim().Equals(string.Empty)) { MessageBox.Show("请输入用户名", CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Information); this.textBox1.Focus(); return false; } else if (this.textBox2.Text.Trim().Equals(string.Empty)) { MessageBox.Show("请输入密码", CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Information); this.textBox2.Focus(); return false; } else if (this.comboBox1.Text.Trim().Equals(string.Empty)) { MessageBox.Show("请输入密码", CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Information); this.comboBox1.Focus(); return false; } else { return true; } } private void quxiao_Click(object sender, EventArgs e) { DialogResult result = MessageBox.Show("确认取消登录吗?", "操作提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { this.Close(); } } private void textBox2_TextChanged(object sender, EventArgs e) { } private void textBox1_TextChanged(object sender, EventArgs e) { } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { } }}
0 0
- 第一章 所有上机练习
- 第一章上机练习2
- 第一章上机练习
- HTML 第一章上机练习3
- HTML第一章上机练习4
- C# 第一章上机练习2
- c#第一章上机练习3
- c#第一章上机练习3
- 第一章魔兽系统上机练习
- HTMl 第一章上机练习1 清平乐
- HTML第一章上机练习2 人物介绍
- ACCP 7.0 第一章 上机练习3
- ACCP 7.0 第一章上机练习4
- HTML 第一章上机练习3、4
- ACCP7.0S1HTML第一章上机练习4
- 第一章上机练习2 求两数的和
- 算法竞赛入门经典 第一章 上机练习(C++代码)
- 《算法竞赛入门经典》上机练习——第一章
- 分享一个快的飞起的maven的settings.xml文件
- CodeForces 66B 暴力
- iOS网络操作之AFNetworking
- JSON learning notes
- 微信,新浪登录分享遇到的问题
- 第一章 所有上机练习
- 宏和函数有什么区别?
- GCC的使用
- JavaScript实践——密码强度验证
- 1439: 2.4.5 Fractions to Decimals 分数化小数
- jvm 内存分配与垃圾回收
- hibernate关联映射
- 【BZOJ 3172】[Tjoi2013]单词 Ac自动机
- struts基本概念