java项目实战-超市管理系统(三)页面设计源码

一、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("!输入有误!");
				System.out.println("重新输入或按 0 返回上一级菜单.");
			}while(true);
		}
					
	/**
	 * 购物结算界面
	 */
		public static void shoppingSettlementPage(int salesManSid)
		{
			System.out.println("\n\t*******购物结算*******\n");
			do
			{
				System.out.println("按 S 开始购物结算.按 0 返回账户登录界面");
				String choNext = ScannerInfoString();
				if ("0".equals(choNext))
				{
					checkstandLogPage();
					
				}else if ("s".equals(choNext) || "S".equals(choNext)) 
						{
							System.out.println("\n--请输入商品关键字--");
							
							int gid = QueryPrint.querySettlement();//当商品件数有且只有一件时返回商品gid号,商品已售空时返回 -1. >1件时返回-2 . 查无此商品时返回-3
							
							switch (gid)
							{
							case -3:
								//无此商品,重新循环
								break;
							case -1:
								System.err.println("\t--抱歉,该商品已售空--");
								break;
								
							default:
								System.out.println("--按商品编号选择商品--");
							 		
							 	//传参gid,调用精确查询商品
							 	int shoppingGid = ScannerNum();
								
							 	ArrayList<Goods> goodsList = new QueryPrint().queryGoodsKey(shoppingGid,null);
								if (goodsList == null || goodsList.size() == 0)
								{
									System.err.println("\t!!查无此商品 !!\n");
								}else 
									{
										Goods goods = goodsList.get(0);
										int gNum = goods.getGnum();	
										double gPrice = goods.getGprice(); 
										
										System.out.println("--请输入购买数量--");
										do
										{
											int choicegoodsNum = ScannerNum();//获取用户要购买的数量
											
											if (choicegoodsNum > gNum)
											{
												System.err.println("\t!!仓库储备不足!!");
												System.out.println("--请重新输入购买数量--");
											}else 
												{
													double allPrice = Arith.mul(choicegoodsNum, gPrice);//利用BigDecimal作乘法运算
													System.out.println("\t\t\t  购物车结算\n");
													System.out.println("\t\t商品名称\t商品单价\t购买数量\t总价\n");
													System.out.println("\t\t"+goods.getGname()+"\t"+gPrice+" $\t"+choicegoodsNum+"\t"+allPrice+" $\n");
													
													do
													{
														System.out.println("确认购买:Y/N");
														String choShopping = ScannerInfoString(); 
														if ("y".equals(choShopping) || "Y".equals(choShopping))
														{
															System.out.println("\n总价:"+allPrice+" $");
															System.out.println("\n实际缴费金额");
															
															do
															{
																double amount = ScannerInfo();
																double balance = Arith.sub(amount, allPrice);  //用户交钱与购买物品总价间的差额
																if (balance < 0)
																{
																	System.err.println("\t!!缴纳金额不足!!");
																	System.out.println("\n请重新输入缴纳金额($)");
																}else{																
																	
		/*	这里是购物结算操作数据库!!!!!!----------------------	  1.更改goods表数量 
		  														  2.增加sales表数量
																原商品数量gNum。 结算员Id  salesManSid */
																
																	//对sales表操作
																	Gsales gSales = new Gsales(goods.getGid(),salesManSid,choicegoodsNum);
																	boolean insert = new GsalesDao().shoppingSettlement(gSales);
																	
																	//对goods表操作
																	int goodsNewNum = gNum - choicegoodsNum; //现在goods表中该商品数量
																	Goods newGoods = new Goods(goods.getGid(),goodsNewNum);
																	boolean update = new GoodsDao().updateGoods(3,newGoods);
											
																		if (update && insert)
																		{
																			System.out.println("找零:"+balance);
																			System.out.println("\n谢谢光临,欢迎下次惠顾");
																		}else 
																			{
																				System.err.println("!支付失败!"); //出现这个错误一定是数据库操作有问题!
																			}
																	shoppingSettlementPage(salesManSid);//最后跳转到到购物结算页面
	   //	结束购物结算操作数据库!!!!!!-----------------------------------
																	 }
															} while (true);	
															
														}else if ("N".equals(choShopping) || "n".equals(choShopping)) 
																{
																	shoppingSettlementPage(salesManSid);
																}
														System.err.println("\t!!请确认购物意向!!");
													} while (true);
												}
										} while (true);
									}					
								break;
							}
						}else
							{
								System.err.println("\t!!请输入合法字符!!\n");
							}
			} while (true);
		}

	/**
	 * 售货员管理界面
	 */
	public static void salesManManagementPage()
	{

		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:
					commodityManagementPage();
					break;
				case 1:
					SalesManPage.addSalesManPage();
					break;
				case 2:
					SalesManPage.updateSalesManPage();
					break;
				case 3:
					SalesManPage.deleteSalesManPage();
					break;
				case 4:
					SalesManPage.querySalesManPage();
					break;
				case 5:
					SalesManPage.displaySalesManPage();
					break;
				default:
					break;
				}
			}
			System.err.println("\t!输入有误!");
			System.out.println("重新输入或按 0 返回上一级菜单.");
		}while(true);
	}
}

