member.hpp文件

#include<bits/stdc++.h>
#include<graphics.h>
#include<easyx.h>
using namespace std;

class RMB {
    
    
public:
	double money;

	RMB operator+(RMB rmb) {
    
    
		 this->money += rmb.money;
		 return *this;
	}

	RMB operator-(RMB rmb) {
    
    
		 this->money -= rmb.money;
		 return *this;
	}

	string get_money() {
    
    
		string end = "";
		string str = to_string(money);
		string str_1 = str.substr(0, str.find("."));
		string str_2 = str.substr(str.find(".") + 1, 1);
		string str_3 = str.substr(str.find(".") + 2, 1);
		if (str_3!="0") {
    
    
			end += str_1 + "元" + str.substr(str.find(".") + 1, 1) + "角" + str.substr(str.find(".") + 2, 1) + "分";
		}
		else if (str_2!="0"&&str_3=="0") {
    
    
			end += str_1 + "元" + str.substr(str.find(".") + 1, 1) + "角" ;
		}
		else if (str_2=="0"&&str_3=="0") {
    
    
			end += str_1 + "元"; 
		}
		
		return end;
	}
};

class member {
    
    
public:
	string pass_word;
	string phone;
	string name;
	string numbering;
	string gender;
};

class memberCar :public RMB, public member {
    
    
public:
	RMB c_money;//现有金额
	RMB g_money;//已消费金额
	memberCar* next = NULL;//链表的下一个指针

	//0   1   2     3    4    5    6+
	//0.账号/密码/名称/性别/余额/消费记录
	vector<string>c;

