电子银行系统---大学c#实训

【项目任务】

编写程序,在控制台上实现一个简单的银行管理系统

【需求分析】

《简单银行管理系统》的功能需求如下图所示:

 

1. 装载账户信息文件:所有账户信息应能永久保存在一个特定的磁盘文件中。在系统开始运行时应首先打开该文件,将  

   文件中的全部信息装载到内存中存放这些信息的账户信息映射表中。

2. 创建账户:通过交互界面输入一个账户的所有信息,并将该账户信息记录添加到账户信息映射表中。账户信息包括:储户

  的身份证号、真实姓、通讯地址和电话号码,账户类型,货币种类,预存款额,账户密码,系统为会账户自动生成一个

  唯一的帐号作为映射表的键值。

3. 登录账户:通过交互界面输入要登录的帐号和密码,系统在账户映射表中搜索待登录账户,并根据搜索结果显示不同的信

  息:如果指定的帐号不存在,则显示”无此帐号!”提示信息;如果帐号存在但密码不符,则显示”密码错误!”提示信息;

  如果信息都符合,则立即出现账户管理界面,显示账户的所有信息包括账号、账户类型、币种、余额和储户的所有信息

  (身份证号、真实姓名、通讯地址、电话号码)。

4. 存款:储户在成功登录账户后,可以进行存款操作。其中一般账户、结算账户和信用卡账户的存款操作相同,定期存款账

  户在用户开户后不得再存款。

5. 取款:储户在成功登录账户后,可以进行取款操作。其中一般账户和结算账户的取款操作相同,定期存款账户不得在未到

  期之前取款,信用卡账户允许透支10000元(各币种)。

6. 修改密码:储户在成功登录账户后,可以重新设置密码。

7. 查询本人所有账户:储户在成功登录某一账户后,可以查询本人(以身份证号为根据)名下的所有其他账户。

9. 查看存储年限:针对定期存款储户的服务,储户可以在正确登录账户后立即查看该账户的到期日期。

10. 查看透支额度:针对信用卡储户的服务,储户可以在正确登录账户后查看到该账户的透支额度。

11. 查看汇款方式:针对结算储户的服务,储户可以在正确登录账户后查看到该账户的汇款方式。

12. 保存账户信息文件:在系统退出运行时,系统自动将增加、删除、修改后的账户信息保存到特定的磁盘文件中。

13.用户能查询资金流动的详情

use类:存取转和数据操作等功能

server类:发email,发短信

Myregex:对用户注册时,身份证,手机号等验证

