⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 userm.cs

📁 用C#与SQL2005写的一个简单的图书管理系统.主要功能:图书及学生信息的添加修改与删除 图书的借出与归还 图书信息的模糊查询.
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace BooksM.UserManagement
{
    public partial class UserM : Form
    {
        public UserM()
        {
            InitializeComponent();
        }

        private void UserM_Load(object sender, EventArgs e)
        {
            MainManage myMainManage = new MainManage();
            if (myMainManage.GetTabPage == 1)
            {
                this.tabControl1.SelectedTab = tabPage1;
                checkBox6.Checked = true;
            }
            else if (myMainManage.GetTabPage == 2)
            {
                this.tabControl1.SelectedTab = tabPage2;
            }
            else if (myMainManage.GetTabPage == 3)
            {
                this.tabControl1.SelectedTab = tabPage3;
            }
            else
            {
                this.tabControl1.SelectedTab = tabPage1;
            }
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //设置权限
            string UserIdentity = "";
            if (checkBox1.Checked == true)
            {
                UserIdentity+= "1";
            }
            else
            {
                UserIdentity += "0";
            }
            if (checkBox2.Checked == true)
            {
                UserIdentity += ",1";
            }
            else
            {
                UserIdentity += ",0";
            }
            if (checkBox3.Checked == true)
            {
                UserIdentity+= ",1";
            }
            else
            {
                UserIdentity += ",0";
            }
            if (checkBox4.Checked == true)
            {
                UserIdentity += ",1";
            }
            else
            {
                UserIdentity += ",0";
            }
            if (checkBox5.Checked == true)
            {
                UserIdentity += ",1";
            }
            else
            {
                UserIdentity += ",0";
            }
            if (checkBox6.Checked == true)
            {
                UserIdentity += ",1";
            }
            else
            {
                UserIdentity += ",0";
            }
              if (textBox1.Text.Trim().Length == 0)
            {
                MessageBox.Show("输入的用户名不能为空!", "提示");
                textBox1.Focus();
                return;
            }
            if (textBox2.Text.Trim().Length == 0)
            {
                MessageBox.Show("输入的用户密码不能为空!", "提示");
                textBox2.Focus();
                return;
            }
            int UserRights=-1;
            if(domainUpDown1.SelectedItem.ToString()=="普通用户")
                UserRights= 1;
            if(domainUpDown1.SelectedItem.ToString()=="管理员")
                UserRights= 0;
            string UserName = textBox1.Text.ToString().Trim();
            string Password = textBox2.Text.ToString().Trim();
            string UserFullName = textBox3.Text.ToString().Trim();
            //string temp = " insert "
            //    + " into UserInfor(UserName, Password,UserRights, UserFullName, UserIdentity)"
            //    + "values ('" + UserName + "','" + Password + "','" + UserRights + "','" + UserFullName + "','" + UserIdentity + "')";
            MyClass.ConnData myConnData = new BooksM.MyClass.ConnData();
            //if (myConnData.Command(temp)) 
            //    MessageBox.Show("添加成功!");
            //else
            //    MessageBox.Show("添加失败!");
            string temp= "exec UserInfor_Insert '"
                +UserName+"','"
                +Password+"',"
                +UserRights+",'"
                +UserFullName+"','"
                +UserIdentity+"'";
            if (myConnData.Command(temp))
                MessageBox.Show("添加成功!");
            else
                MessageBox.Show("添加失败!");
            //try
            //{
            //    SqlDataAdapter da = new SqlDataAdapter();
            //    da.SelectCommand = new SqlCommand();
            //    da.SelectCommand.Connection = myConnData.ConnectDB();
            //    da.SelectCommand.CommandText = "UserInfor_Insert '"+UserName+"','"+Password+"',"+UserRights+",'"+UserFullName+"','"+UserIdentity+"'";
            //    da.SelectCommand.CommandType = CommandType.StoredProcedure;
            //    MessageBox.Show("添加成功!");
            //}
            //catch
            //{
            //    MessageBox.Show("添加失败!");
            //}
            Close();
        }

        private void button9_Click(object sender, EventArgs e)
        {
              if (textBox1.Text.Trim().Length == 0)
            {
                MessageBox.Show("输入的用户名不能为空!", "提示");
                textBox1.Focus();
                return;
            }
            MyClass.ConnData myConnData = new BooksM.MyClass.ConnData();
             SqlCommand mySqlCommand = new SqlCommand(@" 
                                                       select *
                                                       from UserInfor", myConnData.ConnectDB());
            SqlDataReader myDataReader = mySqlCommand.ExecuteReader();
            while (myDataReader.Read())
            {
                if (myDataReader.GetValue(0).ToString() == textBox1.Text.Trim())
                {
                    MessageBox.Show("此用户名不可用!");
                        return;
                }
                else
                {
                    continue;

                }
            }
                     MessageBox.Show("此用户名可用");
                    textBox2.Focus();
                    return;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void button8_Click(object sender, EventArgs e)
        {
              if (textBox6.Text.Trim().Length == 0)
            {
                MessageBox.Show("输入的用户名不能为空!", "提示");
                textBox6.Focus();
                return;
            }
            MyClass.ConnData myConnData = new BooksM.MyClass.ConnData();
             SqlCommand mySqlCommand = new SqlCommand(@" 
                                                       select *
                                                       from UserInfor", myConnData.ConnectDB());
            SqlDataReader myDataReader = mySqlCommand.ExecuteReader();
            while (myDataReader.Read())
            {
                if (myDataReader.GetValue(0).ToString() == textBox6.Text.Trim())
                {
                    textBox5.Text = myDataReader.GetValue(1).ToString();
                    string i=myDataReader.GetValue(2).ToString();
                    if(i=="0")
                        domainUpDown2.SelectedIndex=0;
                    else
                        domainUpDown2.SelectedIndex=1;
                    textBox4.Text = myDataReader.GetValue(3).ToString();
                    string str = myDataReader.GetValue(4).ToString();
                    string[] array = str.Split(new char[] { ',' });
                    if (array[0] == "1")
                    {
                        checkBox12.Checked = true;
                    }
                    if (array[1] == "1")
                    {
                        checkBox11.Checked = true;
                    }
                    if (array[2] == "1")
                    {
                        checkBox10.Checked = true;
                    }
                    if (array[3] == "1")
                    {
                        checkBox9.Checked = true;
                    }
                    if (array[4] == "1")
                    {
                        checkBox8.Checked = true;
                    }
                    if (array[5] == "1")
                    {
                        checkBox7.Checked = true;
                    }
                    return;

                }
                else
                {
                    continue;
                }
            }
                     MessageBox.Show("此用户名不存在,请重新输入!");
                    textBox6.Focus();
                    return;
        }

        private void button4_Click(object sender, EventArgs e)//修改函数
        {
            string UserIdentity = "";
            if (checkBox12.Checked == true)
            {
                UserIdentity += "1";
            }
            else
            {
                UserIdentity += "0";
            }
            if (checkBox11.Checked == true)
            {
                UserIdentity += ",1";
            }
            else
            {
                UserIdentity += ",0";
            }
            if (checkBox10.Checked == true)
            {
                UserIdentity += ",1";
            }
            else
            {
                UserIdentity += ",0";
            }
            if (checkBox9.Checked == true)
            {
                UserIdentity += ",1";
            }
            else
            {
                UserIdentity += ",0";
            }
            if (checkBox8.Checked == true)
            {
                UserIdentity += ",1";
            }
            else
            {
                UserIdentity += ",0";
            }
            if (checkBox7.Checked == true)
            {
                UserIdentity += ",1";
            }
            else
            {
                UserIdentity += ",0";
            }
            if (textBox6.Text.Trim().Length == 0)
            {
                MessageBox.Show("输入的用户名不能为空!", "提示");
                textBox6.Focus();
                return;
            }
            if (textBox5.Text.Trim().Length == 0)
            {
                MessageBox.Show("输入的用户密码不能为空!", "提示");
                textBox5.Focus();
                return;
            }
            int UserRights = -1;
            if (domainUpDown2.SelectedItem.ToString() == "普通用户")
                UserRights =1;
            if (domainUpDown2.SelectedItem.ToString() == "管理员")
                UserRights = 0;
            string UserName = textBox6.Text.ToString().Trim();
            string Password = textBox5.Text.ToString().Trim();
            string UserFullName = textBox4.Text.ToString().Trim();
            string temp = " update "
                + "  UserInfor set UserName='" + UserName + "',Password= '"+Password+"',UserRights='"+ UserRights +"',UserFullName='" + UserFullName +"',UserIdentity='" + UserIdentity +"'"
                + "where UserName='"+ UserName + "'";
            MyClass.ConnData myConnData = new BooksM.MyClass.ConnData();
            if (myConnData.Command(temp))
            {
                MessageBox.Show("修改成功!");
            }
            else
                MessageBox.Show("修改失败!");
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void button7_Click(object sender, EventArgs e)
        {
            if (textBox9.Text.Trim().Length == 0)
            {
                MessageBox.Show("输入的用户名不能为空!", "提示");
                textBox9.Focus();
                return;
            }
            MyClass.ConnData myConnData = new BooksM.MyClass.ConnData();
            SqlCommand mySqlCommand = new SqlCommand(@" 
                                                       select *
                                                       from UserInfor", myConnData.ConnectDB());
            SqlDataReader myDataReader = mySqlCommand.ExecuteReader();
            while (myDataReader.Read())
            {
                if (myDataReader.GetValue(0).ToString() == textBox9.Text.Trim())
                {
                    textBox8.Text = myDataReader.GetValue(1).ToString();
                    string i = myDataReader.GetValue(2).ToString();
                    if (i == "0")
                        domainUpDown3.SelectedIndex = 0;
                    else
                        domainUpDown3.SelectedIndex = 1;
                    textBox7.Text = myDataReader.GetValue(3).ToString();
                    string str = myDataReader.GetValue(4).ToString();
                    string[] array = str.Split(new char[] { ',' });
                    if (array[0] == "1")
                    {
                        checkBox18.Checked = true;
                    }
                    if (array[1] == "1")
                    {
                        checkBox17.Checked = true;
                    }
                    if (array[2] == "1")
                    {
                        checkBox16.Checked = true;
                    }
                    if (array[3] == "1")
                    {
                        checkBox15.Checked = true;
                    }
                    if (array[4] == "1")
                    {
                        checkBox14.Checked = true;
                    }
                    if (array[5] == "1")
                    {
                        checkBox13.Checked = true;
                    }
                    return;

                }
                else
                {
                    continue;
                }
            }
            MessageBox.Show("此用户名不存在,请重新输入!");
            textBox9.Focus();
            return;
        }

        private void button6_Click(object sender, EventArgs e)
        {
            if (textBox9.Text.Trim().Length == 0)
            {
                MessageBox.Show("输入的用户名不能为空!", "提示");
                textBox9.Focus();
                return;
            }
            string temp = " delete "
                + "from UserInfor "
                + " where UserName='" + textBox9.Text.ToString().Trim()+ "'";
            MyClass.ConnData myConnData = new BooksM.MyClass.ConnData();
            if (myConnData.Command(temp))
            {
                MessageBox.Show("删除成功!");
            }
            else
                MessageBox.Show("删除失败!");
        }

        private void button5_Click(object sender, EventArgs e)//关闭窗口
        {
            Close();
        }
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -