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

📄 clientbillingui.java

📁 挺好的JAVA例子,可用MYSQL,ACCESS,ORACLE做后台,例子中包括联结及查询等涵数
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
		filterText.addListener(SWT.DefaultSelection, new Listener() {
			public void handleEvent(Event e) { //check for "enter" key
				processor.setFilter(filterText.getText());
				refreshData();
			}
		});

		//Create radio buttons to switch viewing mode.
		Button nameRadio = new Button(clientListComp, SWT.RADIO);
		nameRadio.setText("View by name");
		data = new GridData();
		data.horizontalSpan = 2;
		nameRadio.setLayoutData(data);

		Button numRadio = new Button(clientListComp, SWT.RADIO);
		numRadio.setText("View by ID");
		data = new GridData();
		data.horizontalSpan = 2;
		numRadio.setLayoutData(data);

		nameRadio.setSelection(true);
		nameRadio.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent arg0) {
				processor.setClientView(ClientBillingProc.VIEW_BY_NAME);
				refreshData();
			}
		});

		numRadio.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent arg0) {
				processor.setClientView(ClientBillingProc.VIEW_BY_ID);
				refreshData();
			}
		});
	}

	private void setupClientsPane() {

		clientsItem = new TabItem(folder, SWT.NONE);
		clientsItem.setText("&Clients");
		clientsPane = new Composite(folder, SWT.NONE);
		clientsItem.setControl(clientsPane);

		//clientsPane has a FormLayout
		clientsPane.setLayout(new FormLayout());

		//clientInfo has a FormLayout
		clientInfo = new Group(clientsPane, SWT.NONE);
		clientInfo.setText("Client Information:");

		FormLayout clientsLayout = new FormLayout();
		clientsLayout.marginHeight = 10;
		clientsLayout.marginWidth = 10;
		clientInfo.setLayout(clientsLayout);

		FormData formData = new FormData();
		formData.left = new FormAttachment(20, 10);
		formData.right = new FormAttachment(100, -10);
		formData.top = new FormAttachment(0, 10);
		formData.bottom = new FormAttachment(100, -10);
		clientInfo.setLayoutData(formData);

		Label acctIDLabel = new Label(clientInfo, SWT.NONE);
		acctIDLabel.setText("Account ID:");
		acctIDText = new Text(clientInfo, SWT.BORDER);
		acctIDText.setEditable(false);

		FormData formData2 = new FormData();
		formData2.left = new FormAttachment(0, 10);
		formData2.right = new FormAttachment(30, 0);
		formData2.top = new FormAttachment(0, 0);
		formData2.height = 15;
		acctIDLabel.setLayoutData(formData2);

		FormData formData2b = new FormData();
		formData2b.left = new FormAttachment(acctIDLabel, 10);
		formData2b.right = new FormAttachment(100, -10);
		formData2b.top = new FormAttachment(0, 0);
		formData2b.height = 15;
		acctIDText.setLayoutData(formData2b);

		Label fnameLabel = new Label(clientInfo, SWT.NONE);
		fnameLabel.setText("First Name:");
		fnameText = new Text(clientInfo, SWT.BORDER);
		fnameText.setEditable(false);

		FormData formData3 = new FormData();
		formData3.left = new FormAttachment(0, 10);
		formData3.right = new FormAttachment(30, 0);
		formData3.top = new FormAttachment(10, 0);
		formData3.height = 15;
		fnameLabel.setLayoutData(formData3);

		FormData formData3b = new FormData();
		formData3b.left = new FormAttachment(fnameLabel, 10);
		formData3b.right = new FormAttachment(100, -10);
		formData3b.top = new FormAttachment(10, 0);
		formData3b.height = 15;
		fnameText.setLayoutData(formData3b);

		Label snameLabel = new Label(clientInfo, SWT.NONE);
		snameLabel.setText("Surname:");
		snameText = new Text(clientInfo, SWT.BORDER);
		snameText.setEditable(false);

		FormData formData4 = new FormData();
		formData4.left = new FormAttachment(0, 10);
		formData4.right = new FormAttachment(30, 0);
		formData4.top = new FormAttachment(20, 0);
		formData4.height = 15;
		snameLabel.setLayoutData(formData4);

		FormData formData4b = new FormData();
		formData4b.left = new FormAttachment(snameLabel, 10);
		formData4b.right = new FormAttachment(100, -10);
		formData4b.top = new FormAttachment(20, 0);
		formData4b.height = 15;
		snameText.setLayoutData(formData4b);

		Label dobLabel = new Label(clientInfo, SWT.NONE);
		dobLabel.setText("Date of birth:");
		dobText = new Text(clientInfo, SWT.BORDER);
		dobText.setEditable(false);

		FormData formData5 = new FormData();
		formData5.left = new FormAttachment(0, 10);
		formData5.right = new FormAttachment(30, 0);
		formData5.top = new FormAttachment(30, 0);
		formData5.height = 15;
		dobLabel.setLayoutData(formData5);

		FormData formData5b = new FormData();
		formData5b.left = new FormAttachment(dobLabel, 10);
		formData5b.right = new FormAttachment(100, -10);
		formData5b.top = new FormAttachment(30, 0);
		formData5b.height = 15;
		dobText.setLayoutData(formData5b);

		Label phoneLabel = new Label(clientInfo, SWT.NONE);
		phoneLabel.setText("Phone number:");
		phoneText = new Text(clientInfo, SWT.BORDER);
		phoneText.setEditable(false);

		FormData formData6 = new FormData();
		formData6.left = new FormAttachment(0, 10);
		formData6.right = new FormAttachment(30, 0);
		formData6.top = new FormAttachment(40, 0);
		formData6.height = 15;
		phoneLabel.setLayoutData(formData6);

		FormData formData6b = new FormData();
		formData6b.left = new FormAttachment(phoneLabel, 10);
		formData6b.right = new FormAttachment(100, -10);
		formData6b.top = new FormAttachment(40, 0);
		formData6b.height = 15;
		phoneText.setLayoutData(formData6b);

		Label emailLabel = new Label(clientInfo, SWT.NONE);
		emailLabel.setText("Email address:");
		emailText = new Text(clientInfo, SWT.BORDER);
		emailText.setEditable(false);

		FormData formData7 = new FormData();
		formData7.left = new FormAttachment(0, 10);
		formData7.right = new FormAttachment(30, 0);
		formData7.top = new FormAttachment(50, 0);
		formData7.height = 15;
		emailLabel.setLayoutData(formData7);

		FormData formData7b = new FormData();
		formData7b.left = new FormAttachment(emailLabel, 10);
		formData7b.right = new FormAttachment(100, -10);
		formData7b.top = new FormAttachment(50, 0);
		formData7b.height = 15;
		emailText.setLayoutData(formData7b);

		Label addressLabel = new Label(clientInfo, SWT.NONE);
		addressLabel.setText("Address:");
		addressText =
			new Text(
				clientInfo,
				SWT.WRAP | SWT.MULTI | SWT.BORDER | SWT.V_SCROLL);
		addressText.setEditable(false);

		FormData formData8 = new FormData();
		formData8.left = new FormAttachment(0, 10);
		formData8.right = new FormAttachment(30, 0);
		formData8.top = new FormAttachment(60, 0);
		formData8.height = 15;
		addressLabel.setLayoutData(formData8);

		FormData formData8b = new FormData();
		formData8b.left = new FormAttachment(addressLabel, 10);
		formData8b.right = new FormAttachment(100, -10);
		formData8b.top = new FormAttachment(60, 0);
		formData8b.height = 15;
		addressText.setLayoutData(formData8b);

		Label miscInfoLabel = new Label(clientInfo, SWT.NONE);
		miscInfoLabel.setText("Miscellaneous Information:");
		miscInfoText =
			new Text(
				clientInfo,
				SWT.WRAP | SWT.MULTI | SWT.BORDER | SWT.V_SCROLL);
		miscInfoText.setEditable(false);

		FormData formData9 = new FormData();
		formData9.left = new FormAttachment(0, 10);
		formData9.right = new FormAttachment(30, 0);
		formData9.top = new FormAttachment(70, 0);
		formData9.height = 15;
		miscInfoLabel.setLayoutData(formData9);

		FormData formData9b = new FormData();
		formData9b.left = new FormAttachment(miscInfoLabel, 10);
		formData9b.right = new FormAttachment(100, -10);
		formData9b.top = new FormAttachment(70, 0);
		formData9b.height = 15;
		miscInfoText.setLayoutData(formData9b);

		//buttonGrp has a FillLayout
		Composite buttonGrp = new Composite(clientInfo, SWT.NONE);
		buttonGrp.setLayout(new FillLayout());

		FormData data = new FormData();
		data.left = new FormAttachment(0, 10);
		data.right = new FormAttachment(100, -10);
		data.top = new FormAttachment(80, 0);
		data.height = 25;
		buttonGrp.setLayoutData(data);

		newClientButton = new Button(buttonGrp, SWT.PUSH);
		newClientButton.setText("&New");
		newClientButton.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent arg0) {
				setClientMode(ADD_MODE);
			}

		});

		delClientButton = new Button(buttonGrp, SWT.PUSH);
		delClientButton.setText("&Delete");
		delClientButton.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent arg0) {

				MessageBox msgBox =
					new MessageBox(
						shell,
						SWT.APPLICATION_MODAL | SWT.YES | SWT.NO);
				msgBox.setText("Confirm Deletion");
				msgBox.setMessage(
					"Are you certain you wish to delete the selected client?\n"
						+ "(All related transactions will also  be deleted.)");

				if (msgBox.open() == SWT.YES) {
					processor.deleteClient(clientList.getSelectionIndex());
					refreshData();
					setClientMode(VIEW_MODE);
				}

			}
		});

		editClientButton = new Button(buttonGrp, SWT.PUSH);
		editClientButton.setText("&Edit");
		editClientButton.addSelectionListener(new SelectionAdapter() {

			public void widgetSelected(SelectionEvent arg0) {
				setClientMode(EDIT_MODE);
			}

		});

		//filler
		Label fill = new Label(buttonGrp, SWT.NONE);

		saveClientButton = new Button(buttonGrp, SWT.PUSH);
		saveClientButton.setText("&Save");
		saveClientButton.setEnabled(false);
		saveClientButton.addSelectionListener(new SaveClientButtonListener());

		cancelClientButton = new Button(buttonGrp, SWT.PUSH);
		cancelClientButton.setText("&Cancel");
		cancelClientButton.setEnabled(false);
		cancelClientButton.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent arg0) {
				setClientMode(VIEW_MODE);
				refreshData();
			}

		});

		//filler2
		Label fill2 = new Label(buttonGrp, SWT.NONE);

		Button printTransButton = new Button(buttonGrp, SWT.PUSH);
		printTransButton.setText("&Print");
		printTransButton.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent arg0) {
				//Cancel any other actions currently in progress
				setTransMode(VIEW_MODE);

				MessageBox msgBox =
					new MessageBox(
						shell,
						SWT.APPLICATION_MODAL | SWT.YES | SWT.NO);
				msgBox.setText("Print Report");
				msgBox.setMessage(
					"Are you sure you would like to print the\naccount statements for the selected client?\n");

				if (msgBox.open() != SWT.YES)
					return;

				//Create styled text widget and print it on the default printer
				StyledText text1 = new StyledText(shell, SWT.BORDER);
				Font f = new Font(display, "Courier New", 12, 0);
				text1.setFont(f);
				text1.setWordWrap(true);
				Printer p = new Printer();
				int width = p.getBounds().width;

				//Create text string to be printed				
				StringBuffer report = new StringBuffer("Client Report - ");
				Client c = processor.getActiveClient();
				report.append(c.firstName + " " + c.lastName + "\n");
				int len = report.length();
				for (int i = 0; i < len; i++)
					report.append('-');
				report.append("\n");
				report.append("Account ID: " + c.clientID + "\n");
				report.append("First Name: " + c.firstName + "\n");
				report.append("Last Name: " + c.lastName + "\n");
				report.append("Date of birth: " + c.dob + "\n");
				report.append("Phone Number: " + c.phone + "\n");
				report.append("Email: " + c.email + "\n");
				report.append("Address:\n" + c.address + "\n");
				report.append(
					"Miscellaneous information:\n" + c.miscInfo + "\n");

				report.append("\nTransactions\n-------------\n");

				//TODO This depends on all characters having identical widths
				//for the table to be laid out approximately correct.
				//Also, dollar values should be laid out with the decimal
				//aligned rather than the leftmost character.
				for (int i = 0; i < processor.getNumTransactions(); i++) {
					Transaction t = processor.getTransactionByIndex(i);

					StringBuffer trans = new StringBuffer("" + t.transactionID);
					while (trans.length() < 7)
						trans.append(' ');

					trans.append(t.dollarAmount());
					while (trans.length() < 18)
						trans.append(' ');

					trans.append(t.date + "   ");

					int lineBreak = t.description.indexOf("\n");
					String descLine =
						lineBreak < 0
							? t.description
							: t.description.substring(0, lineBreak);
					trans.append(descLine);

					//truncate trans to fit on one line...

					trans.append('\n');

					report.append(trans.toString());
				}

				report.append('\n');
				report.append("Total balance: " + totalText.getText());

				text1.setText(report.toString());
				text1.setSize(width, 10000);
				text1.setVisible(false);
				text1.print();
				f.dispose();

			}

		});

	}

	private void setupTransPane() {
		transItem = new TabItem(folder, SWT.NONE);
		transItem.setText("&Transactions");
		transPane = new Composite(folder, SWT.NONE);
		transItem.setControl(transPane);

		//transPane has a FormLayout
		transPane.setLayout(new FormLayout());

		//transInfo has a GridLayout
		transInfo = new Group(transPane, SWT.NONE);
		transInfo.setText("Client Transactions:");
		GridLayout gridLayout = new GridLayout();
		gridLayout.numColumns = 4;
		gridLayout.marginHeight = 10;
		gridLayout.marginWidth = 10;
		gridLayout.verticalSpacing = 10;
		transInfo.setLayout(gridLayout);

		FormData formData = new FormData();
		formData.left = new FormAttachment(20, 10);
		formData.right = new FormAttachment(100, -10);
		formData.top = new FormAttachment(0, 26);
		formData.bottom = new FormAttachment(100, -10);
		transInfo.setLayoutData(formData);

		infoTable =
			new Table(
				transInfo,
				SWT.V_SCROLL | SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER);

		GridData data = new GridData(GridData.FILL_HORIZONTAL);
		data.horizontalSpan = 4;
		data.heightHint = 160;
		infoTable.setLayoutData(data);

		infoTable.setLinesVisible(true);
		infoTable.setHeaderVisible(true);

		infoTable.addSelectionListener(new SelectionAdapter() {

			public void widgetSelected(SelectionEvent arg0) {
				setTransMode(VIEW_MODE);
				int index = infoTable.getSelectionIndex();

				int id = Integer.parseInt(infoTable.getItem(index).getText(0));

				Transaction current = processor.getTransactionByID(id);
				idText.setText("" + current.transactionID);
				amtText.setText(current.dollarAmount());
				dateText.setText(current.date);
				descText.setText(current.description);
			}
		});

		ColumnSelectionListener sortListener = new ColumnSelectionListener();
		numberColumn = new TableColumn(infoTable, SWT.CENTER);
		numberColumn.setText("ID");
		numberColumn.setWidth(58);
		numberColumn.addSelectionListener(sortListener);

		amountColumn = new TableColumn(infoTable, SWT.RIGHT);
		amountColumn.setText("Amount");
		amountColumn.setWidth(80);
		amountColumn.addSelectionListener(sortListener);

⌨️ 快捷键说明

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