use类
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Net;
using System.Net.Mail;
namespace Bank
{
enum CardType
{
CommonCard = 1,//一般卡
CreditCard,//信用卡
DebitCard,//结算卡
SaveCard//定期卡
}
enum OperatTypeOfMoney
{
Save,
Fetch,
Remove,
Receive
}
class Use
{
const decimal MAXYIZHI=10000;//信用卡的最大透支度
const long IDENTITY = 10000;//数据文件里而的唯一索引的起启位置

#region 字段

Int64 id;//身份证号码
string name;
CardType type;//开户类型
decimal money;//金额
Int64 pwd;//用户密码
Int64 cardNo;//用户号
string address;
DateTime time;
int storeYearNum;
Int64 linking;//联系方式
string email;


#endregion

#region 属性
public CardType Type
{
get { return type; }
set { type = value; }
}
public string Email
{
get { return email; }
set { email = value; }
}

public Int64 Id
{
get { return id; }
set { id = value; }
}
public string Name
{
get { return name; }
set { name = value; }
}

public decimal Money
{
get { return money; }
set { money = value; }
}
public Int64 Pwd
{
get { return pwd; }
set { pwd = value; }
}
public Int64 CardNo
{
get { return cardNo; }
set { cardNo = value; }
}
public Int64 Linking
{
get { return linking; }
set { linking = value; }
}
public string Address
{
get { return address; }
set { address = value; }
}
public int StoreYearNum
{
get { return storeYearNum; }
set { storeYearNum = value; }
}
public DateTime Time
{
get { return time; }
set { time = value; }
}
#endregion

public Use()
{ }
public Use(Int64 carNo, Int64 pwd)
{
this.cardNo = carNo;
this.pwd = pwd;
}

#region 逻辑业务层


public string StoreMoney(decimal storeMoneyNum)
{
bool status = true;
string tip = "";
if (Type == CardType.SaveCard && DateTime.Now <= time.AddYears(storeYearNum))
{
status = false;
tip = "\n\n\n\n你使用的是定期卡,在" + this.time.AddYears(this.storeYearNum) + "以后你才能进行存款操作";

}
if (status)
{
Money += storeMoneyNum;
StoreDataToTxt(CardNo,"useInfo.txt");
DatailT0Txt(OperatTypeOfMoney.Save,storeMoneyNum,0);
tip = "\n\n你成功将" + storeMoneyNum + "元存到自己的账户,你现在的余额为:" + Money;
}
return tip;
}
public string Fectch(decimal fecthMoneyNum)//取款
{
string tip = "";
bool status =true;
if (CardType.SaveCard == type && DateTime.Now <= time.AddYears(storeYearNum))
{
status = false;
tip = "\n\n你使用的是定期卡,在" + this.time.AddYears(this.storeYearNum) + "以后你才能进行取款操作";

}
if (money < fecthMoneyNum&&CardType.CreditCard != type)
{
status = false;
tip = "\n\n你的资金不足1";

}
if (CardType.CreditCard == type && fecthMoneyNum - money > MAXYIZHI)
{
status = false;
tip = "\n\n你的资金不足2";
}
if (status)
{
Money -= fecthMoneyNum;
StoreDataToTxt(CardNo,"useInfo.txt");
DatailT0Txt(OperatTypeOfMoney.Fetch, fecthMoneyNum, 0);
tip = "\n\n取款成功!!!你现在的余额为:" + Money;
}
return tip;


}
public bool MondifyPwd(Int64 newPwd)
{
Pwd = newPwd;
StoreDataToTxt(cardNo,"useInfo.txt");
return true;

}//修改
public string RemoveMoney(Int64 targetCardNo, decimal moneyNum)//转账(系统自带转账条件)
{
bool b = true;
bool targetCardIs = false;
string error = "";
Use use = new Use();//对方
#region 检查条件
if (type == CardType.CommonCard && Money < moneyNum)
{
error = "\n\n你的资金不足,转账失败!!!!";
b = false;
}
if (type == CardType.CreditCard && money - moneyNum < -MAXYIZHI)
{
error = "\n\n你的资金不足,转账失败!!!!";
b = false;
}
if (type == CardType.DebitCard && Money < moneyNum)
{
error = "\n\n你的资金不足,转账失败!!!!";
b = false;
}
if (type == CardType.SaveCard && DateTime.Now <= time.AddYears(storeYearNum))
{
error = "\n\n你的是定期卡,且时间还不到,转账失败!!!!";
b = false;
}
if (type == CardType.SaveCard && DateTime.Now >= time.AddYears(storeYearNum) && Money < moneyNum)
{
error = "\n\n你的资金不足,转账失败!!!!";
b = false;
}
foreach (string a in File.ReadAllLines("useInfo.txt", Encoding.Default))
{
if (targetCardNo == Convert.ToInt64(a.Split('')[6]))
{
targetCardIs = true;
use = use.LoadInfo(targetCardNo,"useInfo.txt");

}
}
if (!targetCardIs)
{
b = false;
error = "\n\n卡号不存在,转账失败!!!!";
}
if (DateTime.Now <= use.time.AddYears(use.storeYearNum) && use.type == CardType.SaveCard)
{
b = false;
error = "\n\n对方是定期卡,且未到期,转账失败!!!!";
}
if (cardNo == targetCardNo)
{
b = false;
error = "\n\n不能自己转给自己,转账失败!!!!";
}
#endregion
if (b)
{
Money -= moneyNum;
StoreDataToTxt(CardNo,"useInfo.txt");
DatailT0Txt(OperatTypeOfMoney.Remove, moneyNum, targetCardNo);
DatailT0Txt(OperatTypeOfMoney.Receive, moneyNum, targetCardNo);

use.money += moneyNum;
use.StoreDataToTxt(targetCardNo, "useInfo.txt");
error = "\n\n成功将" + moneyNum + "元转到" + targetCardNo + "你现在的余额为:" + Money;
}
return error;
}
public List<Use> QueryPersonInfo()//查询个人所有账户
{
List<Use> list = new List<Use>();
foreach (string str in File.ReadAllLines("useInfo.txt", Encoding.Default))
{
if (id == Convert.ToInt64(str.Split('')[0]))
{
Use use = new Use();
use = use.LoadInfo(Convert.ToInt64(str.Split('')[6]), "useInfo.txt");
list.Add(use);
}
}
return list;
}
#endregion


#region 数据操作层


public void ShowPersonInfo()//显示信息
{

Console.WriteLine("\n\t|---用户信息-----------------------------------------------------");
Console.WriteLine("\t| 身份证号码:{0} ", Id);
Console.WriteLine("\t| 姓名:{0} ", Name);
Console.WriteLine("\t| 金额:{0} ", Money);
Console.WriteLine("\t| 卡号:{0} ", CardNo);
Console.WriteLine("\t| 类型:{0} ", Type);
Console.WriteLine("\t| email:{0} ", Email);
Console.WriteLine("\t| 联系方式:{0} ", Linking);
Console.WriteLine("\t| 地址:{0} ", Address);
if (Type == CardType.SaveCard)
{
Console.WriteLine("\t| 到期时间:{0}({1}年) ", time.AddYears(StoreYearNum),StoreYearNum);
}


Console.WriteLine("\t|----------------------------------------------------------------\n");
}
public bool LoadInfo(out bool carNoStatus, out bool pwdStatus, string dataPath)//加载登录用户信息
{
carNoStatus = false;
pwdStatus = false;
bool can = false;
//方法一:线性查找(index=carNo-IDENTITY)
string[] data = File.ReadAllLines(dataPath, Encoding.Default);//所有账户信息
string[] userPerson=null;//当前个人用户信息
try
{
carNoStatus = true;
userPerson = data[cardNo - IDENTITY].Split('');
}
catch(IndexOutOfRangeException)
{
carNoStatus = false;
}
if (carNoStatus && userPerson[5] == Pwd.ToString())
{
Id = Convert.ToInt64(userPerson[0]);
Name = userPerson[1];
Money = decimal.Parse(userPerson[2]);
Type = (CardType)Enum.Parse(typeof(CardType), userPerson[3], true);
Linking = Convert.ToInt64(userPerson[4]);
Pwd = Convert.ToInt64(userPerson[5]);
CardNo = Convert.ToInt64(userPerson[6]);
Address = userPerson[7];
Time = Convert.ToDateTime(userPerson[8]);
StoreYearNum = int.Parse(userPerson[9]);
Email = userPerson[10];
can = true;
pwdStatus = true;
}
//方法二:遍历查找
//foreach (string a in File.ReadAllLines(dataPath, Encoding.Default))
//{
// if (a.Split('齹')[6] == CardNo.ToString())
// {
// if (a.Split('齹')[5] == Pwd.ToString())
// pwds = true;
// }
// if (a.Split('齹')[5] == Pwd.ToString() && a.Split('齹')[6] == CardNo.ToString())
// {
// Id = Convert.ToInt64(a.Split('齹')[0]);
// Name = a.Split('齹')[1];
// Money = decimal.Parse(a.Split('齹')[2]);
// Type = (CardType)Enum.Parse(typeof(CardType), a.Split('齹')[3], true);
// Linking = Convert.ToInt64(a.Split('齹')[4]);
// Pwd = Convert.ToInt64(a.Split('齹')[5]);
// CardNo = Convert.ToInt64(a.Split('齹')[6]);
// Address = a.Split('齹')[7];
// Time = Convert.ToDateTime(a.Split('齹')[8]);
// StoreYearNum = int.Parse(a.Split('齹')[9]);
// Email=a.Split('齹')[10];
// can = true;
// }

//}
return can;

}
public Use LoadInfo(Int64 carNos,string dataPath)//加载cardNo用户的信息
{
Use use = new Use();

foreach (string a in File.ReadAllLines(dataPath, Encoding.Default))
{
if (a.Split('')[6] == carNos.ToString())
{
use.Id = Convert.ToInt64(a.Split('')[0]);
use.Name = a.Split('')[1];
use.Money = decimal.Parse(a.Split('')[2]);
use.Type = (CardType)Enum.Parse(typeof(CardType), a.Split('')[3], true);
use.Linking = Convert.ToInt64(a.Split('')[4]);
use.Pwd = Convert.ToInt64(a.Split('')[5]);
use.CardNo = Convert.ToInt64(a.Split('')[6]);
use.Address = a.Split('')[7];
use.Time = Convert.ToDateTime(a.Split('')[8]);
use.StoreYearNum = int.Parse(a.Split('')[9]);
use.Email = a.Split('')[10];
}
}
// IEnumerable<string> b =
//from a in File.ReadAllLines("useInfo.txt", Encoding.Default)
//where a.Split('齹')[6] == "10001"
//select a;
// if (b.Count() > 0)
// {
// Console.WriteLine(b.ToList()[0]);

// }



return use;
}
public void StoreDataToTxt(Int64 carNo,string dataPath)//存信息
{
if (!File.Exists(dataPath))
{
FileStream fss = File.Create(dataPath);
fss.Close();
}
int length = File.ReadAllLines(dataPath, Encoding.Default).Length;
string[] data = new string[length];
data = File.ReadAllLines(dataPath, Encoding.Default);
data[CardNo - IDENTITY] = Id + "" +
Name + "" +
Money + "" +
Type + "" +
Linking + "" +
Pwd + "" +
CardNo + "" +
Address + "" +
Time + "" +
StoreYearNum + "" +
Email + "";

File.Delete(dataPath);
FileStream fs = new FileStream(dataPath, FileMode.Create, FileAccess.ReadWrite);
StreamWriter sw = new StreamWriter(fs, Encoding.Default);
for (int i = 0; i < length; i++)
{
sw.WriteLine(data[i]);
}
sw.Close();
fs.Close();
}
public Int64 StoreDataToTxt(Use use, string dataPath,string detailDataPath)//创建一个账号,并use对象信息保存到数据库
{
if (!File.Exists(dataPath))
{
FileStream fss = File.Create(dataPath);
fss.Close();
}
if (!File.Exists(detailDataPath))
{

FileStream fs1 = File.Create(detailDataPath);
fs1.Close();
}
use.cardNo = File.ReadAllLines(dataPath, Encoding.Default).Length + IDENTITY;
string useinfo = use.Id + "" +
use.Name + "" +
use.Money + "" +
use.Type + "" +
use.Linking + "" +
use.Pwd + "" +
use.CardNo + "" +
use.Address + "" +
use.Time + "" +
use.StoreYearNum + "" +
use.Email + "";


FileStream fs = new FileStream(dataPath, FileMode.Append);
StreamWriter sw = new StreamWriter(fs, Encoding.Default);
sw.WriteLine(useinfo);
sw.Close();
fs.Close();
return use.cardNo;

}
public void DatailT0Txt(OperatTypeOfMoney Operat,decimal money,double target)//将资金流动情况保存
{
string str = "";
if (Operat == OperatTypeOfMoney.Save)
{
str = this.cardNo+ ""
+ Operat + ""
+ money + ""
+ DateTime.Now + ""
+"0齹";
}
else if (Operat == OperatTypeOfMoney.Remove)
{
str = this.cardNo + ""
+ Operat + ""
+ money + ""
+ DateTime.Now + ""
+ target+"";
}
else if (Operat == OperatTypeOfMoney.Receive)
{
str = this.cardNo+ ""
+ Operat + ""
+ money + ""
+ DateTime.Now + ""
+ target + "";
}
else if (Operat == OperatTypeOfMoney.Fetch)
{
str = this.cardNo + ""
+ Operat + ""
+ money + ""
+ DateTime.Now + ""
+ "0齹";
}
FileStream fs = new FileStream("flowDetail.txt", FileMode.Append);
StreamWriter sw = new StreamWriter(fs, Encoding.Default);
sw.WriteLine(str);
sw.Close();
}
public string ReadDatail(OperatTypeOfMoney operate,string path,Int64 cardNo)//读取资金流动情况
{
string str="";
foreach(string a in File.ReadAllLines(path, Encoding.Default))
{
if (operate == (OperatTypeOfMoney)Enum.Parse(typeof(OperatTypeOfMoney), a.Split('')[1], true)
&& cardNo == Convert.ToInt64(a.Split('')[0]))
{
if (operate == OperatTypeOfMoney.Save )
str += a.Split('')[2] + "\t" + a.Split('')[3]+ "\n";
if (operate == OperatTypeOfMoney.Fetch)
str += a.Split('')[2] + "\t" + a.Split('')[3] + "\n";
if (operate == OperatTypeOfMoney.Remove)
{
str += a.Split('')[2] + "\t" + a.Split('')[3] + "\t" + a.Split('')[4] + "\n";
}
}
if (operate == (OperatTypeOfMoney)Enum.Parse(typeof(OperatTypeOfMoney), a.Split('')[1], true)
&& cardNo == Convert.ToInt64(a.Split('')[4]))
{
if (operate == OperatTypeOfMoney.Receive)
{
str += a.Split('')[2] + "\t" + a.Split('')[3] + "\t" + a.Split('')[0] + "\n";
}
}
}
return str;
}
#endregion
}
}
server类
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Mail;
using System.Text.RegularExpressions;