	//查看个人信息
	void GUI_member(string path, string account) {
    
    
		//this->phone = account;
		get_message("member.txt", account);
		clearcliprgn();
		//1000,600
		setfillcolor(RGB(255, 1, 196));
		setcolor(RED);
		fillrectangle(300, 100, 700, 180);
		fillrectangle(300, 200, 700, 280);//查看个人信息
		fillrectangle(300, 300, 700, 380);//修改密码
		fillrectangle(300, 400, 700, 480);//查看消费记录
		fillrectangle(300, 500, 495, 580);//返回
		fillrectangle(505, 500, 700, 580);//退出
		settextstyle(50, 0, _T("微软雅黑"));
		setcolor(RGB(255, 255, 255));
		outtextxy(300, 115, (this->name + "你好").c_str());
		outtextxy(400, 215, "查看个人信息");
		outtextxy(400, 315, "修改密码");
		outtextxy(400, 415, "查看消费记录");
		outtextxy(360, 515, "返回");
		outtextxy(565, 515, "退出");
		while (1) {
    
    
			MOUSEMSG msg = GetMouseMsg();
			if (msg.mkLButton) {
    
    
				//查看个人信息
				if ((msg.x > 300 && msg.x < 700) && (msg.y > 200 && msg.y < 280)) {
    
    //查看个人信息了
					clearcliprgn();
					setfillcolor(RGB(255, 1, 196));
					setcolor(RED);
					fillrectangle(300, 100, 700, 180);//编号
					fillrectangle(300, 200, 700, 280);//名称
					fillrectangle(300, 300, 700, 380);//性别
					fillrectangle(300, 400, 700, 480);//余额
					fillrectangle(300, 500, 700, 580);//返回
					setcolor(RGB(255, 255, 255));
					settextstyle(50, 0, _T("微软雅黑"));
					outtextxy(300, 130, ("编号:" + numbering).c_str());
					outtextxy(350, 230, ("名称(可修改):" + name).c_str());
					outtextxy(350, 330, ("性别(可修改):" + gender).c_str());
					string end = c_money.get_money();
					outtextxy(350, 430, ("余额" + end).c_str());
					outtextxy(350, 530, "返回");
					while (1) {
    
    
						MOUSEMSG msg_1 = GetMouseMsg();
						if (msg_1.mkLButton) {
    
    
							//修改名称
							if ((msg_1.x > 300 && msg_1.x < 700) && (msg_1.y > 200 && msg_1.y < 280)) {
    
    
								char t_name[10] = {
    
     0 };
								InputBox(t_name, 10, "请输入您的名称(name)");

								//重新填充当前的"名称"的边框
								setfillcolor(RGB(255, 1, 196));
								setcolor(RED);
								fillrectangle(300, 200, 700, 280);

								settextcolor(RGB(255, 255, 255));
								settextstyle(30, 0, _T("微软雅黑"));
								c[3] = this->name = t_name;
								outtextxy(350, 230, ("名称(可修改):" + this->name).c_str());
								//能跑不就行了,何必这么担心呢?
								save("member.txt");
							}
							//修改性别
							if ((msg_1.x > 300 && msg_1.x < 700) && (msg_1.y > 300 && msg_1.y < 380)) {
    
    
								char t_name[10] = {
    
     0 };
								InputBox(t_name, 10, "请输入性别(gender)");
								//重新填充当前的"性别"的边框
								setfillcolor(RGB(255, 1, 196));
								setcolor(RED);
								fillrectangle(300, 300, 700, 380);
								settextcolor(RGB(255, 255, 255));
								settextstyle(30, 0, _T("微软雅黑"));
								c[4] = this->gender = t_name;
								outtextxy(350, 330, ("性别(可修改):" + gender).c_str());
								save("member.txt");
							}
							//退出按钮
							if ((msg_1.x > 300 && msg_1.x < 700) && (msg_1.y > 500 && msg_1.y < 580)) {
    
    //“退出”按钮会回到用户自己的界面			
								clearcliprgn();
								//1000,600
								setfillcolor(RGB(255, 1, 196));
								setcolor(RED);
								fillrectangle(300, 100, 700, 180);
								fillrectangle(300, 200, 700, 280);//查看个人信息
								fillrectangle(300, 300, 700, 380);//修改密码
								fillrectangle(300, 400, 700, 480);//查看消费记录
								fillrectangle(300, 500, 700, 580);//退出
								setcolor(RGB(255, 255, 255));
								settextstyle(50, 0, _T("微软雅黑"));
								outtextxy(300, 115, (this->name + "你好").c_str());
								outtextxy(400, 215, "查看个人信息");
								outtextxy(400, 315, "修改密码");
								outtextxy(400, 415, "查看消费记录");
								outtextxy(540, 515, "退出");
								break;
							}
						}
						FlushMouseMsgBuffer();
					}
				}
				//修改密码
				if ((msg.x > 300 && msg.x < 700) && (msg.y > 300 && msg.y < 380)) {
    
    
					clearcliprgn();
					setfillcolor(RGB(255, 1, 196));
					setcolor(RED);
					fillrectangle(300, 200, 700, 300);//输入密码
					fillrectangle(300, 400, 700, 500);//确定
					setcolor(RGB(255, 255, 255));
					settextstyle(50, 0, _T("微软雅黑"));
					outtextxy(300, 230, "输入密码");
					outtextxy(430, 440, "确定");

					char re_password[10] = {
    
     0 };
					FlushMouseMsgBuffer();//进入一个新的鼠标判定的循环前也需要清理一下缓冲区
					while (1) {
    
    
						MOUSEMSG msg_1 = GetMouseMsg();
						if (msg_1.mkLButton) {
    
    
							//输入密码
							if ((msg_1.x > 300 && msg_1.x < 700) && (msg_1.y > 200 && msg_1.y < 300)) {
    
    
								InputBox(re_password, 10, "输入新的密码");
								setfillcolor(RGB(255, 1, 196));
								setcolor(RED);
								fillrectangle(300, 200, 700, 300);//输入密码
								c[2] = this->pass_word = re_password;//不修改第一个同类型的错误就不会给下面的错误报错
								setcolor(RGB(255, 255, 255));
								settextstyle(50, 0, _T("微软雅黑"));
								outtextxy(300, 230, ("新密码:" + c[2]).c_str());
							}
							//确定
							string temp = re_password;//为了让密码的输入不为NULL
							if ((msg_1.x > 300 && msg_1.x < 700) && (msg_1.y > 400 && msg_1.y < 500)) {
    
    
								if (temp == "") {
    
    
									MessageBox(NULL, _T("无效密码"), _T("提示"), MB_OK | MB_SETFOREGROUND | MB_ICONHAND);
								}
								else {
    
    
									save("member.txt");
									MessageBox(NULL, _T("修改密码成功"), _T("提示"), MB_OK | MB_SETFOREGROUND | MB_ICONASTERISK);
									MessageBox(NULL, _T("登录失效需要重新登录"), _T("提示"), MB_OK | MB_SETFOREGROUND | MB_ICONASTERISK);
									msg.y = 550;//通过修改的已得到的鼠标的属性来达到修改退出的目的,不过这种方法只能用于退出方法在此行的下面
									break;
								}
							}
						}
						//当鼠标消息缓冲区满了以后,不再接收任何鼠标消息,所以才需要这样的清理鼠标的缓冲区
						FlushMouseMsgBuffer();
					}
				}

				//消费记录
				if ((msg.x > 300 && msg.x < 700) && (msg.y > 400 && msg.y < 480)) {
    
    
					clearcliprgn();
					setcolor(RGB(255, 255, 255));
					settextstyle(50, 0, _T("微软雅黑"));
					outtextxy(200, 0, "更新的顺序为从上到下,从左到右");

					//为了竟可能多的现实在界面上
					int han = 0;
					int counter = 1;
					//由于循环体中使用到的是i-1,所以可以遍历带c[6]
					for (int i = c.size(); i >= 7; i--) {
    
    
						setfillcolor(RGB(255, 1, 196));
						setcolor(BLACK);
						if (counter > 11) {
    
    
							han++;
							counter -= 11;
						}
						fillrectangle(300 + han * 200, 50 * counter, 300 + (han + 1) * 200, 50 * (counter + 1));
						setcolor(RGB(255, 255, 255));
						settextstyle(50, 0, _T("微软雅黑"));
						RMB rmb;
						rmb.money = atof(c[i-1].c_str());
						outtextxy(310 + 200 * han, 50 * counter, (to_string(counter) + "." + rmb.get_money()).c_str());
						counter++;
					}

					setfillcolor(RGB(255, 1, 196));
					setcolor(RED);
					fillrectangle(100, 250, 290, 350);//返回
					setcolor(RGB(255, 255, 255));
					settextstyle(50, 0, _T("微软雅黑"));
					outtextxy(150, 275, "返回");
					while (1) {
    
    
						MOUSEMSG msg_1 = GetMouseMsg();
						if (msg_1.mkLButton) {
    
    
							if ((msg_1.x > 100 && msg_1.x < 290) && (msg_1.y > 250 && msg_1.y < 350)) {
    
    
								clearcliprgn();
								get_message("member.txt", account);
								clearcliprgn();
								//1000,600
								setfillcolor(RGB(255, 1, 196));
								setcolor(RED);
								fillrectangle(300, 100, 700, 180);
								fillrectangle(300, 200, 700, 280);//查看个人信息
								fillrectangle(300, 300, 700, 380);//修改密码
								fillrectangle(300, 400, 700, 480);//查看消费记录
								fillrectangle(300, 500, 700, 580);//退出
								setcolor(RGB(255, 255, 255));
								settextstyle(50, 0, _T("微软雅黑"));
								outtextxy(300, 115, (this->name + "你好").c_str());
								outtextxy(400, 215, "查看个人信息");
								outtextxy(400, 315, "修改密码");
								outtextxy(400, 415, "查看消费记录");
								outtextxy(540, 515, "退出");
								break;
							}
						}
						FlushMouseMsgBuffer();
					}
				}
				//返回并且回到登录界面
				if ((msg.x > 300 && msg.x < 495) && (msg.y > 500 && msg.y < 580)) {
    
    
					//这个方法需要回到登录的位置
					//closegraph();//关闭图形
					clearcliprgn();
					setfillcolor(RGB(255, 1, 196));
					setcolor(RED);
					fillrectangle(300, 150, 700, 250);//用户登录
					fillrectangle(300, 350, 700, 450);//管理员登录
					fillrectangle(400, 500, 600, 550);
					char str_1_1[] = "用户登录";
					char str_1_2[] = "管理员登录";
					char str_1_3[] = "返回";
					setcolor(RGB(255, 255, 255));
					settextstyle(50, 0, _T("微软雅黑"));
					outtextxy(430, 180, str_1_1);
					outtextxy(405, 380, str_1_2);
					outtextxy(460, 500, str_1_3);
					break;
				}
				//退出图形
				if ((msg.x > 505 && msg.x < 700) && (msg.y > 500 && msg.y < 580)) {
    
    
					closegraph();
				}
			}
			FlushMouseMsgBuffer();
		}
	}

