登入界面的MySQL是什么意思_管理员登陆界面与数据库操作界面设计

form1.cs:管理员登陆界面

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 WindowsFormsApplication2

{

public partial class frm_Login : Form

{

public frm_Login()

{

InitializeComponent();

}

private void Form1_Load(object sender, EventArgs e)

{

}

int count = 0;

private void button2_Click(object sender, EventArgs e)

{

if (tb_User.Text == "")

{

MessageBox.Show("Username is not allowed null");

tb_User.Focus();

return;

}

if (tb_Password.Text == "")

{

MessageBox.Show("Password is not allowed null");

tb_Password.Focus();

return;

}

SqlConnection conn = new SqlConnection();

conn.ConnectionString = "Data Source=M11DBWU0ZBSJLZD;Initial Catalog=db_management;User ID=sa;Password=123";

conn.Open();

SqlCommand cmd = new SqlCommand("select * from tab_admin where username=" + "'" + tb_User.Text.Trim() + "'" +  " and password=" + "'" + tb_Password.Text.Trim() + "'", conn);

SqlDataReader dr = cmd.ExecuteReader();

bool ifcom = dr.Read();

if (ifcom)

{

frm_Info frminfo = new frm_Info();

frminfo.ShowDialog();

this.Hide();

}

else

{

count = count + 1;

if (count < 3)

{

MessageBox.Show ("Account OR Password Error~ Please input it again~", "System Tips", MessageBoxButtons.OK, MessageBoxIcon.Information);

tb_User.Text = "";

tb_Password.Text = "";

tb_User.Focus();

}

else

{

MessageBox.Show ("Error input is near 3 times, the system will use stoped!", "System Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);

btn_Login.Enabled = false;

}

}

conn.Close();

}

private void btn_Cancel_Click(object sender, EventArgs e)

{

Application.Exit();

}

}

}

form2.cs:数据库操作界面

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 WindowsFormsApplication2

{

public partial class frm_Info : Form

{

public frm_Info()

{

InitializeComponent();

}

private void frm_Info_FormClosing(object sender, FormClosingEventArgs e)

{

if (MessageBox.Show("Are you sure exit the window", "System Tips", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)

{

Application.ExitThread();

}

else

{

e.Cancel = true;

}

}

SqlConnection conn = new SqlConnection();

DataSet ds;

SqlDataAdapter sda;

private void btn_Query_Click(object sender, EventArgs e)

{

conn.ConnectionString = "Data Source=M11DBWU0ZBSJLZD;Initial Catalog=db_management;User ID=sa;Password=123";

conn.Open();

ds = new DataSet();

sda = new SqlDataAdapter ("select uid as uid, username as username, role as userrole, intro as introduction from tab_user where username like " + "'" + "%" + textBox1.Text.Trim() + "%" + "'", conn);

sda.Fill(ds, "view");

dataGridView1.DataSource = ds.Tables[0];

conn.Close();

}

private void btn_Count_Click(object sender, EventArgs e)

{

conn.ConnectionString = "Data Source=M11DBWU0ZBSJLZD;Initial Catalog=db_management;User ID=sa;Password=123";

conn.Open();

SqlCommand cmd = new SqlCommand();

cmd.Connection = conn;

cmd.CommandType = CommandType.Text;

cmd.CommandText = "select Count(*) from tab_user where role=" + "'" + textBox2.Text.Trim() + "'";

textBox2.Text = "";

textBox2.Text = Convert.ToInt32(cmd.ExecuteScalar()).ToString();

conn.Close();

}

private void button1_Click(object sender, EventArgs e)

{

DataTable dt = ds.Tables["view"];

sda.FillSchema (dt, SchemaType.Mapped);

DataRow dr = dt.Rows.Find (textBox6.Text.Trim());

dr["username"] = textBox3.Text.Trim();

dr["userrole"]     = textBox4.Text.Trim();

dr["introduction"]    = textBox5.Text.Trim();

SqlCommandBuilder cmdbuider = new SqlCommandBuilder(sda);

sda.Update(dt);

}

private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)

{

textBox6.Text = dataGridView1.SelectedCells[0].Value.ToString();

textBox3.Text = dataGridView1.SelectedCells[1].Value.ToString();

textBox4.Text = dataGridView1.SelectedCells[2].Value.ToString();

textBox5.Text = dataGridView1.SelectedCells[3].Value.ToString();

}

private void button2_Click(object sender, EventArgs e)

{

conn.ConnectionString = "Data Source=M11DBWU0ZBSJLZD;Initial Catalog=db_management;User ID=sa;Password=123";

conn.Open();

SqlCommand cmd = new SqlCommand();

cmd.Connection = conn;

cmd.CommandType = CommandType.Text;

cmd.CommandText = "delete from tab_user where username=" + "'" + textBox7.Text.Trim() + "'";

textBox7.Text = "";

textBox7.Text = "The number of DEL person:";

textBox7.Text += Convert.ToInt32(cmd.ExecuteNonQuery()).ToString();

conn.Close();

}

private void frm_Info_Load(object sender, EventArgs e)

{

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值