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

📄 editservice.java

📁 一个基于JAVA技术的销售信息管理系统
💻 JAVA
字号:
import java.awt.Toolkit;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

import com.swtdesigner.SWTResourceManager;


public class EditService extends Dialog {

	private Combo combo_3;
	private Combo combo_2;
	private Combo combo_1;
	private Combo combo;
	private Text text_1;
	protected Object result;

	protected Shell shell;

	private MessageBox messageBox;
	private Text text;

	private String id;
	private String pwd;
	
	private int serid;
	private int sellID;
	private String sellIDstr;
	private int staffID;
	private String staffName;
	private int type;
	private String descrip	=	"";
	private boolean completed	=	false;
	private int satisfy;
	
	private boolean flag	=	true;
	
	/**
	 * Create the dialog
	 * @param parent
	 * @param style
	 */
	public EditService(Shell parent, int style) {
		super(parent, style);
	}

	/**
	 * Create the dialog
	 * @param parent
	 */
	public EditService(Shell parent,String id,String pwd,int sID,String sellIDstr,String staffName,
			int type,boolean completed,int satisfy,String descrip) {
		this(parent, SWT.NONE);
		this.id	=	id;
		this.pwd	=	pwd;
		
		this.serid	=	sID;;
		this.sellIDstr	=	sellIDstr;
		this.staffName	=	staffName;
		this.type	=	type;
		this.completed	=	completed;
		this.satisfy	=	satisfy;
		this.descrip	=	descrip;
	}

	public EditService(Shell parent,String id,String pwd,int sID,String sellIDstr,String staffName,
			int type,boolean completed,String descrip) {
		this(parent, SWT.NONE);
		this.id	=	id;
		this.pwd	=	pwd;
		
		this.serid	=	sID;;
		this.sellIDstr	=	sellIDstr;
		this.staffName	=	staffName;
		this.type	=	type;
		this.completed	=	completed;
		this.descrip	=	descrip;
	}

	public void setCenter(){
		// 得到屏幕的宽度和高度
		int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;
		int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width;
		// 得到Shell窗口的宽度和高度
		int shellHeight = this.shell.getBounds().height;
		int shellWidth = this.shell.getBounds().width;
		// 如果窗口大小超过屏幕大小,让窗口与屏幕等大
		if (shellHeight > screenHeight)
			shellHeight = screenHeight;
		if (shellWidth > screenWidth)
			shellWidth = screenWidth;
		// 让窗口在屏幕中间显示
		this.shell.setLocation(((screenWidth - shellWidth) / 2),
				((screenHeight - shellHeight) / 2));
	}
	
	/**
	 * Open the dialog
	 * @return the result
	 */
	public Object open() {
		createContents();
		setCenter();
		shell.open();
		shell.layout();
		Display display = getParent().getDisplay();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		return result;
	}

