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

📄 图书类型设置.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 图书馆管理系统
{
    /// <summary>
    /// 新增时系统自动编号
    /// 
    /// </summary>
    public partial class 图书类型设置 : Form
    {
        private BindingManagerBase Navigator;
        
        public 图书类型设置()
        {
            InitializeComponent();
        }

        private void 图书类型设置_Load(object sender, EventArgs e)
        {
            sqlDataAdapter1.Fill(dataSet11, "图书类型");
            Navigator = this.BindingContext[dataSet11, "图书类型"];
            TextReadOnly(true);

        }
        public void TextReadOnly(bool A)
        {
            textBox3.ReadOnly= A;
            textBox4.ReadOnly = A;
            textBox5.ReadOnly = A;
        }
//--------------------------------首记录---------上一条--------------下一条---------------尾记录-------------------------------------
        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 SetDefaultValue()
        {
           sqlConnection1.Open();
           SqlCommand com = new SqlCommand("select max(类型编号)  最大编号 from 图书类型", sqlConnection1);
           int maxID = 1;
           object result=com.ExecuteScalar();
           if ( result!= System.DBNull.Value)
           {
               maxID = Convert.ToInt32(result) + 1;
           }
           int length = maxID.ToString().Length;
           switch (length)
           {
               case 1:
                   textBox3.Text = "00" + maxID.ToString();
                   break;
               case 2:
                   textBox3.Text = "0" + maxID.ToString();
                   break;
               case 3:
                   textBox3.Text =maxID.ToString();
                   break;
           }
           textBox5.Text = "1";
           sqlConnection1.Close();

        }
//---------------------------------------------------------------增加------------------------------------------------
        private void button5_Click(object sender, EventArgs e)
        {
            Navigator.AddNew();
            SetDefaultValue();
            TextReadOnly(false);
        }
 //-------------------------------------------------------------------修改---------------------------------------------
        private void button6_Click(object sender, EventArgs e)
        {
            TextReadOnly(false);        
        }
//------------------------------------------------------------------删除-------------------------------------
        private void button7_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("确定删除吗?", "删除数据", MessageBoxButtons.OKCancel);
            if (result == DialogResult.OK)
            {
                int row = dataGrid1.CurrentRowIndex;
                dataSet11.Tables["图书类型"].Rows[row].Delete();
            }
            else
            {
                MessageBox.Show("无可删除数据", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
//---------------------------------------------------------------------取消--------------------------------------------
        private void button8_Click(object sender, EventArgs e)
        {
            Navigator.CancelCurrentEdit();
            TextReadOnly(true);
        }

        private void button9_Click(object sender, EventArgs e)
        {
            this.Close();
        }
//-----------------------------------------------------------------------提交---------------------------------------------------
        private void button11_Click(object sender, EventArgs e)
        {

            if (textBox4.Text.Trim() == "")
            {
                MessageBox.Show("类型名称不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            Navigator.EndCurrentEdit();
            
            if (dataSet11.GetChanges() != null)
            {
                try
                {
                    sqlDataAdapter1.Update(dataSet11, "图书类型");
                     TextReadOnly(true);     
                 }
                 catch (Exception express)
                 {
                     MessageBox.Show(express.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                     dataSet11.RejectChanges();
                 }
              MessageBox.Show("操作成功!");
            }
            return;
        }
        //---------------------------------------------------------------------------搜索--------------------------------------
        private void button10_Click(object sender, EventArgs e)
        {
            sqlConnection1.Open();
            dataSet11.Clear();
            SqlDataAdapter myda = new SqlDataAdapter("select * from 图书类型 where 类型编号='" + textBox1.Text + "'or 类型名称='" + textBox2.Text + "'", sqlConnection1);
            myda.Fill(dataSet11, "图书类型");
            sqlConnection1.Close();
        }

        private void button12_Click(object sender, EventArgs e)
        {
            图书类型设置_Load(sender, e);
        }

       
    }
}

⌨️ 快捷键说明

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