吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 4204|回复: 3
收起左侧

[Java 转载] 上次看到有人要JAVA的能连接数据库的管理系统,现在分享一个自己以前做的

  [复制链接]
521lht 发表于 2017-6-25 15:49
本帖最后由 521lht 于 2017-6-25 15:58 编辑

部分代码,功能在图片上
package edu.zjhzz.parts.controller;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import edu.zjhzz.parts.dao.PartsDao;
import edu.zjhzz.parts.dao.Sellerdao;
import edu.zjhzz.parts.dao.TCustomer;
import edu.zjhzz.parts.dao.TLoginDao;
import edu.zjhzz.parts.tables.Customer;
import edu.zjhzz.parts.tables.PartsInformation;
import edu.zjhzz.parts.tables.Seller;
import edu.zjhzz.parts.tables.TLogin;
import edu.zjhzz.parts.view.CustomerView;
import edu.zjhzz.parts.view.PartsView;
import edu.zjhzz.parts.view.SellerView;

public class PartsSystem {

        public static void main(String[] args) throws Exception {

                char userInput;
                Scanner keyboard=new Scanner(System.in);

                dispalayMenu();
                userInput=keyboard.nextLine().charAt(0);
                Customer cust;
                PartsInformation pin;
                Seller ser;
                String cId;
                String PartsId;
                String sId;
                TLoginDao tl=new TLoginDao();
                TLogin t=new TLogin();
                Scanner sc =new Scanner(System.in);
                System.out.println("----------用户登入------------");
                System.out.println("请输入账号:");
                String id=sc.nextLine();
                System.out.println("请输入密码:");
                String pd=sc.nextLine();
                t=tl.find(id, pd);
                if(t!=null){
                        System.out.println("登入成功");
                while(userInput!='q'){
                        switch(userInput){
                        case 'o':
                                List<PartsInformation> buy = new ArrayList<PartsInformation>();                                
                                String iscontinue ;
                            boolean isNewAdd = true;
//                            userInput=keyboard.nextLine().charAt(0);                    
                                   
                            do{
                            System.out.println("---------------------------开始购物--------------------------");
                                 List <PartsInformation> list1=PartsDao.getAllParts();
                                 PartsView.showAllPatsInformation(list1);
                            System.out.println("请输入需要购买的商品记录号:");
                        String buyId = keyboard.nextLine();
                        System.out.println("请输入需要购买的数量:");
                       String buyCount = keyboard.nextLine();
                      int a = Integer.parseInt(buyCount);
                      //判断buy的这个集合中是否有我们已经购买过的东西
                        for (int i = 0; i < buy.size(); i++) {
                            PartsInformation pina = buy.get(i);        
                            if (list1.get( Integer.parseInt(buyId) - 1).getProductName().equals(pina.getProductName())) {
                                    a+= pina.count;
                                buy.remove(pina);
                                isNewAdd = true;

                                            }            
                                        }
                        //把买的东西加入到集合中
                        if (isNewAdd) {
                            buy.add(new PartsInformation(list1.get( Integer.parseInt(buyId) - 1).getPartsId(),
                                            list1.get(Integer.parseInt(buyId) - 1).getProductName(),list1.get(Integer.parseInt(buyId) - 1).getPrice(),                          
                                            a));
                                        }
                        System.out.println("是否继续,1:继续 0 退出");
                        iscontinue = keyboard.nextLine();
                        } while (Integer.parseInt(iscontinue) != 0);
                    System.out.println("你购买的商品为");
//                        PartsView.showAllPatsInformation(buy);
                        for(PartsInformation pina:buy){
                                System.out.println(pina);
                        }
//                    keyboard.close();
                                break;
                        case 'a':
                        System.out.println("显示所有顾客的信息");
                        List<Customer> list=TCustomer.findAllSCus();
                        CustomerView.showAllCustomer(list);
                        break;
                        case 'b':
                                System.out.println("请输入顾客的id号");
                                cId=keyboard.nextLine();
                                cust=TCustomer.getOneCusomter(cId);
                                if(cust==null){
                                        System.out.println("查无此人");
                                }else{
                                        CustomerView.showOneCustomer(cust);
                                }
                                break;
                                
                        case 'c':
                                cust=new Customer();
                                System.out.println("请输入要添加的顾客信息");
                                System.out.println("请输入顾客编号");
                                cust.setcId(keyboard.nextLine());
                                System.out.println("请输入顾客名字");
                                cust.setcName(keyboard.nextLine());
                                System.out.println("请输入顾客电话");
                                cust.setcPhone(keyboard.nextLine());
                                System.out.println("请输入顾客地址");
                                cust.setmAddress(keyboard.nextLine());
                                System.out.println("请输入顾客性别");
                                cust.setmGender(keyboard.nextLine());
                                if(TCustomer.addOneCustomer(cust)){
                                        System.out.println("添加成功!");
                                }else
                                        System.out.println("添加失败!");
                                break;
                        //删除顾客信息        
                        case 'd':
                                System.out.println("请输入要删除顾客的编号:");
                                cId=keyboard.nextLine();
                                cust=TCustomer.getOneCusomter(cId);
                                if(cust==null){
                                        System.out.println("编号不存在!");
                                        break;
                                }
                                CustomerView.showOneCustomer(cust);;
                                System.out.println("确定要删除吗?(Y/N):");
                                if(!keyboard.nextLine().equalsIgnoreCase("Y"))
                                        break;
                                if(TCustomer.deleteOneStudent(cId))
                                        System.out.println("删除成功!");
                                else
                                        System.out.println("删除失败!");
                                break;
                                
                        case 'e':
                        System.out.println("请输入编号和地址:");
                        cId=keyboard.nextLine();
                        cust=TCustomer.getOneCusomter(cId);
                        if(cust==null){
                                System.out.println("查无此人");
                                break;
                        }
                        CustomerView.showOneCustomer(cust);
                        System.out.println("请输入顾客地址");
                        String cPhone=keyboard.nextLine();
                        if(TCustomer.modifyName(cPhone, cId)){
                                System.out.println("修改成功");
                        }else{
                                System.out.println("修改失败");
                        }                                
                        break;
                                
                        case 'f':
               
                        pin =new PartsInformation();
                        System.out.println("请输入要添加的配件信息");
                        System.out.println("请输入配件编号");
                        pin.setPartsId(keyboard.nextLine());
                        System.out.println("请输入配件名字");
                        pin.setProductName(keyboard.nextLine());
                        System.out.println("请输入配件售价");
                        pin.setPrice(keyboard.nextLine());
                        System.out.println("请输入配件进价");
                        pin.setPurchasePrice(keyboard.nextLine());
                        System.out.println("请输入产地");
                        pin.setOrigin(keyboard.nextLine());
                        System.out.println("请输入库存");
                        pin.setCgt(keyboard.nextLine());
                        if(PartsDao.addOneParts(pin)){
                                System.out.println("添加成功!");
                        }else
                                System.out.println("添加失败!");
                        break;
                        
                        case 'g':
                                System.out.println("请输入配件编号");
                                PartsId=keyboard.nextLine();
                                pin=PartsDao.getOne(PartsId);
                                if(pin==null){
                                        System.out.println("查无此人");
                                }else{
                                        PartsView.showOneParts(pin);
                                }
                                break;
                        case 'h':
                                System.out.println("显示所有配件信息");
                                List <PartsInformation> list1=PartsDao.getAllParts();
                                PartsView.showAllPatsInformation(list1);
                                break;
                        case 'i':
                                System.out.println("请输入要删除配件编号:");
                                PartsId=keyboard.nextLine();
                                pin=PartsDao.getOne(PartsId);
                                if(pin==null){
                                        System.out.println("编号不存在!");
                                        break;
                                }
                                PartsView.showOneParts(pin);
                                System.out.println("确定要删除吗?(Y/N):");
                                if(!keyboard.nextLine().equalsIgnoreCase("Y"))
                                        break;
                                if(PartsDao.deleteOneParts(PartsId))
                                        System.out.println("删除成功!");
                                else
                                        System.out.println("删除失败!");
                                break;
                        case 'j':
                                System.out.println("请输入编号,名字,售价,进价");
                                PartsId=keyboard.nextLine();
                                pin=PartsDao.getOne(PartsId);
                                if(pin==null){
                                        System.out.println("查无次配件");
                                        break;
                                }
                        PartsView.showOneParts(pin);
                                System.out.println("请输入名字,售价,进价");
                                String pname=keyboard.nextLine();
                                String pp=keyboard.nextLine();
                                String pc=keyboard.nextLine();
                                if(PartsDao.updateParts(PartsId, pname, pp, pc)){
                                        System.out.println("修改成功");
                                }else{
                                        System.out.println("修改失败");
                                }                                
                                break;
                        case 'k':
                                
                        ser=new Seller();
                                System.out.println("请输入要添加的配件信息");
                                System.out.println("请输入卖家编号");
                                ser.setsId(keyboard.nextLine());
                                System.out.println("请输入卖家电话");
                                ser.setsPhone(keyboard.nextLine());
                                System.out.println("请输入卖家地址");
                                ser.setsAddress(keyboard.nextLine());                                
                                if(Sellerdao.addOneSeller(ser)){
                                        System.out.println("添加成功!");
                                }else
                                        System.out.println("添加失败!");
                                break;
                        
                                case 'l':
                                        System.out.println("请输入卖家的id号");
                                        sId=keyboard.nextLine();
                                        ser=Sellerdao.getOneSeller(sId);
                                        if(ser==null){
                                                System.out.println("查无此卖家");
                                        }else{
                                        SellerView.showOneSeller(ser);
                                        }
                                        break;
                                case 'm':
                                        System.out.println("显示所有卖家的信息");
                                        List<Seller> list2=Sellerdao.getAllSeller();
                                        SellerView.showAllSeller(list2);
                                        break;
                                
                        }
                        dispalayMenu2();
                        userInput=keyboard.nextLine().charAt(0);
                        
                        }
                }
        else{
                System.out.println("用户名或密码错误");
        }
        
                keyboard.close();

        }
        public static void dispalayMenu()
        {
                System.out.println("\t请选择:");
                System.out.println("a-显示所有顾客信息");
                System.out.println("b-根据显示对编码应顾客信息");
                System.out.println("c-添加顾客信息");
                System.out.println("d-删除顾客信息");
                System.out.println("e-修改顾客地址");
               
               
                System.out.println("f-添加配件信息");
                System.out.println("g-根据配件编号查询配件");
                System.out.println("h-显示所有的配件信息");
                System.out.println("i-删除配件信息");
               

                System.out.println("k-添加卖家信息");
                System.out.println("l-根据卖家id查看卖家信息");
                System.out.println("m-查看所有卖家信息");
                System.out.println("q-退出系统");
               
                System.out.println("-------请选择功能后登入--------");
        }
        public static void dispalayMenu2()
        {
                System.out.println("\t请选择:");
                System.out.println("a-显示所有顾客信息");
                System.out.println("b-根据显示对编码应顾客信息");
                System.out.println("c-添加顾客信息");
                System.out.println("d-删除顾客信息");
                System.out.println("e-修改顾客地址");
               
               
                System.out.println("f-添加配件信息");
                System.out.println("g-根据配件编号查询配件");
                System.out.println("h-显示所有的配件信息");
                System.out.println("i-删除配件信息");

               
                System.out.println("k-添加卖家信息");
                System.out.println("l-根据卖家id查看卖家信息");
                System.out.println("m-查看所有卖家信息");
                System.out.println("q-退出系统");
               
                System.out.println("-------欢迎光临零配件交易系统--------");
        }
}

百度地址:http://pan.baidu.com/s/1hs1h1QW 密码:6ssq
分享的内容里面没有数据库文件,需要大家自己创建,表格属性在tables里面有


{7$ND`D@[4XP43]4$UW65LH.png

文件目录

文件目录

免费评分

参与人数 1吾爱币 +1 热心值 +1 收起 理由
long9 + 1 + 1 用心讨论,共获提升!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

liuxia 发表于 2017-6-25 17:09
学习学习
rzhxw 发表于 2017-6-25 18:19
zt1995 发表于 2017-6-25 22:54
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-4-25 08:16

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表