package MobileContacts.service;
import java.awt.List;
import java.util.Scanner;
import MobileContacts.dao.Impl.MContactsDaoImpl;
import MobileContacts.entity.Contacts;
public class MobileContactsService {
Scanner sc = new Scanner(System.in);
MContactsDaoImpl mdi = new MContactsDaoImpl();
public void contactsMean() {
// TODO Auto-generated method stub
System.out.println("*****欢迎使用手机通讯录*********");
System.out.println("请您选择你需要的功能:");
System.out.println("1.增加联系人:");
System.out.println("2.删除联系人:");
System.out.println("3.修改联系人:");
System.out.println("4.查询联系人:");
System.out.println("5.显示所有联系人");
System.out.println("0.退出系统");
System.out.println("*******************************");
}
public String getOption() {
// TODO Auto-generated method stub
return sc.next();
}
public void createContacts() {
// 增加联系人
System.out.println("增加联系人:");
System.out.println("请输入联系人名字:");
String name = sc.next();
if(mdi.getContactsByName(name)==null){
System.out.println("请输入联系人手机号:");
String phone = sc.next();
if(phone.matches("1[34578][0-9]{9}")){
System.out.println("请输入联系人微信号:");
String weChar = sc.next();
mdi.insertContacts(new Contacts(name,phone,weChar));
System.out.println(name+"的信息保存成功!");
ask();
}else{
System.out.println("手机号码格式不正确");
}
}else{
System.out.println("联系人姓名已经存在(如果同名请重命名加以区分)");
}
}
public void delectContacts() {
// 删除联系人
System.out.println("---------删除联系人---------------------");
getAll();
System.out.println("请问您想根据什么删除");
System.out.println("1.联系人名字---2.微信---3.返回上一级---0.退出");
boolean flag = true;
while(flag){
switch(getOption()){
case "1":
System.out.println("请输入要删除的联系人名字:");
String name =sc.next();
System.out.println("您确定要删除吗?(Y/N)");
String choose =sc.next();
if(choose.equals("y")||choose.equals("Y")){
Contacts con = mdi.getContactsByName(name);
if(con!=null){
mdi.deleteContacts(con);
System.out.println("删除成功");
}else{
System.out.println("输入的联系人不存在请检查");
}
}else if(choose.equals("n")||choose.equals("N")){
System.out.println("未删除!");
contactsMean();
}else{
System.out.println("选项有误,请确认");
delectContacts();
}
flag = false;
break;
case "2":
System.out.println("请输入要删除的微信号码:");
String weChar =sc.next();
System.out.println("您确定要删除吗?(Y/N)");
String choose1 =sc.next();
if(choose1.equals("y")||choose1.equals("Y")){
Contacts con = mdi.getContactsByName(weChar);
if(con!=null){
mdi.deleteContacts(con);
System.out.println("删除成功");
}else{
System.out.println("输入微信号有误!请检查");
}
}else if(choose1.equals("n")||choose1.equals("N")){
System.out.println("未删除!");
contactsMean();
}else{
System.out.println("选项有误,请确认");
delectContacts();
}
flag = false;
break;
case "3":
flag = false;
break;
case "0":
System.out.println("谢谢使用本系统!再见");
System.exit(0);
default:
System.out.println("输入选项有误!");
}
}
}
public void getAll() {
// 显示所有联系人
if(mdi.getMenus()!=null){
System.out.println("----------------------------------------");
System.out.println("联系人\t\t手机号码\t\t\t微信");
for(Contacts c:mdi.getMenus()){
System.out.println(c.getName()+"\t\t"+c.getPhone()+"\t\t"+c.getWeChar());
}
System.out.println("----------------------------------------");
}else{
System.out.println("没有数据!!!!");
}
}
public void ask() {
// TODO Auto-generated method stub
System.out.println("是否要回到主界面(y/n)");
String choose =sc.next();
if(choose.equals("y")||choose.equals("Y")){
}else if(choose.equals("n")||choose.equals("N")){
System.out.println("谢谢使用本系统!再见");
System.exit(0);
}else{
System.out.println("选项有误,请确认");
ask();
}
}
public void alterContacts() {
//修改页面
System.out.println("---------修改联系人---------------------");
System.out.println("请输入要修改的联系人名字");
String name = sc.next();
Contacts con = mdi.getContactsByName(name);
if(con != null){
System.out.println("您确定要修改该联系人?");
String choose =sc.next();
if(choose.equals("y")||choose.equals("Y")){
mdi.deleteContacts(con);
System.out.println("请输入该联系人新的名字:");
String newName = sc.next();
if(mdi.getContactsByName(newName)==null){
System.out.println("请输入联系人手机号:");
String phone = sc.next();
if(phone.matches("1[34578][0-9]{9}")){
System.out.println("请输入联系人微信号:");
String weChar = sc.next();
mdi.insertContacts(new Contacts(newName,phone,weChar));
System.out.println(name+"的信息更新成功!");
ask();
}else{
System.out.println("手机号码格式不正确");
}
}else{
System.out.println("联系人姓名已经存在(如果同名请重命名加以区分)");
}
}else if(choose.equals("n")||choose.equals("N")){
System.out.println("谢谢使用本系统!再见");
System.exit(0);
}else{
System.out.println("选项有误,请确认");
ask();
}
}else{
System.out.println("未找到该联系人!请确认");
}
}
public void getContacts() {
// 查询
System.out.println("---------查询联系人---------------------");
getAll();
System.out.println("请问您想根据什么查询");
System.out.println("1.联系人名字---2.微信---3.返回上一级---0.退出");
String choose = sc.next();
switch(choose){
case "1":
System.out.println("请输入要查找的联系人姓名:");
String name = sc.next();
Contacts con = mdi.getContactsByName(name);
System.out.println("您要查找的联系人信息为"+con.toString());
break;
case "2":
System.out.println("请输入要查找的联系人微信:");
String weChar = sc.next();
Contacts con1 = mdi.getContactsByweChar(weChar);
System.out.println("您要查找的联系人信息为"+con1.toString());
break;
case "3":
break;
case "0":
System.out.println("谢谢使用本系统!再见");
System.exit(0);
default:
System.out.println("输入选项有误!");
}
}
}
最近下载更多
asdgcyv LV1
2023年5月31日
15342201772 LV9
2022年12月4日
balabalawuyu LV6
2022年11月24日
1102445814 LV1
2022年6月25日
杨小姐好棒棒 LV3
2022年5月24日
Demo1111 LV30
2021年12月6日
N LV1
2021年6月17日
MrLinsir LV2
2020年6月19日
如夝萌灵 LV1
2020年5月13日
byy1314520 LV1
2020年4月18日
最近浏览更多
微信网友_6589859840430080
2023年8月3日
暂无贡献等级
asdgcyv LV1
2023年5月31日
shushs LV1
2023年5月31日
adminadminsqwqe LV8
2023年1月30日
Willson88888 LV3
2022年12月13日
15342201772 LV9
2022年12月4日
balabalawuyu LV6
2022年11月24日
飞梦ff LV8
2022年7月24日
1102445814 LV1
2022年6月25日
又见梨园 LV1
2022年6月1日

