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

📄 javacs.java

📁 java做的c/s图书管理系统,用的是socket编程.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
		if(e.getSource()==jbt5)
		{
			//CSystem cs=new CSystem();
		}
	}
}

class CStoreDlg extends JDialog implements ActionListener
{
	BkImage Dlgbk=new BkImage("bk2.jpg");
	ImageIcon imageicon1=new ImageIcon("OK.gif");
	ImageIcon imageicon2=new ImageIcon("Cancel.gif");
	String []str={"计算机","生物","数学","英语","小说","社科","杂志","食品","物理"};
	String []strp={"一楼杂志文献中心","二楼外文文献中心","三楼社科文献中心","三楼理工科文献中心","四楼计算机文献中心","五楼综合图书文献中心"};
	String []sver={"1th","2th","3th","4th","5th","6th","7th","8th"};
	JLabel labn=new JLabel("             书名:");
	JLabel labN=new JLabel("             书号:");
	JLabel laba=new JLabel("             作者:");
	JLabel labc=new JLabel("             书类:");
	JLabel labp=new JLabel("             出版社:");
	JLabel labt=new JLabel("             数目:");
	JLabel lplace=new JLabel("            地点:");
	JLabel lprice=new JLabel("             价格");
	JLabel lversion=new JLabel("            版本");
	JTextField tfn=new JTextField(30);
	JTextField tfN=new JTextField(10);
	JTextField tfa=new JTextField(25);
	JComboBox tfc=new JComboBox(str);
	JTextField tfp=new JTextField(20);
	JTextField tft=new JTextField(20);
	JComboBox tplace=new JComboBox(strp);
	JTextField tprice=new JTextField(20);
	JComboBox tversion=new JComboBox(sver);
	JButton bok=new JButton("确定",imageicon1);
	JButton bcancel=new JButton("取消",imageicon2);
	JPanel cot=new JPanel();
    Container dcot=getContentPane();
    String bookID="",bname="",author="",bclass="",publish="",place="",version="",date;
    int quantity;
    float price;
    int month,day,year;
    String sql="";
    int count=0;
    String cout="0";
    client cl=new client();
    Calendar current=new GregorianCalendar();
	CStoreDlg()
	{
		tft.setText("0");
		tprice.setText("0");
		tfc.setBackground(Color.white);
		tplace.setBackground(Color.white);
		tversion.setBackground(Color.white);
		cot.setLayout(new GridLayout(11,2,5,8));
		cot.add(labn);
		cot.add(tfn);
		cot.add(labN);
		cot.add(tfN);
		cot.add(laba);
		cot.add(tfa);
		cot.add(labc);
		cot.add(tfc);
		cot.add(labp);
		cot.add(tfp);
		cot.add(labt);
        cot.add(tft);
        cot.add(lprice);
	    cot.add(tprice);
	    cot.add(lplace);
	    cot.add(tplace);
	    cot.add(lversion);
	    cot.add(tversion);
	    cot.add(bok);
		cot.add(bcancel);
		bok.addActionListener(this);
		bcancel.addActionListener(this);
        dcot.setLayout(new GridLayout(1,2));
        dcot.add(cot);
        dcot.add(Dlgbk);
		setSize(600,400);
		setVisible(true);
	}
	public void actionPerformed(ActionEvent e)
	{
		if(e.getSource()==bok)
		{
			bookID=tfN.getText();
			bname=tfn.getText();
			bclass=""+tfc.getSelectedItem();
			author=tfa.getText();
			publish=tfp.getText();
			try
			{
				quantity=Integer.parseInt(tft.getText());
			    price=Float.parseFloat(tprice.getText());
			}
			catch(Exception ex)
			{
				JOptionPane.showMessageDialog(null,"请输入正确的格式","错误",JOptionPane.ERROR_MESSAGE);
				return;
			}
			place=""+tplace.getSelectedItem();
            version=""+tversion.getSelectedItem();
            month=current.get(Calendar.MONTH);
            day=current.get(Calendar.DAY_OF_MONTH);
            year=current.get(Calendar.YEAR);
            month+=1;
            date=month+"-"+day+"-"+year;
            sql="q"+"01"+"select count(*) from book where bookID='"+bookID+"'";
            cl.sendsql(sql);
            try{
				Thread.currentThread().sleep(200);
			}
			catch(Exception ex)
			{
				System.out.print(ex.getMessage());
			}
            cout=cl.getresult();
            System.out.print(cout);
            count=Integer.parseInt(cout.trim());

           if(count>0)
            {
				sql="u"+"update book set total=total+"+quantity+",quantity=quantity+"+quantity+
				" where bookID='"+bookID+"'";
				cl.sendsql(sql);
				JOptionPane.showMessageDialog(null,"图书添加成功","",JOptionPane.INFORMATION_MESSAGE);
			}
			else
			{
				sql="u"+"insert into book values('"+bookID+"','"+bname+"','"+bclass+"',"+price+",'"+
                publish+"',"+quantity+","+quantity+",'"+place+"','"+author+"','"
                +version+"','"+date+"'"+")";
                cl.sendsql(sql);
                goglevarity.str=bname;
                goglevarity.isnull=false;
                JOptionPane.showMessageDialog(null,"新书已入库","",JOptionPane.INFORMATION_MESSAGE);
			}
		}
		if(e.getSource()==bcancel)
		{
			setVisible(false);
			this.dispose();
		}
	}
}
class CBorPanel extends JPanel implements ActionListener
{
	javax.swing.Timer timer=new javax.swing.Timer(1000,this);
	ImageIcon imic=new ImageIcon("welcome.gif");
	Image image=imic.getImage();
	int x;Calendar date=new GregorianCalendar();
    boolean wh=true;
    String str="欢迎借书";
    String str2="今天是"+(date.get(Calendar.MONTH)+1)+"-"+date.get(Calendar.DAY_OF_MONTH)+" "+"星期"+(date.get(Calendar.DAY_OF_WEEK)-1);
	CBorPanel()
	{
		timer.start();

	}
	public void actionPerformed(ActionEvent e)
	{
		repaint();
	}
	protected void paintComponent(Graphics g)
	{
		super.paintComponent(g);
		g.drawString(str,x-150,15);
		g.drawString(str2,x-150,30);
		g.drawImage(image,x,0,this);
		x+=3;
		if(x>300)
		  {
			  x=0;
			  str="欢迎借书";
		  }

	}
	public void setstr(String s)
	{
		str=s;
	}
}
class CBorrow extends JDialog implements ActionListener
{

