一、duan.page.MainPage
package duan.page;
import java.util.ArrayList;
import duan.dao.GoodsDao;
import duan.dao.GsalesDao;
import duan.dao.SalesManDao;
import duan.entity.Goods;
import duan.entity.Gsales;
import duan.entity.SalesMan;
import duan.tools.Arith;
import duan.tools.QueryPrint;
import duan.tools.ScannerChoice;
/**
* 商超购物管理系统主界面
* @author duan
* @version 2.0
*/
public final class MainPage extends ScannerChoice
{
/**
* 入口函数
*/
public static void main(String[] args)
{
MainPage.mainPage();
}
/**
* 主界面 已实现!已校验!
*/
public static void mainPage()
{
System.out.println("***************************\n");
System.out.println("\t 1.商品维护\n");
System.out.println("\t 2.前台收银\n");
System.out.println("\t 3.商品管理\n");
System.out.println("***************************");
System.out.println("\n请输入选项,或者按0退出.");
do
{
String choice = ScannerInfoString();
String regex = "[0-3]";//正则表达式
if (choice.matches(regex))
{
int info = Integer.parseInt(choice);
switch (info)
{
case 0:
System.out.println("------------------");
System.out.println("您已经退出系统!");
System.exit(1);//退出程序,返回值随便设置
break;
case 1:
MaintenancePage();
break;
case 2:
checkstandLogPage();
break;
case 3:
commodityManagementPage();
break;
default:
break;
}
}
System.err.println("!输入有误!");
System.out.println("重新选择或者按0退出.");
} while (true);
}
/**
* 1.商品维护界面
*/
public static void MaintenancePage()
{
System.out.println("***************************\n");
System.out.println("\t 1.添加商品\n");
System.out.println("\t 2.更改商品\n");
System.out.println("\t 3.删除商品\n");
System.out.println("\t 4.查询商品\n");
System.out.println("\t 5.显示所有商品\n");
System.out.println("***************************");
System.out.println("\n请输入选项,或者按 0 返回上一级菜单.");
do
{
String choice = ScannerInfoString();
String regex = "[0-5]";
if (choice.matches(regex))
{
int info = Integer.parseInt(choice);
switch (info)
{
case 0:
mainPage();
break;
case 1:
GoodsPage.addGoodsPage();
break;
case 2:
GoodsPage.updateGoodsPage();
break;
case 3:
GoodsPage.deleteGoodsPage();
break;
case 4:
GoodsPage.queryGoodsPage();
break;
case 5:
GoodsPage.displayGoodsPage();
break;
default:
break;
}
}
System.err.println("!输入有误!");
System.out.println("重新输入或按 0 返回上一级菜单.");
}while(true);
}
/**
* 2.前台收银登陆界面
*/
public static void checkstandLogPage()
{
System.out.println("\n*******欢迎使用商超购物管理系统*******\n");
System.out.println("\t 1.登录系统\n");
System.out.println("\t 2.退出\n");
System.out.println("-----------------------------");
System.out.println("请输入选项,或者按 0 返回上一级菜单.");
do
{
String choice = ScannerInfoString();
String regex = "[0-2]";
if (choice.matches(regex))
{
int info = Integer.parseInt(choice);
switch (info)
{
case 0:
mainPage();
break;
case 1:
int loginTimes = 3;//3次登陆机会
while (loginTimes!=0)
{
loginTimes--;
System.out.println("---用户名---");
String sName = ScannerInfoString();
System.out.println("---密码---");
String sPssWord = ScannerInfoString();
ArrayList<SalesMan> salesManInfo = new SalesManDao().checkstandLog(sName); //以用户名从数据库中获取用户密码.
if (salesManInfo == null || salesManInfo.size() == 0)//没有此用户的情况!
{
System.err.println("\t!!用户名输入有误!!\n");
System.out.println("\n剩余登陆次数:"+loginTimes);
}else
{
SalesMan salesMan = salesManInfo.get(0);//此地,只返回了一组数值,只遍历1次即可
if (sPssWord.equals(salesMan.getSPassWord()))//验证密码,登陆成功了!!
{
System.out.println("\t ---账户成功登陆---");
shoppingSettlementPage(salesMan.getSId());//参数为营业员编号sId
}else
{
System.err.println("\t!!密码错误!!\n");
System.out.println("\n剩余登陆次数:"+loginTimes);
}
}
}
//loginTimes = 0
System.out.println("------------------");
System.err.println("\t!!您已被强制退出系统!!");
System.exit(1);
break;
case 2:
System.out.println("------------------");
System.out.println("您已经退出系统!");
System.exit(-1);
break;
default:
break;
}
}
System.err.println("!输入有误!");
System.out.println("重新输入或按 0 返回上一级菜单");
}while(true);
}
/**
* 3.商品管理界面
*/
public static void commodityManagementPage()
{
System.out.println("***************************\n");
System.out.println("\t 1.售货员管理\n");
System.out.println("\t 2.列出当日卖出列表\n");
System.out.println("***************************");
System.out.println("\n请输入选项,或者按 0 返回上一级菜单.");
do
{
String choice = ScannerInfoString();
String regex = "[0-2]";
if (choice.matches(regex))
{
int info = Integer.parseInt(choice);
switch (info)
{
case 0:
mainPage();
break;
case 1:
salesManManagementPage();
break;
case 2:
GsalesPage.dailySaleGoodsPage();
break;
default:
break;
}
}
System.err.println("!输