二、duan.page.GoodsPage

package duan.page;

import java.util.ArrayList;

import duan.dao.GoodsDao;
import duan.entity.Goods;
import duan.tools.QueryPrint;
import duan.tools.ScannerChoice;

/**
 * 操作商品界面
 * @author duan
 */

public final class GoodsPage extends ScannerChoice
{

	/**
	 * 1.添加商品界面
	 */
	public static void  addGoodsPage()
	{
		
		System.out.println("\t正在执行添加商品操作\n");
		
		System.out.println("\n請輸入添加商品-名称");
		String goodsName = ScannerInfoString();
		
		System.out.println("\n請輸入添加商品-价格");
		double goodsPrice = ScannerInfo();
	
		System.out.println("\n請輸入添加商品-数量");
		int goodsNumber = ScannerNum();
		
		Goods goods  = new Goods(goodsName,goodsPrice,goodsNumber);
		boolean bool = new GoodsDao().addGoods(goods);
		
		if (bool)
		{
			System.out.println("\n\t!您已成功添加商品到数据库!");			
		}else 
			{
				System.out.println("添加商品失败");	
			}
	 changedInfoNext("addGoodsPage");//选择下一步
	}

	/**
	 * 2.更改商品界面
	 */
	public static void  updateGoodsPage()
	{
		System.out.println("\t正在执行 更改商品 操作\n");
		System.out.println("请输入想要更改的商品名字");
		
		//调用查找商品函数,显示将要更改的商品信息
		int gid = QueryPrint.query("updateGoodsPage"); //return the goods gid

		System.out.println("\n--------请选择您要更改的内容\n");
		System.out.println("\t1.更改商品-名称");
		System.out.println("\t2.更改商品-价格");
		System.out.println("\t3.更改商品-数量");
		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:
					 MainPage.MaintenancePage();
					 break;
				 case 1:
					 System.out.println("请输入商品-新名称");
					 String gname = ScannerInfoString();
					 Goods goodsName = new Goods(gid,gname);
					 boolean boolName = new GoodsDao().updateGoods(1, goodsName);
					 if (boolName)
					 {
						 System.out.println("\n\t!!成功更新商品名至数据库!!\n");
					 }else 
					 	{
						 	System.err.println("\n\t!!更新商品名失敗!!");
					 	}
					 changedInfoNext("updateGoodsPage");
					 break;
				 case 2:
					 System.out.println("请输入商品-新价格 ");
					 double gprice = ScannerInfo();
					 Goods  goodsPrice = new Goods(gid,gprice);
					 boolean boolPrice = new GoodsDao().updateGoods(2,goodsPrice);
					 
					 if (boolPrice)
					 {
						 System.out.println("\n\t!!成功更新商品价格至数据库!!\n");
					 }else 
					 	{
						 	System.err.println("\n\t!!更新商品价格失敗!!");
					 	}
					 changedInfoNext("upateGoodsPage");
					 break;
				 case 3:
					 System.out.println("请输入商品-新数量 ");
					 int gNum = ScannerNum();	
					 Goods  goodsNum= new Goods(gid,gNum);
					 boolean boolNum = new GoodsDao().updateGoods(3,goodsNum);
					 if (boolNum)
					 {
						 System.out.println("\n\t!!成功更新商品数量至数据库!!\n");
					 }else 
					 	{
						 	System.err.println("\n\t!!更新商品数量失敗!!");
					 	}
					 	changedInfoNext("upateGoodsPage");
					 break;
				 default:
					 System.out.println("请输入正确的选择!");
				 break;
				 }
			 }
			 System.err.println("!输入有误!");
			System.out.println("请重新选择,或者按0返回上一级菜单.");
		 } while (true);	
	}
	
	/**
	 * 3.删除商品界面
	 */
	public static void deleteGoodsPage()
	{
		System.out.println("\t正在执行 删除商品 操作\n");
		System.out.println("请输入想要删除的商品名字");
		
		//调用查找商品函数,显示将要删除的商品
		int gid = QueryPrint.query("deleteGoodsPage"); //return the goods gid
		
		//确认删除!
			do
			{
				System.out.println("\n确认删除该商品:Y/N");
				String choice = ScannerInfoString();
					if ("y".equals(choice) || "Y".equals(choice))
					{
						//进行刪除-数据库操作
						boolean boolDeleteGoods = new GoodsDao().deleteGoods(gid);//調用刪除功能
						
						if (boolDeleteGoods)
						{
							System.err.println("\t!!已成功刪除该商品!!\n");
						}else 
							{
								System.err.println("\n\t!!刪除该商品失敗!!");
							}
						changedInfoNext("deleteGoodsPage"); 
					}else if ("N".equals(choice) || "n".equals(choice)) 
							{
								MainPage.MaintenancePage();
							}
				System.out.println("\t!!输入有误,请重新输入!!\n");
			} while (true);
	}

	/**
	 * 4.查询商品界面
	 */
	public static void queryGoodsPage()
	{
		System.out.println("\t\t  正在执行查询商品操作\n");
		System.out.println("\t\t1.按照商品 数量升序 查询");
		System.out.println("\t\t2.按照商品 价格升序 查询");
		System.out.println("\t\t3.输入商品  关键字  查询");
		System.out.println("\n请输入选项,或者按0返回上一级菜单.");
			
		 do
		{
			 String info = ScannerInfoString();//用户选择上述提示信息
			 String regex = "[0-3]";
			 if (info.matches(regex))
			 { 
				 int choice = Integer.parseInt(info);
				 switch (choice)
				 {
				 case 0:
					 MainPage.MaintenancePage();
					 break;
				 case 1:
				 case 2:
				 case 3:
					 if (choice == 3)//当用户使用3(即关键字查询)时,需要打印此项目。
					 {
						 System.out.println("\t\t正在执行商品  关键字  查询操作\n");
						 System.out.println("\n请输入商品关键字");
					 }
					 //调用查询功能
					 ArrayList<Goods> goodsList = new GoodsDao().queryGoods(choice);
					 if (goodsList == null || goodsList.size() <= 0)
					 {
						 System.err.println("\n\t!!您查询的商品不存在!!\n");
						 queryGoodsPage();
					 } else
					 	  {
							 if (choice == 1) //打印目录,不要放在功能函数中,会影响其他方法调用
							 {	
								 System.out.println("\t\t\t\t\t商品按照 数量升序 列表\n\n");
							 }else if (choice == 2) 
									 {
										 System.out.println("\t\t\t\t\t商品按照 价格升序 列表\n\n");
									 }else
										 {
											 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,length = goodsList.size(); i < length; i++)
							 {
								 Goods goods = goodsList.get(i);
								 System.out.print("\t"+goods.getGid()+"\t\t"+goods.getGname()+"\t\t"+goods.getGprice()+"\t\t"+goods.getGnum());
								 int gnum = goods.getGnum();
								 if (gnum ==0)
								 {
									 System.out.println("\t\t该商品已售空!");
								 }else if (gnum<10)
										 {
											 System.out.println("\t\t该商品已不足10件");
										 }else 
											 {
												 System.out.println("\t\t-");
											 }
								 System.out.println("\t");
							 }
						 	System.out.println("---------------------");
							 do
							{
								 System.out.println("输入 0 返回上一级菜单");
								 String choiceNext = ScannerInfoString();
								
								 if ("0".equals(choiceNext))
								{
									 MainPage.MaintenancePage();
								}
								 System.err.println("输入有误!");
							} while (true);
					 	  }
					 break;
				 default:
				 break;
				 }
			 break;
			 }
		 System.err.println("输入有误!");
		 System.out.println("请重新选择,或者按0返回上一级菜单.");
		} while (true);

		 //用户选择操作完查询后的下一步
		System.out.println("\n\n输入 0 返回上一级菜单");
		boolean boolNext = true;
		 do
		{
			 String choice = ScannerInfoString();
			 if ("0".equals(choice))
			 { 
				 boolNext = false;
				 queryGoodsPage();
			 }
			System.err.println("!输入有误!");
			System.out.println("请输入 0 返回上一级菜单");
		} while (boolNext);	
	}

	/**
	 * 5.展示所有商品界面
	 */
	public static void displayGoodsPage()
	{
		System.out.println("\t\t\t\t\t所有商品列表\n\n");
		ArrayList<Goods> goodsList = new GoodsDao().displayGoods();
		
		if (goodsList.size() <= 0)
		{
			System.err.println("!库存为空!");
			MainPage.MaintenancePage();
		}else 
			{
				System.out.println("\t商品编号\t\t商品名称\t\t商品价格\t\t商品数量\t\t备注\n");
				for (int i = 0,length = goodsList.size(); i < length; i++) //避免重复计算变量,浪费资源!
				{
					Goods goods = goodsList.get(i);
					System.out.print("\t"+goods.getGid()+"\t\t"+goods.getGname()+"\t\t"+goods.getGprice()+" $\t\t"+goods.getGnum());
					
					int gNum = goods.getGnum();
					if (gNum==0)
					{
						System.out.println("\t\t该商品已售空!");
					}else if (gNum<10) 
							{
								System.out.println("\t\t该商品已不足10件");
							}else
								{
									System.out.println("\t\t-");
								}
					System.out.println("\t");
				}
				//下一步
				System.out.println("---------------------");
				do
				{
					System.out.println("输入 0 返回上一级菜单");
					String choice = ScannerInfoString();
					if ("0".equals(choice))
					{
						MainPage.MaintenancePage();
					}
					System.out.println("输入有误!");
				} while (true);
			}
	}
}

