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

📄 form2.java

📁 JAVA语言实现的图书馆图书管理系统设计与源码
💻 JAVA
字号:
//Form2.java

import com.ms.wfc.app.*;
import com.ms.wfc.core.*;
import com.ms.wfc.ui.*;
import com.ms.wfc.data.*;
import com.ms.wfc.data.ui.*;

public class Form2 extends Form
{

    public void btnAdd_Click(Object sender, Event evt)
    {
        try
        {
            dataSource1.getRecordset().cancelUpdate();
            dataSource1.getRecordset().addNew();
            m_bAddNew = true;
            btnDelete.setText ("&返回" );
            btnAdd.setEnabled( false );
            btnRefresh.setEnabled( false );
        }
        catch (Exception e)
        {
            handleADOException(e);
        }
    }

    public void btnDelete_Click(Object sender, Event evt)
    {
        try
        {
            if( m_bAddNew )
            {
                dataSource1.getRecordset().cancelUpdate();
                m_bAddNew = false;
                btnDelete.setText ("&删除" );
                btnRefresh.setEnabled( true );
                btnAdd.setEnabled( true );
            }
            else
            {
                dataSource1.getRecordset().delete(AdoEnums.Affect.CURRENT);
                if( !dataSource1.getRecordset().getEOF() )
                {
                    dataSource1.getRecordset().moveNext();
                    if( dataSource1.getRecordset().getEOF() )
                        dataSource1.getRecordset().movePrevious();
                }
            }
        }
        catch (Exception e)
        {
            handleADOException(e);
            dataSource1.getRecordset().cancelBatch();
        }
    }

    public void btnRefresh_Click(Object sender, Event evt)
    {
        try
        {
            btnRefresh.setEnabled( false );
            dataSource1.getRecordset().cancelBatch();
            Object bm =  dataSource1.getRecordset().getBookmark();
            dataSource1.requery();
            if( bm != null ) 
                dataSource1.getRecordset().setBookmark( bm );
            
        }
        catch (Exception e)
        {
            handleADOException(e);
        }
        btnRefresh.setEnabled( true );
    }

    public void btnUpdate_Click(Object sender, Event evt)
    {
        try
        {
            this.setCursor( Cursor.WAIT );
            dataBinder1.commitChanges();
            dataSource1.getRecordset().update();

            if( m_bAddNew )
            {
                dataSource1.requery();
                
                dataSource1.getRecordset().moveLast();
            }
        }
        catch (Exception e)
        {
            handleADOException(e);
            if( m_bAddNew )
            {
                this.setCursor( Cursor.DEFAULT );
                return;
            }
            else
                dataSource1.getRecordset().cancelUpdate();
        }

        this.setCursor( Cursor.DEFAULT );
        m_bAddNew = false;
        btnDelete.setText ("&删除" );
        btnRefresh.setEnabled( true );
        btnAdd.setEnabled( true );
    }

    public void btnClose_Click(Object sender, Event evt)
    {
        this.dispose();
    }

    boolean    m_bAddNew;
    public void dispose()
    {
        super.dispose();
        components.dispose();
    }
	
    public Form2()
    {
        // Required for Visual J++ Form Designer support
        initForm();
        
        this.show();
        this.update();

        //TODO: Add any constructor code after initForm call
    }    

    public void formClose(Event e)
    {
        Application.exit();
    }    

    
    void handleADOException(Exception e)
    {
        e.printStackTrace();
        MessageBox.show( e.toString(), "Form2" );
    }

	private void Form2_click(Object source, Event e)
	{
		
	}

