01
来源:互联网 发布:php 读取json文件 编辑:程序博客网 时间:2024/04/28 02:18
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 LJL{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button2_Click(object sender, EventArgs e) { DialogResult result=MessageBox.Show("确定退出吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { 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_1(object sender, EventArgs e) { string mingzi = textBox1.Text.Trim(); if (CheckInput()) { if (this.comboBox1.Text.Equals(ADMIN)) { guanliyuan guanli = new guanliyuan(); guanli.name = mingzi; guanli.Show(); } this.Hide(); } } public bool CheckInput() { if (this.label1.Text.Trim().Equals(string.Empty)) { MessageBox.Show("请输入用户名", CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Information); this.label1.Focus(); return false; } else if (this.label2.Text.Trim().Equals(string.Empty)) { MessageBox.Show("请输入密码", CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Information); this.label2.Focus(); return false; } else if (this.label3.Text.Trim().Equals(string.Empty)) { MessageBox.Show("请选择登录类型", CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Information); this.label3.Focus(); return false; } else { return true; } } public bool CheckUser(ref string message) { bool i = false; string mingzi =textBox1.Text.Trim(); string mima = textBox2.Text.Trim(); StringBuilder sb = new StringBuilder(); if (label3.Equals(ADMIN)) { sb.AppendFormat("SELECT COUNT(*) FROM [Table_1]" + " WHERE [mingzi]='{0}' AND [mima]='{1}'", mingzi, 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.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;namespace LJL{ public partial class guanliyuan : Form { public string name = ""; public guanliyuan() { InitializeComponent(); } private void guanliyuan_Load(object sender, EventArgs e) { this.label1.Text = name; } }}
0 0