package com.sec.shop;
import java.awt.AWTException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.InputMismatchException;
import java.util.Random;
import java.util.Scanner;
import util.DBUtil;
public class CustomerManager {
private int customerId;
private String customerNo;
private String customerName;
private String customerPwd;
static private float balance;
static private int score;
private String email;
private String phone;
private String address;
public int getCustomerId() {
return customerId;
}
public void setCustomerId(int customerId) {
this.customerId = customerId;
}
public String getCustomerNo() {
return customerNo;
}
public void setCustomerNo(String customerNo) {
this.customerNo = customerNo;
}
public String getCustomerName() {
return customerName;
}
public void setCustomerName(String customerName) {
this.customerName = customerName;
}
public String getCustomerPwd() {
return customerPwd;
}
public void setCustomerPwd(String customerPwd) {
this.customerPwd = customerPwd;
}
public float getBalance() {
return balance;
}
public void setBalance(float balance) {
this.balance = balance;
}
public int getScore() {
return score;
}
public void setScore(int score) {
this.score = score;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
private String remark;
static Scanner sc=new Scanner(System.in);
static SystemMenu sm=new SystemMenu();
static ProductManager pm=new ProductManager();
static CustomerManager cm=new CustomerManager();
static BuyManager bm=new BuyManager();
static CustomerDAO cd=new CustomerDAO();
static ProductDAO pd=new ProductDAO();
//定义selectCustomer()方法查询所有的客户信息
public void selectCustomer(){
try {
SystemMenu.clear();
} catch (AWTException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
System.out.println();
System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *");
System.out.println("*思宇青春购物系统 >>客户信息管理 >>显示所有客户信息 *");
System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *");
System.out.println();
System.out.println("会员号\t\t姓名\t\t余额\t\t积分\t");
System.out.println("-----------|---------------|--------------|--------------\n");
/*for(int i=0;i<list.size();i++){
CustomerManager cm=new CustomerManager();
System.out.println(cm.getCustomerNo()+"\t\t"+cm.getCustomerName()+"\t\t"+cm.getBalance()+"\t\t"+cm.getScore());
}*/
ArrayList<CustomerManager> list=cd.select(null,null,0);
System.out.println();
System.out.println();
}
//定义addCuCustomer()方法添加一个客户信息
public void addCustomer(){
try {
SystemMenu.clear();
} catch (AWTException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
System.out.println();
System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *");
System.out.println("*思宇青春购物系统 >>客户信息管理 >>添加客户信息 *");
System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *");
System.out.println();
CustomerManager cm=new CustomerManager();
Scanner sc=new Scanner(System.in);
cm.customerNo=autoCustomerNo();
cm.score=0;
System.out.println("请填写以下内容:\n");
System.out.println("客户姓名:");
cm.customerName=sc.next();
for(;;){
try{
System.out.println("客户密码:");
cm.customerPwd=sc.next();
boolean flag=cm.customerPwd.length()>=6;
if(flag){
break;
}
else{
System.out.println("\n客户密码不能少于6位,请重新输入:\n");
}
}catch(InputMismatchException e){
System.out.println("您的输入有误,请重新输入");
sc.nextLine();
}
}
for(;;){
try{
System.out.println("客户充值:");
cm.balance=sc.nextFloat();
if(cm.balance<100){
System.out.println("\n单次充值最低充值100元,请重新输入\n");
}else if(cm.balance>10000){
System.out.println("\n单次充值最高充值10000元,请重新输入\n");
}
else{
break;
}
}catch(InputMismatchException e){
System.out.println("您的输入有误,请重新输入");
sc.nextLine();
}
}
for(;;){
System.out.println("电子邮件:");
cm.email=sc.next();
int number=cm.email.indexOf("@");
int number1=cm.email.indexOf(".com");
if(number<0){
System.out.println("\n格式错误,电子邮件要有 @ 符号!\n");
}else if(number1<0){
System.out.println("\n格式错误,电子邮件要以 .com! 结尾!\n");
}else if(number>=number1){
System.out.println("\n格式错误,@ 符号应该出现在 .com之前!\n");
}
else{
break;
}
}
for(;;){
try{
System.out.println("联系电话:");
cm.phone=sc.next();
boolean flag=cm.phone.length()==11;
if(flag){
break;
}
else{
System.out.println("\n联系电话的长度是11位,请重新输入:\n");
}
}catch(Exception e){
System.out.println("您的输入有误,请重新输入");
sc.nextLine();
}
}
System.out.println("家庭地址:");
cm.address=sc.next();
System.out.println("备注信息:");
cm.remark=sc.next();
System.out.println("\n请稍后......");
if(cd.insert(cm)){
System.out.println("\n客户添加成功!");
}else{
System.out.println("\n客户添加失败,请重新输入!");
cm.addCustomer();
}
sm.returnUp();
sm.showCustomerMenu();
}
//定义updateCustomer()方法修改客户信息
public void updateCustomer(){
try {
SystemMenu.clear();
} catch (AWTException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
System.out.println();
System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *");
System.out.println("*思宇青春购物系统 >>客户信息管理 >>修改客户信息 *");
System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *");
System.out.println();
boolean flag;
System.out.println("请先登录:\n");
System.out.println("请输入会员号:");
cm.customerNo=sc.next();
System.out.println("请输入密码:");
cm.customerPwd=sc.next();
ArrayList<CustomerManager> list=cd.select(cm.customerNo, cm.customerPwd,0);
if(list.size()==1){
System.out.println("会员号\t\t姓名\t\t余额\t\t积分\t");
System.out.println("----------|----------------|-----------------|-----------------\n");
}
ArrayList<CustomerManager> list1=cd.select(cm.customerNo, cm.customerPwd,1);
if(list1.size()==1){
System.out.println("\n1.修改密码\n");
System.out.println("2.修改余额\n");
System.out.println("3.修改积分\n");
String answer="";
boolean flag_1;
do{
boolean flag_2;
do{
flag_2=true;
int choose = 0;
try{
System.out.println("\n请选择功能(1~3)");
choose =sc.nextInt();
switch(choose){
case 1:
System.out.println("请输入修改后的密码\n:");
String newCustomerPwd=sc.next();
System.out.println("\n请稍后......")