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

📄 querycharge.java

📁 上传个比较简单的代码 有问题的大家及时交流啊!!(家用管理JAVA版,用SWT开发的)
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
				}
				if(txtDay.getText().length()>2)
				{
					showMessage("错误!","输入的形式为不符合逻辑!",SWT.ICON_INFORMATION);
					txtDay.setText("");
				}
				else
				{
					try
					{
						int day=Integer.parseInt(txtDay.getText());
					}
					catch(Exception e)
					{
						showMessage("错误!","输入的日只能为0-9的数字!",SWT.ICON_INFORMATION);
						txtDay.setText("");
					}
				}
				return;
			}
		});
		txtDay.addKeyListener(new KeyAdapter(){
			public void keyPressed(KeyEvent day)
			{
				if(day.keyCode==SWT.CR)
				{
					if(txtDay.getText().length()==0)
					{
						btnQuery.setFocus();
					}
					else if(Integer.parseInt(txtDay.getText())>31|Integer.parseInt(txtDay.getText())<1)
					{
						showMessage("错误!","月份需要在1-31中间!",SWT.ICON_INFORMATION);
					}
					else
					{
						btnQuery.setFocus();
					}	
				}
			}
		});
		btnQuery.addSelectionListener(new SelectionAdapter(){
			public void widgetSelected(SelectionEvent set)
			{
				table.removeAll();
				if(btnDH.getSelection())
				{
					getJZMX(txtDH.getText());
				}
				else
				{
					String strQuery=txtYear.getText();
					String strMonth=txtMonth.getText();
					String strDay=txtDay.getText();
					if(strMonth.length()==1)
					{
						strQuery=strQuery+"0"+strMonth;
					}
					else
					{
						strQuery=strQuery+strMonth;
					}
					if(strDay.length()==1)
					{
						strQuery=strQuery+"0"+strDay;
					}
					else
					{
						strQuery=strQuery+strDay;
					}
				getJZMX(strQuery);
				}
			}
		});
		btnReturn.addSelectionListener(new SelectionAdapter(){
			public void widgetSelected(SelectionEvent set)
			{
				shell.getDisplay().dispose();
				shell.dispose();
				String[] retMain=null;
				HomeManage.main(retMain);
			}
		});
	}
	private void creatTable()
	{
		table=new Table(shell,SWT.BORDER|SWT.SINGLE|SWT.FULL_SELECTION);
		table.setBounds(20,65,485,150);
		table.setHeaderVisible(true);
		table.setLinesVisible(true);
		TableColumn[] column=new TableColumn[tableHead.length];
		for(int i=0;i<tableHead.length;i++)
		{
			column[i]=new TableColumn(table,SWT.LEFT);
			column[i].setText(tableHead[i]);
		}
		column[0].setWidth(70);
		column[1].setWidth(40);
		column[2].setWidth(80);
		column[3].setWidth(75);
		column[4].setWidth(60);
		column[5].setWidth(40);
		column[6].setWidth(40);
		column[7].setWidth(40);
		column[8].setWidth(60);
		
		table.addSelectionListener(new SelectionAdapter(){
			public void widgetDefaultSelected(SelectionEvent select)
			{
				TableItem itemSelect=table.getSelection()[0];
				tableToText(itemSelect);
				System.out.println("查看的列数为"+itemSelect);
			}
		});

	}
	private void creatGroup()
	{
		group=new Group(shell,SWT.None);
		group.setBounds(20,215,485,95);
		
		Label lblGroupDH=new Label(group,SWT.None);
		lblGroupDH.setText("记帐单号");
		lblGroupDH.setBounds(5,20,50,15);
		txtGroupDH=new Text(group,SWT.BORDER);
		txtGroupDH.setBounds(60,15,80,20);
		txtGroupDH.setEditable(false);
		
		Label lblDetails=new Label(group,SWT.None);
		lblDetails.setText("消费内容");
		lblDetails.setBounds(145,20,50,15);
		txtDetails=new Text(group,SWT.BORDER);
		txtDetails.setBounds(200,15,120,20);
		
		Label lblUseTime=new Label(group,SWT.None);
		lblUseTime.setText("消费时间");
		lblUseTime.setBounds(325,20,50,15);
		txtUseTime=new Text(group,SWT.BORDER);
		txtUseTime.setBounds(380,15,95,20);
		
		Label lblPlace=new Label(group,SWT.None);
		lblPlace.setText("消费地点");
		lblPlace.setBounds(5,45,50,15);
		txtPlace=new Text(group,SWT.BORDER);
		txtPlace.setBounds(60,40,105,20);

		Label lblPrice=new Label(group,SWT.None);
		lblPrice.setText("商品单价");
		lblPrice.setBounds(170,45,50,15);
		txtPrice=new Text(group,SWT.BORDER);
		txtPrice.setBounds(225,40,45,20);
		
		Label lblCount=new Label(group,SWT.None);
		lblCount.setText("消费数量");
		lblCount.setBounds(275,45,50,15);
		txtCount=new Text(group,SWT.BORDER);
		txtCount.setBounds(330,40,40,20);
		
		Label lblItemPrice=new Label(group,SWT.None);
		lblItemPrice.setText("合计金额");
		lblItemPrice.setBounds(375,45,50,15);
		txtItemPrice=new Text(group,SWT.BORDER);
		txtItemPrice.setBounds(430,40,45,20);
		txtItemPrice.setEditable(false);
		
		Label lblMark=new Label(group,SWT.None);
		lblMark.setText("帐单备注");
		lblMark.setBounds(5,70,50,15);
		txtMark=new Text(group,SWT.BORDER);
		txtMark.setBounds(60,65,260,20);
		
		btnAlter=new Button(group,SWT.None);
		btnAlter.setText("修改账单");
		btnAlter.setBounds(330,65,70,25);
		
		btnSet=new Button(group,SWT.None);
		btnSet.setText("系统设置");
		btnSet.setBounds(405,65,70,25);
		
		setDisEdit();
		txtYear.setFocus();
	}
	private int checkValidate(String Check)
	{
		String strCheck=Check;
		String string=null;
		int flag=1;
		int len=strCheck.length();
		for(int i=0;i<=len-1;i++)
		{
			string=strCheck.substring(i,i+1);
			if(string.equals("\'")|string.equals("\""))
			{
				flag=0;
			}
			string=null;
		}
		return flag;
	}

	private void setDisEdit()
	{
		txtGroupDH.setEditable(false);
		txtDetails.setEditable(false);
		txtUseTime.setEditable(false);
		txtPlace.setEditable(false);
		txtPrice.setEditable(false);
		txtCount.setEditable(false);
		txtMark.setEditable(false);
		txtItemPrice.setEditable(false);
		btnAlter.setEnabled(false);
		btnSet.setEnabled(false);
	}
	private void getJZMX(String strDH)
	{
    	int i=0;					//设置一个记数号,返回一共多少条记录!
    	i=DB.getJZMX(strDH);
    	System.out.println("一共有 "+i+":条记录!");
    	System.out.println("-----------------------------------------------------------------------------");
    	if(i>0)
    	{
    		table.removeAll();		//删除表格中上次的数据
	    	try
			{	
				getTableMX();
				while(DB.rstSelect.previous())
				{
					getTableMX();
				}
		    }
			catch(Exception eMX)
			{
				System.out.println(eMX.getMessage());
			}
    	}
    	else
    	{
    		showMessage("信息提示!","对不起!查询的记录为空!",SWT.ICON_INFORMATION);
    	}
	}
	
    private void getTableMX()
    {
    	String[] lstMX=new String[9];
    	String time=null;
		try
		{
			lstMX[0]=DB.rstSelect.getString("JZDH");						//取出药名
			lstMX[1]=DB.rstSelect.getString("amountID");					//取出药品单价
			lstMX[2]=DB.rstSelect.getString("details");					//取出计价单位
			time=DB.rstSelect.getString("useTime");					//取出数量
			lstMX[3]=time.substring(0,10);
			lstMX[4]=DB.rstSelect.getString("place");						//取出剂型
			lstMX[5]=DB.rstSelect.getString("price").substring(0,3);						//取出规格
			lstMX[6]=DB.rstSelect.getString("amount");						//取出产地
			lstMX[7]=DB.rstSelect.getString("itemCharge");						//取出厂家
			lstMX[8]=DB.rstSelect.getString("mark");						//取出备注
			TableItem itemMX = new TableItem(table,SWT.None);		//将得到的结果和从数据库中取出的数据加入到表格中
			itemMX.setText(new String[] {lstMX[0],lstMX[1],lstMX[2],lstMX[3],lstMX[4],lstMX[5],lstMX[6],lstMX[7],lstMX[8]});
		}
		catch(Exception eMX)
		{
			System.out.println(eMX.getMessage());
						
		}
	}
