博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
管理员登陆界面与数据库操作界面设计
阅读量:5050 次
发布时间:2019-06-12

本文共 4699 字,大约阅读时间需要 15 分钟。

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)

        {

        }

    }
}

转载于:https://www.cnblogs.com/milantgh/p/3710894.html

你可能感兴趣的文章
Vue中使用key的作用
查看>>
二叉索引树 树状数组
查看>>
日志框架--(一)基础篇
查看>>
Java设计模式之原型模式
查看>>
Spring学习(四)-----Spring Bean引用同xml和不同xml bean的例子
查看>>
哲理故事与管理之道(20)-用危机激励下属
查看>>
关于源程序到可运行程序的过程
查看>>
wepy的使用
查看>>
转载:mysql数据库密码忘记找回方法
查看>>
scratch少儿编程第一季——06、人在江湖混,没有背景怎么行。
查看>>
面向对象1
查看>>
在ns2.35中添加myevalvid框架
查看>>
【贪心+DFS】D. Field expansion
查看>>
为什么要使用href=”javascript:void(0);”
查看>>
二进制文件的查看和编辑
查看>>
C# Async与Await的使用
查看>>
Mysql性能调优
查看>>
iOS基础-UIKit框架-多控制器管理-实例:qq界面框架
查看>>
javascript学习---BOM
查看>>
IOS-每个程序员的编程之路上都应该看这11本书
查看>>