• 管理员登陆界面与数据库操作界面设计


    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)
            {

            }
        }
    }

  • 相关阅读:
    Git 安装配置,key导入
    Android集成支付宝的坑
    RxJava 的使用入门
    RecyclerView 介绍 02 – 重要概念
    AndroidTips:selector的disable状态为什么无效?
    AndroidTips:解决Dialog全屏显示以及Dialog显示自动弹出输入法
    RecyclerView 介绍 01
    python模块-----sqlAlchemy
    python模块-----pyinstaller
    python模块------socket
  • 原文地址:https://www.cnblogs.com/milantgh/p/3710894.html
Copyright © 2020-2023  润新知