Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fuzzy query and fuzzy matching of user's input selection #37

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import lyons.tools.ScannerChoice;

/**
* ���ݿ�goods������
* 数据库goods表操作
* @author lyons(zhanglei)
*/
public final class GoodsDao
Expand All @@ -22,8 +22,8 @@ public final class GoodsDao
ResultSet rs = null;

/**
* 1.������Ʒ�����ݿ�goods��
* @param goods ��Ʒ����
* 1.添加商品到数据库goods表
* @param goods 商品对象
* @return boolean
*/
public boolean addGoods(Goods goods)
Expand Down Expand Up @@ -55,9 +55,9 @@ public boolean addGoods(Goods goods)
}

/**
* 2.������Ʒ��Ϣ�����ݿ�goods��
* @param key ѡ��Ҫ������Ʒ��Ϣ
* @param goods ��Ʒ����
* 2.更改商品信息到数据库goods表
* @param key 选择要更改商品信息
* @param goods 商品对象
* @return boolean
*/
public boolean updateGoods(int key,Goods goods)
Expand All @@ -66,7 +66,7 @@ public boolean updateGoods(int key,Goods goods)
conn = DbConn.getconn();
switch (key)
{
case 1: // key=1,������Ʒ����
case 1: // key=1,更改商品名称
String sqlName = "UPDATE GOODS SET GNAME=? WHERE GID=?";

try
Expand All @@ -87,7 +87,7 @@ public boolean updateGoods(int key,Goods goods)
DbClose.addClose(pstmt,conn);
}
break;
case 2: // key=2,������Ʒ�۸�
case 2: // key=2,更改商品价格
String sqlPrice = "UPDATE GOODS SET GPRICE=? WHERE GID=?";

try
Expand All @@ -108,7 +108,7 @@ public boolean updateGoods(int key,Goods goods)
DbClose.addClose(pstmt,conn);
}
break;
case 3: // key=3,������Ʒ����
case 3: // key=3,更改商品数量
String sqlNum = "UPDATE GOODS SET GNUM=? WHERE GID=?";

try
Expand Down Expand Up @@ -136,8 +136,8 @@ public boolean updateGoods(int key,Goods goods)
}

/**
* 3.�����ݿ�goods����-�h����Ʒ
* @param gid ��Ʒ���
* 3.从数据库goods表中-刪除商品
* @param gid 商品编号
* @return boolean
*/
public boolean deleteGoods(int gid)
Expand Down Expand Up @@ -165,8 +165,8 @@ public boolean deleteGoods(int gid)
}

/**
*4.��ѯ��Ʒ��Ϣ
* @param key ��ѯ��ʽ
*4.查询商品信息
* @param key 查询方式
* @return ArrayList<Goods>
*/
public ArrayList<Goods> queryGoods(int key)
Expand All @@ -177,7 +177,7 @@ public ArrayList<Goods> queryGoods(int key)
switch (key)
{
case 1:
// key=1��Ʒ ���� �����ѯ
// key=1商品 数量 升序查询
String sqlGnum = "SELECT * FROM GOODS ORDER BY GNUM ASC";
try
{
Expand All @@ -202,7 +202,7 @@ public ArrayList<Goods> queryGoods(int key)
}
break;
case 2:
// key=2��Ʒ �۸� �����ѯ
// key=2商品 价格 升序查询
String sqlGprice = "SELECT * FROM GOODS ORDER BY GPRICE ASC";
try
{
Expand All @@ -227,8 +227,8 @@ public ArrayList<Goods> queryGoods(int key)
}
break;
case 3:
// key=3��Ʒ �ؼ��� ��ѯ
String nameGet = ScannerChoice.ScannerInfoString();
// key=3商品 关键字 查询
String nameGet = "%"+ScannerChoice.ScannerInfoString()+"%";
String sqlGname = "SELECT * FROM GOODS WHERE GNAME LIKE '%'||?||'%'";
try
{
Expand Down Expand Up @@ -260,7 +260,7 @@ public ArrayList<Goods> queryGoods(int key)
}

/**
*5.��ʾ������Ʒ��Ϣ
*5.显示所有商品信息
* @return ArrayList<Goods>
*/
public ArrayList<Goods> displayGoods()
Expand All @@ -278,11 +278,11 @@ public ArrayList<Goods> displayGoods()
{
int gid = rs.getInt(1);
String gname = rs.getString(2);
double gprice = rs.getDouble("gprice"); //˫����+������,Ҳ�������ֱ�ʾ.
double gprice = rs.getDouble("gprice"); //双引号+主键名,也可用数字表示.
int gnum = rs.getInt(4);

Goods goods = new Goods(gid,gname,gprice,gnum); //����Goods���󣬲���ֵ.
goodsList.add(goods); //������Ϣ����̬������.
Goods goods = new Goods(gid,gname,gprice,gnum); //创建Goods对象,并赋值.
goodsList.add(goods); //添加信息到动态数组中.
}
} catch (SQLException e)
{
Expand All @@ -295,4 +295,4 @@ public ArrayList<Goods> displayGoods()

}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import lyons.entity.SalesMan;

/**
* ��ѯ&&��ӡ ��������(�����Ż����ܻ�ɾ)
* 查询&&打印 函数工具(后期优化可能会删)
*@author lyons(zhanglei)
*/

Expand All @@ -24,61 +24,61 @@ public final class QueryPrint
ResultSet rs = null;

