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

📄 读者档案管理.cs

📁 图书管理系统源代码,很图书管理系统源代码,很不错,有参考作用不错,有参考作用
💻 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 图书馆管理系统
{
    public partial class 读者档案管理 : Form
    {
        public 读者档案管理()
        {
            InitializeComponent();
        }
        public BindingManagerBase Navigator;
        public void TextReadOnly(bool A)
        {
            textBox2.ReadOnly = A;
            textBox3.ReadOnly = A;
            textBox4.ReadOnly = A;
            textBox5.ReadOnly = A;
            textBox6.ReadOnly = A;
            textBox7.ReadOnly = A;
            textBox8.ReadOnly = A;
            textBox9.ReadOnly = A;
            textBox10.ReadOnly = A;
            comboBox2.Enabled = !A;
            comboBox3.Enabled = !A;
            comboBox4.Enabled = !A;
            dateTimePicker1.Enabled = !A;
            comboBox6.Enabled = !A;
            dateTimePicker2.Enabled = !A;
        }
        private void 读者档案管理_Load(object sender, EventArgs e)
        {
            sqlDataAdapter1.Fill(dataSet11,"读者信息");
            Navigator = this.BindingContext[dataSet11, "读者信息"];
            TextReadOnly(true);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            dataGrid1.UnSelect(Navigator.Position);
            Navigator.Position = 0;
            dataGrid1.Select(Navigator.Position);
            dataGrid1.CurrentRowIndex = Navigator.Position;
            return;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (Navigator.Position != 0)
            {
                dataGrid1.UnSelect(Navigator.Position);
                Navigator.Position--;
                dataGrid1.Select(Navigator.Position);
                dataGrid1.CurrentRowIndex = Navigator.Position;
            }
            else
                return;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (Navigator.Position != Navigator.Count - 1)
            {
                dataGrid1.UnSelect(Navigator.Position);
                Navigator.Position++;
                dataGrid1.Select(Navigator.Position);
                dataGrid1.CurrentRowIndex = Navigator.Position;
            }
            else
                return;
        }

        private void button4_Click(object sender, EventArgs e)
        {
            dataGrid1.UnSelect(Navigator.Position);
            Navigator.Position = Navigator.Count - 1;
            dataGrid1.Select(Navigator.Position);
            dataGrid1.CurrentRowIndex = Navigator.Position;
            return;
        }
        //------------------新增-------------------
        private void button5_Click(object sender, EventArgs e)
        {
            Navigator.AddNew();
            comboBox6.Text = System.DateTime.Now.ToShortDateString();
            //textBox3.Text = SetValue();
            SetValue();
            TextReadOnly(false);
        }
        //-------------------------------------------------显示日期位置
        private void selectDate(ComboBox cb)
        {
            monthCalendar1.Left = cb.Left;
            monthCalendar1.Top = cb.Top - monthCalendar1.Height - 10;
            monthCalendar1.SelectionStart = Convert.ToDateTime(cb.Text);
            monthCalendar1.SelectionEnd = Convert.ToDateTime(cb.Text);
            monthCalendar1.Visible = true;
            monthCalendar1.Show();
        }
        private void monthCalendar1_DateSelected(object sender, DateRangeEventArgs e)
        {
            if (monthCalendar1.Left == comboBox6.Left)
                comboBox6.Text = monthCalendar1.SelectionEnd.ToString();
           
        }

        private void comboBox6_DropDown(object sender, EventArgs e)
        {
            selectDate(comboBox6);
        }

        private void comboBox6_Leave(object sender, EventArgs e)
        {
            monthCalendar1.Visible = false;
        }

        //-----------------------------删除---------------
        private void button6_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("确定删除这条记录吗?", "删除提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
            if (result == DialogResult.OK)
            {
                Navigator.RemoveAt(Navigator.Position);
                sqlDataAdapter1.Update(dataSet11, "读者信息");
            }
            else
            {
                MessageBox.Show("无可删除数据", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void button7_Click(object sender, EventArgs e)
        {
            TextReadOnly(false);
        }

        private void button8_Click(object sender, EventArgs e)
        {
            Navigator.CancelCurrentEdit();
            TextReadOnly(true);
        }
        //---------------------提交 
        private void button9_Click(object sender, EventArgs e)
        {
            if (textBox4.Text == "" || textBox6.Text == "")
            {
                MessageBox.Show("读者编号、姓名和证件是必填字段!");
            }
            Navigator.EndCurrentEdit();
            if (dataSet11.GetChanges() != null)
            {
                try
                {
                    sqlDataAdapter1.Update(dataSet11, "读者信息");
                    MessageBox.Show("操作成功");
                    TextReadOnly(true);
                }
                catch (Exception express)
                {
                    MessageBox.Show(express.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    dataSet11.RejectChanges();
                }
                
            }
        }

        private void button10_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        //--------------------------------------------搜索---------------
        private void button11_Click(object sender, EventArgs e)
        {
            sqlConnection1.Open();
            SqlDataAdapter da = new SqlDataAdapter("select * from 读者信息 where "+comboBox1.Text+" like '%"+textBox1.Text+"%'",sqlConnection1);
            dataSet11.Clear();
            da.Fill(dataSet11,"读者信息");
            sqlConnection1.Close();
        }
        private void SetValue()
        {
            int Max=0;
            sqlConnection1.Open();
            SqlCommand mycom = new SqlCommand("select max(编号) from 读者信息",sqlConnection1);
            SqlDataReader dr =mycom.ExecuteReader();
            if (dr.Read())
            {
                Max = Convert.ToInt32(dr[0])+1;
            }
            int len = Max.ToString().Length;
            switch (len)
            {
                case 1:
                    textBox3.Text = "0000" + Max.ToString();
                    break;
                case 2:
                    textBox3.Text = "000" + Max.ToString();
                    break;
                case 3:
                    textBox3.Text = "00" + Max.ToString();
                    break;
                case 4:
                    textBox3.Text = "0" + Max.ToString();
                    break;
                case 5:
                    textBox3.Text = Max.ToString();
                    break;
            }
            sqlConnection1.Close();
        }
     }
}

⌨️ 快捷键说明

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