	/**
	 * 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();
	DataSource dataSource1 = new DataSource(components);
	DataBinder dataBinder1 = new DataBinder(components);
	Label label供应商名称 = new Label();
	Edit edit供应商名称 = new Edit();
	Label label联系人姓名 = new Label();
	Edit edit联系人姓名 = new Edit();
	Label label供应商ID = new Label();
	Edit edit供应商ID = new Edit();
	Label label地址 = new Label();
	Edit edit地址 = new Edit();
	Label label邮政编码 = new Label();
	Edit edit邮政编码 = new Edit();
	Button btnAdd = new Button();
	Button btnDelete = new Button();
	Button btnRefresh = new Button();
	Button btnUpdate = new Button();
	Button btnClose = new Button();
	Panel panel1 = new Panel();
	DataNavigator dataNavigator = new DataNavigator();

	private void initForm()
	{
		this.setBackColor(new Color(0, 192, 192));
		this.setForeColor(new Color(0, 0, 128));
		this.setLocation(new Point(7, 7));
		this.setText("发行商数据库管理");
		this.setAutoScaleBaseSize(new Point(6, 12));
		this.setAutoScroll(true);
		this.setClientSize(new Point(420, 240));
		this.setStartPosition(FormStartPosition.CENTER_SCREEN);
		this.addOnClick(new EventHandler(this.Form2_click));

		dataSource1.setConnectionString("PROVIDER=Microsoft.Jet.OLEDB.3.51;Data Source=C:\\My Documents\\db1.mdb");
		dataSource1.setCommandText("select 供应商名称, 联系人姓名, 供应商ID, 地址, 邮政编码 from 供应商 ORDER by 供应商ID");
		dataSource1.setSort(null);
		dataSource1.setStayInSync(true);
		dataSource1.setUserId(null);
		dataSource1.setPassword(null);

		label供应商名称.setBackColor(Color.CONTROL);
		label供应商名称.setLocation(new Point(10, 20));
		label供应商名称.setSize(new Point(100, 20));
		label供应商名称.setTabIndex(0);
		label供应商名称.setTabStop(false);
		label供应商名称.setText("供应商名称");

		edit供应商名称.setAnchor(ControlAnchor.TOPLEFTRIGHT);
		edit供应商名称.setLocation(new Point(120, 20));
		edit供应商名称.setSize(new Point(280, 20));
		edit供应商名称.setTabIndex(1);
		edit供应商名称.setText("www");
		edit供应商名称.setMaxLength(50);
		edit供应商名称.setMultiline(true);

		label联系人姓名.setBackColor(Color.LIGHTGRAY);
		label联系人姓名.setLocation(new Point(10, 50));
		label联系人姓名.setSize(new Point(100, 20));
		label联系人姓名.setTabIndex(2);
		label联系人姓名.setTabStop(false);
		label联系人姓名.setText("联系人姓名");

		edit联系人姓名.setAnchor(ControlAnchor.TOPLEFTRIGHT);
		edit联系人姓名.setLocation(new Point(120, 50));
		edit联系人姓名.setSize(new Point(280, 20));
		edit联系人姓名.setTabIndex(3);
		edit联系人姓名.setText("ee");
		edit联系人姓名.setMaxLength(50);
		edit联系人姓名.setMultiline(true);

		label供应商ID.setBackColor(Color.CONTROL);
		label供应商ID.setLocation(new Point(10, 80));
		label供应商ID.setSize(new Point(100, 20));
		label供应商ID.setTabIndex(4);
		label供应商ID.setTabStop(false);
		label供应商ID.setText("供应商ID");

		edit供应商ID.setAnchor(ControlAnchor.TOPLEFTRIGHT);
		edit供应商ID.setLocation(new Point(120, 80));
		edit供应商ID.setSize(new Point(280, 20));
		edit供应商ID.setTabIndex(5);
		edit供应商ID.setText("0");
		edit供应商ID.setMultiline(true);

		label地址.setBackColor(Color.CONTROL);
		label地址.setLocation(new Point(10, 110));
		label地址.setSize(new Point(100, 20));
		label地址.setTabIndex(6);
		label地址.setTabStop(false);
		label地址.setText("地址");

		edit地址.setAnchor(ControlAnchor.TOPLEFTRIGHT);
		edit地址.setLocation(new Point(120, 110));
		edit地址.setSize(new Point(280, 20));
		edit地址.setTabIndex(7);
		edit地址.setText("sssssss");
		edit地址.setMaxLength(255);
		edit地址.setMultiline(true);

		label邮政编码.setBackColor(Color.CONTROL);
		label邮政编码.setLocation(new Point(10, 140));
		label邮政编码.setSize(new Point(100, 20));
		label邮政编码.setTabIndex(8);
		label邮政编码.setTabStop(false);
		label邮政编码.setText("邮政编码");

		edit邮政编码.setAnchor(ControlAnchor.TOPLEFTRIGHT);
		edit邮政编码.setLocation(new Point(120, 140));
		edit邮政编码.setSize(new Point(280, 20));
		edit邮政编码.setTabIndex(9);
		edit邮政编码.setText("1212");
		edit邮政编码.setMultiline(true);

		dataBinder1.setDataSource(dataSource1);
		dataBinder1.setDataMember("");
		dataBinder1.setBindings(new DataBinding[] {
								new DataBinding(edit供应商名称, "Text", "供应商名称", null), 
								new DataBinding(edit联系人姓名, "Text", "联系人姓名", null), 
								new DataBinding(edit供应商ID, "Text", "供应商ID", null), 
								new DataBinding(edit地址, "Text", "地址", null), 
								new DataBinding(edit邮政编码, "Text", "邮政编码", null)});
		/* @designTimeOnly dataBinder1.setLocation(new Point(96, 0)); */