	//更新余额的方法
	void re_money(double number, bool is_reduce) {
    
    
		if (!is_reduce) {
    
    
			c_money.money += number;
			c[5] = to_string(c_money.money);
			save("member.txt");
		}
		else {
    
    
			g_money.money += number;
			c.push_back(to_string(number));
			save("member.txt");
		}
	}

	//判断本会员的余额是否足够
	bool enough_money(double number) {
    
    
		if (atof(c[5].c_str()) > number) {
    
    
			return 1;
		}
		return 0;
	}

	//得到类的各种信息
	void get_message(string path, string account) {
    
    
		ifstream ifs;
		ifs.open(path, ios::in);
		if (!ifs.fail()) {
    
    
			string len = "";
			while (getline(ifs, len)) {
    
    
				string temp = len.substr(len.find(".") + 1, len.find_first_of("/") - len.find(".") - 1);
				if (temp == account) {
    
    
					c.push_back(len.substr(0, len.find(".")));
					c.push_back(account);
					len = len.substr(len.find("/") + 1);
					while (len.find("/") != -1) {
    
    
						c.push_back(len.substr(0, len.find_first_of("/")));
						len = len.substr(len.find("/") + 1);
					}
					c.push_back(len);
					this->numbering = c[0];//编号
					this->phone = account; //账号
					this->pass_word = c[2];//密码
					this->name = c[3];//名称
					this->gender = c[4];//性别
					this->c_money.money = atof(c[5].c_str());//现有金额
					for (unsigned int i = 6; i < c.size(); i++) {
    
    //获得消费金额
						g_money.money += atof(c[i].c_str());
					}
					return;
				}
			}
		}
	}

