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

📄 readerinform.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.ReaderInforManagement
{
    public partial class ReaderInforM : Form
    {
        public ReaderInforM()
        {
            InitializeComponent();
        }

        private void ReaderInforM_Load(object sender, EventArgs e)
        {
                 textBox8.Text = DateTime.Now.ToString();
           MainManage myMainManage = new MainManage();
            if (myMainManage.GetTabPage == 1)
            {
                this.tabControl1.SelectedTab = tabPage1;
            }
            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 button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text.Trim().Length == 0)
            {
                MessageBox.Show("输入的读者编号不能为空!", "提示");
                textBox1.Focus();
                return;
            }
            if (textBox2.Text.Trim().Length == 0)
            {
                MessageBox.Show("输入的读者姓名不能为空!", "提示");
                textBox2.Focus();
                return;
            }
            //int id = Convert.ToInt32(textBox1.Text);
            string sex;
            if (radioButton1.Checked==true)
                sex = radioButton1.Text ;
            else
                sex = radioButton2.Text ;
            MyClass.ConnData myConnData = new BooksM.MyClass.ConnData();
            string temp = "exec ReaderInfor_Insert '"
                + textBox1.Text.ToString().Trim() + "','"
                + textBox2.Text.ToString().Trim() + "','"
                + sex + "','"
                + textBox3.Text.ToString().Trim() + "','"
                + textBox4.Text.ToString().Trim() + "','"
                + textBox5.Text.ToString().Trim() + "','"
                + textBox6.Text.ToString().Trim() + "','"
                + textBox7.Text.ToString().Trim() + "','"
                + textBox8.Text.ToString().Trim() + "'";
            if (myConnData.Command(temp))
                MessageBox.Show("添加成功!");
            else
                MessageBox.Show("添加失败!");
            textBox1.Text =Convert.ToString(Convert.ToInt32(textBox1.Text)+1);
            textBox2.Text = "";
            textBox3.Text = "";
            textBox4.Text = "";
            textBox5.Text = "";
            textBox6.Text = "";
            textBox7.Text = "";
            textBox8.Text = DateTime.Now.ToString();
             textBox1.Focus();
        }

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

        private void button5_Click(object sender, EventArgs e)
        {
            if (textBox24.Text.Trim().Length == 0)
            {
                MessageBox.Show("输入的读者编号不能为空!", "提示");
                textBox24.Focus();
                return;
            }
            MyClass.ConnData myConnData = new BooksM.MyClass.ConnData();
            SqlCommand mySqlCommand = new SqlCommand(@" 
                                                       select *
                                                       from ReaderInfor", myConnData.ConnectDB());
            SqlDataReader myDataReader = mySqlCommand.ExecuteReader();
            while (myDataReader.Read())
            {
                if (myDataReader.GetValue(0).ToString().Trim() == textBox24.Text.ToString().Trim())
                {
                    textBox23.Text = myDataReader.GetValue(1).ToString();
                    string i = myDataReader.GetValue(2).ToString().Trim();
                    if (i == "男")
                        radioButton6.Checked=true;
                    else
                        radioButton5.Checked=true;
                    textBox22.Text = myDataReader.GetValue(3).ToString();
                    textBox21.Text = myDataReader.GetValue(4).ToString();
                    textBox20.Text = myDataReader.GetValue(5).ToString();
                    textBox19.Text = myDataReader.GetValue(6).ToString();
                    textBox18.Text = myDataReader.GetValue(7).ToString();
                    textBox17.Text = myDataReader.GetValue(8).ToString();
                   return;
                }
                else
                {
                    continue;
                }
            }
            MessageBox.Show("此用读者不存在,请重新输入!");
            textBox24.Focus();
            return;
        }

        private void button4_Click(object sender, EventArgs e)
        {
            if (textBox24.Text.Trim().Length == 0)
            {
                MessageBox.Show("输入的用户名不能为空!", "提示");
                textBox24.Focus();
                return;
            }
            if (textBox23.Text.Trim().Length == 0)
            {
                MessageBox.Show("输入的读者姓名不能为空!", "提示");
                textBox23.Focus();
                return;
            }
            //int id = Convert.ToInt32(textBox1.Text);
            string sex;
            if (radioButton6.Checked == true)
                sex = radioButton6.Text;
            else
                sex = radioButton5.Text;
            MyClass.ConnData myConnData = new BooksM.MyClass.ConnData();
            string temp = "exec ReaderInfor_updata '"
                + textBox24.Text.ToString().Trim() + "','"
                + textBox23.Text.ToString().Trim() + "','"
                + sex + "','"
                + textBox22.Text.ToString().Trim() + "','"
                + textBox21.Text.ToString().Trim() + "','"
                + textBox20.Text.ToString().Trim() + "','"
                + textBox19.Text.ToString().Trim() + "','"
                + textBox18.Text.ToString().Trim() + "','"
                + textBox17.Text.ToString().Trim() + "'";
            if (myConnData.Command(temp))
                MessageBox.Show("修改成功!");
            else
                MessageBox.Show("修改失败!");
            textBox24.Text = Convert.ToString(Convert.ToInt32(textBox24.Text) + 1);
            textBox23.Text = "";
            textBox22.Text = "";
            textBox21.Text = "";
            textBox20.Text = "";
            textBox19.Text = "";
            textBox18.Text = "";
            textBox17.Text = DateTime.Now.ToString();
            textBox24.Focus();
        }

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

        private void button6_Click(object sender, EventArgs e)
        {
            if (textBox32.Text.Trim().Length == 0)
            {
                MessageBox.Show("输入的读者编号不能为空!", "提示");
                textBox32.Focus();
                return;
            }
            MyClass.ConnData myConnData = new BooksM.MyClass.ConnData();
            SqlCommand mySqlCommand = new SqlCommand(@" 
                                                       select *
                                                       from ReaderInfor", myConnData.ConnectDB());
            SqlDataReader myDataReader = mySqlCommand.ExecuteReader();
            while (myDataReader.Read())
            {
                if (myDataReader.GetValue(0).ToString().Trim() == textBox32.Text.ToString().Trim())
                {
                    textBox31.Text = myDataReader.GetValue(1).ToString();
                    string i = myDataReader.GetValue(2).ToString().Trim();
                    if (i == "男")
                        radioButton8.Checked = true;
                    else
                        radioButton7.Checked = true;
                    textBox30.Text = myDataReader.GetValue(3).ToString();
                    textBox29.Text = myDataReader.GetValue(4).ToString();
                    textBox28.Text = myDataReader.GetValue(5).ToString();
                    textBox27.Text = myDataReader.GetValue(6).ToString();
                    textBox26.Text = myDataReader.GetValue(7).ToString();
                    textBox25.Text = myDataReader.GetValue(8).ToString();
                    return;
                }
                else
                {
                    continue;
                }
            }
            MessageBox.Show("此用读者不存在,请重新输入!");
            textBox32.Focus();
            return;
        }

        private void button8_Click(object sender, EventArgs e)
        {
            if (textBox32.Text.Trim().Length == 0)
            {
                MessageBox.Show("输入的用户名不能为空!", "提示");
                textBox32.Focus();
                return;
            }
            string temp = " delete "
                + "from ReaderInfor "
                + " where ReaderID='" + textBox32.Text.ToString().Trim() + "'";
            MyClass.ConnData myConnData = new BooksM.MyClass.ConnData();
            if (myConnData.Command(temp))
            {
                MessageBox.Show("删除成功!");
            }
            else
                MessageBox.Show("删除失败!");
            textBox32.Text = Convert.ToString(Convert.ToInt32(textBox24.Text) + 1);
            textBox31.Text = "";
            textBox30.Text = "";
            textBox29.Text = "";
            textBox28.Text = "";
            textBox27.Text = "";
            textBox26.Text = "";
            textBox25.Text = "";
            textBox32.Focus();
        }

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

    }
}

⌨️ 快捷键说明

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