		btnAdd.setLocation(new Point(12, 8));
		btnAdd.setSize(new Point(70, 30));
		btnAdd.setTabIndex(0);
		btnAdd.setText("&添加");
		btnAdd.addOnClick(new EventHandler(this.btnAdd_Click));

		btnDelete.setLocation(new Point(94, 8));
		btnDelete.setSize(new Point(70, 30));
		btnDelete.setTabIndex(1);
		btnDelete.setText("&删除");
		btnDelete.addOnClick(new EventHandler(this.btnDelete_Click));

		btnRefresh.setLocation(new Point(176, 8));
		btnRefresh.setSize(new Point(70, 30));
		btnRefresh.setTabIndex(2);
		btnRefresh.setText("&刷新纪录");
		btnRefresh.addOnClick(new EventHandler(this.btnRefresh_Click));

		btnUpdate.setLocation(new Point(258, 8));
		btnUpdate.setSize(new Point(70, 30));
		btnUpdate.setTabIndex(3);
		btnUpdate.setText("&更新");
		btnUpdate.addOnClick(new EventHandler(this.btnUpdate_Click));

		btnClose.setLocation(new Point(340, 8));
		btnClose.setSize(new Point(70, 30));
		btnClose.setTabIndex(4);
		btnClose.setText("&关闭");
		btnClose.addOnClick(new EventHandler(this.btnClose_Click));

		panel1.setDock(ControlDock.BOTTOM);
		panel1.setLocation(new Point(0, 170));
		panel1.setSize(new Point(420, 50));
		panel1.setTabIndex(10);
		panel1.setText("");

		dataNavigator.setDock(ControlDock.BOTTOM);
		dataNavigator.setLocation(new Point(0, 220));
		dataNavigator.setSize(new Point(420, 20));
		dataNavigator.setTabIndex(11);
		dataNavigator.setTabStop(false);
		dataNavigator.setText("");
		dataNavigator.setDataMember("");
		dataNavigator.setDataSource(dataSource1);

		this.setNewControls(new Control[] {
							dataNavigator, 
							panel1, 
							label供应商名称, 
							edit供应商名称, 
							label联系人姓名, 
							edit联系人姓名, 
							label供应商ID, 
							edit供应商ID, 
							label地址, 
							edit地址, 
							label邮政编码, 
							edit邮政编码});
		panel1.setNewControls(new Control[] {
							  btnAdd, 
							  btnDelete, 
							  btnRefresh, 
							  btnUpdate, 
							  btnClose});

		dataSource1.begin();
		dataBinder1.begin();
	}
    //NOTE: End of form designer support code.

    /**
    * The main entry point for the application.
    *
    * @param args Array of parameters passed to the application
    * via the command line.
    */
    public static void main(String args[])
    {
        Application.run( new Form2() );
    }
}

⌨️ 快捷键说明

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