namespace Bank
{
class Server
{
public Server()
{ }
public void Email(string email,string subject,string body)
{
//\smtp.163.com
//smtp.sina.com.cn
Dictionary<string, string> type = new Dictionary<string, string>();
string t="";
type.Add("qq", "smtp.qq.com");
type.Add("sina", "smtp.sina.com.cn");
type.Add("163", "smtp.163.com");
foreach (string a in type.Keys)
{
if (email.Contains(a))
{
t = a;
}
}
type.TryGetValue(t,out t);
try
{
SmtpClient smtp = new SmtpClient(t, 25);
MailMessage message = new MailMessage("923406033@qq.com",email,subject,body);
smtp.Credentials = new NetworkCredential("923406033@qq.com", "请在这里输入你的密码");
smtp.Send(message);//CredentialCache.DefaultNetworkCredentials;
}
catch (Exception)
{
Console.WriteLine("注册成功,但不能把你的信息发到你的email,请检查你网络是否连通");
}
}//发送email
public void Phone()//发送短信
{ }
public void Listen()//每月收取业务费用
{ }
}
}
MYregex
 1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4 using System.Text.RegularExpressions;
5 namespace Bank
6 {
7 class MyRegex
8 {
9
10 public static bool regex(string text, string type)
11 {
12 Regex reg;
13 bool status = false;
14 if (type == "phone")
15 {
16 reg = new Regex(@"^(1)(\d){10}$");
17 status = reg.IsMatch(text);
18 }
19 if (type == "email")
20 {
21 reg = new Regex(@"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*");
22 status = reg.IsMatch(text);
23 }
24 if (type == "code")
25 {
26 reg = new Regex(@"^(\d){6}$");
27 status = reg.IsMatch(text);
28 }
29 if (type == "identity")
30 {
31 reg = new Regex(@"\d{17}[xX]$|\d{18}");
32 status = reg.IsMatch(text);
33 }
34 if (type == "pwd" && text.Length >= 6 && text.Length <= 12)
35 status = true;
36 return status;
37
38 }
39 }
40 }
Program
  1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4 using System.Timers;
