package a1;
import java.sql.*;
public class OrderForm
{   String logname,  //用户名。
           realname, //真实姓名。
           order_number,//图书订购号
           phone,
           address,
           book_name, //书名。
           mount;     //数量。
    Connection con;
    Statement sql; 
    ResultSet rs;
    public OrderForm()
    {  //加载桥接器：
       try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
          }
       catch(ClassNotFoundException e){}
    }
   //设置属性值、获取属性值的方法：
  public void setLogname(String name)
    {  logname=name;
    }
   public String getLogname()
    {return logname;
    }
  public void setRealname(String name)
    {  realname=name;
    }
    public String getRealname()
    {return realname;
    }
  public void setOrder_number(String number)
    {  order_number=number;
    }
  public String getOrder_number()
    {return order_number;
    }
  public void setBook_name(String name)
    {  book_name=name;
    }
  public String getBook_name()
    {return book_name;
    }
  public void setPhone(String ph)
    {  phone=ph;
    }
   public String getPhone()
    {return phone;
    }
   public void setAddress(String ad)
    {  address=ad;
    }
   public String getAddress()
    {return address;
    }
   public void setMount(String n)
    {  mount=n;
    }
   public String getMount()
    {return mount;
    }
  //向数据库的orderform订单表添加订购记录：
   public String setOrderBook()
    { try{con=DriverManager.getConnection("jdbc:odbc:shop","","");
          sql=con.createStatement();
          String s=
           "'"+logname+"'"+","+"'"+realname+"'"+","+"'"+order_number+"'"+","+"'"+
            book_name+"'"+","+"'"+mount+"'"+","+"'"+phone+"'"+","+"'"+address+"'";
          String condition="INSERT INTO orderform VALUES"+"("+s+")";
          sql.executeUpdate(condition);
          con.close();
         return "该书被添加到你的订单";
       }
     catch(SQLException e)
       { return "你已经订购了该书，请去修改订单后再订购";
       }
    }
}