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

📄 出版社管理.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 BindingManagerBase Navigator;
        public int NowStatus = 0;
        public 出版社管理()
        {
            InitializeComponent();
        }
        //---提交---------------------
        private void button5_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        //------------窗体加载-------------
        private void 出版社管理_Load(object sender, EventArgs e)
        {
            sqlDataAdapter1.Fill(dataSet11, "出版社");
            Navigator = this.BindingContext[dataSet11, "出版社"];
            TextReadOnly(true);
        }
        //------------首记录----------------
        private void button8_Click(object sender, EventArgs e)
        {
            dataGrid1.UnSelect(Navigator.Position);
            Navigator.Position = 0;
            dataGrid1.Select(Navigator.Position);
            dataGrid1.CurrentRowIndex = Navigator.Position;
        }
        //-------------上一条记录 --------------
        private void button9_Click(object sender, EventArgs e)
        {
            if (Navigator.Position != 0)
            {
                dataGrid1.UnSelect(Navigator.Position);
                Navigator.Position--;
                dataGrid1.Select(Navigator.Position);
                dataGrid1.CurrentRowIndex = Navigator.Position;
            }
            else
            {
                dataGrid1.UnSelect(Navigator.Position);
                Navigator.Position = 0;
                dataGrid1.Select(Navigator.Position);
                dataGrid1.CurrentRowIndex = Navigator.Position;
            }
        }
        //-------------下一条记录-----------------
        private void button10_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
            {
                dataGrid1.UnSelect(Navigator.Position);
                Navigator.Position = Navigator.Count - 1;
                dataGrid1.Select(Navigator.Position);
                dataGrid1.CurrentRowIndex = Navigator.Position;
            }
        }
        //-----------------尾记录----------------------
        private void button11_Click(object sender, EventArgs e)
        {
            dataGrid1.UnSelect(Navigator.Position);
            Navigator.Position = Navigator.Count - 1;
            dataGrid1.Select(Navigator.Position);
            dataGrid1.CurrentRowIndex = Navigator.Position;
        }
        public void TextReadOnly(bool A)
        {
            textBox2.ReadOnly = A;
            textBox3.ReadOnly = A;
            textBox4.ReadOnly = A;
        }
        //----------------------------------------------------------------[添加]--------------------
        private void button2_Click(object sender, EventArgs e)
        {
            Navigator.AddNew();
            TextReadOnly(false);
            NowStatus = 1;
        }
//-----------------------------------------------------------------------[修改]---------------------
        private void button3_Click(object sender, EventArgs e)
        {
            TextReadOnly(false);
            NowStatus = 2;
        }
//---------------------------------------------------------------------------[删除]---------------------
        private void button4_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("确定要删除这条记录吗?", "提示", MessageBoxButtons.OKCancel);
            if (result == DialogResult.OK)
            {
                Navigator.RemoveAt(Navigator.Position);
                sqlDataAdapter1.Update(dataSet11, "出版社");
            }
            else
                MessageBox.Show("无可删除记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
//-------------------------------------------------------------------------[提交]--------------------------
        private void button6_Click(object sender, EventArgs e)
        {
            //----(添加)-----
            if (NowStatus == 1)
            {
                sqlConnection1.Open();
                if (textBox2.Text == "" || textBox3.Text == "" || textBox4.Text == "")
                    MessageBox.Show("必须填写完整!");
                SqlCommand mycom = new SqlCommand("select * from 出版社 where 出版社编号='" + textBox2.Text.ToString().Trim() + "'", sqlConnection1);
                SqlDataReader mydr = mycom.ExecuteReader();
                if (mydr.Read())
                {
                    MessageBox.Show("发生主键值冲突!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                     mydr.Close();
                    Navigator.EndCurrentEdit();
                    if (dataSet11.GetChanges() != null)
                    {
                        try
                        {
                            sqlDataAdapter1.Update(dataSet11, "出版社");
                            TextReadOnly(true);
                        }
                        catch (Exception a)
                        {
                            MessageBox.Show(a.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            dataSet11.RejectChanges();
                        }
                    }
                }
                mydr.Close();
                sqlConnection1.Close();
            }
           //------(修改)------------
            if (NowStatus == 2)
            {
                Navigator.EndCurrentEdit();
                if (dataSet11.GetChanges() != null)
                {
                    try
                    {
                        sqlDataAdapter1.Update(dataSet11, "出版社");
                        TextReadOnly(true);
                    }
                    catch (Exception a)
                    {
                        MessageBox.Show(a.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        dataSet11.RejectChanges();
                    }
                }
            }
            }
       
        //------------------------------------------------------------------------------[取消]---------------------
        private void button7_Click(object sender, EventArgs e)
        {
            Navigator.CancelCurrentEdit();
            TextReadOnly(true);
        }
//---------------------------------------------------------------------[搜索]------------------------------
        private void button1_Click(object sender, EventArgs e)
        {
            sqlConnection1.Open();
            string str = "";
            switch (comboBox1.SelectedIndex)
            {
                case 0:
                    str = "select * from 出版社";
                    break;
                case 1:
                    str = "select * from 出版社 where "+comboBox1.Text+" like '%"+textBox1.Text.ToString()+"%'";
                    break;
                case 2:case 3:
                    str = "select * from 出版社 where " + comboBox1.Text + " like '%" + textBox1.Text + "%'";
                    break;
                default:
                    str = "select * from 出版社";
                    break;
            }
            SqlDataAdapter myda = new SqlDataAdapter(str, sqlConnection1);
            dataSet11.Clear();
            myda.Fill(dataSet11, "出版社");
            sqlConnection1.Close();
        }
    }
}

⌨️ 快捷键说明

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