employee.java
来自「用java操作数据库」· Java 代码 · 共 395 行
JAVA
395 行
//employee.java
import wfc.app.*;
import wfc.core.*;
import wfc.ui.*;
import wfc.data.*;
import wfc.data.ui.*;
public class employee extends Form
{
public void btnAdd_Click(Object sender, Event evt)
{
try
{
m_rs.addNew();
m_bAddNew = true;
btnDelete.setText ("Cancel" );
btnRefresh.setEnabled( false );
btnAdd.setEnabled( false );
}
catch (Exception e)
{
handleADOException(e);
}
}
public void btnDelete_Click(Object sender, Event evt)
{
try
{
if( m_bAddNew )
{
m_rs.cancelUpdate();
m_bAddNew = false;
btnDelete.setText ("Delete" );
btnRefresh.setEnabled( true );
btnAdd.setEnabled( true );
}
else
{
m_rs.delete(AdoEnums.Affect.CURRENT);
m_rs.moveNext();
if( m_rs.getEOF() )
m_rs.moveLast();
}
}
catch (Exception e)
{
handleADOException(e);
}
}
public void btnRefresh_Click(Object sender, Event evt)
{
try
{
m_rs.cancelBatch();
m_rs.requery();
}
catch (Exception e)
{
handleADOException(e);
}
}
public void btnUpdate_Click(Object sender, Event evt)
{
try
{
m_rs.update();
}
catch (Exception e)
{
handleADOException(e);
}
m_bAddNew = false;
btnDelete.setText ("Delete" );
btnRefresh.setEnabled( true );
btnAdd.setEnabled( true );
}
public void btnClose_Click(Object sender, Event evt)
{
Application.exit();
}
Recordset m_rs;
Connection m_con;
DataBinder m_dataBinder;
boolean m_bAddNew;
protected void finalize()
{
try
{
m_rs.close();
m_con.close();
}
catch (Exception e)
{
handleADOException( e );
}
}
public employee()
{
//Required for Visual J++ Form Designer support
initForm();
//TODO: Add any constructor code after initForm call
try
{
openDataConnection();
initializeBindings();
}
catch (Exception e)
{
handleADOException( e );
}
}
public void formClose(Event e)
{
Application.exit();
}
public static void main(String args[])
{
Application.run( new employee() );
}
void openDataConnection()
{
m_con = new Connection();
m_rs = new Recordset();
// The Jet provider connection was not used because your database contains one or more memo/ boolean fields.
// The Beta2 release does not support binding to a memo/ boolean field using the Jet provider.
// Here is the Jet connection string: m_con.setConnectionString ("PROVIDER=Microsoft.Jet.OLEDB.3.51;Data Source=C:\\Ph.D\\IDSc8440\\employee.mdb");
m_con.setConnectionString ("Provider=MSDASQL;UID=admin;Driver={Microsoft Access Driver (*.mdb)};DBQ=C:\\Ph.D\\IDSc8440\\employee.mdb");
m_con.setCursorLocation (AdoEnums.CursorLocation.CLIENT);
m_con.open();
m_rs.setActiveConnection(m_con);
m_rs.setSource("select * from Employee");
m_rs.setCursorType(AdoEnums.CursorType.STATIC);
m_rs.setCursorLocation(AdoEnums.CursorLocation.CLIENT);
m_rs.setLockType(AdoEnums.LockType.OPTIMISTIC);
m_rs.open();
dataNavigator.setDataSource(m_rs);
}
void initializeBindings()
{
try
{
m_dataBinder = new DataBinder(m_rs);
m_dataBinder.addBinding( this.editEmployeeID,"Text","EmployeeID");
m_dataBinder.addBinding( this.editName,"Text","Name");
m_dataBinder.addBinding( this.editSSN,"Text","SSN");
m_dataBinder.addBinding( this.editSupervisor,"Text","Supervisor");
m_dataBinder.addBinding( this.editDepartment,"Text","Department");
m_dataBinder.addBinding( this.editPaytype,"Text","Paytype");
m_dataBinder.addBinding( this.chkBenefits,"Checked","Benefits");
m_dataBinder.addBinding( this.chkFlextime,"Checked","Flextime");
m_dataBinder.addBinding( this.chkProbation,"Checked","Probation");
m_rs.moveFirst();
}
catch (Exception e)
{
handleADOException( e );
}
}
void handleADOException(Exception e)
{
e.printStackTrace();
MessageBox.show( e.toString(), "employee" );
}
/**
* NOTE: The following code is required by the Visual J++ form
* designer. It can be modified using the form editor. Do not
* modify it using the code editor.
*/
Container components = new Container();
Label labelEmployeeID = new Label();
Edit editEmployeeID = new Edit();
Label labelName = new Label();
Edit editName = new Edit();
Label labelSSN = new Label();
Edit editSSN = new Edit();
Label labelSupervisor = new Label();
Edit editSupervisor = new Edit();
Label labelDepartment = new Label();
Edit editDepartment = new Edit();
Label labelPaytype = new Label();
Edit editPaytype = new Edit();
Checkbox chkBenefits = new Checkbox();
Checkbox chkFlextime = new Checkbox();
Checkbox chkProbation = new Checkbox();
Button btnAdd = new Button();
Button btnDelete = new Button();
Button btnRefresh = new Button();
Button btnUpdate = new Button();
Button btnClose = new Button();
DataNavigator dataNavigator = new DataNavigator();
private void initForm()
{
this.setBackColor(Color.CONTROL);
this.setLocation(new Point(7, 7));
this.setSize(new Point(420, 390));
this.setTabIndex(-1);
this.setTabStop(true);
this.setText("employee");
this.setAutoScaleBaseSize(13);
this.setClientSize(new Point(412, 363));
labelEmployeeID.setBackColor(Color.CONTROL);
labelEmployeeID.setLocation(new Point(10, 20));
labelEmployeeID.setSize(new Point(100, 20));
labelEmployeeID.setText("EmployeeID");
labelEmployeeID.setTabIndex(0);
editEmployeeID.setAnchor(ControlAnchor.TOPLEFTRIGHT);
editEmployeeID.setBackColor(Color.ACTIVEBORDER);
editEmployeeID.setCursor(Cursor.NO);
editEmployeeID.setEnabled(false);
editEmployeeID.setLocation(new Point(120, 20));
editEmployeeID.setSize(new Point(280, 20));
editEmployeeID.setTabIndex(1);
editEmployeeID.setTabStop(true);
editEmployeeID.setText("EmployeeID");
editEmployeeID.setBorderStyle(BorderStyle.NONE);
editEmployeeID.setReadOnly(true);
labelName.setBackColor(Color.CONTROL);
labelName.setLocation(new Point(10, 50));
labelName.setSize(new Point(100, 20));
labelName.setText("Name");
labelName.setTabIndex(2);
editName.setAnchor(ControlAnchor.TOPLEFTRIGHT);
editName.setBackColor(Color.WINDOW);
editName.setCursor(Cursor.IBEAM);
editName.setLocation(new Point(120, 50));
editName.setSize(new Point(280, 20));
editName.setTabIndex(3);
editName.setTabStop(true);
editName.setText("Name");
labelSSN.setBackColor(Color.CONTROL);
labelSSN.setLocation(new Point(10, 80));
labelSSN.setSize(new Point(100, 20));
labelSSN.setText("SSN");
labelSSN.setTabIndex(4);
editSSN.setAnchor(ControlAnchor.TOPLEFTRIGHT);
editSSN.setBackColor(Color.WINDOW);
editSSN.setCursor(Cursor.IBEAM);
editSSN.setLocation(new Point(120, 80));
editSSN.setSize(new Point(280, 20));
editSSN.setTabIndex(5);
editSSN.setTabStop(true);
editSSN.setText("SSN");
labelSupervisor.setBackColor(Color.CONTROL);
labelSupervisor.setLocation(new Point(10, 110));
labelSupervisor.setSize(new Point(100, 20));
labelSupervisor.setText("Supervisor");
labelSupervisor.setTabIndex(6);
editSupervisor.setAnchor(ControlAnchor.TOPLEFTRIGHT);
editSupervisor.setBackColor(Color.WINDOW);
editSupervisor.setCursor(Cursor.IBEAM);
editSupervisor.setLocation(new Point(120, 110));
editSupervisor.setSize(new Point(280, 20));
editSupervisor.setTabIndex(7);
editSupervisor.setTabStop(true);
editSupervisor.setText("Supervisor");
labelDepartment.setBackColor(Color.CONTROL);
labelDepartment.setLocation(new Point(10, 140));
labelDepartment.setSize(new Point(100, 20));
labelDepartment.setText("Department");
labelDepartment.setTabIndex(8);
editDepartment.setAnchor(ControlAnchor.TOPLEFTRIGHT);
editDepartment.setBackColor(Color.WINDOW);
editDepartment.setCursor(Cursor.IBEAM);
editDepartment.setLocation(new Point(120, 140));
editDepartment.setSize(new Point(280, 20));
editDepartment.setTabIndex(9);
editDepartment.setTabStop(true);
editDepartment.setText("Department");
labelPaytype.setBackColor(Color.CONTROL);
labelPaytype.setLocation(new Point(10, 170));
labelPaytype.setSize(new Point(100, 20));
labelPaytype.setText("Paytype");
labelPaytype.setTabIndex(10);
editPaytype.setAnchor(ControlAnchor.TOPLEFTRIGHT);
editPaytype.setBackColor(Color.WINDOW);
editPaytype.setCursor(Cursor.IBEAM);
editPaytype.setLocation(new Point(120, 170));
editPaytype.setSize(new Point(280, 20));
editPaytype.setTabIndex(11);
editPaytype.setTabStop(true);
editPaytype.setText("Paytype");
chkBenefits.setAnchor(ControlAnchor.TOPLEFTRIGHT);
chkBenefits.setBackColor(Color.CONTROL);
chkBenefits.setLocation(new Point(10, 200));
chkBenefits.setSize(new Point(120, 20));
chkBenefits.setTabIndex(12);
chkBenefits.setTabStop(true);
chkBenefits.setText("Benefits");
chkBenefits.setAlignText(LeftRightAlignment.LEFT);
chkFlextime.setAnchor(ControlAnchor.TOPLEFTRIGHT);
chkFlextime.setBackColor(Color.CONTROL);
chkFlextime.setLocation(new Point(10, 230));
chkFlextime.setSize(new Point(120, 20));
chkFlextime.setTabIndex(13);
chkFlextime.setTabStop(true);
chkFlextime.setText("Flextime");
chkFlextime.setAlignText(LeftRightAlignment.LEFT);
chkProbation.setAnchor(ControlAnchor.TOPLEFTRIGHT);
chkProbation.setBackColor(Color.CONTROL);
chkProbation.setLocation(new Point(10, 260));
chkProbation.setSize(new Point(120, 20));
chkProbation.setTabIndex(14);
chkProbation.setTabStop(true);
chkProbation.setText("Probation");
chkProbation.setAlignText(LeftRightAlignment.LEFT);
btnAdd.setAnchor(ControlAnchor.BOTTOMLEFT);
btnAdd.setLocation(new Point(12, 290));
btnAdd.setSize(new Point(70, 30));
btnAdd.setTabIndex(18);
btnAdd.setTabStop(true);
btnAdd.setText("&Add");
btnAdd.addOnClick(new EventHandler(this.btnAdd_Click));
btnDelete.setAnchor(ControlAnchor.BOTTOMLEFT);
btnDelete.setLocation(new Point(94, 290));
btnDelete.setSize(new Point(70, 30));
btnDelete.setTabIndex(19);
btnDelete.setTabStop(true);
btnDelete.setText("&Delete");
btnDelete.addOnClick(new EventHandler(this.btnDelete_Click));
btnRefresh.setAnchor(ControlAnchor.BOTTOMLEFT);
btnRefresh.setLocation(new Point(176, 290));
btnRefresh.setSize(new Point(70, 30));
btnRefresh.setTabIndex(20);
btnRefresh.setTabStop(true);
btnRefresh.setText("&Refresh");
btnRefresh.addOnClick(new EventHandler(this.btnRefresh_Click));
btnUpdate.setAnchor(ControlAnchor.BOTTOMLEFT);
btnUpdate.setLocation(new Point(258, 290));
btnUpdate.setSize(new Point(70, 30));
btnUpdate.setTabIndex(21);
btnUpdate.setTabStop(true);
btnUpdate.setText("&Update");
btnUpdate.addOnClick(new EventHandler(this.btnUpdate_Click));
btnClose.setAnchor(ControlAnchor.BOTTOMLEFT);
btnClose.setLocation(new Point(340, 290));
btnClose.setSize(new Point(70, 30));
btnClose.setTabIndex(15);
btnClose.setTabStop(true);
btnClose.setText("&Close");
btnClose.addOnClick(new EventHandler(this.btnClose_Click));
dataNavigator.setAnchor(ControlAnchor.BOTTOMLEFTRIGHT);
dataNavigator.setLocation(new Point(10, 330));
dataNavigator.setSize(new Point(400, 20));
dataNavigator.setTabIndex(17);
dataNavigator.setTabStop(false);
dataNavigator.setText("");
this.setNewControls(new Control[] {
dataNavigator,
btnAdd,
btnDelete,
btnRefresh,
btnUpdate,
btnClose,
labelEmployeeID,
editEmployeeID,
labelName,
editName,
labelSSN,
editSSN,
labelSupervisor,
editSupervisor,
labelDepartment,
editDepartment,
labelPaytype,
editPaytype,
chkBenefits,
chkFlextime,
chkProbation});
}
//NOTE: End of form designer support code.
public static class ClassInfo extends Form.ClassInfo
{
//TODO: Add your property and event infos here
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?