5 using System.Net;
6 using System.Net.Mail;
7 using System.Text.RegularExpressions;
8 namespace Bank
9 {
10 class Program
11 {
12 enum UseOperate
13 {
14 Exit,//0
15 Save,//1
16 Fetch,//2
17 Remove,//3
18 MondifyPwd,//4
19 QueryAllAccounts,//5
20 Detail,//6
21 returnMainMenu//7
22 }
23 static void Main(string[] args)
24 {
25
26
27 Console.ForegroundColor = ConsoleColor.Red;
28 Console.WriteLine("测试账户");
29 Console.WriteLine("卡号\t卡型\t\t\t密码");
30 Console.WriteLine("10000\tCommonCard一般卡\t123456");
31 Console.WriteLine("10001\tCreditCard信用卡\t123456");
32 Console.WriteLine("10002\tDebitCard结算卡\t\t123456");
33 Console.WriteLine("10003\tSaveCard定期卡(未到期)\t123456");
34 Console.WriteLine("10004\tSaveCard定期卡(到期)\t123456\n\n\n");
35
36 Console.SetWindowSize(90,35);
37 Console.Title = "电子银行系统||软件2班 学号:20102203092 姓名:张艺龙||email:923406033@qq.com";
38 MainMenu();
39 }
40
41 #region 主菜单及一些操作
42
43 static void MainMenu()
44 {
45 string num = "10";
46 Console.WriteLine("\t|-----------------电子银行系统---------------------|");
47 Console.WriteLine("\t| *1.用户开户 |");
48 Console.WriteLine("\t| *2.前台登录 |");
49 Console.WriteLine("\t| *3.退出 |");
50 Console.WriteLine("\t|--------------------------------------------------|");
51 Console.WriteLine("请输入选项:");
52 num = Console.ReadLine();
53 try
54 {
55 switch (Convert.ToInt16(num))
56 {
57 case 1: Console.Clear(); RegistMenu(); break;
58 case 2: Login(); break;
59 case 3: break;
60 default:
61 Console.Clear();
62 MainMenu();
63 Login();
64 break;
65 }
66 }
67 catch (Exception e)
68 {
69 Console.WriteLine(e.Message);
70 Console.Clear();
71 MainMenu();
72
73 }
74 }
75
76 static void RegistMenu()
77 {
78 Console.WriteLine("===============================开户你要填写以下信息=========================");
79 Console.WriteLine("== *1、身份证号码 *5、开卡类型(一般卡、信用卡、定期卡、结算卡)==");
80 Console.WriteLine("== *2、真实姓名 *6、存储年数 ==");
81 Console.WriteLine("== *3、存入金额 *7、手机号码 ==");
82 Console.WriteLine("== *4、密码 *8、常用住址 ==");
83 Console.WriteLine("============================================================================");
84 Console.Write("是否同意以上协议Y/N(退出):");
85 string isAgreet = Console.ReadLine();
86 if (isAgreet.Equals("n") || isAgreet.Equals("N"))
87 {
88 Console.Clear();
89 MainMenu();
90 }
91
92 else if (isAgreet.Equals("y") || isAgreet.Equals("Y"))
93 {
94 Use use = new Use();
95 loop1:
96 Console.Write("请输入身份证号码:");
97 string id = Console.ReadLine();
98
99 if (MyRegex.regex(id, "identity"))
100 {
101 use.Id = long.Parse(id);
102 }
103 else
104 {
105 Console.WriteLine("\n你输入的格式不正确(18位数)\n");
106 goto loop1;
107 }
108 Console.Write("请输入真实姓名:"); use.Name = Console.ReadLine();
109 loop2: try { Console.Write("请输入存入金额 :"); use.Money = decimal.Parse(Console.ReadLine()); }
110 catch (FormatException e) { Console.WriteLine(e.Message); goto loop2; }
111
112
113 loop3:
114 try
115 {
116 Console.Write("请输入密码 :");
117 string pwd=Console.ReadLine();
118
119 if (MyRegex.regex(pwd, "pwd"))
120 {
121 use.Pwd = Int64.Parse(pwd);
122
123 }
124 else
125 {
126 Console.WriteLine("长度不对(6-12的数子)");goto loop3;
127 }
128 }
129 catch (FormatException e) { Console.WriteLine(e.Message); goto loop3; }
130
131
132 loop4:
133 Console.WriteLine("-----卡种选择-------------------------");
134 Console.WriteLine("\t*1、一般卡(CommonCard)");
135 Console.WriteLine("\t*2、信用卡(CreditCard)");
136 Console.WriteLine("\t*3、结算卡(DebitCard)");
137 Console.WriteLine("\t*4、定期卡(SaveCard)");
138 Console.Write("请输入开卡类型:");
139
140 try
141 { int type = int.Parse(Console.ReadLine());
142 Console.WriteLine("\n-------------------------------------");
143 use.Type = (CardType)Enum.Parse(typeof(CardType), type.ToString(), true);
144 if (type == 1 ||
145 type == 2 ||
146 type == 3 ||
147 type == 4)
148 {
149 use.StoreYearNum = 0;
150 if (use.Type == CardType.SaveCard)
151 {
152 Console.Write("请输入存储年数 :");
153 use.StoreYearNum = int.Parse(Console.ReadLine());
154 }
155 }
156 else
157 {
158 Console.WriteLine("\n你输入的选项不存在,你重新输入!!!!!!!!!!!!!!\n");
159 goto loop4;
160 }
161 }
162 catch (Exception e)
163 {
164 Console.WriteLine(e.Message);
165 goto loop4;
166 }
167
168 loop5:
169 Console.Write("请输入手机号码 :");
170 string link;
171 link = Console.ReadLine();
172 if (MyRegex.regex(link, "phone"))
173 {
174 use.Linking =long.Parse(link);
175 }
176 else
177 {
178 Console.WriteLine("\n你输入的手机格式不正确(以1开头的11位数)!!!!!!!!!!!\n");
179 goto loop5;
180
181 }
182
183
184 loop6:
185 Console.Write("请输入email(支持QQ,163,sina且开启了smtp服务) :");
186 string email;
187 email = Console.ReadLine();
188 if (MyRegex.regex(email, "email"))
189 {
190 use.Email = email;
191 }
192 else
193 {
194 Console.WriteLine("\n你输入的email格式不正确(以1开头的11位数)\n");
195 goto loop6;
196 }
197 Console.WriteLine("请输入常用住址 :");
198 use.Address = Console.ReadLine();
199 Console.WriteLine("信息填写完成,y提交/其他返回:");
200 use.Time = DateTime.Now;
201 if ((Console.ReadLine()).Equals("y") || (Console.ReadLine()).Equals("Y"))
202 {
203 Console.Clear();
204 string message = "亲爱的用户:\n\t你在" + DateTime.Now + "注册了********,请保护好你的信息,你注册的信息为\n"
205 + "身份证号码:" + use.Id + "\n"
206 + "真实姓名:" + use.Name + "\n"
207 + "开户时存入金额 :" + use.Money + "\n"
208 + "密码 :" + use.Pwd + "\n"
209 + "卡类型:" + use.Type + "\n"
210 + "手机号码 :" + use.Linking + "\n"
211 + "email :" + use.Email + "\n"
212 + "常用住址 :" + use.Address + "\n"
213 + "真实姓名:" + use.Name + "\n";
214 Server s = new Server();
215 Console.WriteLine("正在处理,你稍等");
216 Console.Clear();
217 s.Email(use.Email, "***电子银行系统", message);
218 Console.WriteLine("开户成功!!!!!\n你的密码为:{0}\n卡号为:{1}", use.Pwd, use.StoreDataToTxt(use,"useInfo.txt","flowDetail.txt"));
219 use.ShowPersonInfo();
220 MainMenu();
221 }
222 else
223 {
224 Console.Clear();
225 Console.WriteLine("你放弃不提交数据!!!!!!!");
226 RegistMenu();
227
228 }
229
230 }
231 else
232 {
233 Console.Clear();
234 RegistMenu();
235 }
236
237 }
238
239 static void Login()
240 {
241
242 try
243 {
244 Int64 carNo;
245 Int64 pwd;
246 Console.WriteLine("请输入卡号:");
247 carNo = Convert.ToInt64(Console.ReadLine());
248 Console.WriteLine("请输入密码:");
249 pwd = Convert.ToInt64(Console.ReadLine());
250
251
252 Use use = new Use(carNo, pwd);
253 bool p, c;
254 bool can = use.LoadInfo(out c, out p,"useInfo.txt");
255 if (!c)
256 {
257 Console.WriteLine("无此号");
258 Login();
259 }
260 if (!p)
261 {
262 Console.WriteLine("你输入的密码不正确");
263 Login();
264 }
265 if (can)
266 {
267 Console.Clear();
268 useOperate(use);
269 }
270 }
271 catch (FormatException e)
272 {
273 Console.WriteLine(e.Message);
274 Login();
275 }
276 }
277 #endregion
278
279 #region 登录以的菜单及一些操作
280 static void UseOperateMenu(Use use)
281 {
282 Console.WriteLine("\t|---用户操作-------------------------------------|");
283 Console.WriteLine("\t| *1、存款(Save) |");
284 Console.WriteLine("\t| *2、取款(Fetch) |");
285 Console.WriteLine("\t| *3、转账(Remove) |");
286 Console.WriteLine("\t| *4、修改密码(MondifyPwd) |");
287 Console.WriteLine("\t| *5、查询本人所有账户(QueryAllAccounts) |");
288 Console.WriteLine("\t| *6、资金流动详情(detail) |");
289 Console.WriteLine("\t| *7返回登录界面(returnMainMenu) |");
290 Console.WriteLine("\t|------------------------------------------------|");
291 Console.WriteLine("请输入选项:");
292 }
293 static void useOperate(Use use)
294 {
295
296 use.ShowPersonInfo();
297 UseOperateMenu(use);
298 try
299 {
300 UseOperate item = (UseOperate)Enum.Parse(typeof(UseOperate), Console.ReadLine(), true);
301 switch (item)
302 {
303 case UseOperate.Save:
304 Console.WriteLine("请输入你要存款的金额:");
305 decimal storeMoney = decimal.Parse(Console.ReadLine());
306 Console.Clear();
307 Console.WriteLine(use.StoreMoney(storeMoney));
308 useOperate(use);
309 break;
310 case UseOperate.Fetch:
311 Console.WriteLine("请输入你要取款的金额:");
312 decimal money = decimal.Parse(Console.ReadLine());
313 Console.Clear();
314 Console.WriteLine(use.Fectch(money));
315 useOperate(use);
316 break;
317 case UseOperate.Remove:
318 Int64 targeCardNo;
319 decimal removeMoney;
320 Console.WriteLine("请输入对方卡号:");
321 targeCardNo = Convert.ToInt64(Console.ReadLine());
322 Console.WriteLine("请输入转账金额:");
323 removeMoney = decimal.Parse(Console.ReadLine());
324 Console.Clear();
325 Console.WriteLine(use.RemoveMoney(targeCardNo, removeMoney));
326 useOperate(use); break;
327 case UseOperate.MondifyPwd:
328 Console.WriteLine("请输入新密码:");
329 Int64 newPwd = Convert.ToInt64(Console.ReadLine());
330 Console.Clear();
331 if (use.MondifyPwd(newPwd))
332 {
333 Console.WriteLine("密码更新成功!!!");
334 useOperate(use);
335 }
336 break;
337 case UseOperate.QueryAllAccounts:
338 List<Use> myuses = use.QueryPersonInfo();
339 Console.Clear();
340 Console.WriteLine("\n====本人所有账户信息==================================================");
341 foreach (Use u in myuses)
342 {
343 u.ShowPersonInfo();
344 }
345 Console.WriteLine("====以上是你本人所有账户信息============================================\n");
346 useOperate(use);
347 break;
348 case UseOperate.Detail:
349 Console.Clear();
350 Detail();
351 OperateDetail(use);
352 break;
353 case UseOperate.returnMainMenu: Console.Clear(); MainMenu(); Login(); break;
354 default:
355 Console.Clear();
356 Console.WriteLine("你输入的格式不对,操作失败!!!!");
357 useOperate(use);
358 break;
359 }
360 }
361 catch (Exception)
362 {
363 Console.Clear();
364 Console.WriteLine("你输入的格式不对,操作失败!!!!");
365 useOperate(use);
366 }
367 }
368 #endregion
369
370 #region 资金流动详情菜单及操作
371
372 static void Detail()
373 {
374 Console.WriteLine("\t|---资金流动详情------------------|");
375 Console.WriteLine("\t| *1、存款详情 |");
376 Console.WriteLine("\t| *2、取款详情 |");
377 Console.WriteLine("\t| *3、转账详情 |");
378 Console.WriteLine("\t| *4、收账详情 |");
379 Console.WriteLine("\t| *5、返回用户操作菜单 |");
380 Console.WriteLine("\t|---------------------------------|");
381 Console.WriteLine("请输入选项");
382 }
383 static void OperateDetail(Use use)
384 {
385 try
386 { int item = Convert.ToInt16(Console.ReadLine());
387 Console.Clear();
388 Detail();
389 string list;
390
391 switch (item)
392 {
393 case 1:
394 list = "存款金额\t存款时间\n" + use.ReadDatail(OperatTypeOfMoney.Save, "flowDetail.txt", use.CardNo);
395 Console.WriteLine(list);
396 OperateDetail(use);
397 break;
398 case 2:
399 list = "取款金额\t取款时间\n" + use.ReadDatail(OperatTypeOfMoney.Fetch, "flowDetail.txt", use.CardNo);
400 Console.WriteLine(list);
401 OperateDetail(use);
402 break;
403 case 3:
404 list = "转账金额\t转款时间\t对方账号\n" + use.ReadDatail(OperatTypeOfMoney.Remove, "flowDetail.txt", use.CardNo);
405 Console.WriteLine(list);
406 OperateDetail(use);
407
408 break;
409 case 4:
410 list = "收账金额\t收款时间\t来自账号\n" + use.ReadDatail(OperatTypeOfMoney.Receive, "flowDetail.txt", use.CardNo);
411 Console.WriteLine(list);
412 OperateDetail(use); break;
413 case 5:
414 Console.Clear();
415 useOperate(use); break;
416 default:
417 Console.Clear();
418 Console.WriteLine("输入格式有误");
419 Detail();
420 OperateDetail(use); ; break;
421 }
422 }
423 catch(Exception)
424 {
425 Console.Clear();
426 Console.WriteLine("输入格式有误");
427 Detail();
428 OperateDetail(use);
429 }
430
431 }
432 #endregion
433
434 #region 增值业务
435 static void AddServerMenu()
436 {
437 Console.WriteLine("\t|----增值业务---------------------------|");
438 Console.WriteLine("\t|----1、邮件提醒---------------------------|");
439 Console.WriteLine("\t|----2、手机短信提醒---------------------------|");
440 Console.WriteLine("\t|----3、普通卡转向信用卡---------------------------|");
441 Console.WriteLine("\t|----4、信用卡转向普通卡---------------------------|");
442
443 }
444 static void AddServerOperate()
445 {
446
447 }
448
449 #endregion
450
451 }
452 }

注:server类里面的发短信功能还没有实现,本想调用sina无线手机接口来实现的,但找不到注册页面





posted @ 2011-12-26 13:06  蓝亭赏月  阅读(1377)  评论(0编辑  收藏  举报