#define _CRT_SECURE_NO_WARNINGS
#include<fstream>
#include<iostream>
#include<time.h>
#include<admin.hpp>
using namespace std;
//2021/6/18 计划·实现管理员的各种功能,实现完这个后也就实训工作就完成了。
//2.做出了用户界面的功能的实现 具体有查看个人信息,修改密码
// 做出了管理员的界面 具体有 查看全部用户用户的个人信息,按消费金额给会员排序,充值,扣费,查看所有用户的余额,查询所有用户的消费金额
//1.之前的登录判定方法出了问题,当时我的数据还只有编号.账号/密码
//管理员方面可以查看用户的个人信息,按消费金额排序,输出快捷店当前会员数,当前所有会员的消费总额,所有会员卡剩余的额度总数;
//具体有用户可以查看自己的个人信息,可以修改自己的名称,修改密码,查询消费记录
//2021/6/17,数据显示在界面上
//无论如何我只会将这个项目写到星期5再往后我不会再写下去,下星期我在写这个项目我就是伞兵
//好像是界面间的刷新问题,使得我在一些界面中//使用goto语句解决
// 1.实现了登录是匹配账号和密码
//2021/6/16,做出登录系统,实现文件的随机读写,将文件要求的信息实现
//2021/6/15,做成初始界面,实现注册系统,并完成了文件的写入,随手搞定了三个要求的类,但码量只有300多一点
// 初始化界面的类
class initialization {
public:
//初始化界面的方法 按钮有 登录,注册,退出
initialization(char temp) {
setfillcolor(RGB(255, 1, 196));
setcolor(RED);
fillrectangle(300, 100, 700, 200);//登录
fillrectangle(300, 250, 700, 350);//注册
fillrectangle(300, 400, 700, 500);//退出
char str_1[] = "登录";
char str_2[] = "注册";
char str_3[] = "退出";
setcolor(RGB(255, 255, 255));
settextstyle(50, 0, _T("宋体"));
outtextxy(450, 130, str_1);
outtextxy(450, 280, str_2);
outtextxy(450, 430, str_3);
}
//初始化登录界面的方法 按钮有 输入账号,输入密码,检测 ,返回
initialization(int temp) {
setfillcolor(RGB(255, 1, 196));
setcolor(RED);
fillrectangle(300, 100, 700, 200);//输入账号
fillrectangle(300, 300, 700, 400);//输入密码
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);
}
//用户自己的界面 ,准备实现的功能:检测个人信息,修改密码,返回上一级;
initialization(string account) {
FlushMouseMsgBuffer();
(new memberCar())->GUI_member("member.txt",account);
}
//管理员的界面 ,需要查看会员的信息,充值,扣费,按消费金额排序,
// 管理员方面可以查看用户的个人信息,按消费金额排序,输出快捷店当前会员数,当前所有会员的消费总额,所有会员卡剩余的额度总数;
initialization(float f) {
setfillcolor(RGB(255, 1, 196));
setcolor(RED);
fillrectangle(300, 100, 700, 200);//查看用户的信息
fillrectangle(300, 300, 700, 400);//按消费金额排序用户
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);
}
};
//一个检测字符串是否全部为数字的方法
bool all_number(string& s) {
for (int i = 0; i < s.size();i++) {
if (!(s[i]>='0'&&s[i]<='9')) {
return false;
}
}
return true;
}
/// 编号/账号/密码/名字/性别/现有金额/已消费金额
/// member.txt 这个文件用来第一次存储账号和密码
/// 但是这个方法一定要重写
/// <param name="path">文件的路径</param>
/// <param name="s">要写入文件的一行</param>
/// <returns></returns>
bool write_path(string path,string s) {
ifstream ifs(path,ios::in);
if (ifs.fail()) {
//写入文件失败
return 0;
}
string len="";
int han = 0;
stringstream ss;
ss.clear();
string str_fail_date="";//这个一定要初始化
while(getline(ifs,len)){
ss << han;
string temp="";
ss >> temp;
ss.clear();
if (len.find(".") == -1) {
str_fail_date += temp + "." + len;
}
else {
str_fail_date += len;
}
str_fail_date += "\n";
han++;
}
ifs.close();
ss.clear();
ss << han;
string temp = "";
ss >> temp;
str_fail_date += temp + "." + s;//传入新账号密码默认填写在最后
str_fail_date += "\n";
ofstream out;
out.open(path);
out.flush();
out << str_fail_date;
out.close();
}
/// 用来检测账号是否存在的方法,关于字符串截取方面的bug一被修复
/// <param name="path">文件路劲</param>
/// <param name="acount">需要检测的账号</param>
/// <returns>账号已存在是返回true ,不存在返回false</returns>
bool exist_accout(string path,string acount) {
ifstream ifs (path,ios::in);//只读
string len;
if(ifs.is_open())
while (getline(ifs,len)) {
if (acount._Equal(len.substr(len.find(".")+1, len.find_first_of("/")-len.find(".")-1))) {
return 1;
}
}
return 0;
}
/// 用来登录的方法
/// <param name="path">文件路径</param>
/// <param name="ac_pass">要验证的账号和秘密 格式为账号/密码 </param>
/// <returns>账号密码不对是登录失败,返回false ,成功返回true</returns>
bool login_ac_pass(string path,string ac_pass) {
ifstream ifs;
ifs.open(path,ios::in);//只读
if (!ifs.fail()) {
string len = "";
vector<string> c;
while (getline(ifs,len)) {
string temp = len.substr(len.find(".")+1,len.find_first_of("/")-len.find(".")-1);//抽取账号
c.push_back(temp);
temp = len = len.substr(len.find_first_of("/") + 1);//去除了编号和账号
while (len.find("/") != -1) {
temp = len.substr(0,len.find_first_of("/"));
c.push_back(temp);
len= len.substr(len.find_first_of("/")+1);
}
if ((c[0]==ac_pass.substr(0,ac_pass.find("/")))&&(c[1]==ac_pass.substr(ac_pass.find("/")+1))) {
return 1;
}
}
}
return 0;
}
/// 这个是登录的方法只要的按钮有 输入账号,输入密码,检测可以根据传参不同有不同的功能
/// <param name="is_log">这个参数来决定这个方法是用于注册的时候还是用于登录的时候</param>
/// <returns>
/// 返回值为 TRUE代表登录成功
/// false 代表登录失败但是这个只是不可能返回的了
/// </returns>
bool login(bool is_log,string path,string &throws_account) {
clearcliprgn();//进来先清空画布
initialization in_2(1);//初始化界面
char str_2_1[] = "输入账号";
char str_2_2[] = "输入密码";
//下面的鼠标可能会出现使用的名称不对的情况
//FlushMouseMsgBuffer();
char account[10] = {
0 };
char password[10] = {
0 };
//清除外部的鼠标缓冲区
FlushMouseMsgBuffer();
//输入 账号 ,密码 检测
while (1) {
MOUSEMSG msg_2 = GetMouseMsg();
//应该在循环的最后清除鼠标的缓冲流
if (msg_2.mkLButton) {
//当检测到鼠标点击了输入账号的方块时
if ((msg_2.x > 300 && msg_2.x < 700) && (msg_2.y > 100 && msg_2.y < 200)) {
InputBox(account, 10, "请输入账号(acount)");
//重新填充当前的"输入账号"的边框
setfillcolor(RGB(255, 1, 196));
setcolor(RED);
fillrectangle(300, 100, 700, 200);
settextcolor(RGB(255, 255, 255));
settextstyle(30, 0, _T("宋体"));
outtextxy(300, 140, str_2_1);
outtextxy(435, 140, account);
//把这个外部的账号需要得到的赋值,这里是灵魂
throws_account = account;
}
//当检测到鼠标点击"输入密码"的方块时
if ((msg_2.x > 300 && msg_2.x < 700) && (msg_2.y > 300 && msg_2.y < 400)) {
InputBox(password, 10, "请输入密码password");
//重新填充当前的输入密码的边框
setfillcolor(RGB(255, 1, 196));
setcolor(RED);
fillrectangle(300, 300, 700, 400);
settextcolor(RGB(255, 255, 255));
settextstyle(30, 0, _T("宋体"));
outtextxy(300, 340, str_2_1);
outtextxy(435, 340, "******");
}
//当检测到鼠标点击"检测"的方块时
if ((msg_2.x > 400 && msg_2.x < 600) && (msg_2.y > 450 && msg_2.y < 550)) {
string s_account(&account[0], &account[strlen(account)]);
throws_account = s_account;
string s_password(&password[0], &password[strlen(password)]);
if (s_account.find(" ") != -1) {
s_account.substr(0, s_account.find_first_of(" "));
}
if (s_password.find(" ") != -1) {
s_password.substr(0, s_password.find_first_of(" "));
}
if (s_account._Equal("")) {
// 只有一个确定的按钮 | 前置消息框 | 出现一个警告的图标
MessageBox(NULL, _T("账号不能为空"), _T("提示"), MB_OK | MB_SETFOREGROUND | MB_ICONEXCLAMATION);
}
else if (!all_number(s_account)) {
MessageBox(NULL, _T("账号信息输入非法(不可输入非数字)"), _T("提示"), MB_OK | MB_SETFOREGROUND | MB_ICONEXCLAMATION);
}
else if (exist_accout("member.txt", s_account)) {
if (!is_log) {
MessageBox(NULL, _T("账号已经存在"), _T("提示"), MB_OK | MB_SETFOREGROUND | MB_ICONEXCLAMATION);
}
}
else if (!exist_accout(path,s_account)&&is_log) {
MessageBox(NULL, _T("账号不存在"), _T("提示"), MB_OK | MB_SETFOREGROUND | MB_ICONEXCLAMATION);
}
else if (s_password._Equal("")) {
MessageBox(NULL, _T("密码不能为空"), _T("提示"), MB_OK | MB_SETFOREGROUND | MB_ICONEXCLAMATION);
}
//else {
if(is_log&& exist_accout(path, s_account)){
//if (exist_accout(path, s_account)) {
MessageBox(NULL,_T("你按了检测的按钮"),_T("提示"), MB_OK | MB_SETFOREGROUND | MB_ICONEXCLAMATION);
return true;//登录或者是注册成功就直接将返回true然后结束这个while训话外加上这个函数
//}
}
string account_password = s_account + "/" + s_password;//能够整合账号和密码的说
if (!is_log&&s_account!=""&&s_password!="") {
//注册的时候直接将账号和密码写到文件里
MessageBox(NULL, _T("注册成功,并返回上一级"), _T("提示"), MB_OK | MB_SETFOREGROUND | MB_ICONEXCLAMATION);
write_path(path, account_password + "/NULL/男/0");
//清理窗口,初始化界面
clearcliprgn();
initialization in('1');
return true;//结束方法
}
//}
}
//当检测到鼠标点击"返回"的方块时
if ((msg_2.x > 640 && msg_2.x < 760) && (msg_2.y > 480 && msg_2.y < 550)) {
//如果是登录的时候·返回到管理和用户登录的选择页面
if (is_log) {
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);
}
//再注册的时候返回的话是返回到登录注册和退出的界面
else {
clearcliprgn();
initialization::initialization('1');
}
break;
}
}
//清除本次循环得到的鼠标信息
FlushMouseMsgBuffer();
}
return 0;
}
// 开始的函数,万物的开端
void be() {
initgraph(1000, 600);//初始化一个窗口
initialization in('1');
FlushMouseMsgBuffer();
while (1) {
//通过这个就可以获得鼠标事件
MOUSEMSG msg=GetMouseMsg();
if (msg.mkLButton == true) {
//登录
if ((msg.x > 300 && msg.x < 700) && (msg.y > 100 && msg.y < 200)) {
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);
FlushMouseMsgBuffer();
while (1) {
//持续
MOUSEMSG msg_1 = GetMouseMsg();
if (msg_1.mkLButton) {
//用户登录登录
if ((msg_1.x>300&&msg_1.x<700)&&(msg_1.y>150&&msg_1.y<250)) {
string account="";
if (login(true,"member.txt",account)) {
initialization in_1(account);
}
}
//管理员登录
if ((msg_1.x>300&&msg_1.y<700)&&(msg_1.y>350&&msg_1.y<450)) {
string str_null = "";
if (login(true,"admin.txt",str_null)) {
MessageBox(NULL,_T("已检测到你是管理员"),_T("提示"),MB_OK|MB_SETFOREGROUND|MB_ICONEXCLAMATION);
clearcliprgn();
admin ad(1);
}
}
//返回
if ((msg_1.x>400&&msg_1.x<600)&&(msg_1.y>500&&msg_1.y<550)) {
clearcliprgn();//清理窗口
initialization in('1');
break;
}
}
//清除鼠标缓冲区
FlushMouseMsgBuffer();
}
}
//注册
if ((msg.x > 300 && msg.x < 700) && (msg.y > 250 && msg.y < 350)) {
string str_null = "";
login(false,"member.txt",str_null);
}
//退出
if ((msg.x > 300 && msg.x < 700) && (msg.y > 400 && msg.y < 500)) {
break;
}
}
FlushMouseMsgBuffer();//在这个位置清除鼠标事件就可以,鼠标的缓冲区采用的是队列的形式
};
clearcliprgn();//这个方法是用来清理画布的
closegraph();//关闭画布
}
int main() {
be();
return 0;
}
main.cpp文件内容
猜你喜欢
转载自blog.csdn.net/blastospore/article/details/118175996
今日推荐
周排行