//	private void editTable()
//	{
//		int itemIndex=table.getSelectionIndex();
//		TableItem[] item=table.getItems();
//		item[itemIndex].setText(new String[]{txtDetails.getText(),cmbPlace.getText(),txtPrice.getText(),txtCount.getText(),txtItemPrice.getText(),txtMark.getText()});
//		delGroup();
//	}
	private void tableToText(TableItem item)
	{
		txtGroupDH.setText(item.getText(0));
		txtDetails.setText(item.getText(2));
		txtUseTime.setText(item.getText(3));
		txtPlace.setText(item.getText(4));
		txtPrice.setText(item.getText(5));
		txtCount.setText(item.getText(6));
		txtItemPrice.setText(item.getText(7));
		txtMark.setText(item.getText(8));
	}

	/**
	* 函数名:showMessage
	* 编写者:郭军
	* 功  能:加载数据及应用相关设置
	* 输入参数:标题,信息,报警类型
	* 输出参数:返回值
	* 备  注:
	*/
	private int showMessage(String title,String message,int flag)
	{
		int retFlag;							//定义一个返回值的接收变量
		MessageBox msgbox=new MessageBox(shell,flag);
		msgbox.setText(title);					//设置消息的桂标题
		msgbox.setMessage(message);				//设置消息的内容
		retFlag=msgbox.open();
		return retFlag;
	}
}

⌨️ 快捷键说明

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