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

📄 booktostock.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.Sql;

namespace BMS
{
    public partial class BookToStock : Form
    {
        public BookToStock()
        {
            InitializeComponent();
        }

        private void BookToStore_Load(object sender, EventArgs e)
        {
            string sql = "select Id,publishid,Bookname,Booksort,Bookinprice,Bookamount,Booksum,bookstocks,Bookaddpoeple,Bookaddtime from booktable";
            BookStockInfo.DataSource = Operator.SelectSql(sql).Tables[0];
        }

        private void Magazine_CheckedChanged(object sender, EventArgs e)
        {
            if (Magazine.Checked)
            {
                Writer.Enabled = false;
                M_qishu.Enabled = true;
                //Writer.Text = "";
            }
            else
            {
                Writer.Enabled = true;
                M_qishu.Enabled = false;
                //M_qishu.Text = "";
            }
        }

        private void Published_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = !Check.Integer(e);

        }

        private void BookName_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = !Check.safe(e);
        }

        private void BookClass_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = !Check.safe(e);
        }

        private void BookPrice_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = !Check.num(BookPrice,e);
        }

        private void M_qishu_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = !Check.Integer(e);
        }

        private void BookNum_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = !Check.Integer(e);
        }

        private void PaySum_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = !Check.num(PaySum,e);
        }

        private void Writer_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = !Check.safe(e);
        }

        private void Bookpublish_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = !Check.safe(e);
        }

        private void Add_Click(object sender, EventArgs e)
        {
            if (Published.Text.Trim() == "") 
            {
                MessageBox.Show("请输入图书出版号!","图书入库");
                Published.Focus();
                return;
            }
            if (Published.Text.Trim().Length < 7)
            {
                MessageBox.Show("出版号不能小于7位!请重新输入!", "图书入库");
                Published.Text = "";
                Published.Focus();
                return;
            }
            if (BookName.Text.Trim() =="")
            {
                MessageBox.Show("请输入书名!", "图书入库");
                BookName.Focus();
                return;
            }
            if (BookClass.Text.Trim() == "")
            {
                MessageBox.Show("请输入图书类别!", "图书入库");
                BookClass.Focus();
                return;
            }
            if (BookPrice.Text.Trim() == "")
            {
                MessageBox.Show("请输入图书定价!", "图书入库");
                BookPrice.Focus();
                return;
            }
            if (BookNum.Text.Trim() =="")
            {
                MessageBox.Show("请输入图书数量!", "图书入库");
                BookNum.Focus();
                return;
            }
            if (PaySum.Text.Trim() == "")
            {
                MessageBox.Show("请输入图书总花费!", "图书入库");
                PaySum.Focus();
                return;
            }
            if (Bookpublish.Text.Trim() == "")
            {
                MessageBox.Show("请输入图书的出版号!", "图书入库");
                Bookpublish.Focus();
                return;
            }
            DialogResult dr = MessageBox.Show("添加后图书的图书编号和数量将不能修改,请仔细检查!点确定添加图书,点取消放弃操作!", "图书入库", MessageBoxButtons.OKCancel);
            if (dr == DialogResult.Cancel)
            {
                return;
            }
            
            string Sql = "insert into Booktable (publishid,Bookname,Booksort,Bookinprice,Bookamount,Booksum,bookstocks,"
                + "Bookaddpoeple,Bookaddtime) values(";
            int i,IntId;
            string bookid;
            string Sql1,Sql2;
            Sql += Published.Text.Trim()+",'"+BookName.Text.Trim()+"','"+BookClass.Text.Trim()+"',"+BookPrice.Text.Trim()+",";
            Sql += BookNum.Text.Trim() + "," + PaySum.Text.Trim() + "," + BookNum.Text.Trim() + ",'" + Value.CurrentLoger1 + "',getdate());";
            if (!Magazine.Checked)
            {
                if (Writer.Text.Trim() == "")
                {
                    MessageBox.Show("请输入图书的作者!", "图书入库");
                }
                Sql1 = "insert into Bookinf (Bookid,published,bookname,booksort,bookwriter,bookpublish,bookpubdate,"
                    +"bookprice,bookstate) values('";
                Sql2 = "'," + Published.Text.Trim() + ",'" + BookName.Text.Trim() + "','" + BookClass.Text.Trim() + "','"
                + Writer.Text.Trim() + "','" + Bookpublish.Text.Trim() + "','" + Pub_time.Value.Date.ToString() + "'," + BookPrice.Text.Trim()
                + ",'在库');";
                
                bookid = Published.Text.Trim().Substring(Published.Text.Trim().Length - 7, 6) 
                    + DateTime.Now.Date.ToString().Substring(0,DateTime.Now.Date.ToString().IndexOf(" "));
                IntId = Operator.select("select count(*) from bookinf where bookid like('"+bookid+"%');");
            }
            else
            {
                if (M_qishu.Text.Trim() == "")
                {
                    MessageBox.Show("请输入刊物的期号!", "图书入库");
                }
                Sql1 = "insert into magazine (M_id,M_name,m_qishu,M_publish,M_pubtime,m_price,m_sort,"
                    +"m_isbreak,m_addpeople,m_time) values('";
                Sql2 = "','" + BookName.Text.Trim() + "'," + M_qishu.Text.Trim() + ",'" + Bookpublish.Text.Trim() + "','"
                +Pub_time.Value.Date.ToString()+"',"+ BookPrice.Text.Trim() + ",'" + BookClass.Text.Trim() + "','否','" + Value.CurrentLoger1 + "','" 
                + Pub_time.Value.Date.ToString() + "');";

                bookid = Published.Text.Trim().Substring(Published.Text.Trim().Length - 7, 6)
                    + DateTime.Now.Date.ToString().Substring(0, DateTime.Now.Date.ToString().IndexOf(" "));
                IntId = Operator.select("select count(*) from Magazine where M_Id like('" + bookid +"%')") ;

            }
            MessageBox.Show("系统分配" + bookid + IntId.ToString() + "到" + bookid + BookNum.Text.Trim() + "做为这些图书的唯一编号!", "图书入库");
            for (i = 0; i < Convert.ToInt32(BookNum.Text.Trim());i++ )
            {
                Sql+= Sql1 + bookid + Convert.ToString(IntId + i) + Sql2;
            }
            Sql = "BEGIN TRAN;" + Sql + "COMMIT TRAN";
            //textBox1.Text = Sql;
            if (Operator.ExecuteSql(Sql) <= 0)
            {
                MessageBox.Show("图书添加失败!", "图书入库");
               
            } 
            BookToStore_Load(sender, e);
        }

        private void BookPrice_TextChanged(object sender, EventArgs e)
        {
            if (BookNum.Text != "" && BookPrice.Text!="")
            {
                PaySum.Text = Convert.ToString(Convert.ToDouble(BookPrice.Text.Trim()) * Convert.ToDouble(BookNum.Text.Trim()));
            }
        }

        private void BookNum_TextChanged(object sender, EventArgs e)
        {
            if (BookPrice.Text != "" && BookNum.Text != "")
            {
                PaySum.Text = Convert.ToString(Convert.ToDouble(BookPrice.Text.Trim()) * Convert.ToDouble(BookNum.Text.Trim()));
            }
        }

        private void Clear_Click(object sender, EventArgs e)
        {
            BookPrice.Text = "";
            Writer.Text = "";
            BookNum.Text = "";
            Bookpublish.Text = "";
            Published.Text = "";
            BookName.Text = "";
            BookClass.Text = "";
            M_qishu.Text = "";
            Magazine.Checked = false;
            PaySum.Text = "";
            Pub_time.Value = DateTime.Now;
        }

        private void BookStockInfo_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            string Sql,bkId;
            if (BookStockInfo.RowCount > 0 && BookStockInfo.CurrentRow.Cells.Count > 0)
            {
                Published.Text = BookStockInfo.CurrentRow.Cells["pubID"].Value.ToString().Trim();
                BookName.Text = BookStockInfo.CurrentRow.Cells["BookName1"].Value.ToString().Trim();
                BookClass.Text = BookStockInfo.CurrentRow.Cells["Booksort"].Value.ToString().Trim();
                BookPrice.Text = BookStockInfo.CurrentRow.Cells["Price"].Value.ToString().Trim();
                BookNum.Text = BookStockInfo.CurrentRow.Cells["Num"].Value.ToString().Trim();
                PaySum.Text = BookStockInfo.CurrentRow.Cells["Sum"].Value.ToString().Trim();
                bkId = Published.Text.Trim().Substring(Published.Text.Trim().Length - 7, 6)
                    + BookStockInfo.CurrentRow.Cells["AddTime"].Value.ToString().Trim().Substring(0,BookStockInfo.CurrentRow.Cells["AddTime"].Value.ToString().Trim().IndexOf(" "))+"%";

                Sql = "select top 1 bookwriter,bookpublish,bookpubdate from Bookinf where Published = " + Published.Text.Trim()
                    + " and Bookid like('" + bkId + "');";

                DataSet ds = Operator.SelectSql(Sql);
                if (!(ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0))
                {
                    Sql = "select top 1 M_qishu,M_publish,M_pubtime from magazine where M_Id like('" + bkId + "');";
                    ds = Operator.SelectSql(Sql);
                    Magazine.Checked = true;
                }
                else
                {
                    Magazine.Checked = false;
                }
                if (Magazine.Checked)
                {
                    M_qishu.Text = ds.Tables[0].Rows[0].ItemArray[0].ToString().Trim();
                }
                else
                {
                    Writer.Text = ds.Tables[0].Rows[0].ItemArray[0].ToString().Trim();
                }
                Bookpublish.Text = ds.Tables[0].Rows[0].ItemArray[1].ToString().Trim();
                Pub_time.Value = Convert.ToDateTime(ds.Tables[0].Rows[0].ItemArray[2].ToString().Trim());
            }
        }
        private void Reset_Click(object sender, EventArgs e)
        {
            string bkId,Sql = "BEGIN TRAN;";
            Sql += "update booktable set Bookname = '" + BookName.Text.Trim()+ "',BookSort = '" 
                + BookClass.Text.Trim() + "',bookinprice = " + BookPrice.Text.Trim() + ",Booksum = "
                + PaySum.Text.Trim() + " where id = "+BookStockInfo.CurrentRow.Cells["ID"].Value.ToString().Trim()+";";

            bkId = Published.Text.Trim().Substring(Published.Text.Trim().Length - 7, 6)
                   + BookStockInfo.CurrentRow.Cells["AddTime"].Value.ToString().Trim().Substring(0, BookStockInfo.CurrentRow.Cells["AddTime"].Value.ToString().Trim().IndexOf(" ")) + "%";
            if (Magazine.Checked)
            {
                Sql += "update magazine set m_name = '" + BookName.Text.Trim() + "',m_qishu = "
                    + M_qishu.Text.Trim() + ",m_publish = '" + Bookpublish.Text.Trim() + "',m_pubtime = '"
                    + Pub_time.Value.ToString().Substring(0, Pub_time.Value.ToString().IndexOf(" ")) + "',m_price = " + BookPrice.Text.Trim()
                    + ",m_sort ='" + BookClass.Text.Trim() + "' where m_id like('"+bkId+"');COMMIT TRAN;";
            MessageBox.Show(Sql); 
            }
            else
            {
                Sql += "Update BookInf set BookName = '" + BookName.Text.Trim() + "',booksort = '"
                    + BookClass.Text.Trim() + "',bookwriter = '" + Writer.Text.Trim() + "',Bookpublish = '"
                    + Bookpublish.Text.Trim() + "',bookprice = "+BookPrice.Text.Trim()+",bookpubdate = '" + Pub_time.Value.ToString().Substring(0,Pub_time.Value.ToString().IndexOf(" ")) + "' where bookid like('"+bkId+"');COMMIT TRAN;";
               
            }
            if (Operator.ExecuteSql(Sql) < 0)
            {
                MessageBox.Show("图书信息修改成功!", "图书信息修改");
            }
            BookToStore_Load(sender, e);
        }
       
    }
}

⌨️ 快捷键说明

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