用C#写的一个DVD管理器,供大家参考,具体内容如下
(大神勿喷,初学者以借鉴为主)
一共分为三个类分别是:DVD(启动类),XinXi(信息类),GongNeng(功能类)
代码部分(如下):
DVD(启动类):
复制代码
1
2
3
4
5
6
7
8
9
10class DVD { static void Main(string[] args) { GongNeng gongNeng = new GongNeng(); gongNeng.initial(); //初始化 gongNeng.XianShi(); //遍历初始化信息 gongNeng.CaiDan(); //选项菜单 } }
XinXi(信息类):
复制代码
1
2
3
4
5
6
7
8
9
10
11class 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为文本
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276class 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菜单 #region DVD菜单 public void CaiDan() { Console.WriteLine("------------欢迎使用明宇迷你DVD管理器------------"); Console.WriteLine("1.新增DVDn2.查看DVDn3.删除DVDn4.借出DVDn5.归还DVDn6.退出"); Console.WriteLine("-------------------------------------------------"); Console.Write("请输入您的选择:"); int xuanZe = int.Parse(Console.ReadLine()); switch (xuanZe) { case 1: //新增DVD XinZeng(); break; case 2: //查看DVD ChaXun(); break; case 3: //删除DVD ShanChu(); break; case 4: //借出DVD JieChu(); break; case 5: //归还DVD GuiHuan(); 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 新增DVD public 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 查询DVD public 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 删除DVD public 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 借出DVD public 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 归还DVD public 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借出归还管理系统的全部内容,更多相关C#实现DVD借出归还管理系统内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复