?? commoditymanage.java
字號:
outF.write(" Updated table order detail \r\n");
outF.write("-----------------------------------------------------\r\n");
outF.close();
Order o=new Order();
System.out.println("--------------Update Detail-------------------");
o.Display();
}
public void DeleteOrder()throws IOException
{
System.out.println("-----------------4.DeleteOrder--------------------");
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 OrderDetail where cOrderID=?");
System.out.print("Enter cOrderID(3):");
String cOrderID=br.readLine(); //從鍵盤讀入值存入字串變量中
stat.setString(1,cOrderID); //用值替換SQL語句中的問號參數
res=stat.executeUpdate();
if (res!=0) System.out.println("-------Your details have been registered-------");
}
catch(Exception ex)
{
System.out.println("Could not Delete: "+ex);
}
if (con!=null) con=null;
Log l=new Log();
l.GetDate();
FileWriter outF = new FileWriter("log.txt",true);
outF.write(" Deleted an order \r\n");
outF.write("-----------------------------------------------------\r\n");
outF.close();
Order o=new Order();
System.out.println(" ");
System.out.println("----------The Detail that after delete----------");
o.DisplayOrder();
}
public static void main(String args[])throws IOException
{
Order o=new Order();
o.OrderMenu();
}
}
//-----------------------------------------------------------------------------------------------------------------//
//-------------------------------------------------Here's Sold Detail----------------------------------------------//
class SoldDetail
{
static String ID;
public void SoldMenu() throws IOException
{
System.out.println(" |-----------Sold Menu----------|");
System.out.println(" 1.Display Sold");
System.out.println(" 2.Sell Commodity");
System.out.println(" 0.Exit");
System.out.println(" |------------------------------|");
System.out.print(" Please choose a number(0~2):");
SoldDetail c=new SoldDetail();
c.choose();
System.out.println("");
}
public void again()throws IOException
{
System.out.println("Return to the Sold Menu ?");
System.out.print("Press '10' for Yes,Press '20' for No! ");
BufferedReader ar=new BufferedReader(new InputStreamReader(System.in));
String d=ar.readLine();
int m=Integer.parseInt(d);
SoldDetail c=new SoldDetail();
Business b=new Business();
if(m==10)
{
c.SoldMenu();
c.choose();
}
else if(m==20)
{
System.out.println("You have exited the Main Menu!");
System.exit(0);
}
else
{
System.out.println("Please Enter again!");
c.again();
}
}
public void choose()throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String w=br.readLine();
int k=Integer.parseInt(w);
SoldDetail s=new SoldDetail();
Business b=new Business();
{
switch(k)
{
case 1: s.DisplaySold(); s.again(); break;
case 2: s.Sold(); s.again(); break;
case 0: System.out.println("You have returned to the Business Menu!");
b.BusinessMenu();
b.choose();
break;
default:
System.out.println("Please Enter again:"); s.choose(); break;
}
}
}
public void DisplaySold() throws IOException
{
Connection con=null;
Statement stat;
ResultSet res=null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:Commodity");
stat=con.createStatement();
res=stat.executeQuery("select * from Sold");
System.out.println(" ");
if(res==null)
{
System.out.println("--------------Sold Table is Null!--------------");
return;
}
while(res.next())
{
System.out.println(" Journal No : "+res.getString(1));
System.out.println(" Commodity ID : "+res.getString(2));
System.out.println(" Supplier ID : "+res.getString(3));
System.out.println(" Commodity Name : "+res.getString(4));
System.out.println(" Sold Quantity : "+res.getString(5));
System.out.println(" Sold Date : "+res.getString(6));
System.out.println("\n--------------------Sold Detail-------------------\n");
}
}
catch(Exception e)
{
System.out.println("Could not query: "+e);
}
if (con!=null) con=null;
}
public void Sold() throws IOException
{
Connection con=null;
PreparedStatement stat=null;
int res=0;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try
{
String JournalNo,CommodityID,Qty,judge;
int i;
System.out.println("\n");
while(true)
{
System.out.print("Please Input the JournalNo(4) : ");
JournalNo=br.readLine();
System.out.print("Please Input the ID of Commodity(6) : ");
CommodityID=br.readLine();
System.out.print("Please Input the Quantity(int) : ");
Qty=br.readLine();
System.out.println("\n----------------Please Check Input----------------\n");
System.out.print("Press 1 to Continue,Press Any Key to Input again : ");
judge=br.readLine();
System.out.println("");
i=Integer.parseInt(judge);
if(i!=1)continue;
else break;
}
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:Commodity");
stat=con.prepareStatement("exec prcSold ?,?,?");
stat.setString(1,JournalNo);
stat.setString(2,CommodityID);
stat.setInt(3,Integer.parseInt(Qty));
res=stat.executeUpdate();
if (res!=0) System.out.println("\n-------Table CommodityDetail has Updated!-------\n");
}
catch(Exception ex)
{
System.out.println("\n------------Error! Please Check the Input------------\n\n");
}
if (con!=null) con=null;
Log l=new Log();
l.GetDate();
FileWriter outF = new FileWriter("log.txt",true);
outF.write(" Sold some commodities \r\n");
outF.write("-----------------------------------------------------\r\n");
outF.close();
}
public static void main(String args[])throws IOException
{
try
{
SoldDetail s=new SoldDetail();
s.SoldMenu();
}
catch(IOException e)
{
System.out.println("main() Error!");
}
}
}
//-----------------------------------------------------------------------------------------------------------------//
//-------------------------------------------------Here's Log Detail-----------------------------------------------//
class Log
{
public void GetDate() throws IOException
{
Connection con=null;
PreparedStatement stat;
ResultSet res=null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:Commodity");
stat=con.prepareStatement("select Date=getdate()");
res=stat.executeQuery();
if(res.next())
{
FileWriter outF = new FileWriter("log.txt",true);
outF.write("\r\n---------------"+res.getString(1)+"---------------\r\n");
outF.close();
}
}
catch(Exception e)
{
System.out.println("Could not query: "+e);
}
if (con!=null)
con=null;
}
}
//-----------------------------------------------------------------------------------------------------------------//
//-------------------------------------------Here's CommodityManage Detail-----------------------------------------//
public class CommodityManage
{
public void DisplayMenu() //顯示菜單
{
System.out.println(" |--------------------Main Menu--------------------|");
System.out.println(" 1.Maintenance Commodity Detail");
System.out.println(" 2.Maintenance Supplier Detail");
System.out.println(" 3.Maintenance Business(Order/Sold) Detail");
System.out.println(" 0.Exit");
System.out.println(" |-------------------------------------------------|");
System.out.print(" Please choose a number(0~3):");
}
public void chooseMenu() throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String w=br.readLine();
int y=Integer.parseInt(w);
CommodityManage CM=new CommodityManage();
Commodity c=new Commodity();
Supplier s=new Supplier();
Order o=new Order();
Business b=new Business();
{
switch(y)
{
case 1: c.CommodityMenu(); c.again(); break;
case 2: s.SupplierMenu() ; s.again(); break;
case 3: b.BusinessMenu() ; b.again(); break;
case 0: System.out.println("You have exited the main menu!");
System.exit(0); break;
default:
System.out.println("Please Enter again:"); CM.chooseMenu(); break;
}
if(y==0)return;
}
}
public void exit()throws IOException
{
System.out.println("Exit or not ?");
System.out.print("Press '10' for Yes,Press '20' for No! ");
BufferedReader ar=new BufferedReader(new InputStreamReader(System.in));
String d=ar.readLine();
int m=Integer.parseInt(d);
CommodityManage CM=new CommodityManage();
if(m==10)
{
CM.DisplayMenu();
CM.chooseMenu();
}
else if(m==20)
{
System.out.println("You have exited the Main Menu!");
System.exit(0);
}
else
{
System.out.println("Please Enter again!");
CM.exit();
}
}
public static void main(String args[])throws IOException
{
CommodityManage CM=new CommodityManage();
CM.DisplayMenu();
CM.chooseMenu();
}
}
//-----------------------------------------------------------------------------------------------------------------//
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -