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

📄 shopmanager.java

📁 一个基于局域网的c/s模式网上购物系统,功能比较全面.数据库为Access.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
					{
						while(!next.equals("OVER"))
						{
							echoMsg = echoMsg+next+"\n";
							next = is.readLine();
						}
						
						JOptionPane.showMessageDialog(null,echoMsg,"取消定单信息",1);
						echoMsg = "";
						amount.setText(merchant.checkBalance(in,out)+"");
						renovate();
					}

					
					this.sleep(5000);
				}
			}catch(Exception e){e.printStackTrace();}
		}
	}
	
	/////////////////////编辑商品对话框///////////////
	private class EditDialog implements ActionListener
	{
		private JTextField t1,t2;
		private JTextArea t3;
		private JDialog jd;
		private String name;
		private int i;
		
		EditDialog() 
		{
			i = table.getSelectedRow();
			name = (String)table.getValueAt(i,0);
			jd = new JDialog(f,"编辑商品",true);
			Container contentPane = jd.getContentPane();
			
			JPanel textPanel = new JPanel();
			textPanel.setLayout(new GridBagLayout());
    		GridBagConstraints gbc = new GridBagConstraints();
    		gbc.anchor = GridBagConstraints.WEST; 
    		gbc.insets = new Insets(2,2,2,2); 
    	
    		textPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY,2),
	  	    	            "更改商品:"+name,TitledBorder.CENTER,TitledBorder.TOP));
			JLabel l1 = new JLabel("新价格:");        
		    JLabel l2 = new JLabel("新数量:");   
		    JLabel l3 = new JLabel("商品描述:");     
	   
    		t1 = new JTextField(12);
    		t1.setText(""+table.getValueAt(i,1));
			t2 = new JTextField(12);
			t2.setText(""+table.getValueAt(i,2));
			
			t3 = new JTextArea(4,12);
			t3.setLineWrap(true);
			t3.setText(goodsInfo[i]);
			
		    gbc.gridy=1;
		    gbc.gridx=0;
		    textPanel.add(l1,gbc);
		    gbc.gridx=1;
		    textPanel.add(t1,gbc);
    		gbc.gridy=2;
    		gbc.gridx=0;
    		textPanel.add(l2,gbc);
    		gbc.gridx=1;
    		textPanel.add(t2,gbc);
    		gbc.gridy=3;
    		gbc.gridx=0;
    		textPanel.add(l3,gbc);
    		gbc.gridx=1;
    		textPanel.add(new JScrollPane(t3),gbc);

			JPanel buttonPanel=new JPanel();
			JButton b=new JButton("确定");
			b.addActionListener(this);
 			buttonPanel.add(b);
			b=new JButton("取消");
			b.addActionListener(this);
			buttonPanel.add(b);
			
			contentPane.add(textPanel,BorderLayout.NORTH);
    		contentPane.add(buttonPanel,BorderLayout.CENTER);
    		jd.pack();
    		jd.setBounds(400,300,230,230);
    		jd.setVisible(true);
		}
		
		public void actionPerformed(ActionEvent e)
		{
			String cmd=e.getActionCommand();
  	 		if (cmd.equals("确定"))
  	 		{
  	 			try
  	 			{
  	 				out.println("EDIT");
  	 				out.println(merchant.getShopName());
  	 				out.println(name);
  	 				out.println(t1.getText());
  	 			 	out.println(t2.getText());
  	 			 	out.println(t3.getText());
  	 			 
  	 			 	String result = in.readLine();
  	 			 	if(result.equals("SUCCESS"))
  	 			 	{
  	 			 		table.setValueAt(t1.getText(),i,1);
  	 			 		table.setValueAt(t2.getText(),i,2);
  	 			 		goodsInfo[i] = t3.getText();
  	 			 		jd.dispose();
  	 			 	}
  	 			 	else
  	 			 	{
  	 			 		JOptionPane.showMessageDialog(null,"           更新信息失败!","提交失败",2);
  	 			 	}
  	 			 }catch(IOException ex){}
  	 		}
  	 		
  	 		else if (cmd.equals("取消"))
  	 		{
  	 			 jd.dispose();
  	 		}
		}
	}
	
	////////////////////添加商品对话框////////////////
	private class AddDialog implements ActionListener
	{
		private JTextField t1,t2,t3;
		private JDialog jd;
		
		AddDialog() 
		{
			jd = new JDialog(f,"添加商品",true);
			Container contentPane = jd.getContentPane();
			
			JPanel textPanel = new JPanel();
			textPanel.setLayout(new GridBagLayout());
    		GridBagConstraints gbc = new GridBagConstraints();
    		gbc.anchor = GridBagConstraints.WEST; 
    		gbc.insets = new Insets(2,2,2,2); 
    	
    		textPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY,2),
	  	    	            "输入新商品信息",TitledBorder.CENTER,TitledBorder.TOP));
			JLabel l1 = new JLabel("新商品名称:");  
			JLabel l2 = new JLabel("新商品价格:");        
		    JLabel l3 = new JLabel("新商品数量:");        
	   
    		t1 = new JTextField(12);
 			t2 = new JTextField(12);
			t3 = new JTextField(12);

		    gbc.gridy=1;
		    gbc.gridx=0;
		    textPanel.add(l1,gbc);
		    gbc.gridx=1;
		    textPanel.add(t1,gbc);
    		gbc.gridy=2;
    		gbc.gridx=0;
    		textPanel.add(l2,gbc);
    		gbc.gridx=1;
    		textPanel.add(t2,gbc);
    		gbc.gridy=3;
    		gbc.gridx=0;
    		textPanel.add(l3,gbc);
    		gbc.gridx=1;
    		textPanel.add(t3,gbc);

			JPanel buttonPanel=new JPanel();
			JButton b=new JButton("确定");
			b.addActionListener(this);
 			buttonPanel.add(b);
			b=new JButton("取消");
			b.addActionListener(this);
			buttonPanel.add(b);
			
			contentPane.add(textPanel,BorderLayout.NORTH);
    		contentPane.add(buttonPanel,BorderLayout.CENTER);
    		jd.pack();
    		jd.setBounds(372,280,280,180);
    		jd.setVisible(true);
		}
		
		public void actionPerformed(ActionEvent e)
		{
			String cmd=e.getActionCommand();
  	 		if (cmd.equals("确定"))
  	 		{
  	 			try
  	 			{
  	 				out.println("ADD");
  	 				out.println(merchant.getShopName());
  	 				out.println(t1.getText());
  	 				out.println(t2.getText());
  	 			 	out.println(t3.getText());
  	 			 
  	 			 	String result = in.readLine();
  	 			 	if(result.equals("SUCCESS"))
  	 			 	{
  	 			 		jd.dispose();
  	 			 		
  	 			 		defaultModel.addRow(new Vector());
  	 			 		int row = defaultModel.getRowCount();
  	 			 		table.setValueAt(t1.getText(),row-1,0);
  	 			 		table.setValueAt(""+Double.parseDouble(t2.getText()),row-1,1);
  	 			 		table.setValueAt(t3.getText(),row-1,2);
  	 			 		
  	 			 		table.revalidate();
  	 			 	}
  	 			 	else
  	 			 	{
  	 			 		JOptionPane.showMessageDialog(null,"           更新信息失败!","提交失败",2);
  	 			 	}
  	 			 }catch(IOException ex){}
  	 		}
  	 		
  	 		else if (cmd.equals("取消"))
  	 		{
  	 			 jd.dispose();
  	 		}
		}
	}
	
	///////////////////////留言板/////////////////////
	private class CheckMessageDialog
	{
		public CheckMessageDialog()
		{
			final JDialog jd = new JDialog(f,"留言板",true);
			Container contentPane = jd.getContentPane();
				
			final JTextArea msg = new JTextArea(10,25);
			msg.setBackground(new Color(238,238,238));
			msg.setEditable(false);
			msg.setLineWrap(true);
			msg.setText(message);
			JPanel textPanel = new JPanel();
			textPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY,0),
	  	    	        "查看留言",TitledBorder.CENTER,TitledBorder.TOP));
		
			textPanel.add(new JScrollPane(msg));
			
			JPanel buttonPanel=new JPanel();
			JButton b=new JButton("清空");
			b.addActionListener(new ActionListener(){
				public void actionPerformed(ActionEvent e)
				{
					message = "";
					msg.setText(message);
				}
			});
 			buttonPanel.add(b);
			b=new JButton("关闭");
			b.addActionListener(new ActionListener(){
				public void actionPerformed(ActionEvent e)
				{
					jd.dispose();
				}
			});
			buttonPanel.add(b);
			
			contentPane.add(textPanel,BorderLayout.NORTH);
    		contentPane.add(buttonPanel,BorderLayout.CENTER);
    		jd.setBounds(362,200,300,300);
    		jd.setVisible(true);
		}
	}
	
	/////////////////////编辑店铺信息对话框////////////
	private class ShopEditDialog
	{
		private JDialog d;
		private JTextArea shopInfo;
		private String shopType;
		private JComboBox cb;
		
		ShopEditDialog()
		{
			shopType = merchant.getShopType();
			
			d = new JDialog(f,"修改店铺: "+merchant.getShopName()+" 的信息",true);
			Container contentPane = d.getContentPane();
			
			GridBagConstraints gbc = new GridBagConstraints();
	     	gbc.anchor = GridBagConstraints.CENTER; 
	     	gbc.insets = new Insets(2,2,2,2); 
		
			JPanel selectPanel = new JPanel();
   	 		selectPanel.setLayout(new GridLayout());
   	 		
   	 		   	 		
   	 		String[] type = {"computer","dress","sports","food","book","electric","game"};
   	 		cb = new JComboBox(type);
   		 	cb.setEditable(true);
   		 	ComboBoxEditor editor = cb.getEditor();
		  	cb.configureEditor(editor,shopType);
   	 		cb.addItemListener(new ItemListener(){
   	 			public void itemStateChanged(ItemEvent e)
   	 			{
   	 				if (e.getStateChange()==e.SELECTED)
  		  			{
   	 					shopType = (String)e.getItem();
   	 				}
   	 			}
      
   	 		});
   	 		
   	 		selectPanel.add(cb);

       	 	JPanel stextPanel = new JPanel();
   		  	stextPanel.setLayout(new GridBagLayout());



    	 	JLabel l2 = new JLabel("店铺简介:");
      		shopInfo = new JTextArea(4,20);
      		shopInfo.setText(merchant.getShopInfo());
      		shopInfo.setLineWrap(true);
      		gbc.gridy = 1;
     		gbc.gridx = 0;
     		stextPanel.add(l2,gbc);
     		gbc.gridx = 1;
     		stextPanel.add(new JScrollPane(shopInfo),gbc);
     		shopInfo.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY,1));
     		
     		JPanel buttonPanel = new JPanel();
  			JButton b = new JButton("确定");
  			b.addActionListener(new ActionListener(){
  				public void actionPerformed(ActionEvent e)
  				{
  					boolean legal = true;
  					
  					if(shopInfo.getText().indexOf('\n')!=-1)
      	 			{
      	 			legal = false;
      	 			JOptionPane.showMessageDialog(null,"        简介中不允许回车!","填写信息不正确",2);	
       	 			}
	 			
      	 			if(legal)
      	 			{
      	 				try
      	 				{
      	 					out.println("UPDATESHOP");
      	 					out.println(merchant.getId());
      	 					out.println(shopType);
           					out.println(shopInfo.getText());
           					
           					String result = in.readLine();
           						
           					if(result.equals("SUCCESS"))
           					{	
           						JOptionPane.showMessageDialog(null,"    已成功修改店铺信息!","更新成功",1);
	       						merchant.setShopType(shopType);
	       						merchant.setShopInfo(shopInfo.getText());
	       						d.dispose();
           					}

   	        				else
   	        				{
   	        					JOptionPane.showMessageDialog(null,"服务器更新失败!","申请失败",0);
   	        				}
   	        			}catch(Exception ex){}
   	   	 			}
      	 		}
  			});
  			buttonPanel.add(b);
  			
  			b = new JButton("取消");
  			b.addActionListener(new ActionListener(){
  				public void actionPerformed(ActionEvent e)
  				{
  					d.dispose();
  				}
  			});
  			buttonPanel.add(b);
  			
  			
  			
  			
  			JPanel p = new JPanel();
  			p.setLayout(new GridBagLayout());
  			
  			b = new JButton("我要关闭该店铺!!");
  			b.addActionListener(new ActionListener(){
  				public void actionPerformed(ActionEvent e)
  				{
  					int accept = JOptionPane.showConfirmDialog(null,"警告:该行为无法撤消,一旦确定则将删除所有与该店铺相关的信息!\n确定要关闭该店铺吗?","警告",JOptionPane.YES_NO_OPTION);
    			
    				if(accept==JOptionPane.YES_OPTION)
    				{
    					out.println("CLOSESHOP");
    					out.println(merchant.getId());
    					out.println(merchant.getShopName());
    					
    					d.dispose();
    					
    					JOptionPane.showMessageDialog(null,"您已经关闭了该店铺,请重新登录!","重新登录",1);
   	        				
    					try
 						{
 							if(isOpen)
 							{
 								out.println("AD");
				  	 			out.println(merchant.getUserName()+"的商店:"+merchant.getShopName()+"关店了!");
				  	 			out.println("OVER");
 							}
 							f.dispose();
 							close();
 							saveMsg();
 							logout();
 							in.close();
 							out.close();
 							socket.close();
 						}catch(IOException ex){}  	   	
   	   					 
   	   					 new InputAddressDialog();
    				}
  				}
  			});
  			
  			JPanel close = new JPanel();
  			close.add(b);
  			
  			gbc.gridx = 0;
  			gbc.gridy = 0;
  			gbc.gridwidth = GridBagConstraints.REMAINDER;
  			p.add(close,gbc);
  			gbc.anchor = GridBagConstraints.WEST;
  			gbc.gridx = 0;
  			gbc.gridy = 1;
  			gbc.gridwidth = 1;
  			p.add(new JLabel("请选择店铺类型:"),gbc);
	     	gbc.gridx = 1;
	     	gbc.gridwidth = GridBagConstraints.REMAINDER;
     		p.add(selectPanel,gbc);
     		gbc.gridx = 0;
     		gbc.gridy = 2;
     		p.add(stextPanel,gbc);
     		gbc.gridy = 3;
     		gbc.anchor = GridBagConstraints.CENTER;
     		p.add(buttonPanel,gbc);
     		p.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY,2),
  	                "请填写新的店铺相关信息",TitledBorder.CENTER,TitledBorder.TOP));
     		
     		contentPane.add(p);
     		d.pack();
     		d.setBounds(347,230,330,260);
	        d.setResizable(false);
	        d.setVisible(true);
        
			}
	}
	//////////////////////构造函数////////////////////
	ShopManager(Merchant m,final Socket socket)
	{
		goodsInfo = new String[100];
		message = "";
		isOpen = false;
		this.socket=socket;
		this.merchant=m;
		loadMsg();
		try
    	{
    		in = 
		     new BufferedReader(
	          new InputStreamReader(
	           socket.getInputStream()));
	           
    	   	out =
	    	 new PrintWriter(
    		  new BufferedWriter(
     		   new OutputStreamWriter(
       			socket.getOutputStream())),true);

   		}catch(Exception e)
       	{
      		System.out.println(e);
       	}
       	
       	
        	
       	f = new JFrame("ShopManager");
       	Container contentPane=f.getContentPane();
       	
       	
       	
       	////////////////////////个人相关///////////////////////////////
       	JPanel p1 = new JPanel();
       	p1.setLayout(new GridBagLayout());
       	p1.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY,2),
	  	                "个人管理选项",TitledBorder.CENTER,TitledBorder.TOP));
   
       	GridBagConstraints gbc = new GridBagConstraints();
	    gbc.anchor = GridBagConstraints.WEST; 
	    gbc.insets = new Insets(5,11,5,11);
	    
	    JLabel l1 = new JLabel("用户名:");
	    gbc.gridx=0;
	    gbc.gridy=0;
	    p1.add(l1,gbc);
	    
	    user = new JTextField(6);
	    gbc.gridx=1;
	    user.setEditable(false);
	    user.setText(merchant.getUserName());
	    p1.add(user,gbc);
	    
	    JButton b = new JButton("  修改个人信息  ");
	    b.setSize(130,30);
	    b.addActionListener(this);
	    gbc.gridx=0;
	    gbc.gridy=3;
	    gbc.gridwidth = GridBagConstraints.REMAINDER;
	    p1.add(b,gbc);
	    
	    b = new JButton("  修改店铺信息  ");
	    b.addActionListener(this);
	    gbc.gridx=0;
	    gbc.gridy=4;
	    gbc.gridwidth = GridBagConstraints.REMAINDER;
	    p1.add(b,gbc);
	    
	    JLabel l2 = new JLabel("存款余额:");
	    gbc.gridx=0;

⌨️ 快捷键说明

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