	//按编号进行寻找位置存储
	// <param name="path">文件路径</param>
	void save(string path) {
    
    
		string s;
		s += c[0] + ".";
		for (int i = 1; i < c.size(); i++) {
    
    
			if(i!=c.size()-1)
			s += c[i] + "/";
			else {
    
    
				s += c[i];
			}
		}


		ifstream ifs(path, ios::in);
		string str;
		if (ifs.is_open()) {
    
    
			int han = 0;
			string len;
			while (getline(ifs, len)) {
    
    
				if (to_string(han) == c[0]) {
    
    
					str += s + "\n";
				}
				else {
    
    
					str += len + "\n";
				}
				han++;
			}
		}
		ifs.close();
		ofstream ofs(path);
		if (!ofs.fail()) {
    
    
			ofs.flush();
			ofs << str;
			ofs.close();
		}
		ofstream ofs1("member.dat",ios::binary);
		if (!ofs1.fail()) {
    
    
			ofs1.flush();
			ofs1.write(str.c_str(),sizeof(str));;
			ofs1.close();
		}
	}

	//将会员的数据整合成字符串输出,没有密码
	string get_str_message() {
    
    
		string str = "";
		str += "编号" + c[0] + '.';//编号
		str += "账号:" + c[1] + "|";//账号
		str += "名字:" + c[3] + "|";//名字
		str += "性别:" + c[4] + "|";
		RMB rmb;
		rmb.money = atof(c[5].c_str());
		str += "余额:"+rmb.get_money()+"|";
		str += "消费:"+g_money.get_money();
		return str;
	}

	//得到会员的消费
	double get_g_money(string path,string account) {
    
    
		this->get_message(path,account);
		return this->g_money.money;
	}
};

猜你喜欢

转载自blog.csdn.net/blastospore/article/details/118176154