三、duan.page.GsalesPage

package duan.page;

import java.util.ArrayList;

import duan.dao.GsalesDao;
import duan.entity.Gsales;
import duan.tools.ScannerChoice;

/**
 * 当日卖出商品列表界面
 * @author duan
 */

public final class GsalesPage
{
	public static void dailySaleGoodsPage()
	{
		System.out.println("\t正在执行列出当日售出商品列表操作\n");
		ArrayList<Gsales> GsalesList = new GsalesDao().dailyGsales();//当日售出商品数组集

		if (GsalesList.size() <= 0)
		{
			System.err.println("\t!!今日无商品售出!!");
			MainPage.commodityManagementPage();
		}else 
			{
				System.out.println("\t\t\t\t今日售出商品列表\n");
				System.out.println("\t商品名称\t\t商品价格\t\t商品数量\t\t销量\t\t备注\n");
	
				for (int i = 0,length = GsalesList.size(); i < length; i++)
				{
					//获取售出商品:gname,gprice,gnum
					Gsales gSales = GsalesList.get(i);
					System.out.print("\t"+gSales.getGName()+"\t\t"+gSales.getGPrice()+" $\t\t"+gSales.getGNum()+"\t\t");
					int gNUm = gSales.getGNum();
					if (gNUm==0)
					{
						System.out.println("\t\t该商品已售空");
					}else if (gNUm<10)
							{
								System.out.println("\t\t该商品已不足10件");
							}else 
								{
									System.out.println("\t\t-");
								}
				  System.out.println("\t");
				}
				do
				{
					System.out.println("\n\n输入 0 返回上一级菜单");
					String choice = ScannerChoice.ScannerInfoString();
					if ("0".equals(choice))
					{
						MainPage.salesManManagementPage();
					}
				 MainPage.commodityManagementPage();
				} while (true);
			}
	}
}

