?? ware.java
字號:
package com.chapter14;
import java.util.*;
import java.sql.*;
import java.text.*;
public class Ware extends ExecuteDB
{
//定義類成員變量
private long WareID;
private String WareName;
private String Company;
private String Addr;
private float Price;
private String PicUrl;
private long SortID;
private String Intro;
private String CreateTime;
private String strSql;
//初始化類成員變量
public Ware()
{
this.WareID=0;
this.WareName="";
this.Company="";
this.SortID=0;
this.Price=0;
this.Addr="";
this.PicUrl = "00000000000000.gif";
this.Intro = "";
java.util.Date NowTime = new java.util.Date();
this.CreateTime = NowTime.toLocaleString();
this.strSql="";
}
//向wares數(shù)據(jù)表中添加一條新記錄
public boolean add()
{
this.strSql="insert into wares ";
this.strSql=this.strSql + "(WareName,Company,Addr,Price,SortID,PicUrl,Intro,CreateTime) ";
this.strSql=this.strSql + "values('" + this.WareName + "','" + this.Company + "','" + this.Addr + "','" + this.Price + "','" + this.SortID + "','" + this.PicUrl + "','" + this.Intro + "','" + this.CreateTime + "')";
boolean isAdd = super.exeSql(this.strSql);
return isAdd;
}
//修改類成員變量WareID對應的商品信息
public boolean modify()
{
this.strSql="update wares set ";
this.strSql=this.strSql + "WareName=" + "'" + this.WareName + "',";
this.strSql=this.strSql + "Company=" + "'" + this.Company + "',";
this.strSql=this.strSql + "Addr=" + "'" + this.Addr + "',";
this.strSql=this.strSql + "Price=" + "'" + this.Price + "',";
this.strSql=this.strSql + "SortID=" + "'" + this.SortID + "',";
this.strSql=this.strSql + "PicUrl=" + "'" + this.PicUrl + "',";
this.strSql=this.strSql + "Intro=" + "'" + this.Intro + "',";
this.strSql=this.strSql + "CreateTime=" + "'" + this.CreateTime + "'";
this.strSql=this.strSql + " where WareID=" + this.WareID;
boolean isUpdate = super.exeSql(this.strSql);
return isUpdate;
}
//刪除類sWareID中對應的商品信息
public boolean delete(String sWareID)
{
this.strSql="delete from wares where WareID in (";
this.strSql=this.strSql + sWareID + ")";
boolean isDelete = super.exeSql(this.strSql);
return isDelete;
}
//獲取類成員變量WareID對應的商品信息
public boolean init()
{
this.strSql="select * from wares where WareID=";
this.strSql=this.strSql + this.WareID;
try
{
ResultSet rs = super.exeQuery(this.strSql);
if (rs.next())
{
this.WareID=rs.getLong("WareID");
this.WareName=rs.getString("WareName");
this.Addr=rs.getString("Addr");
this.Company=rs.getString("Company");
this.PicUrl=rs.getString("PicUrl");
this.Price=rs.getFloat("Price");
this.SortID=rs.getInt("SortID");
this.Intro=rs.getString("Intro");
this.CreateTime=rs.getString("CreateTime");
return true;
}
else
return false;
}
catch(Exception e)
{
return false;
}
}
//獲取所有普通商品信息,返回一個ResultSet類型對象
public ResultSet show_wares()
{
this.strSql="select * from wares order by CreateTime desc";
ResultSet rs = null;
try
{
rs = super.exeQuery(this.strSql);
}
catch(Exception ex)
{
System.out.println(ex.toString());
}
return rs;
}
//以WareName、Company、Addr、SortID為條件搜索wares數(shù)據(jù)表,獲得符合條件的記錄,返回一個ResultSet類型對象
public ResultSet search_wares()
{
this.strSql="select * from wares where";
this.strSql=this.strSql + " WareName like '%" + this.WareName +"%'";
this.strSql=this.strSql + " and Company like '%" + this.Company +"%'";
this.strSql=this.strSql + " and Addr like '%" + this.Addr +"%'";
if(SortID != 0)
this.strSql=this.strSql + " and SortID =" + this.SortID;
ResultSet rs = null;
try
{
rs = super.exeQuery(this.strSql);
}
catch(Exception ex)
{
System.out.println(ex.toString());
}
return rs;
}
//設置類成員變量WareID的值
public void setWareID(long WareID)
{
this.WareID = WareID;
}
//獲取類成員變量WareID的值
public long getWareID()
{
return this.WareID;
}
//設置類成員變量WareName的值
public void setWareName(String WareName)
{
this.WareName = WareName;
}
//獲取類成員變量WareName的值
public String getWareName()
{
return this.WareName;
}
//設置類成員變量Company的值
public void setCompany(String Company)
{
this.Company = Company;
}
//獲取類成員變量Company的值
public String getCompany()
{
return this.Company;
}
//設置類成員變量Addr的值
public void setAddr(String Addr)
{
this.Addr = Addr;
}
//獲取類成員變量Addr的值
public String getAddr()
{
return this.Addr;
}
//設置類成員變量Price的值
public void setPrice(float Price)
{
this.Price = Price;
}
//獲取類成員變量Price的值
public float getPrice()
{
return this.Price;
}
//設置類成員變量SortID的值
public void setSortID(long SortID)
{
this.SortID = SortID;
}
//獲取類成員變量SortID的值
public long getSortID()
{
return this.SortID;
}
//設置類成員變量PicUrl的值
public void setPicUrl(String PicUrl)
{
this.PicUrl = PicUrl;
}
//獲取類成員變量PicUrl的值
public String getPicUrl()
{
return this.PicUrl;
}
//設置類成員變量Intro的值
public void setIntro(String Intro)
{
this.Intro = Intro;
}
//獲取類成員變量Intro的值
public String getIntro()
{
return this.Intro;
}
//設置類成員變量CreateTime的值
public void setCreateTime(String CreateTime)
{
this.CreateTime = CreateTime;
}
//獲取類成員變量CreateTime的值
public String getCreateTime()
{
return this.CreateTime;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -