#include<memberCar.hpp>
using namespace std;
struct s_memberCar {
string account="";
double number=0.0;//消费金额
s_memberCar* next=NULL;
};
//链表排序的方法
void insert_sort(s_memberCar* &head,s_memberCar *s) {
if (head==NULL) {
head = s;
return;
}
else {
s_memberCar* temp = new s_memberCar();
temp=head;
s_memberCar* m = new s_memberCar();
m = temp;
//不会对最后一个加以判断
for (; temp->next; m = temp, temp = temp->next) {
if (temp->number<s->number) {
m->next = s;
s->next = temp;
return;
}
}
//能走到最后就说明这个s的数值是最小的
temp->next = s;
s->next = NULL;
}
}
bool cmd(s_memberCar a,s_memberCar b) {
return a.number > b.number;
}
class admin :public RMB{
public :
RMB c_money;//余额
RMB g_money;//已消费金额
int counter = get_member_number("member.txt");
//路径文件是否存在账号
bool exist_accout(string path, string acount) {
ifstream ifs(path, ios::in);//只读
string len;
if (!ifs.fail())
while (getline(ifs, len)) {
if (acount._Equal(len.substr(len.find(".") + 1, len.find_first_of("/") - len.find(".") - 1))) {
return 1;
}
}
return 0;
}
//判断字符串中是否全是数字
bool all_number(string& s) {
for (int i = 0; i < s.size(); i++) {
if (!(s[i] >= '0' && s[i] <= '9')) {
return false;
}
}
return true;
}
//得到会员的数量
const int get_member_number(string path) {
ifstream ifs(path,ios::in);
int counter = 0;
if (ifs.is_open()) {
string len = "";
while (getline(ifs, len)) {
if (atoi(len.substr(0,len.find(".")).c_str())>0) {
counter++;
}
}
}
return counter;
}
//初始化管理员的界面
admin(int a) {
//先得到钱的数量,
c_money.money = 0;
g_money.money = 0;
get_money("member.txt");
setfillcolor(RGB(255, 1, 196));
setcolor(RED);
fillrectangle(200, 10, 700, 110);//查看用户的信息
fillrectangle(200, 130, 700, 230);//按消费金额排序用户
fillrectangle(200, 250, 700, 350);//用户的余额总数
fillrectangle(200, 370, 700, 470);//总余额
fillrectangle(200, 490, 600, 590);//会员余额变动
fillrectangle(640, 500, 760, 580);//返回
fillrectangle(770, 500, 890, 580);//退出
char str_2_1[] = "查看用户的信息";
char str_2_2[] = "按消费金额排序用户";
char str_2_3[] = "总余额度:";
char str_2_4[] = "总消费额:";
char str_2_5[] = "会员余额变动";
char str_2_7[] = "返回";
char str_2_8[] = "退出";
settextcolor(RGB(255, 255, 255));
settextstyle(50, 0, _T("微软雅黑"));
outtextxy(210, 40, str_2_1);
outtextxy(210, 160, str_2_2);
outtextxy(210, 280, str_2_3);
outtextxy(210, 410, str_2_4);
outtextxy(440, 280, c_money.get_money().c_str());
outtextxy(440, 410, g_money.get_money().c_str());
outtextxy(210, 520, str_2_5);
outtextxy(650, 520, str_2_7);
outtextxy(780, 520, str_2_8);
FlushMouseMsgBuffer();
while (1) {
MOUSEMSG msg = GetMouseMsg();
if (msg.mkLButton) {
//查看所有用户的数据
if ((msg.x > 200 && msg.x < 700) && (msg.y > 10 && msg.y < 110)) {
clearcliprgn();
ifstream ifs("member.txt",ios::in);
string len;
int han = 0;
//数据显示为 编号.名称/消费金额
while (getline(ifs,len)) {
if (atoi(len.substr(0, len.find(".")).c_str()) > 0) {
memberCar mc;
mc.get_message("member.txt",len.substr(len.find(".")+1,len.find_first_of("/")-len.find(".")-1));
setfillcolor(RGB(255,1,196));
setcolor(BLACK);
fillrectangle(300,50*han,1000,40+50*han);
settextcolor(RGB(255, 255, 255));
settextstyle(30, 0, _T("微软雅黑"));
outtextxy(310,5+50*han,mc.get_str_message().c_str());
han++;
}
}
setfillcolor(RGB(255, 1, 196));
setcolor(BLACK);
fillrectangle(50,200,290,300);
settextstyle(50,0,_T("微软雅黑") );
settextcolor(RGB(255, 255, 255));
outtextxy(140,230,"返回");
FlushMouseMsgBuffer();
while (1) {
MOUSEMSG msg_1 = GetMouseMsg();
if (msg_1.mkLButton) {
if ((msg_1.x>50&&msg_1.x<290)&&(msg_1.y>200&&msg_1.y<300)) {
clearcliprgn();
get_money("member.txt");
setfillcolor(RGB(255, 1, 196));
setcolor(RED);
fillrectangle(200, 10, 700, 110);//查看用户的信息
fillrectangle(200, 130, 700, 230);//按消费金额排序用户
fillrectangle(200, 250, 700, 350);//用户的余额总数
fillrectangle(200, 370, 700, 470);//总余额
fillrectangle(200, 490, 600, 590);//会员余额变动
fillrectangle(640, 500, 760, 580);//返回
fillrectangle(770, 500, 890, 580);//退出
char str_2_1[] = "查看用户的信息";
char str_2_2[] = "按消费金额排序用户";
char str_2_3[] = "总余额度:";
char str_2_4[] = "总消费额:";
char str_2_5[] = "会员余额变动";
char str_2_7[] = "返回";
char str_2_8[] = "退出";
settextcolor(RGB(255, 255, 255));
settextstyle(50, 0, _T("微软雅黑"));
outtextxy(210, 40, str_2_1);
outtextxy(210, 160, str_2_2);
outtextxy(210, 280, str_2_3);
outtextxy(210, 410, str_2_4);
outtextxy(440, 280, c_money.get_money().c_str());
outtextxy(440, 410, g_money.get_money().c_str());
outtextxy(210, 520, str_2_5);
outtextxy(650, 520, str_2_7);
outtextxy(780, 520, str_2_8);
break;
}
}
FlushMouseMsgBuffer();
}
}
//按消费金额排序用户
if ((msg.x > 200 && msg.x < 700) && (msg.y > 130 && msg.y < 230)) {
vector<s_memberCar> v;
ifstream ifs("member.txt", ios::in);
string len = "";
if (ifs.is_open()) {
while (getline(ifs,len)) {
if (atoi(len.substr(0,len.find(".")).c_str())>0) {
memberCar temp;
s_memberCar sm;
sm.account = len.substr(len.find(".")+1,len.find_first_of("/")-len.find(".")-1);
sm.number = temp.get_g_money("member.txt",sm.account);
v.push_back(sm);
}
}
sort(v.begin(),v.end(),cmd);
clearcliprgn();
setfillcolor(RGB(255,1,196));
setfillcolor(BLACK);
for (int i = 0; i < v.size();i++) {
fillrectangle(300,50*i,700,50+50*i);
}
setcolor(BLACK);
settextstyle(30, 0, _T("微软雅黑"));
for (int i = 0; i < v.size(); i++) {
memberCar mc;
mc.get_message("member.txt", v[i].account);
settextcolor(RGB(255, 255, 255));
outtextxy(310, 10 + 50 * i, mc.get_str_message().c_str());
}
setfillcolor(RGB(255, 1, 196));
setcolor(BLACK);
fillrectangle(50, 200, 290, 300);
settextstyle(50, 0, _T("微软雅黑"));
settextcolor(RGB(255,255,255));
outtextxy(140, 230, "返回");
FlushMouseMsgBuffer();
while (1) {
MOUSEMSG msg_1 = GetMouseMsg();
if ((msg_1.mkLButton)&&(msg_1.x > 50 && msg_1.x < 290) && (msg_1.y > 200 && msg_1.y < 300)) {
clearcliprgn();
get_money("member.txt");
setfillcolor(RGB(255, 1, 196));
setcolor(RED);
fillrectangle(200, 10, 700, 110);//查看用户的信息
fillrectangle(200, 130, 700, 230);//按消费金额排序用户
fillrectangle(200, 250, 700, 350);//用户的余额总数
fillrectangle(200, 370, 700, 470);//总余额
fillrectangle(200, 490, 600, 590);//会员余额变动
fillrectangle(640, 500, 760, 580);//返回
fillrectangle(770, 500, 890, 580);//退出
char str_2_1[] = "查看用户的信息";
char str_2_2[] = "按消费金额排序用户";
char str_2_3[] = "总余额度:";
char str_2_4[] = "总消费额:";
char str_2_5[] = "会员余额变动";
char str_2_7[] = "返回";
char str_2_8[] = "退出";
settextcolor(RGB(255, 255, 255));
settextstyle(50, 0, _T("微软雅黑"));
outtextxy(210, 40, str_2_1);
outtextxy(210, 160, str_2_2);
outtextxy(210, 280, str_2_3);
outtextxy(210, 410, str_2_4);
outtextxy(440, 280, c_money.get_money().c_str());
outtextxy(440, 410, g_money.get_money().c_str());
outtextxy(210, 520, str_2_5);
outtextxy(650, 520, str_2_7);
outtextxy(780, 520, str_2_8);
break;
}
FlushMouseMsgBuffer();
}
}
}
//会员余额的变动
if ((msg.x > 200 && msg.x < 700) && (msg.y > 490 && msg.y < 590)) {
clearcliprgn();
setfillcolor(RGB(255, 1, 196));
setcolor(RED);
fillrectangle(300, 100, 700, 200);//输入账号
fillrectangle(300, 300, 700, 400);//输入金额
fillrectangle(10, 100, 290, 200);//充值?
fillrectangle(20, 210, 130, 300);//是
fillrectangle(150, 210, 260, 300);//否
fillrectangle(400, 450, 600, 550);//检测
fillrectangle(640, 480, 760, 550);//返回
char str_2_1[] = "输入账号:";
char str_2_2[] = "输入金额";
char str_2_3[] = "检测";
char str_2_4[] = "返回";
settextcolor(RGB(255, 255, 255));
settextstyle(50, 0, _T("微软雅黑"));
outtextxy(400, 130, str_2_1);
outtextxy(400, 330, str_2_2);
outtextxy(450, 480, str_2_3);
outtextxy(650, 490, str_2_4);
outtextxy(30, 130, "充值?");
outtextxy(50, 240, "是");
outtextxy(190, 240, "否");
char s_account[10] = {
0 };//接受账号
char s_number[10] = {
0 }; //接受数字
bool is_reduce = false; //判断时候是让余额减少的变量
FlushMouseMsgBuffer();
while (1) {
MOUSEMSG msg_3 = GetMouseMsg();
if (msg_3.mkLButton) {
//输入账号
if ((msg_3.x > 300 && msg_3.x < 700) && (msg_3.y > 100 && msg_3.y < 200)) {
InputBox(s_account, 10, "请输入账号(acount)");
setfillcolor(RGB(255, 1, 196));
setcolor(RED);
fillrectangle(300, 100, 700, 200);//输入账号
settextstyle(50, 0, _T("微软雅黑"));
outtextxy(400,130,"账号:");
outtextxy(520, 130, s_account);
}
//输入扣除金额
if ((msg_3.x > 300 && msg_3.x < 700) && (msg_3.y > 300 && msg_3.y < 400)) {
setfillcolor(RGB(255, 1, 196));
setcolor(RED);
fillrectangle(300, 300, 700, 400);//输入账号
InputBox(s_number, 10, "请输入金额(无论输入的正负,最终数据都是正的)");
settextstyle(50, 0, _T("微软雅黑"));
outtextxy(400,330,"金额");
outtextxy(510,330,s_number);
}
//点击是
if ((msg_3.x > 20 && msg_3.x < 130) && (msg_3.y > 210 && msg_3.y < 300)) {
is_reduce = false;
setfillcolor(BLACK);
fillrectangle(150, 210, 260, 300);//额外填充“否”的方块
setfillcolor(RGB(255, 1, 196));
setcolor(RED);
fillrectangle(20, 210, 130, 300);//清除“是”的方块
outtextxy(50, 240, "是");
}
//点击否
if ((msg_3.x > 150 && msg_3.x < 260) && (msg_3.y > 210 && msg_3.y < 300)) {
is_reduce = 1;
setfillcolor(BLACK);
fillrectangle(20, 210, 130, 300);//额外填充“否”的方块
setfillcolor(RGB(255, 1, 196));
setcolor(RED);
fillrectangle(150, 210, 260, 300);//清除“是”的方块
outtextxy(190, 240, "否");
}
//检测按钮
if ((msg_3.x > 400 && msg_3.x < 600) && (msg_3.y > 450 && msg_3.y < 550)) {
memberCar mc;
string mc_account = s_account;
string mc_number = s_number;
mc.get_message("member.txt",mc_account);
if (mc_number[0] == '-') {
mc_number = mc_number.substr(mc_number.find_first_of("-") + 1);
}
//1.账号错误
if (mc_account == "") {
MessageBox(NULL, _T("无效账号"), _T("警告"), MB_OK | MB_SETFOREGROUND | MB_ICONHAND);
}
//2.没有输入账号
else if (!exist_accout("member.txt", mc_account)) {
MessageBox(NULL, _T("无效账号"), _T("警告"), MB_OK | MB_SETFOREGROUND | MB_ICONHAND);
}
//3.输入的金额错误,不全是数字
else if (!all_number(mc_number)) {
MessageBox(NULL, _T("输入金额有误"), _T("警告"), MB_OK | MB_SETFOREGROUND | MB_ICONHAND);
}
//4.会员的余额不足
else if ((!mc.enough_money(atof(mc_number.c_str())))&&is_reduce) {
MessageBox(NULL, _T("会员的余额不足"), _T("警告"), MB_OK | MB_SETFOREGROUND | MB_ICONHAND);
}
if(exist_accout("member.txt",mc_account)){
if (is_reduce&& mc.enough_money(atof(mc_number.c_str()))) {
mc.re_money(atof(mc_number.c_str()),is_reduce);
}
if (!is_reduce) {
mc.re_money(atof(mc_number.c_str()), is_reduce);
}
MessageBox(NULL, _T("余额变动成功"), _T("警告"), MB_OK | MB_SETFOREGROUND | MB_ICONEXCLAMATION);
}
}
//返回
if ((msg_3.x > 640 && msg_3.x < 760) && (msg_3.y > 480 && msg_3.y < 550)) {
clearcliprgn();
setfillcolor(RGB(255, 1, 196));
setcolor(RED);
fillrectangle(200, 10, 700, 110);//查看用户的信息
fillrectangle(200, 130, 700, 230);//按消费金额排序用户
fillrectangle(200, 250, 700, 350);//用户的余额总数
fillrectangle(200, 370, 700, 470);//总余额
fillrectangle(200, 490, 600, 590);//会员余额变动
fillrectangle(640, 500, 760, 580);//返回
fillrectangle(770, 500, 890, 580);//退出
char str_2_1[] = "查看用户的信息";
char str_2_2[] = "按消费金额排序用户";
char str_2_3[] = "总余额度:";
char str_2_4[] = "总消费额:";
char str_2_5[] = "会员余额变动";
char str_2_7[] = "返回";
char str_2_8[] = "退出";
settextcolor(RGB(255, 255, 255));
settextstyle(50, 0, _T("宋体"));
outtextxy(210, 40, str_2_1);
outtextxy(210, 160, str_2_2);
outtextxy(210, 280, str_2_3);
outtextxy(210, 410, str_2_4);
outtextxy(440, 280, c_money.get_money().c_str());
outtextxy(440, 410, g_money.get_money().c_str());
outtextxy(210, 520, str_2_5);
outtextxy(650, 520, str_2_7);
outtextxy(780, 520, str_2_8);
break;
}
}
FlushMouseMsgBuffer();
}
}
//返回按钮,返回到用户和管理员的登录界面
if ((msg.x > 640 && msg.x < 760) && (msg.y >500 && msg.y < 580)) {
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 > 770 && msg.x < 890) && (msg.y > 500 && msg.y < 580)) {
closegraph();//直接关闭图形
}
}
FlushMouseMsgBuffer();
}
}
int next_counter = 0;
void get_money(string path) {
ifstream ifs(path,ios::in);
if (next_counter!=0) {
return;
}
next_counter++;
if (!ifs.fail()) {
string len = "";
while (getline(ifs,len)) {
//序号大于0才是符合的数据
if (atoi(len.substr(0,len.find(".")).c_str())>0) {
memberCar mc;
string account = len.substr(len.find(".")+1,len.find_first_of("/")-len.find(".")-1);
mc.get_message(path,account);
c_money.money += mc.c_money.money;
g_money.money += mc.g_money.money;
}
}
}
ifs.close();
}
};
admin.cpp
おすすめ
転載: blog.csdn.net/blastospore/article/details/118176227
おすすめ
ランキング