4、duan.page.SalesManPage

package duan.page;

import java.util.ArrayList;

import duan.dao.SalesManDao;
import duan.entity.SalesMan;
import duan.tools.QueryPrint;
import duan.tools.ScannerChoice;

/**
 * 操作售货员界面           
 * @author duan
 */

public final class SalesManPage extends ScannerChoice
{
	/**
	 * 1.添加售货员界面 
	 */
	public static void  addSalesManPage()
	{
		System.out.println("\t正在执行添加售货员操作\n");
		
		System.out.println("\n添加售货员-姓名");
		String sName = ScannerInfoString();
		
		System.out.println("\n添加售货员-密码");
		String sPssswd = ScannerInfoString();
		
		SalesMan salesMan = new SalesMan(sName,sPssswd);
		boolean bool = new SalesManDao().addSalesMan(salesMan);
		
		if (bool)
		{
			System.out.println("\n\t!您已成功添加售货员到数据库!");
		}else 
			{
				System.out.println("添加售货员失败");	
			}
	 choiceSalesManNext("addSalesMan");
	}
	
	/**
	 * 2.更改售货员界面
	 */
	public static void updateSalesManPage()
	{
		System.out.println("\t正在执行更改售货员操作\n");
		System.out.println("请输入想要更改的售货员名字");
		String sName = ScannerInfoString();

		//调用精确查找售货员函数
		ArrayList<SalesMan> salesManList = new QueryPrint().querySalesMan(sName);
			if (salesManList.size() <= 0)
			{
				System.err.println("\t!!查无此人!!");
				choiceSalesManNext("updateSalesMan");
			}else 
				{
					//显示将要更改的售货员信息
					System.out.println("\t\t\t售货员信息\n\n");
					System.out.println("\t售货员编号\t\t售货员姓名\t\t售货员密码");
					
					SalesMan salesMan = salesManList.get(0); //上面的精确查找中,只能返回一组数值。无需遍历!
					System.out.println("\t"+salesMan.getSId()+"\t\t\t"+salesMan.getSName()+"\t\t\t"+salesMan.getSPassWord());
					System.out.println();
					
					//选择更改售货员内容
					System.out.println("\n--------请选择您要更改的内容\n");
					System.out.println("\t1.更改售货员-姓名");
					System.out.println("\t2.更改售货员-密码");
					do
					{
						String choice = ScannerInfoString();
						String regex  = "[0-2]";
						if (choice.matches(regex))
						{
							int info = Integer.parseInt(choice);
							switch (info)
							{
							case 0:
									MainPage.salesManManagementPage();
								break;
							case 1:
									System.out.println("更改售货员-新姓名");
									String sNewName = ScannerInfoString();
									
									SalesMan salesManName = new SalesMan(salesMan.getSId(),sNewName,null);
									boolean boolsName = new SalesManDao().updateSalesMan(1, salesManName);
									
									if (boolsName)
									{
										System.out.println("\n\t!!成功更新售货员名字至数据库!!\n");
									}else 
										{
											System.err.println("\n\t!!更新售货员名字失敗!!");
										}
									choiceSalesManNext("updateSalesMan");
								break;
							case 2:
									System.out.println("更改售货员-新密码");
									String sNewPasswd = ScannerInfoString();
									
									SalesMan salesManPasswd = new SalesMan(salesMan.getSId(),null,sNewPasswd);
									boolean boolsPasswd = new SalesManDao().updateSalesMan(2, salesManPasswd);
									
									if (boolsPasswd)
									{
										System.out.println("\n\t!!成功更新售货员密码至数据库!!\n");
									}else 
										{
											System.err.println("\n\t!!更新售货员密码失敗!!");
										}
									choiceSalesManNext("updateSalesMan");
								break;
							default:
								break;
							}
						}
						System.out.println("\t!输入有误!");
						System.out.println("\n请选择选项.或者按 0 返回上一级菜单.");
					} while (true);
				}
	}