	JPanel jpanel=new JPanel();
	JPanel jinfo=new JPanel();
	JLabel labSID=new JLabel("学生学号");
	JLabel labBID=new JLabel("图书号");
	JTextField jtfs=new JTextField();
	JTextField jtfb=new JTextField();
	ImageIcon iok=new ImageIcon("queding.gif");
	ImageIcon icancel=new ImageIcon("leave.gif");
	ImageIcon ict=new ImageIcon("ct5.gif");
	JButton button=new JButton("确定",iok);
	JButton butcancel=new JButton("取消",icancel);
	JButton repay=new JButton("超期罚款",ict);
    CBorPanel bp=new CBorPanel();
    String sql="";
    float nID;
    String studentID="",bookID="";
    client cl=new client();
    Calendar date=new GregorianCalendar();
    String strdate;
    int year,month,day;
    String res;
    boolean btenable=false;
	CBorrow()
	{
		year=date.get(Calendar.YEAR);
		month=date.get(Calendar.MONTH)+1;
		day=date.get(Calendar.DAY_OF_MONTH);
		strdate=month+"-"+day+"-"+year;
		jpanel.setLayout(new GridLayout(3,2));
		jpanel.add(labSID);
		jpanel.add(jtfs);
		jpanel.add(labBID);
		jpanel.add(jtfb);
		jpanel.add(button);
		jpanel.add(butcancel);
		button.addActionListener(this);
		butcancel.addActionListener(this);
		repay.addActionListener(this);
		getContentPane().add(jpanel,BorderLayout.NORTH);
        getContentPane().add(bp,BorderLayout.CENTER);
		getContentPane().add(repay,BorderLayout.SOUTH);
		setSize(300,300);
		setLocation(100,100);
		setVisible(true);
	}
	public void actionPerformed(ActionEvent e)
	{
		if(e.getSource()==button)
		{

			studentID=jtfs.getText();
			bookID=jtfb.getText();
			sql="m"+studentID+"','"+studentID+"',"+"'ruru'"+",'"+strdate+"','"+bookID+"',"+1+",'1'"+")";
			System.out.println(sql);
			cl.sendsql(sql);
			System.out.println(sql);
			try
			{
				Thread.currentThread().sleep(100);
			}
			catch(Exception eth)
			{
				System.out.println(eth.getMessage());
			}
            String res=cl.getresult().trim();
			if(res.equals("-1"))
			{

				MessageBox mb=new MessageBox("学生号或图书ID有错误","");
				return;
			}
		    if(res.equals("-2"))
			{
				bp.setstr("您已借满6本书");
				MessageBox mb=new MessageBox("您已借满6本书","");
				return;
		    }
		    if(res.equals(""))
		    {
				bp.setstr("借书成功");
				MessageBox mb=new MessageBox("借书成功","");
				return;
			}
			if(res.substring(0,5).equals("over2"))
			{
				bp.setstr("您已欠费"+res.substring(5)+"毛");
				MessageBox mb=new MessageBox("您已欠费"+res.substring(5)+"毛","");
				btenable=true;
				return;
			}
		    if(res.substring(0,4).equals("over"))
			{
				bp.setstr("您借阅的书已超期"+res.substring(4));
				MessageBox mb=new MessageBox("您借阅的书已超期"+res.substring(4)+"天","");
				btenable=true;
				return;
			}
		}
		if(e.getSource()==butcancel)
		{
			setVisible(false);
			dispose();
		}
		if(e.getSource()==repay)
		{
			if(!btenable)
			  return;
            bp.setstr("您还得归还超期书籍");
			sql="p"+studentID;
			cl.sendsql(sql);
			MessageBox mb=new MessageBox("您还得归还超期书籍","");
			btenable=false;
		}
	}
}
class CReturn extends JDialog implements ActionListener
{
	JLabel lsid=new JLabel("学生号:");
	JTextField sid=new JTextField(20);
	JLabel lbid=new JLabel("图书ID号:");
	JTextField bid=new JTextField(20);
	JPanel panel=new JPanel();
	ImageIcon iok=new ImageIcon("re.gif");
	ImageIcon icn=new ImageIcon("can.gif");
	ImageIcon image=new ImageIcon("rebk.jpg");
	ImageIcon ipay=new ImageIcon("pay.gif");
    JLabel bkim=new JLabel("",image,JLabel.CENTER);
	JButton jok=new JButton("确定",iok);
	JButton jcancel=new JButton("取消",icn);
	JButton jpay=new JButton("付款",ipay);
	JPanel panel2=new JPanel();
	String bookid="",stid="";
	client cl=new client();
	String str="";
	CReturn()
	{
		jpay.setEnabled(false);
		panel.setLayout(new GridLayout(2,2,5,10));
		panel2.setLayout(new GridLayout(1,3,5,0));
		panel.add(lsid);
		panel.add(sid);
		panel.add(lbid);
		panel.add(bid);
		getContentPane().add(panel,BorderLayout.NORTH);
		panel2.add(jok);
	    panel2.add(jcancel);
	    panel2.add(jpay);
	    getContentPane().add(panel2,BorderLayout.SOUTH);
	    getContentPane().add(bkim,BorderLayout.CENTER);
	    jok.addActionListener(this);
	    jcancel.addActionListener(this);
	    jpay.addActionListener(this);
		setSize(400,400);
		setLocation(100,100);
		setVisible(true);
	}
	public void actionPerformed(ActionEvent e)
	{
		if(e.getSource()==jok)
		{
			stid=sid.getText();
			bookid=bid.getText();
	        cl.sendsql("r"+stid+"\\"+bookid);
			try
			{
				Thread.currentThread().sleep(200);
			}
			catch(Exception ex)
			{
			}
			String rs=cl.getresult();
			if(rs.equals("-1"))
			{
				MessageBox mb=new MessageBox("图书号或学号有错误","Error");
				return;
			}
			System.out.println(rs);
			if(rs.equals("-3"))
			{
				MessageBox mb2=new MessageBox("归还成功","");
			}
			if(rs.substring(0,4).equals("over"))
			{
				  str="须付"+rs.substring(4)+"毛";
                 jpay.setEnabled(true);
			}
		}
		if(e.getSource()==jcancel)
		{
			setVisible(false);
			dispose();
		}
		if(e.getSource()==jpay)
		{
		   if(JOptionPane.showConfirmDialog(null,str,"",JOptionPane.YES_NO_OPTION)==JOptionPane.YES_OPTION)
		   {
             cl.sendsql("o"+stid);
             MessageBox mb3=new MessageBox("您可以继续借书了","");
             jpay.setEnabled(false);
		   }
		   else
		   {
			   return;
		   }

		}
	}
}
class CJoin extends JDialog implements ActionListener
{
    static client serverhost=new client();
	ImageIcon image=new ImageIcon("conserver.gif");
	ImageIcon img=new ImageIcon("ct4.gif");
	ImageIcon im=new ImageIcon("join.gif");
	JLabel lab=new JLabel("服务器名:");
	JTextField jtf=new JTextField(10);
	JButton conserver=new JButton("连接服务器",image);
	JButton contalk=new JButton("进行对话",img);
	JLabel map=new JLabel();
	CJoin()
	{
		map.setIcon(im);
		lab.setHorizontalAlignment(JLabel.CENTER);
		JPanel panel1=new JPanel();
		Container cot=getContentPane();
		panel1.setLayout(new GridLayout(2,2,5,10));
		panel1.add(lab);
		panel1.add(jtf);
		panel1.add(conserver);
		panel1.add(contalk);
		cot.add(panel1,BorderLayout.NORTH);
		cot.add(map,BorderLayout.SOUTH);
		setSize(300,300);
		setLocation(300,100);
		setVisible(true);
		conserver.addActionListener(this);

	}
	public void actionPerformed(ActionEvent e)
	{
		if(e.getSource()==conserver)
		{
			serverhost.host=jtf.getText();
			if(serverhost.sendsql("u"+"create table overdue(tranID char(10),studentID char(10))"))
			    JOptionPane.showMessageDialog(null,"连接成功","",JOptionPane.INFORMATION_MESSAGE);
			else
			    JOptionPane.showMessageDialog(null,"连接失败","",JOptionPane.INFORMATION_MESSAGE);

		}
	}
}
class CRegister extends JDialog //implements ActionListener
{
	JLabel label1=new JLabel("");
	CRegister()
	{
	}
}
class CHelp extends JDialog implements ActionListener
{
	javax.swing.Timer timer=new javax.swing.Timer(3000,this);
	JLabel jlabel=new JLabel();
	JPanel jpanel=new JPanel();
	ImageIcon ig=new ImageIcon("help.gif");
	ImageIcon ilv=new ImageIcon("leave.gif");
	JButton button=new JButton("help",ig);
	JButton leaveb=new JButton("leave",ilv);
	ImageIcon imageicon1=new ImageIcon("start.gif");
	ImageIcon imageicon2=new ImageIcon("wake.gif");
	ImageIcon imageicon3=new ImageIcon("thinking.gif");
	ImageIcon imageicon4=new ImageIcon("happy.gif");
	ImageIcon imageicon5=new ImageIcon("byebye.gif");
	JTextField jtf=new JTextField(20);
	JPanel jp2=new JPanel();
	JPanel jp3=new JPanel();
	boolean be=true,bl=false,leave=false;
	CHelp()
	{
		leaveb.setToolTipText("ByeBye!");
		button.setToolTipText("What can i do for you?");
		timer.start();
		setSize(300,250);
		setLocation(700,400);
        jlabel.setIcon(imageicon1);
        jlabel.setText("hello!!");
		jpanel.add(jlabel,BorderLayout.SOUTH);
		jp2.add(jtf,BorderLayout.SOUTH);

⌨️ 快捷键说明

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