/**
* ģ����ѯ�����в�ѯ��Ϣ����С����
* @param oper ������
* @return ��ѯ������Ϣ��gid,�������ֵ����-1���������ѯ�쳣��
* 模糊查询并陈列查询信息函数小工具
* @param oper 调用者
* @return 查询到的信息的gid,如果返回值等于-1,则代表查询异常。
*/
public static int query(String oper)
{
int gid = -1;
String shopping = ScannerChoice.ScannerInfoString(); //���̻�ȡ��Ʒ����
ArrayList<Goods> goodsList = new QueryPrint().queryGoodsKey(-1,shopping); //���ݼ��̻�ȡ����Ʒ�����{�� ��ȷ��ѯ�������_���Ñ���Ҫ����������
String shopping = ScannerChoice.ScannerInfoString(); //键盘获取商品名字
ArrayList<Goods> goodsList = new QueryPrint().queryGoodsKey(-1,shopping); //根据键盘获取的商品名字調用 精确查询函数,確定用戶所要操作的数据
if (goodsList == null || goodsList.size() <= 0)
{
System.err.println("\t�������޴���Ʒ ����");
System.err.println("\t!!查无此商品 !!");

//�{��ѡ����һ������
//調用选择下一步函数
ScannerChoice.changedInfoNext(oper);

}else //�鵽�д���Ʒ��ʵ�ֽ��� ������Ʒ ��Ϣ������
}else //查到有此商品,实现进行 更改商品 信息操作!
{
Goods goods = goodsList.get(0);

System.out.println("\t\t\t\t\t��Ʒ�б�\n\n");
System.out.println("\t��Ʒ���\t\t��Ʒ����\t\t��Ʒ�۸�\t\t��Ʒ����\t\t��ע\n");
System.out.println("\t\t\t\t\t商品列表\n\n");
System.out.println("\t商品编号\t\t商品名称\t\t商品价格\t\t商品数量\t\t备注\n");
System.out.print("\t"+goods.getGid()+"\t\t"+goods.getGname()+"\t\t"+goods.getGprice()+"\t\t"+goods.getGnum());
if (goods.getGnum()==0)
{
System.out.println("\t\t����Ʒ���ۿ�");
System.out.println("\t\t该商品已售空");
}else if (goods.getGnum()<10)
{
System.out.println("\t\t����Ʒ�Ѳ���10��");
System.out.println("\t\t该商品已不足10件");
}else
{
System.out.println("\t\t-");
}
gid = goods.getGid(); //����Ʒ��ŷ��ظ�������
gid = goods.getGid(); //将商品编号返回给调用者
}
return gid;
}

/**
* ģ����ѯ����С����
* @return int ����Ʒ��������ֻ��һ��ʱ������Ʒgid�ţ���Ʒ���ۿ�ʱ���� -1. >1��ʱ����-2 . ���޴���Ʒʱ����-3
* 模糊查询函数小工具
* @return int 当商品件数有且只有一件时返回商品gid号,商品已售空时返回 -1. >1件时返回-2 . 查无此商品时返回-3
*
*/
public static int querySettlement()
{
int gid = -1;
ArrayList<Goods> goodsSettlement = new GoodsDao().queryGoods(3);//�{�� �ؼ��ֲ�ѯ����
ArrayList<Goods> goodsSettlement = new GoodsDao().queryGoods(3);//調用 关键字查询函数
if (goodsSettlement == null || goodsSettlement.size() <= 0)
{
System.err.println("\t�������޴���Ʒ ����\n");
System.err.println("\t!!查无此商品 !!\n");
gid = -3;
}else //�鵽�д���Ʒ��ʵ�ֽ��� ������Ʒ ��Ϣ������
}else //查到有此商品,实现进行 更改商品 信息操作!
{
System.out.println("\t\t\t\t\t��Ʒ�б�\n\n");
System.out.println("\t��Ʒ���\t\t��Ʒ����\t\t��Ʒ�۸�\t\t��Ʒ����\t\t��ע\n");
System.out.println("\t\t\t\t\t商品列表\n\n");
System.out.println("\t商品编号\t\t商品名称\t\t商品价格\t\t商品数量\t\t备注\n");
for (int i = 0; i < goodsSettlement.size(); i++)
{
Goods goods = goodsSettlement.get(i);
Expand All @@ -88,17 +88,17 @@ public static int querySettlement()

if (goods.getGnum()==0)
{
System.out.println("\t\t����Ʒ���ۿ�");
System.out.println("\t\t该商品已售空");
}else if (goods.getGnum()<10)
{
System.out.println("\t\t����Ʒ�Ѳ���10��");
System.out.println("\t\t该商品已不足10件");
}else
{
System.out.println("\t\t-");
}
if (goodsSettlement.size()==1)
{
gid = goods.getGid(); //����Ʒ��ŷ��ظ�������
gid = goods.getGid(); //将商品编号返回给调用者
}else
{
gid = -2;
Expand All @@ -111,9 +111,9 @@ public static int querySettlement()


/**
* ������Ʒ gid or gName��ѯ��Ʒ
* @param ��Ʒid,��Ʒ����
* @return ��Ʒ��Ϣ
* 根据商品 gid or gName查询商品
* @param 商品id,商品名称
* @return 商品信息
*/
public ArrayList<Goods> queryGoodsKey(int gId,String gName)
{
Expand All @@ -125,7 +125,7 @@ public ArrayList<Goods> queryGoodsKey(int gId,String gName)
{
pstmt = conn.prepareStatement(sql);
pstmt.setInt(1, gId);
pstmt.setString(2, gName);
pstmt.setString(2, "%"+gName+"%");
rs = pstmt.executeQuery();
while (rs.next())
{
Expand All @@ -148,8 +148,8 @@ public ArrayList<Goods> queryGoodsKey(int gId,String gName)
}

/**
* ��ȷ��ѯ�ۻ�Ա��Ϣ
* @param �ۻ�Ա����
* 精确查询售货员信息
* @param 售货员名字
* @return
*/
public ArrayList<SalesMan> querySalesMan(String sName)
Expand Down
Loading