本文共 5098 字,大约阅读时间需要 16 分钟。
本项目旨在开发并实现一个基于文本界面的客户关系管理软件(CRM)。系统将支持客户信息的增删改查,并提供详细的客户信息查询功能。
系统界面分为主界面和功能操作界面设计,具体如下:
展示系统名称及功能菜单,用户可通过输入选择不同的操作。
分为添加客户、修改客户、删除客户和客户列表四个主要界面,分别对应不同的操作流程。
显示所有客户信息,用户可进行筛选和排序,支持查看单个客户详情。
系统采用MVC模式设计,包含以下主要模块:
customerManager/├── model/│ ├── customer.go│ └── customer_service.go├── service/│ └── customer_service.go└── view/ └── customer_view.go
package modelimport ( "fmt")type Customer struct { Id int Name string Gender string Age int Phone string Email string}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, }}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 { return 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)}
package serviceimport ( "mygotest/customerManager/model")type CustomerService struct { customers []model.Customer customerNum int}func NewCustomerService() *CustomerService { service := &CustomerService{} service.customerNum = 1 customer := model.NewCustomer(1, "张三", "男", 20, "010-56253825", "zs@sohu.com") service.customers = append(service.customers, customer) return service}func (this *CustomerService) List() []model.Customer { return this.customers}func (this *CustomerService) Add(customer model.Customer) bool { this.customerNum++ customer.Id = this.customerNum this.customers = append(this.customers, customer) return true}func (this *CustomerService) Delete(id int) bool { index := this.FindById(id) if index == -1 { return false } this.customers = append(this.customers[:index], this.customers[index+1:]...) return true}func (this *CustomerService) FindById(id int) int { index := -1 for i := 0; i < len(this.customers); i++ { if this.customers[i].Id == id { index = i } } return index}
package mainimport ( "fmt" "mygotest/customerManager/model" "mygotest/customerManager/service")type customerView struct { key string loop bool 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].GetInfo()) } fmt.Printf("\n-------------------------客户列表完成-------------------------\n\n")}func (this *customerView) add() { fmt.Println("---------------------添加客户---------------------") name := "" fmt.Scanln(&name) gender := "" fmt.Scanln(&gender) age := 0 fmt.Scanln(&age) phone := "" fmt.Scanln(&phone) email := "" fmt.Scanln(&email) customer := model.NewCustomer2(name, gender, age, phone, email) if this.customerService.Add(customer) { fmt.Println("---------------------添加完成---------------------") } else { fmt.Println("---------------------添加失败---------------------") }}func (this *customerView) delete() { fmt.Println("---------------------删除客户---------------------") id := -1 fmt.Scanln(&id) if id == -1 { return } fmt.Println("确认是否删除(Y/N):") choice := "" fmt.Scanln(&choice) if choice == "y" || choice == "Y" { 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("已退出了客户关系管理系统...")}
系统运行后,用户将看到以下界面和功能:
通过以上设计和实现,完成了一个功能完善的客户关系管理系统,满足用户对客户信息管理的基本需求。
转载地址:http://ctkwk.baihongyu.com/