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

📄 commoditymanage.java

📁 这是用java实现的一个仓储管理系统
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
		System.out.println(" ");
		System.out.println("        |--------Supplier Menu-------|");
		System.out.println("          1.Display Supplier Detail");
		System.out.println("          2.Insert  Supplier Detail");
		System.out.println("          3.Update  Supplier Detail");
		System.out.println("          4.Delete  Supplier Detail");
		System.out.println("                   0.Exit");
		System.out.println("        |----------------------------|");
		System.out.print("        Please choose a number(0~4):");
		Supplier s=new Supplier();
		s.choose();
	}
	
	public void again()throws IOException
	{
		System.out.println("Return to the Supplier Menu?");
		System.out.print("choose '10'for yes,'20' for no! ");
		BufferedReader ar=new BufferedReader(new InputStreamReader(System.in));
		String d=ar.readLine();
		int m=Integer.parseInt(d);
		Supplier s=new Supplier();
		CommodityManage CM=new CommodityManage();
		if(m==10)
		{
			s.SupplierMenu();
			s.choose();
		}
		else if(m==20)
		{
			System.out.println("-------------You have exited Main Menu!-------------");
			System.exit(0);
		}
		else	
		{
			System.out.println("Please enter again!");
			s.again();
		}				
	}	
	public void choose()throws IOException
	{
	  BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String w=br.readLine();
		n=Integer.parseInt(w);
		Supplier s=new Supplier();
		CommodityManage CM=new CommodityManage();
		{
			switch(n)
			{
				case 1:	s.DisplaySupplier();	s.again();	break;
				case 2:	s.InsertSupplier() ;	s.again();	break;
				case 3:	s.UpdateSupplier() ;	s.again();	break;
				case 4:	s.DeleteSupplier() ;	s.again();	break;
				case 0:	System.out.println("You have returned to the Main Menu!");	
								CM.DisplayMenu();
								CM.chooseMenu();
								break;
				default:
								System.out.print("Please enter again:");	s.choose();	break;	
			}
		}	
	}
	public void DisplaySupplier()  
	{
		System.out.println("-----------------1.DisplaySupplier--------------------");
		Connection con=null;
		Statement stat;
		ResultSet res;
    try
    {
	    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
	    con=DriverManager.getConnection("jdbc:odbc:Commodity");
	    stat=con.createStatement();
	    res=stat.executeQuery("select * from SupplierDetail");
	    while(res.next())
	    {
	      System.out.println("	            ID : "+res.getString(1));
	      System.out.println("	          Name : "+res.getString(2));
	      System.out.println("	   Description : "+res.getString(3));
        System.out.println("	     Telephone : "+res.getString(4));
        System.out.println("	       Address : "+res.getString(5));
        System.out.println("	Shipment Delay : "+res.getString(6));
	      System.out.println("	     Appraisal : "+res.getString(7));
	      System.out.println("\n--------------------Supplier Detail-------------------\n");
	    }
     }
     catch(Exception e)
     {
	    	System.out.println("Could not query: "+e);
     }
		 if (con!=null) con=null;
	}
	
	public void Display()  
	{
			Connection con=null;
	    PreparedStatement stat;
	    ResultSet res=null;
	    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      try
      {
		    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
		    con=DriverManager.getConnection("jdbc:odbc:Commodity");
		    stat=con.prepareStatement("select * from SupplierDetail where cSupplierID=?");
		    stat.setString(1,(String)ID);  //用值替换SQL语句中的问号参数
		    res=stat.executeQuery();  
		    while(res.next())
		    {
		      System.out.println("	            ID : "+res.getString(1));
		      System.out.println("	          Name : "+res.getString(2));
		      System.out.println("	   Description : "+res.getString(3));
	        System.out.println("	     Telephone : "+res.getString(4));
	        System.out.println("	       Address : "+res.getString(5));
	        System.out.println("	Shipment Delay : "+res.getString(6));
		      System.out.println("	     Appraisal : "+res.getString(7));
		      System.out.println("");
		    }
     }
     catch(Exception e)
     {
	    	System.out.println("Could not display: "+e);
     }
		 if (con!=null) con=null;
	}
	
	public void InsertSupplier() throws IOException 
	{
			System.out.println("-----------------2.InsertSupplier--------------------");
			Connection con=null;
	    PreparedStatement stat=null;
	    int res=0;

	    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	    try
	    {
	        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
	        con=DriverManager.getConnection("jdbc:odbc:Commodity");
	        stat=con.prepareStatement("insert into SupplierDetail values(?,?,?,?,?,?,?)");

	        System.out.print("SupplierID(6) = ");
	        String SupplierID=br.readLine();   //从键盘读入值存入字串变量中
	        ID=SupplierID;

	        System.out.print("SlpplierName(50) = ");
	        String SlpplierName=br.readLine();

	        System.out.print("Description(50) = ");
	        String Description=br.readLine();

	        System.out.print("Telephone (like 1234-1234567) = ");
	        String Telephone=br.readLine();
	        
					System.out.print("Address(50) = ");
	        String Address=br.readLine();

	        System.out.print("ShipmentDelay (day) = ");
	        String ShipmentDelay=br.readLine();

	        System.out.print("CredibilityDegree (best or high or medium or so-so) = ");
	        String CredibilityDegree=br.readLine();
					
					System.out.println(" ");
					
	        stat.setString(1,SupplierID);  //用值替换SQL语句中的问号参数
	        stat.setString(2,SlpplierName);
	        stat.setString(3,Description);
          stat.setString(4,Telephone);
          stat.setString(5,Address);
          stat.setInt(6,Integer.parseInt(ShipmentDelay)); 
	        stat.setString(7,CredibilityDegree);

	        res=stat.executeUpdate();
	        if (res!=0) System.out.println("-------Your details have been registered-------");
	    }

	    catch(Exception ex)
      {      
     	   System.out.println("Error registe: "+ex);
      }

			 if (con!=null) con=null;
			 Log l=new Log();
			 l.GetDate();
			 FileWriter outF = new FileWriter("log.txt",true);
			 outF.write("                Inserted a supplier \r\n");
			 outF.write("-----------------------------------------------------\r\n");
			 outF.close();
			 Supplier s=new Supplier();
			 System.out.println(" ");
			 System.out.println("-------------Insert Detail-------------------");
			 s.Display();
	}
	
	public void UpdateSupplier() throws IOException 
	{
      System.out.println("-----------------3.UpdateSupplier--------------------");
      Connection con=null;
	    PreparedStatement stat=null;
	    int res=0;
	    
	    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	    try
	    {
	        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
	        con=DriverManager.getConnection("jdbc:odbc:Commodity");
	        System.out.print("Please enter the cSupplierID:");
	        String SupplierID=br.readLine();
	        ID=SupplierID;
	        System.out.println();
	        System.out.println("Update what?");
	        System.out.println("1.vSupplierName");
	        System.out.println("2.vSupplierDescription");
	        System.out.println("3.cSupplierTele");
	        System.out.println("4.vSupplierAddress");
	        System.out.println("5.iShipmentDelay");
	        System.out.println("6.cCredibilityDeg");
	        System.out.print("Please choose(1-6) : ");
					String w=br.readLine();
					int n=Integer.parseInt(w);
					switch(n)
					{
						case 1:	stat=con.prepareStatement("update SupplierDetail set vSupplierName=? where cSupplierID=?");
										System.out.print("Enter the new vSupplierName(6) : ");break;
						case 2:	stat=con.prepareStatement("update SupplierDetail set vSupplierDescription=? where cSupplierID=?");
										System.out.print("Enter the new vSupplierDescription(50) : ");break;
						case 3:	stat=con.prepareStatement("update SupplierDetail set cSupplierTele=? where cSupplierID=?");
										System.out.print("Enter the new cSupplierTele(like 1234-1234567) : ");break;
						case 4:	stat=con.prepareStatement("update SupplierDetail set vSupplierAddress=? where cSupplierID=?");
										System.out.print("Enter the new vSupplierAddress(50) : ");break;
						case 5:	stat=con.prepareStatement("update SupplierDetail set iShipmentDelay=? where cSupplierID=?");
										System.out.print("Enter the new iShipmentDelay(day) : ");break;
						case 6: stat=con.prepareStatement("update SupplierDetail set cCredibilityDeg=? where cSupplierID=?");
										System.out.print("Enter the new cCredibilityDeg(best or high or medium or so-so) : ");break;
						default:break;
					}
	        
	        String newdata=br.readLine();
	        stat.setString(1,(String)newdata);  //用值替换SQL语句中的问号参数
	        stat.setString(2,(String)SupplierID);  //用值替换SQL语句中的问号参数
	        
					res=stat.executeUpdate();
	        if (res!=0) System.out.println("-------Your details have been updata-------");
	    }

      catch(Exception e)
      {
	    System.out.println("Could not Updata: "+e);
      }
      if (con!=null)con=null;
      Log l=new Log();
			l.GetDate();
			FileWriter outF = new FileWriter("log.txt",true);
			outF.write("          Updated table supplier detail \r\n");
			outF.write("-----------------------------------------------------\r\n");
			outF.close();
      Supplier s=new Supplier();
      System.out.println("--------------Update Detail-------------------");
      s.Display();
	}
	public void DeleteSupplier()throws IOException
	{
			System.out.println("-----------------4.DeleteSupplier--------------------");
			Connection con=null;
	    PreparedStatement stat=null;
	    int res=0;

	    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	    try
	    {
	        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
	        con=DriverManager.getConnection("jdbc:odbc:Commodity");
	        stat=con.prepareStatement("delete SupplierDetail where cSupplierID=?");

	        System.out.print("Enter cSupplierID(6):");
	        String SupplierID=br.readLine();   //从键盘读入值存入字串变量中

	        stat.setString(1,SupplierID);  //用值替换SQL语句中的问号参数
	    
	        res=stat.executeUpdate();
	        if (res!=0) System.out.println("-------Your details have been registered-------");
	    }

	    catch(Exception e)
      {      
     	   System.out.println("Could not Delete: "+e);
      }
	    if (con!=null) con=null;
	    Log l=new Log();
			l.GetDate();
			FileWriter outF = new FileWriter("log.txt",true);
			outF.write("                Deleted a supplier \r\n");
			outF.write("-----------------------------------------------------\r\n");
			outF.close();
	    Supplier s=new Supplier();
	    System.out.println("----------The Detail that after delete----------");
	    s.DisplaySupplier();

	}
	public static void main(String args[])throws IOException
	{
			Supplier s=new Supplier();
			s.SupplierMenu();
	}
}
//-----------------------------------------------------------------------------------------------------------------//

//---------------------------------------------Here's Business Detail----------------------------------------------//
class Business
{
	static String ID;
	public void BusinessMenu()throws IOException
	{
		System.out.println("        |---------Business Menu--------|");
		System.out.println("                 1.Order Detail");
		System.out.println("                 2.Sold  Detail");
		System.out.println("                     0.Exit");
		System.out.println("        |------------------------------|");
		System.out.print("        Please choose a number(0~2):");
		Business c=new Business();
		c.choose();
	  System.out.println("");
	}
	
	public void again()throws IOException
	{
		System.out.println("Return to the Business Menu ?");
		System.out.print("Press '10' for Yes,Press '20' for No! ");
		BufferedReader ar=new BufferedReader(new InputStreamReader(System.in));
		String d=ar.readLine();

⌨️ 快捷键说明

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