Golang项目:客户信息管理系统(附源码) (Golang经典编程案例)
1.项目需求分析
- 模拟实现基于文本界面的《客户关系管理软件》;
- 该软件能够实现对客户对象的插入,修改和删除(用切片实现),并且能够打印客户信息明细表。
2.项目的界面设计
主界面:
添加界面:
修改界面:
删除客户界面:
客户列表界面:
3.系统的程序框架图
4.功能实现的代码
首先,看一下项目结构:
在costumer.go中,代码如下:
package modelimport ("fmt"
)//声明一个Customer结构体,表示一个客户信息
type Customer struct {Id int Name stringGender stringAge intPhone stringEmail 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}
在costumerService.go中,代码如下:
package serviceimport ("mygotest/customerManager/model"
)//该CustomerService, 完成对Customer的操作,包括
//增删改查
type CustomerService struct {customers []model.Customer//声明一个字段,表示当前切片含有多少个客户//该字段后面,还可以作为新客户的id+1customerNum int
}//编写一个方法,可以返回 *CustomerService
func NewCustomerService() *CustomerService {//为了能够看到有客户在切片中,我们初始化一个客户customerService := &CustomerService{}customerService.customerNum = 1customer := model.NewCustomer(1, "张三", "男", 20, "010-56253825", "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.customerNumthis.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
}
在costumerView.go中,代码如下:
package mainimport ("fmt""mygotest/customerManager/model""mygotest/customerManager/service"
)type customerView struct {//定义必要字段key string //接收用户输入...loop bool //表示是否循环的显示主菜单//增加一个字段customerServicecustomerService *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.Print("姓名:")name := ""fmt.Scanln(&name)fmt.Print("性别:")gender := ""fmt.Scanln(&gender)fmt.Print("年龄:")age := 0fmt.Scanln(&age)fmt.Print("电话:")phone := ""fmt.Scanln(&phone)fmt.Print("邮箱:")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.Print("请选择待删除客户编号(-1退出):")id := -1fmt.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.Print("确认是否退出(Y/N):")for {fmt.Scanln(&this.key)if this.key == "Y" || this.key == "y" || this.key == "N" || this.key == "n" {break}fmt.Print("你的输入有误,确认是否退出(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()}
执行结果如下图所示:
Golang项目:客户信息管理系统(附源码) (Golang经典编程案例)相关推荐
- java毕业生设计房产客户信息管理系统计算机源码+系统+mysql+调试部署+lw
java毕业生设计房产客户信息管理系统计算机源码+系统+mysql+调试部署+lw java毕业生设计房产客户信息管理系统计算机源码+系统+mysql+调试部署+lw 本源码技术栈: 项目架构:B/S ...
- java毕业设计企业客户信息管理系统mybatis+源码+调试部署+系统+数据库+lw
java毕业设计企业客户信息管理系统mybatis+源码+调试部署+系统+数据库+lw java毕业设计企业客户信息管理系统mybatis+源码+调试部署+系统+数据库+lw 本源码技术栈: 项目架构 ...
- 基于JavaWeb学生成绩信息管理系统(附源码资料)-毕业设计
1. 适用人群 本课程主要是针对计算机专业相关正在做毕业设计.或者是需要实战项目的Java开发学习者. 2. 你将收获 提供:项目源码.项目文档.数据库脚本.软件工具等所有资料(在平台的课程附件中进行 ...
- Java版学生信息管理系统 附源码(JavaFX图形界面)
1.登录界面 其中的图片存储路径可以替换成自己的,当然我这里的账号密码是先设置好的,其实可以做一个注册的功能,把账号密码存进文件中 package SchoolWork.ManagementSyste ...
- c语言学生信息管理系统作用,C语言学生信息管理系统(附源码).doc
. word范文 学生信息管理系统 #include #include #include #include #include #define LEN sizeof(struct student) #d ...
- java毕业生设计眼科医疗室信息管理系统计算机源码+系统+mysql+调试部署+lw
java毕业生设计眼科医疗室信息管理系统计算机源码+系统+mysql+调试部署+lw java毕业生设计眼科医疗室信息管理系统计算机源码+系统+mysql+调试部署+lw 本源码技术栈: 项目架构:B ...
- java毕业生设计畜牧场信息管理系统计算机源码+系统+mysql+调试部署+lw
java毕业生设计畜牧场信息管理系统计算机源码+系统+mysql+调试部署+lw java毕业生设计畜牧场信息管理系统计算机源码+系统+mysql+调试部署+lw 本源码技术栈: 项目架构:B/S架构 ...
- 计算机毕业设计Java消防站信息管理系统(源码+系统+mysql数据库+Lw文档)
计算机毕业设计Java消防站信息管理系统(源码+系统+mysql数据库+Lw文档) 计算机毕业设计Java消防站信息管理系统(源码+系统+mysql数据库+Lw文档) 本源码技术栈: 项目架构:B/S ...
- 软件工程通信录管理系统c语言,软件工程设计管理系统附源码.doc
软件工程设计管理系统附源码 学 年 设 计 课程名称: 软件工程学年设计 实验项目: 通讯录管理系统 姓 名: XXX 专 业: 计算机科学与技术 班 级: XXX班 学 号: XXX 指导教师 XX ...
- JAVA毕业设计建筑公司工程信息管理系统计算机源码+lw文档+系统+调试部署+数据库
JAVA毕业设计建筑公司工程信息管理系统计算机源码+lw文档+系统+调试部署+数据库 JAVA毕业设计建筑公司工程信息管理系统计算机源码+lw文档+系统+调试部署+数据库 本源码技术栈: 项目架构:B ...
最新文章
- automation服务器不能创建对象的问题
- 【Java 虚拟机原理】Class 字节码二进制文件分析 一 ( 字节码文件附加信息 | 魔数 | 次版本号 | 主版本号 | 常量池个数 )
- PostgreSQL 10.1 手册_部分 II. SQL 语言_第 11 章 索引_11.5. 组合多个索引
- Maven : Log4j2 could not find a logging implementation
- wxParse解析iframe播放视频
- Windows XP下用Modem发送传真(ZZ)
- 顶级域名 一级域名 二级域名 三级域名什么区别?
- 颠覆传统股票证券市场的可能是ICO代币(TOKEN)
- Excel中用REPT函数制作图表
- vue2.x和3.x中mock数据方式
- cubase打开时,别的软件和网页无法正常播放视频。
- 【CVPR 2018】Image Generation from Scene Graphs从场景图中生成图像 [文本转图]
- 解读 | 自监督视觉特征学习综述
- 入门月薪8k,3年年薪35w,大数据的就业前景与薪酬待遇浅析
- 程序员接私活的6个网站,你有技术就有钱!
- SpringWeb项目Maven执行clean命令后编译拒绝访问的解决方法
- python微信小程序实例制作入门_python flask零基础打造微信小程序实战教程
- Breakpoint is not hit
- 大学应用计算机二级,大学计算机二级ps考试试题内容(3)
- 面试java想要高工资的看这里