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

📄 form1.java

📁 java 编写的图书管理系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
import com.ms.wfc.app.*;
import com.ms.wfc.core.*;
import com.ms.wfc.ui.*;
import com.ms.wfc.html.*;

/**
 * This class can take a variable number of parameters on the command
 * line. Program execution begins with the main() method. The class
 * constructor is not invoked unless an object of type 'Form1' is
 * created in the main() method.
 */
public class Form1 extends Form
{
	int NUM = 100;
	boolean SORTED = false;
	int m_nCount;
	Book[] m_arBook;
	
	
	/**
	 * TODO: make sure all your constructors/initialization code
	 * paths have the following line:
	 * 		initForm();
	 */
	public Form1()
	{
		// Required for Visual J++ Form Designer support
		initForm();	
		m_nCount = 0;
		m_arBook = new Book[NUM];
		m_arBook[m_nCount++] = new Book("A1101","Book1","A1","Me",5,34.0f);
		m_arBook[m_nCount++] = new Book("B1101","Book2","B1","He",5,23.0f);
		m_arBook[m_nCount++] = new Book("C1101","Book3","C1","She",5,45.0f);
		m_arBook[m_nCount++] = new Book("D1101","Book4","D1","Me",5,24.0f);

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

	/**
	 * Form1 overrides dispose so it can clean up the
	 * component list.
	 * 
	 * TODO: have dispose call
	 * 		components.dispose();
	 */
	public void dispose()
	{
		super.dispose();
		components.dispose();
	}

	private void btnSearch_click(Object source, Event e)
	{
		if(m_nCount > 0)
		{
			SearchForm sForm = new SearchForm ();
			sForm.m_Parent = this;
			sForm.show ();
		}
		else
			MessageBox.show ("数据库中暂无数据!","提示:",MessageBox.ICONINFORMATION );
	}

	private void btnOpen_click(Object source, Event e)
	{
		if(this.openDlg .showDialog () == DialogResult.OK )
			editOpen.setText (openDlg.getFileName ());
	}

	private void btnAdd_click(Object source, Event e)
	{
		String strIndex,strName,strCategory,strAname;
		int iCount = 0;
		boolean bAdd = true;
		float fPrice = 0.0f;
		strIndex = editIndex.getText ();
		strName  = editName.getText ();
		strCategory = editCategory.getText ();
		strAname = editAname.getText ();
		if(!editCount.getText ().equals (""))
			iCount = Integer.parseInt(editCount.getText ());
		if(!editPrice.getText ().equals (""))
			fPrice = Float.valueOf (editPrice.getText ()).floatValue ();
		
		if(strIndex.equals ("") || strName.equals ("") || strCategory.equals ("") || strAname.equals (""))
			MessageBox.show ("所书号,书名,类别及作者名都不能为空!","提示:",MessageBox.ICONINFORMATION );
		else
		{
			for(int i = 0; i <  m_nCount;i++)
				if(m_arBook[i].getBookIndex ().equals (strIndex))  bAdd = false; 
			if(bAdd)	
			{
				m_arBook[m_nCount++] = new Book(strIndex,strName,strCategory,strAname,iCount,fPrice);
				MessageBox.show ("数据库成功添加 "+strName+"!","提示:",MessageBox.ICONINFORMATION );
				
			}
			else
			{
				MessageBox.show ("所书号重名或库中已有此记录!","提示:",MessageBox.ICONINFORMATION );
				bAdd = true;
			}
			editIndex.setText ("");
			editName.setText ("");
			editCategory.setText ("");
			editAname.setText ("");
			editCount.setText ("");
			editPrice.setText ("");
		}
	}

	private void btnShow_click(Object source, Event e)
	{
		MessageBox.show ("数据库中现有 "+m_nCount +" 条记录。","记录数:",MessageBox.ICONINFORMATION );
		if((m_nCount >= 3) && (SORTED == false))
		{
			if(MessageBox.show ("是否要对这些数据按所书号进行排序?","Question:",MessageBox.ICONQUESTION +MessageBox.YESNO ) == DialogResult.YES )
				sort();
			SORTED = true;
		}
	}

	private void btnDel_click(Object source, Event e)
	{
		String strIndex,strName,strCategory,strAname;
		int Flag = 0;
		int iDel = 0;
		String sField = "";
		strIndex = editIndex.getText ();
		strName  = editName.getText ();
		strCategory = editCategory.getText ();
		strAname = editAname.getText ();
		if(!strIndex.equals (""))
		{
			sField = strIndex;
			Flag = 0;
		}
		if(!strName.equals (""))
		{
			sField = strName;
			Flag = 1;
		}
		if(!strCategory.equals (""))
		{
			sField = strCategory;
			Flag = 2;
		}
		if(!strAname.equals (""))
		{
			sField = strAname;
			Flag = 3;
		}
		if(m_nCount > 0)
		{			
			if(sField.equals (""))
				MessageBox.show ("请填写要删除的记录的所书号、书名、类别名或者作者名中的一个。","提示:",MessageBox.ICONINFORMATION );		   
			else
			{
				if((MessageBox.show ("真的要删除吗?","询问:",MessageBox.ICONQUESTION+MessageBox.YESNO ) == DialogResult.YES ) )
				{
					if(sField.equals ("*"))
					{
					   MessageBox.show ("共删除 "+ String.valueOf (m_nCount) +" 条记录!","提示:",MessageBox.ICONINFORMATION );
					   m_nCount = 0;
					}
					else
					{
						for(int i = 0; i < m_nCount;i++)
							if(isEqual(m_arBook[i].getMember (Flag),sField))
							{
								m_arBook[i] = null;
								m_nCount--;
								//this.delete (i);
								iDel++;
							}
						if(iDel > 0)
							MessageBox.show ("共删除 "+ String.valueOf (iDel) +" 条记录!","提示:",MessageBox.ICONINFORMATION );
						else
							MessageBox.show ("库中没有满足要求的记录!","提示:",MessageBox.ICONINFORMATION );
					}
					editIndex.setText ("");
					editName.setText ("");
					editCategory.setText ("");
					editAname.setText ("");
				}
			}
		}
		else
			MessageBox.show ("数据库中已无数据!","提示:",MessageBox.ICONINFORMATION );
	}
	
	public boolean isEqual(String strField,String strBook) // 进行 '*' ,'?' 的检测
	{
		String str1 ="";
		String str2 = "";
		int len1 = strField.length ();
		int	len2 = strBook.length ();
		int t;
			
		if(strBook.equals (strField))
		   return true;
		try
		{
			if(strField.startsWith ("*"))
			{
				str1 = strField.substring (1,len1-1);
				if(strBook.endsWith (str1))
					return true;
				else 
					return false;
			}
			else if(strField.endsWith ("*"))
			{
				str1 = strField.substring (0,len1 -1);
				if(strBook.startsWith (str1))
					return true;
				else
					return false;
			}
			else if(strField.startsWith ("?"))
			{
				str1 = strField.substring (1);
				str2 = strBook.substring (1);
				if(str1.equals (str2))
					return true;
				else 
					return false;
			}
			else if(strField.endsWith ("?"))
			{
				str1 = strField.substring (0,len1 -1);
				str2 = strBook.substring (0,len2 -1);
				if(str1.equals (str2))
					return true;
				else
					return false;
			}
			/*if((t = strField.indexOf ((int)'?')) != -1)
			{
				
				int starts = 0;
				//MessageBox.show ("Find '?' now!","Notice");
				while(((t = strField.indexOf ((int)'?')) != -1) && (t < len1))
				{
					str1 += strField.substring (starts,t);
					str2 += strBook.substring (starts,t);
					starts = t +1;
				}
				if(str1.equals (str2))
					return true;
				else
					return false;
			}
		
			else if( (t = strField.indexOf ((int)'*')) != -1)
			{
				if(t == 0)
				{
					str1 = strField.substring (1,len1-1);
					str2 = strBook;
					if(str1.equals (str2))
						return true;
					else
						return false;
				}
				else if( t == len1-1)
				{
					str1 = strField.substring (0,len1-2);
					str2 = strField.substring (0,len2-1);
					if(str2.indexOf (str1) != -1)
						return true;
					else
						return false;
				}
				else
				{
				}
				

⌨️ 快捷键说明

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