	/**
	 * 3.删除售货员界面
	 */
	public static void deleteSalesManPage()
	{
		
		System.out.println("\t正在执行 删除售货员 操作\n");
		System.out.println("请输入想要删除的售货员名字");
		String sName = ScannerInfoString();
		
		//调用精确查找售货员函数
		ArrayList<SalesMan> salesManList = new QueryPrint().querySalesMan(sName);
			if (salesManList.size() <= 0)
			{
				System.err.println("\t!!查无此人!!");
				choiceSalesManNext("deleteSalesMan");
			}else 
				{
					//显示将要删除的售货员信息
					System.out.println("\t\t\t删除售货员信息\n\n");
					System.out.println("\t售货员编号\t\t售货员姓名\t\t售货员密码");
					
					for (int i = 0,length = salesManList.size(); i < length; i++)
					{
						SalesMan salesMan = salesManList.get(i);
						System.out.println("\t"+salesMan.getSId()+"\t\t\t"+salesMan.getSName()+"\t\t\t"+salesMan.getSPassWord());
						System.out.println();
					}
					//确认是否真的删除!
					do
					{
						System.out.println("\n确认删除该售货员:Y/N");
						String choice = ScannerInfoString();
						if ("y".equals(choice) || "Y".equals(choice))
						{
							//进行刪除-数据库操作
							boolean boolDeleteSalesMan = new SalesManDao().deleteSalesMan(sName);//調用刪除功能
							
							if (boolDeleteSalesMan)
							{
								System.err.println("\t!!已成功刪除该售货员!!\n");
							}else 
								{
									System.err.println("\t!!刪除该售货员失敗!!");
								}
							choiceSalesManNext("deleteGoods"); 
						}else if ("N".equals(choice) || "n".equals(choice)) 
						{
							MainPage.salesManManagementPage();
						}
						System.err.println("\t!!输入有误,请重新输入!!");
					} while (true);
				}
	}
	
	
	/**
	 * 4.查询售货员界面 已实现!
	 */
		public static void querySalesManPage()
		{
			System.out.println("\t\t  正在执行查询售货员操作\n");
			System.out.println("要查询的售货员关键字");
			String sName = ScannerInfoString();
			
			ArrayList<SalesMan> salesManList = new SalesManDao().querySalesMan(sName);
				
			if (salesManList.size() <=0)
			{
				System.err.println("\t!没有人员符合查询条件!");
			}else 
				{
					System.out.println("\t\t\t所有售货员列表\n\n");
					System.out.println("\t售货员编号\t\t售货员姓名\t\t售货员密码");
					
					for (int i = 0,length = salesManList.size(); i < length; i++)
					{
						SalesMan salesMan = salesManList.get(i);
						System.out.println("\t"+salesMan.getSId()+"\t\t\t"+salesMan.getSName()+"\t\t\t"+salesMan.getSPassWord());
						System.out.println();
					}
				}
		 choiceSalesManNext("querySalesMan"); //param:调用者
		}
		
	/**
	 * 5.显示所有售货员界面
	 */
	public static void displaySalesManPage()
	{
		ArrayList<SalesMan> salesManList = new SalesManDao().displaySalesMan();
		if (salesManList.size() <= 0)
		{
			System.err.println("\t!!售货员列表为空!!");
			MainPage.salesManManagementPage();
		}else 
			{
				System.out.println("\t\t\t所有售货员列表\n\n");
				System.out.println("\t售货员编号\t\t售货员姓名\t\t售货员密码");
				
				for (int i = 0,length = salesManList.size(); i < length; i++)
				{
					SalesMan salesMan = salesManList.get(i);
					System.out.println("\t"+salesMan.getSId()+"\t\t\t"+salesMan.getSName()+"\t\t\t"+salesMan.getSPassWord());
					System.out.println();
				}
				do
				{
					System.out.println("\n\n输入 0 返回上一级菜单");
					String choice = ScannerInfoString();
					
					if ("0".equals(choice))
					{
						MainPage.salesManManagementPage();
					}
					System.err.print("\t输入有误!");
				} while (true);
			}
	}
}

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页