C#实现DVD借出归还管理系统
用C#写的一个DVD管理器,供大家参考,具体内容如下
(大神勿喷,初学者以借鉴为主)
一共分为三个类分别是:DVD(启动类),XinXi(信息类),GongNeng(功能类)
代码部分(如下):
DVD(启动类):
class DVD{static void Main(string[] args){GongNeng gongNeng = new GongNeng(); gongNeng.initial(); //初始化gongNeng.XianShi(); //遍历初始化信息gongNeng.CaiDan(); //选项菜单}}
XinXi(信息类):
class XinXi{private string _name; //名称private int state; //借出状态private string date; //时间 //属性封装public string Name { get => _name; set => _name = value; }//名称public int State { get => state; set => state = value; }//借出状态public string Date { get => date; set => date = value; }//时间}
GongNeng(功能类):
因为功能类使用了正则表达式来判断日期格式,所以在使用的时候头部还需加上:
using System.Text.RegularExpressions; // RegularExpressions为正则表达式,Text为文本
class GongNeng{XinXi[] xinxi = new XinXi[10]; //对象数组存储数据//初始化信息#region初始化信息public void initial() {xinxi[0] = new XinXi(); xinxi[0].Name = "罗马假日"; xinxi[0].State = 0; xinxi[0].Date = "2010-7-1"; xinxi[1] = new XinXi(); xinxi[1].Name = "风声鹤唳"; xinxi[1].State = 1; xinxi[1].Date = ""; xinxi[2] = new XinXi(); xinxi[2].Name = "浪漫满屋"; xinxi[2].State = 1; xinxi[2].Date = ""; }#endregion //显示初始化信息#region显示初始化信息public void XianShi() {Console.WriteLine("********初始化信息如下:********"); foreach (XinXi item in xinxi) {if (item != null) {Console.WriteLine(item.Name+"\t"+item.State+"\t"+item.Date); }}Console.WriteLine("********************************"); }#endregion //DVD菜单#regionDVD菜单public void CaiDan(){Console.WriteLine("------------欢迎使用明宇迷你DVD管理器------------"); Console.WriteLine("1.新增DVD\n2.查看DVD\n3.删除DVD\n4.借出DVD\n5.归还DVD\n6.退出"); Console.WriteLine("-------------------------------------------------"); Console.Write("请输入您的选择:"); int xuanZe = int.Parse(Console.ReadLine()); switch (xuanZe){case 1://新增DVDXinZeng(); break; case 2://查看DVDChaXun(); break; case 3://删除DVDShanChu(); break; case 4://借出DVDJieChu(); break; case 5://归还DVDGuiHuan(); break; case 6://退出Console.WriteLine("欢迎下次光临!"); break; default://无选项Console.WriteLine("对不起,没有该选项!"); break; }}#endregion //输入0,返回#region输入0,返回public void FanHui() {do {Console.WriteLine("输入0,返回:"); string Ling = Console.ReadLine(); if (Ling.Equals("0")) {CaiDan(); }} while (true); }#endregion //新增DVD#region新增DVDpublic void XinZeng() {bool flag = true; Console.WriteLine("此处实现新增DVD----->"); Console.WriteLine("请输入DVD名称:"); string dvdName = Console.ReadLine(); for (int i=0; i< xinxi.Length; i++) {if (xinxi[i] == null) {flag = false; xinxi[i] = new XinXi(); xinxi[i].Name = dvdName; xinxi[i].State = 1; xinxi[i].Date = ""; Console.WriteLine("名称为{0}的DVD添加成功!", xinxi[i].Name); break; }}if (flag) {Console.WriteLine("对不起,存储空间已满"); }FanHui(); //返回}#endregion //查询DVD#region查询DVDpublic void ChaXun() {Console.WriteLine("此处实现查询DVD----->"); Console.WriteLine("{0,-8}{1,-10}{2,-8}", "名称","状态","时间"); string zhuangTai = String.Empty; foreach (XinXi item in xinxi){if (item != null){if (item.State == 0) {zhuangTai = "以借出"; } else if (item.State == 1) {zhuangTai = "未借出"; }Console.WriteLine("{0,-8}{1,-10}{2,-8}",item.Name, zhuangTai, item.Date); }}FanHui(); //返回}#endregion //判断对应下标#region判断对应下标public XinXi Duan(string dvdName) {foreach (XinXi item in xinxi) {if (item != null && item.Name.Equals(dvdName)) {return item; }}return null; }#endregion //删除DVD#region删除DVDpublic void ShanChu() {Console.WriteLine("此处实现删除DVD----->"); Console.WriteLine("请输入DVD名称:"); string dvdName = Console.ReadLine(); XinXi renWu = Duan(dvdName); if (renWu == null) {Console.WriteLine("对不起,没有该DVD"); return; }for (int i=0; i< xinxi.Length; i++) {if (renWu == xinxi[i] && xinxi[i].State == 1) {for (int j = i; j < xinxi.Length-1; j++) {xinxi[j] = xinxi[j + 1]; }int nu = xinxi.Length - 1; xinxi[nu] = null; Console.WriteLine("订单删除成功!"); break; } else if (renWu == xinxi[i] && xinxi[i].State == 0) {Console.WriteLine("对不起,订单为以借出状态不能删除!"); break; }}FanHui(); //返回}#endregion //借出DVD#region借出DVDpublic void JieChu() {Console.WriteLine("此处实现借出DVD----->"); Console.WriteLine("请输入DVD名称:"); string dvdName = Console.ReadLine(); XinXi renWu = Duan(dvdName); if (renWu == null){Console.WriteLine("对不起,没有该DVD"); FanHui(); //返回}if (renWu.State == 0) {Console.WriteLine("对不起,该DVD以被人抢先借走了!"); FanHui(); //返回}Console.WriteLine("请输入借出日期(年-月-日):"); string riQi = Console.ReadLine(); bool flag = Money(riQi); if (!flag){Console.WriteLine("对不起,您输入的日期不正确!"); FanHui(); //返回}else {renWu.State = 0; renWu.Date = riQi; Console.WriteLine("借出DVD成功!"); }FanHui(); //返回}#endregion //判断借出日期格式#region判断借出日期格式public bool Money(string riQi){string monval = @"^\d{4}-\d{1,2}-\d{1,2}$"; return Regex.IsMatch(riQi, monval); }#endregion //归还DVD#region归还DVDpublic void GuiHuan() {Console.WriteLine("此处实现归还DVD----->"); Console.WriteLine("请输入DVD名称:"); string dvdName = Console.ReadLine(); XinXi renWu = Duan(dvdName); if (renWu == null){Console.WriteLine("对不起,没有该DVD"); FanHui(); //返回}if (renWu.State == 1){Console.WriteLine("对不起,该DVD还没有借出不可归还!"); FanHui(); //返回}Console.WriteLine("请输入归还日期(年-月-日):"); string riQi = Console.ReadLine(); bool flag = Money(riQi); if (!flag){Console.WriteLine("对不起,您输入的日期不正确!"); FanHui(); //返回}else{string jieChu = renWu.Date; if (String.Compare(jieChu, riQi) < 0){//字符串转换为日期格式DateTime dat1 = Convert.ToDateTime(jieChu); //借出DateTime dat2 = Convert.ToDateTime(riQi); //日期TimeSpan span = dat2.Subtract(dat1); //求借出与归还之间的差值int cha = span.Days + 1; renWu.State = 1; renWu.Date = ""; Console.WriteLine("\n归还《{0}》成功!", renWu.Name); Console.WriteLine("借出日期为:{0}", dat1); Console.WriteLine("归还日期为:{0}", dat2); Console.WriteLine("应付租金为:{0}",cha); }else {Console.WriteLine("对不起,归还日期不能小于借出日期!"); FanHui(); //返回}}FanHui(); //返回}#endregion}
代码展示完毕!
【C#实现DVD借出归还管理系统】以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
推荐阅读
- 关于QueryWrapper|关于QueryWrapper,实现MybatisPlus多表关联查询方式
- MybatisPlus使用queryWrapper如何实现复杂查询
- python学习之|python学习之 实现QQ自动发送消息
- 孩子不是实现父母欲望的工具——林哈夫
- opencv|opencv C++模板匹配的简单实现
- Node.js中readline模块实现终端输入
- java中如何实现重建二叉树
- 人脸识别|【人脸识别系列】| 实现自动化妆
- paddle|动手从头实现LSTM
- pytorch|使用pytorch从头实现多层LSTM