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

📄 addbooks.cs

📁 这是个C#做成的图书管理系统,请大家参考,多提建议
💻 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.IO;

namespace BookMS
{
    public partial class AddBooks : Form
    {
        public AddBooks()
        {
            InitializeComponent();
        }
        DataSet ds = new DataSet("BookDs");
        private void Savebutton_Click(object sender, EventArgs e)
        {
            if (File.Exists("..\\..\\BookDs.ds"))
            {
                if (BookIDBox.Text != "" && BookNameBox.Text != "" && BookNumBox.Text != "")
                {
                    ds.Clear();
                    ds.ReadXml("..\\..\\BookDs.ds");

                    ds.Tables["BookTab"].PrimaryKey = new DataColumn[] { ds.Tables["BookTab"].Columns["BookID"] };
                    try
                    {
                        DataRow dr = ds.Tables["BookTab"].NewRow();
                        dr["BookID"] = BookIDBox.Text.ToString();
                        dr["BookName"] = BookNameBox.Text.ToString();
                        dr["Publishing"] = PublishBox.Text.ToString();
                        dr["BookNum"] = Convert.ToInt32(BookNumBox.Text.Trim());
                        dr["Author"] = AuthorBox.Text.ToString();
                        dr["Publishingtime"] = Convert.ToDateTime(PubtimePicker.Text).ToLongDateString();

                        ds.Tables["BookTab"].Rows.Add(dr);
                        ds.Tables["BookTab"].WriteXml("..\\..\\BookDs.ds");

                        MessageBox.Show("图书添加成功!");
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("对不起,图书编号不能重复使用!");
                        ds.Clear();
                    }
                }
                else
                {
                    MessageBox.Show("字体加重的项目必须填写完整!", "提示");
                }
            }
        }

        private void Returnbutton_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}

⌨️ 快捷键说明

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