	/**
	 * Create contents of the dialog
	 */
	protected void createContents() {
		shell = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
		shell.setSize(426, 446);
		shell.setText("修改售后服务信息");

		final Label label = new Label(shell, SWT.CENTER);
		label.setFont(SWTResourceManager.getFont("", 11, SWT.NONE));
		label.setText("销售编号");
		label.setBounds(60, 59, 80, 17);

		final Label label_1 = new Label(shell, SWT.CENTER);
		label_1.setFont(SWTResourceManager.getFont("", 11, SWT.NONE));
		label_1.setText("服务人员");
		label_1.setBounds(60, 96, 80, 17);

		final Label label_2 = new Label(shell, SWT.CENTER);
		label_2.setFont(SWTResourceManager.getFont("", 11, SWT.NONE));
		label_2.setText("服务类型");
		label_2.setBounds(60, 133, 80, 17);

		final Label label_3 = new Label(shell, SWT.CENTER);
		label_3.setFont(SWTResourceManager.getFont("", 11, SWT.NONE));
		label_3.setText("是否完成");
		label_3.setBounds(60, 171, 80, 17);

		final Label label_4 = new Label(shell, SWT.CENTER);
		label_4.setFont(SWTResourceManager.getFont("", 11, SWT.NONE));
		label_4.setText("客户满意度");
		label_4.setBounds(62, 212, 80, 17);

		final Label emailLabel = new Label(shell, SWT.CENTER);
		emailLabel.setFont(SWTResourceManager.getFont("", 11, SWT.NONE));
		emailLabel.setText("详细情况");
		emailLabel.setBounds(60, 250, 80, 17);

		text = new Text(shell, SWT.BORDER);
		text.setFont(SWTResourceManager.getFont("", 11, SWT.NONE));
		text.setBounds(155, 209, 106, 22);

		text_1 = new Text(shell, SWT.V_SCROLL | SWT.MULTI | SWT.BORDER | SWT.WRAP);
		text_1.setBounds(155, 244, 190, 88);

		combo = new Combo(shell, SWT.READ_ONLY);
		combo.setBounds(152, 55, 106, 20);

		combo_1 = new Combo(shell, SWT.READ_ONLY);
		combo_1.setBounds(152, 93, 104, 20);

		combo_2 = new Combo(shell, SWT.READ_ONLY);
		combo_2.setItems(new String[] {"咨询", "维修", "更换", "投诉"});
		combo_2.setBounds(153, 132, 104, 20);

		combo_3 = new Combo(shell, SWT.READ_ONLY);
		combo_3.setBounds(260, 93, 53, 20);
		combo_3.setVisible(false);

		getAllInfor("Sell",combo);
		getAllInfor("Staff",combo_1,combo_3);
		
		final Button button = new Button(shell, SWT.RADIO);
		button.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(final SelectionEvent e) {
				text.setEnabled(true);
			}
		});
		button.setFont(SWTResourceManager.getFont("", 11, SWT.NONE));
		button.setText("是");
		button.setBounds(155, 170, 38, 17);

		final Button button_1 = new Button(shell, SWT.RADIO);
		button_1.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(final SelectionEvent e) {
				text.setText("");
				text.setEnabled(false);
			}
		});
		button_1.setFont(SWTResourceManager.getFont("", 11, SWT.NONE));
		button_1.setText("否");
		button_1.setBounds(228, 170, 38, 17);

		getOneInfor(sellIDstr,staffName,type,completed,satisfy,descrip,
				combo,combo_1,combo_2,button,button_1,text,text_1);
		
		final Button button_2 = new Button(shell, SWT.NONE);
		button_2.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(final SelectionEvent e) {
				
				flag = true;
				
				if(combo.getSelectionIndex() == -1 || combo_1.getSelectionIndex() == -1
					|| combo_2.getSelectionIndex() == -1)
				{
					messageBox = new MessageBox(shell,SWT.ICON_INFORMATION);
					messageBox.setMessage("请选择[销售编号][售后人员][服务类型]");
					messageBox.setText("修改服务信息");
					messageBox.open();
					flag = false;
				}
				if(flag && text.isEnabled() )
			    try{
			    	sellID	=	Integer.parseInt(combo_3.getItem(combo_1.getSelectionIndex()));
				  }
				  catch(NumberFormatException m)
				  {
						messageBox = new MessageBox(shell,SWT.ICON_ERROR);
						messageBox.setMessage("销售编号格式错误,请重新选择");
						messageBox.setText("修改服务信息");
						messageBox.open();
						flag = false;
				  }

				if(flag)
				try
				{
					satisfy = Integer.parseInt(text.getText());
				}
				catch(NumberFormatException m1)
				{
					messageBox = new MessageBox(shell,SWT.ICON_ERROR);
					messageBox.setMessage("客户满意度只能是 0 - 100");
					messageBox.setText("修改加服务信息");
					messageBox.open();
					flag = false;
				}
				if(flag)
				{
					staffID = Integer.parseInt(combo_3.getItem(combo_1.getSelectionIndex()));

					messageBox = new MessageBox(shell,SWT.ICON_QUESTION|SWT.OK|SWT.CANCEL);
					messageBox.setMessage("销售编号:		" + combo.getItem(combo.getSelectionIndex()) +
							"\n服务人员:		" + combo_1.getItem(combo_1.getSelectionIndex()) +
							"\n服务类型:	" + combo_2.getItem(combo_2.getSelectionIndex()) +
							"\n已完成:	" + completed +
							"\n客户满意度:	" + satisfy +
							"\n详细情况:	" + descrip +
							"\n\n请确认服务信息是否正确");
					messageBox.setText("信息确认");
					if(messageBox.open() == SWT.OK)
					{
						if(completed)
						{
							if(updateService(serid,sellID,staffID,type,descrip,completed,satisfy))
							{
								messageBox = new MessageBox(shell,SWT.ICON_INFORMATION);
								messageBox.setMessage("服务信息添加完成");
								messageBox.setText("完成");
								messageBox.open();
							}
							else
							{
								messageBox = new MessageBox(shell,SWT.ICON_ERROR);
								messageBox.setMessage("请确认输入信息是否正确");
								messageBox.setText("添加服务信息失败");
								messageBox.open();
								flag = false;
							}
						}
						else
						{
							if(updateService(serid,sellID,staffID,type,descrip,completed))
							{
								messageBox = new MessageBox(shell,SWT.ICON_INFORMATION);
								messageBox.setMessage("服务信息添加完成");
								messageBox.setText("完成");
								messageBox.open();
							}
							else
							{
								messageBox = new MessageBox(shell,SWT.ICON_ERROR);
								messageBox.setMessage("请确认输入信息是否正确");
								messageBox.setText("添加服务信息失败");
								messageBox.open();
								flag = false;
							}
						}
					}
				}

				if(flag)
					clearAll();
			}
		});
		button_2.setText("提 交");
		button_2.setBounds(62, 339, 65, 22);

		final Button button_3 = new Button(shell, SWT.NONE);
		button_3.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(final SelectionEvent e) {
				clearAll();
				button_1.setSelection(true);
			}
		});
		button_3.setText("重 填");
		button_3.setBounds(133, 339, 65, 22);
		Button button_4 = new Button(shell, SWT.NONE);
		button_4.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(final SelectionEvent e) {
				shell.dispose();
			}
		});
		button_4.setText("取 消");
		button_4.setBounds(280, 338, 65, 22);

		final Label label_5 = new Label(shell, SWT.NONE);
		label_5.setFont(SWTResourceManager.getFont("新宋体", 14, SWT.BOLD));
		label_5.setAlignment(SWT.CENTER);
		label_5.setText("请修改新售后服务信息");
		label_5.setBounds(0, 20, 420, 25);

		final Label label_6 = new Label(shell, SWT.NONE);
		label_6.setText("( 0 - 100)");
		label_6.setBounds(265, 215, 65, 17);
	}

	private void clearAll()
	{
		text.setText("");
		text_1.setText("");
		combo.deselectAll();
		combo_1.deselectAll();
		combo_2.deselectAll();
	}
	
	public void getAllInfor(String table,Combo comboID){//sql
		Connection con;
		Statement stmt;
		try{
			combo.removeAll();
			comboID.removeAll();
			DBCon dbc = new DBCon();
			con = DriverManager.getConnection(dbc.url,id,pwd);
			stmt = con.createStatement();
			String query = "select ID from " + table +" order by ID";
			ResultSet rs = stmt.executeQuery(query);
			while( rs.next()){
				comboID.add(rs.getString("ID"));
			}
			dbc.dbClose(con,rs);
		}
		catch(Exception e){
			e.printStackTrace();
		}
	}
	
	public void getAllInfor(String table,Combo combo,Combo comboID){//sql
		Connection con;
		Statement stmt;
		try{
			combo.removeAll();
			comboID.removeAll();
			DBCon dbc = new DBCon();
			con = DriverManager.getConnection(dbc.url,id,pwd);
			stmt = con.createStatement();
			String query = "select ID,Name from " + table +" order by Name";
			ResultSet rs = stmt.executeQuery(query);
			while( rs.next()){
				combo.add(rs.getString("Name"));
				comboID.add(rs.getString("ID"));
			}
			dbc.dbClose(con,rs);
		}
		catch(Exception e){
			e.printStackTrace();
		}
	}
	
	public void getOneInfor(String sellIDstr,String staffName,int type,boolean completed,int satisfy,String descrip,
			Combo combo,Combo combo_1,Combo combo_2,Button button,Button button_1,Text text_d,Text text_p){//sql
		
			combo.deselectAll();
			combo_1.deselectAll();
			combo_2.deselectAll();
			
			for(int i = 0;i<combo.getItemCount();i++)
				if(combo.getItem(i).equals(sellIDstr))
					combo.select(i);
			for(int i = 0;i<combo_1.getItemCount();i++)
				if(combo_1.getItem(i).equals(staffName))
					combo_1.select(i);
			combo_2.select(type);
			if(completed)
			{
				button.setSelection(true);
				text_d.setText(String.valueOf(satisfy));
				text_d.setEnabled(true);
			}
			else
			{
				button_1.setSelection(true);
				text_d.setText("");
				text_d.setEnabled(false);
			}
			text_p.setText(descrip);
	}
	
	public boolean updateService(int serid,int sellid,int staffid,int type,String descrip,boolean completed,int satisfy){//sql
		Connection con;
		try{
			DBCon dbc = new DBCon();
			con = DriverManager.getConnection(dbc.url,id,pwd);
			CallableStatement cs = con.prepareCall("{call dbo.sp_UpdateService(?,?,?,?,?,?,?)}");
			cs.setInt(1, serid);
			cs.setInt(2, sellid);
			cs.setInt(3, staffid);
			cs.setInt(4, type);
			cs.setString(5, descrip);
			cs.setBoolean(6, completed);
			cs.setInt(7, satisfy);
			cs.execute();
			dbc.dbClose(con);
			return true;
		}
		catch(Exception e){
			return false;
		}
	}

	
	public boolean updateService(int serid,int sellid,int staffid,int type,String descrip,boolean completed){//sql
		Connection con;
		try{
			DBCon dbc = new DBCon();
			con = DriverManager.getConnection(dbc.url,id,pwd);
			CallableStatement cs = con.prepareCall("{call dbo.sp_UpdateServiceNull(?,?,?,?,?,?)}");
			cs.setInt(1, serid);
			cs.setInt(2, sellid);
			cs.setInt(3, staffid);
			cs.setInt(4, type);
			cs.setString(5, descrip);
			cs.setBoolean(6, completed);
			cs.execute();
			dbc.dbClose(con);
			return true;
		}
		catch(Exception e){
			e.printStackTrace();
			return false;
		}
	}
	
}

⌨️ 快捷键说明

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