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

📄 jieyuexinxichaxun.cs

📁 Vs2005C#图书管理系统初学的看看有好处的
💻 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 tsh
{
    public partial class jieyuexinxichaxun : Form
    {
        public jieyuexinxichaxun()
        {
            InitializeComponent();
        }
        DB.ClsSQL sql = new DB.ClsSQL(".", "mylw", "sa", "", 3);
        DataSet ds, ds1, ds2,ds3;
        private void labjiage_Click(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {  
            string s1 = "select * from book where tushubianhao='" + textBtshbianhao.Text.Trim() + "'";
            //ds.Clear();
            ds = sql.DBToDS(s1, "book");
            int n = ds.Tables["book"].Rows.Count;
            if (n == 0)
            {
                textBchubanshe.Text = "";
                textBtshbianhao.Focus();
                textBjiage.Text = "";
                textBtshumingcheng.Text = "";
                textBzuozhe.Text = "";

               // ds3.Clear();

                label1.Visible = false;
                MessageBox.Show("无此图书编号!!!", "信息提示");
                textBtshbianhao.Text = "";
                textBtshbianhao.Focus();
            }
            else
            {
                textBchubanshe.Text = ds.Tables["book"].Rows[0]["chubanshe"].ToString();
                textBjiage.Text = ds.Tables["book"].Rows[0]["jiage"].ToString();
                textBtshumingcheng.Text = ds.Tables["book"].Rows[0]["shuming"].ToString();
                textBzuozhe.Text = ds.Tables["book"].Rows[0]["zuozhe"].ToString();
                string s2 = "select * from borrow where tushubianhao='" + textBtshbianhao.Text.Trim() + "'";
                //ds1.Clear();
                ds1 = sql.DBToDS(s2, "borrow");

                int i = ds1.Tables["borrow"].Rows.Count;
                string s3 = "select * from reader where duzhebianhao in (select duzhebianhao from borrow where tushubianhao='" + textBtshbianhao.Text.Trim() + "')";
                ds3 = sql.DBToDS(s3, "reader");
                if (i == 0)
                {
                    MessageBox.Show("该书当前没有任何借出记录!!!", "信息提示");
                    textBchubanshe.Text = "";
                    textBjiage.Text = "";
                    textBtshumingcheng.Text = "";
                    textBzuozhe.Text = "";
                    label1.Visible = false;
                    textBtshbianhao.Text = "";
                    textBtshbianhao.Focus();
                }
                else
                {
                    label1.Visible = true;
                    
                    
                }
                dataGVi2.DataSource = ds3.Tables["reader"];
            }


        }


        private void jieyuexinxichaxun_Load(object sender, EventArgs e)
        {
            
            label1.Visible = false;
            label2.Visible = false;
           //tabControl1.SelectedIndex = 0;
           // tabControl1.Select();
           // groupBox1.Focus();
            //textBbianhao.Focus();
            //switch (tabControl1.SelectedTab.Text)
            //{
            //    case "查询某一读者当前借阅的所有书籍": textBbianhao.Focus();
            //        break;
            //    case "查询某一本书正被哪些读者借阅": textBtshbianhao.Focus();
            //        break;
            //}



            
        }

        private void textBbianhao_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!(((e.KeyChar >= '0') && (e.KeyChar <= '9')) || e.KeyChar <= 31))
                e.Handled = true; 
        }

        private void buttcha_Click(object sender, EventArgs e)
        {
            int yjss = 0;
            int kjss = 0;
            int kjts = 0;
                   
            string s1 = "select * from reader where duzhebianhao='" + textBbianhao.Text + "'";
                ds = sql.DBToDS(s1, "reader");
                int n = ds.Tables["reader"].Rows.Count;
                if (n == 0)
                {
                    MessageBox.Show("无此读者编号!!!", "信息提示");
                    //ds1.Clear();
                    textBbianhao.Text = "";
                    textBbianhao.Focus();
                }
                else
                {
                    textBxingming.Text = ds.Tables["reader"].Rows[0]["duzhexingming"].ToString();

                    textBleibie.Text = ds.Tables["reader"].Rows[0]["duzheleibie"].ToString();
                    textBzhuangtai.Text = ds.Tables["reader"].Rows[0]["shuzhengzhuangtai"].ToString();
                    textBxingbie.Text = ds.Tables["reader"].Rows[0]["xingbie"].ToString();
                    string s2 = "select * from borrow where duzhebianhao='" + textBbianhao.Text.Trim() + "'";
                    ds1 = sql.DBToDS(s2, "borrow");
                    yjss = ds1.Tables["borrow"].Rows.Count;
                    textByjshushu.Text = yjss.ToString();
                    if (yjss == 0)
                    {
                        label1.Visible = false;
                        MessageBox.Show("该读者当前没有借出任何书籍!!!", "信息提示");
                    }
                    else
                    {

                        label2.Visible = true;
                        
                    }

                    dataGVi1.DataSource = ds1.Tables["borrow"];
                  
                       
                   
                        
                      string s3 = "select * from readerc where duzheleibie='" + textBleibie.Text + "'";
                     
                       ds2 = sql.DBToDS(s3, "readerc");

                       kjss = int.Parse(ds2.Tables["readerc"].Rows[0][1].ToString());
                       kjts = int.Parse(ds2.Tables["readerc"].Rows[0][2].ToString());

                       if (yjss >= kjss)
                       {

                           MessageBox.Show("该读者书已借满!!", "信息提示");
                           
                       }
                       else
                       {

                           int cqss = 0;
                           DateTime d1 = DateTime.Now;
                           for (int i = 0; i < yjss; i++)
                           {
                               DateTime d2 = (DateTime)ds1.Tables["borrow"].Rows[i]["jieshuriqu"];

                               string g = ds1.Tables["borrow"].Rows[i]["duzhebianhao"].ToString();
                               string g1 =ds1.Tables["borrow"].Rows[i]["tushubianhao"].ToString();

                               System.TimeSpan t = d1 - d2;
                               int jsts = (int)t.TotalDays;
                               int cqts = jsts - kjts;
                               if (cqts > 0)
                               {
                                   ds1.Tables["borrow"].Rows[i]["chaoqutianshu"] = cqts;
                                   //更新数据源中borrow表的chaoqutianshu字段
                                   string gx = "update borrow set chaoqutianshu=" + cqts + " where duzhebianhao='" + g + "' and tushubianhao='" + g1 + "'";
                                   sql.SQLCommand(gx);
                                   
                                   
                                   //sqldar.Update(ds1, "borrow");
                                   cqss++;
                               }
                               else
                                   ds1.Tables["borrow"].Rows[i]["chaoqutianshu"] = 0;
                               
                           }
                           if (cqss > 0)
                           {
                               MessageBox.Show("该读者有" + cqss.ToString() + "本书超期,请速归还!!!", "提示");
                               
                           }
                          


                           }
                       
                    }
                 }

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

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

     

        private void jieyuexinxichaxun_Activated(object sender, EventArgs e)
        {
            if (tabControl1.SelectedIndex == 0)
                textBbianhao.Focus();
            if (tabControl1.SelectedIndex == 1)
                textBtshbianhao.Focus();
        }

       
       
        //属性值更改时发生
        private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (tabControl1.SelectedIndex == 0)
                textBbianhao.Focus();

            if (tabControl1.SelectedIndex == 1)
                textBtshbianhao.Focus();
        }
        }
    }

⌨️ 快捷键说明

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