go-客户信息关系系统
客户信息关系系统
项目需求分析
- 模拟实现基于文本界面的《 客户信息管理软件》。
- 该软件能够实现对客户对象的插入、修改和删除(用切片实现),并能够打印客户明细表
项目的界面设计
见代码的运行结果
项目功能实现-显示主菜单和完成退出软件功能
功能的说明
当用户运行程序时,可以看到主菜单,当输入 5 时,可以退出该软件.
思路分析
编写 customerView.go ,另外可以把 customer.go 和 customerService.go 写上.
项目功能实现-完成显示客户列表的功能
项目功能实现-添加客户的功能
项目功能实现-完成删除客户的功能
代码实现:customerService.go
package service
import (
"go_code/code/customerManage/model"
)
//该CustomerService, 完成对Customer的操作,包括
//增删改查
type CustomerService struct {
customers []model.Customer
//声明一个字段,表示当前切片含有多少个客户
//该字段后面,还可以作为新客户的id+1
customerNum int
}
//编写一个方法,可以返回 *CustomerService
func NewCustomerService() *CustomerService {
//为了能够看到有客户在切片中,我们初始化一个客户
customerService := &CustomerService{}
customerService.customerNum = 1
customer := model.NewCustomer(1, "张三", "男", 20, "112", "zs@sohu.com")
customerService.customers = append(customerService.customers, customer)
return customerService
}
//返回客户切片
func (this *CustomerService) List() []model.Customer {
return this.customers
}
//添加客户到customers切片
//!!!
func (this *CustomerService) Add(customer model.Customer) bool {
//我们确定一个分配id的规则,就是添加的顺序
this.customerNum++
customer.Id = this.customerNum
this.customers = append(this.customers, customer)
return true
}
//根据id删除客户(从切片中删除)
func (this *CustomerService) Delete(id int) bool {
index := this.FindById(id)
//如果index == -1, 说明没有这个客户
if index == -1 {
return false
}
//如何从切片中删除一个元素
this.customers = append(this.customers[:index], this.customers[index+1:]...)
return true
}
//根据id查找客户在切片中对应下标,如果没有该客户,返回-1
func (this *CustomerService) FindById(id int) int {
index := -1
//遍历this.customers 切片
for i := 0; i < len(this.customers); i++ {
if this.customers[i].Id == id {
//找到
index = i
}
}
return index
}
代码实现:customer.go
package model
import (
"fmt"
)
//声明一个Customer结构体,表示一个客户信息
type Customer struct {
Id int
Name string
Gender string
Age int
Phone string
Email string
}
//使用工厂模式,返回一个Customer的实例
func NewCustomer(id int, name string, gender string,
age int, phone string, email string ) Customer {
return Customer{
Id : id,
Name : name,
Gender : gender,
Age : age,
Phone : phone,
Email : email,
}
}
//第二种创建Customer实例方法,不带id
func NewCustomer2(name string, gender string,
age int, phone string, email string ) Customer {
return Customer{
Name : name,
Gender : gender,
Age : age,
Phone : phone,
Email : email,
}
}
//返回用户的信息,格式化的字符串
func (this Customer) GetInfo() string {
info := fmt.Sprintf("%v\t%v\t%v\t%v\t%v\t%v\t", this.Id,
this.Name, this.Gender,this.Age, this.Phone, this.Email)
return info
}
代码实现:customerView.go
package main
import (
"fmt"
"go_code/code/customerManage/service"
"go_code/code/customerManage/model"
)
type customerView struct {
//定义必要字段
key string //接收用户输入...
loop bool //表示是否循环的显示主菜单
//增加一个字段customerService
customerService *service.CustomerService
}
//显示所有的客户信息
func (this *customerView) list() {
//首先,获取到当前所有的客户信息(在切片中)
customers := this.customerService.List()
//显示
fmt.Println("---------------------------客户列表---------------------------")
fmt.Println("编号\t姓名\t性别\t年龄\t电话\t邮箱")
for i := 0; i < len(customers); i++ {
//fmt.Println(customers[i].Id,"\t", customers[i].Name...)
fmt.Println(customers[i].GetInfo())
}
fmt.Printf("\n-------------------------客户列表完成-------------------------\n\n")
}
//得到用户的输入,信息构建新的客户,并完成添加
func (this *customerView) add() {
fmt.Println("---------------------添加客户---------------------")
fmt.Println("姓名:")
name := ""
fmt.Scanln(&name)
fmt.Println("性别:")
gender := ""
fmt.Scanln(&gender)
fmt.Println("年龄:")
age := 0
fmt.Scanln(&age)
fmt.Println("电话:")
phone := ""
fmt.Scanln(&phone)
fmt.Println("电邮:")
email := ""
fmt.Scanln(&email)
//构建一个新的Customer实例
//注意: id号,没有让用户输入,id是唯一的,需要系统分配
customer := model.NewCustomer2(name, gender, age, phone, email)
//调用
if this.customerService.Add(customer) {
fmt.Println("---------------------添加完成---------------------")
} else {
fmt.Println("---------------------添加失败---------------------")
}
}
//得到用户的输入id,删除该id对应的客户
func (this *customerView) delete() {
fmt.Println("---------------------删除客户---------------------")
fmt.Println("请选择待删除客户编号(-1退出):")
id := -1
fmt.Scanln(&id)
if id == -1 {
return //放弃删除操作
}
fmt.Println("确认是否删除(Y/N):")
//这里同学们可以加入一个循环判断,直到用户输入 y 或者 n,才退出..
choice := ""
fmt.Scanln(&choice)
if choice == "y" || choice == "Y" {
//调用customerService 的 Delete方法
if this.customerService.Delete(id) {
fmt.Println("---------------------删除完成---------------------")
} else {
fmt.Println("---------------------删除失败,输入的id号不存在----")
}
}
}
//退出软件
func (this *customerView) exit() {
fmt.Println("确认是否退出(Y/N):")
for {
fmt.Scanln(&this.key)
if this.key == "Y" || this.key == "y" || this.key == "N" || this.key == "n" {
break
}
fmt.Println("你的输入有误,确认是否退出(Y/N):")
}
if this.key == "Y" || this.key == "y" {
this.loop = false
}
}
//显示主菜单
func (this *customerView) mainMenu() {
for {
fmt.Println("-----------------客户信息管理软件-----------------")
fmt.Println(" 1 添 加 客 户")
fmt.Println(" 2 修 改 客 户")
fmt.Println(" 3 删 除 客 户")
fmt.Println(" 4 客 户 列 表")
fmt.Println(" 5 退 出")
fmt.Print("请选择(1-5):")
fmt.Scanln(&this.key)
switch this.key {
case "1" :
this.add()
case "2" :
fmt.Println("修 改 客 户")
case "3" :
this.delete()
case "4" :
this.list()
case "5" :
this.exit()
default :
fmt.Println("你的输入有误,请重新输入...")
}
if !this.loop {
break
}
}
fmt.Println("你退出了客户关系管理系统...")
}
func main() {
//在main函数中,创建一个customerView,并运行显示主菜单..
customerView := customerView{
key : "",
loop : true,
}
//这里完成对customerView结构体的customerService字段的初始化
customerView.customerService = service.NewCustomerService()
//显示主菜单..
customerView.mainMenu()
}
go-客户信息关系系统的更多相关文章
- 配置 CSV Data Set Config 来参数化新增客户信息操作
1.首先根据新增客户信息的http请求,来确定需要参数化的变量,选取符合测试需求且经常变化或未来会变化的变量为需要参数化的变量,如本文中的客户端名称(sys_name).描述(description) ...
- 获取客户信息SQL
/*取客户信息SQL*/ --客户信息 SELECT hou.name 业务实体, hca.account_number 客户编号, hp.party_name 客户名称, arp_addr_pkg. ...
- 客户信息全SQL
SELECT hp.party_name "客户名称", --客户名称 hca.account_number "客户编号", --客户编号 hca.cust_a ...
- loadrunner笔记(二):飞机订票系统--客户信息注册
(一) 几个重要概念说明 集合点:同步虚拟用户,以便同一时间执行任务. 事务:事务是指服务器响应用户请求所用的时间,当然它可以衡量某个操作,如登录所需要的时间,也可以衡量一系列的操作所用的时间,如从 ...
- JavaWeb 简单实现客户信息管理系统
项目介绍 本项目使用Jsp+Servlet+MySQL实现 功能介绍 查询客户信息:查询数据库中所有客户信息,分页展示 添加客户信息:创建新客户并添加到数据库中 搜索客户信息:根据用户的输入查询客户信 ...
- golang实战--客户信息管理系统
总计架构图: model/customer.go package model import ( "fmt" ) type Customer struct { Id int Name ...
- 客户关系管理系统-CRM源码
QQ:2112326142 邮箱:jxsupport@qq.com 本公司开发的CRM源代码系统一份,附源代码,本公司产品唯一销售客服QQ号:2112326142 请联系此QQ号,以免给您的工作 ...
- java web 之客户关系管理系统
这个周末真的是觉得自己学会了一个比较高大上的本领,为什么这么觉得呢?那是因为星期六的时候觉得自己可以看看源码能做出来,可是让我头疼的是花费了一上午的时间还是没有弄出来,还好上天给了我机会,要是没有老师 ...
- ASP.NET MVC搭建项目后台UI框架—6、客户管理(添加、修改、查询、分页)
目录 ASP.NET MVC搭建项目后台UI框架—1.后台主框架 ASP.NET MVC搭建项目后台UI框架—2.菜单特效 ASP.NET MVC搭建项目后台UI框架—3.面板折叠和展开 ASP.NE ...
随机推荐
- 损失函数--KL散度与交叉熵
损失函数 在逻辑回归建立过程中,我们需要一个关于模型参数的可导函数,并且它能够以某种方式衡量模型的效果.这种函数称为损失函数(loss function). 损失函数越小,则模型的预测效果越优.所以我 ...
- 案例:使用dbms_xplan.display_cursor无法获取执行计划
案例:使用dbms_xplan.display_cursor无法获取执行计划 环境:RHEL 6.5 + Oracle 11.2.0.4 在一次测试中发现使用dbms_xplan.display_cu ...
- jvm虚拟机笔记<一> 内存区域
运行时数据区域: 程序计数器:字节码的行号指示器. 虚拟机栈:为每个方法创建一个栈帧(存放方法中的局部变量,变量引用等). 本地方法栈:存放本地方法. ------------------------ ...
- JVM GC监控
一.jps常看java进程 Java版的ps命令,查看java进程及其相关的信息,如果你想找到一个java进程的pid,那可以用jps命令替代linux中的ps命令了,简单而方便. [root@tsp ...
- SAP depreciation key config
正常折旧 Configure 1.分配总帐科目 spro进入后台配置 –> Financial Accounting(New) –> Asset Accounting –> Depr ...
- 【转载】Android N 完全不同以往的四个新特性
Google最近发布了Android的下一个版本,Android N的开发者预览版.此次预览版,可以让我们开发者在正式发布之前就测试代码,包括一些新的API,甚至于也可以提前反馈那些对于我们来说有些困 ...
- python 错误信息是:sudo :apt-get:command not found
1.问题描述 错误信息是:sudo :apt-get:command not found 2.问题原因及解决 在centos下用yum install xxx yum和apt-get的区别一般来说著名 ...
- request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath()+"/"
String path = request.getContextPath(); String basePath = request.getScheme()+"://"+reques ...
- Day6 - Python基础6 模块shelve、xml、re、subprocess、pymysql
本节目录: 1.shelve模块 2.xml模块 3.re模块 4.subprocess模块 5.logging模块 6.pymysql 1.shelve 模块 shelve模块是一个简单的k,v将内 ...
- flask之web网关、三件套、配置、路由(参数、转化器及自定义转化器)、cbv、模板语言、session
目录 1.wsgiref.py 2.werzeug.py 3.三件套 4.配置文件 5.路由本质 6.cbv.py 7.路由转化器 8.自定义转化器 9.模板语言 10.session原理 11.te ...