1 Star 1 Fork 0

yxyc-137/Team collaboration calendar

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
main_interface.h 11.91 KB
一键复制 编辑 原始数据 按行查看 历史
yxyc-137 提交于 2023-07-11 00:21 . exit命令可用e快捷代替
#ifndef MAIN_INTERFACE_H
#define MAIN_INTERFACE_H
#include<iostream>
#include<string>
#include<ctime>
#include<array>
#include<chrono>
#include<limits>
#include<vector>
#include"global.h"
#include"month.h"
#include"year.h"
#include"day_interface.h"
#include"manage_interface.h"
#include"user.h"
#include"dialogue_interface.h"
//下标年=年份-2023,下标月=月份-1,下标日=号数-1
//函数
const std::vector<year> get_year_vec();
//void welcome_interface();
void print_daiban_schedule();
void list_chengyuan(std::vector<user>& user_vec);
//变量
extern std::vector<riqi>riqi_vec;
extern std::vector<year> year_vec;
extern std::vector<user>user_vec;
//跳转到当前月份
const std::array<unsigned int,2> skip_default()
{
year_vec[now_year - 2023].get_month_arr()[now_month - 1].display_month();
return {now_year,now_month};
}
//跳转任意月份
const std::array<unsigned int,2> skip(unsigned int display_year,unsigned int display_month,std::string user_name)//不能返回引用
{
if(std::cin.get() == '\n')
{
system("cls");
std::string text = '*' + user_name + '*';
// 计算文本两侧的空格数,使文本居中
int padding = (139 - text.length()) / 2;
// 设置填充字符
std::cout << std::setfill(' ');
// 输出居中的文本
std::cout << std::setw(padding + text.length()) << text << std::endl;
std::cout << "键入help/h获取帮助..." << std::endl;
std::cout << " ---------------------------------------------------------------------------------------------------------------------------------"<<std::endl;
print_daiban_schedule();
std::cout << " ---------------------------------------------------------------------------------------------------------------------------------"<<std::endl;
skip_default();
return {now_year,now_month};
}
unsigned int year_2000 = 0,month = 0;
if(!(std::cin >> year_2000) || (year_2000 + 2000) < 2023 || (year_2000 + 2000) > (2023 + 49))
{
if(year_2000 >= 1 && year_2000 <= 12)//默认情况
{
std::cin.ignore();
system("cls");
std::string text = '*' + user_name + '*';
// 计算文本两侧的空格数,使文本居中
int padding = (139 - text.length()) / 2;
// 设置填充字符
std::cout << std::setfill(' ');
// 输出居中的文本
std::cout << std::setw(padding + text.length()) << text << std::endl;
std::cout << "键入help/h获取帮助..." << std::endl;
std::cout << " ---------------------------------------------------------------------------------------------------------------------------------"<<std::endl;
print_daiban_schedule();
std::cout << " ---------------------------------------------------------------------------------------------------------------------------------"<<std::endl;
month = year_2000;
year_vec[display_year - 2023].get_month_arr()[month - 1].
display_month();
return {display_year,month};
}
else
{
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(),'\n');
std::cout << f_red << "操作失败:输入格式不正确!" << reset << std::endl;
return{display_year,display_month};
}
}
if(!(std::cin >> month) || month < 1 || month>12)
{
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(),'\n');
std::cout << f_red << "操作失败:输入格式不正确!" << reset << std::endl;
return{display_year,display_month};
}
//正常情况
std::cin.ignore();
system("cls");
std::string text = '*' + user_name + '*';
// 计算文本两侧的空格数,使文本居中
int padding = (139 - text.length()) / 2;
// 设置填充字符
std::cout << std::setfill(' ');
// 输出居中的文本
std::cout << std::setw(padding + text.length()) << text << std::endl;
std::cout << "键入help/h获取帮助..." << std::endl;
std::cout << " ---------------------------------------------------------------------------------------------------------------------------------"<<std::endl;
print_daiban_schedule();
std::cout << " ---------------------------------------------------------------------------------------------------------------------------------"<<std::endl;
year_vec[year_2000 + 2000 - 2023].get_month_arr()[month - 1].
display_month();
return {year_2000 + 2000,month};
}
//主界面帮助菜单
void main_interface_qunzhu_help()
{
std::cout << f_qingse;
std::cout << "manage/m:管理成员\n";
std::cout << "dialogue/d:进入对话\n";
std::cout << "today/t:查看今天日程\n";
std::cout << "n(n为号数):查看此天日程\n";
std::cout << "skip:跳转到当前月份\n";
std::cout << "skip a:跳转到当年a月\n";
std::cout << "skip a(a为年份后两位)b:跳转到a年b月\n";
std::cout << "back/b:回到上一级" << std::endl;
std::cout << "exit/e:退出日历" << std::endl;
std::cout << reset;
}
void main_interface_guanliyuan_qunchengyuan_help()
{
std::cout << f_qingse;
std::cout << "dialogue/d:进入对话\n";
std::cout << "today/t:查看今天日程\n";
std::cout << "n(n为号数):查看此天日程\n";
std::cout << "skip:跳转到当前月份\n";
std::cout << "skip a:跳转到当年a月\n";
std::cout << "skip a(a为年份后两位)b:跳转到a年b月\n";
std::cout << "back/b:回到上一级" << std::endl;
std::cout << "exit/e:退出日历" << std::endl;
std::cout << reset;
}
//主界面接受命令
std::string acceptcommand(std::string command,unsigned int diaplay_year_number,
unsigned int display_month_number,user u)
{
std::string user_name = u.get_user_name();
if(u.get_user_shenfen() == "群主")
{
if(string_is_space(command))
{
return command;
}
else if(command == "help"||command=="h")
{
std::cin.ignore();
main_interface_qunzhu_help();
return command;
}
else if(command == "manage"||command=="m")
{
manage_interface(user_vec, user_name);
system("cls");
std::string text = '*' + user_name + '*';
// 计算文本两侧的空格数,使文本居中
int padding = (139 - text.length()) / 2;
// 设置填充字符
std::cout << std::setfill(' ');
// 输出居中的文本
std::cout << std::setw(padding + text.length()) << text << std::endl;
std::cout << "键入help/h获取帮助..." << std::endl;
std::cout << " ---------------------------------------------------------------------------------------------------------------------------------"<<std::endl;
print_daiban_schedule();
std::cout << " ---------------------------------------------------------------------------------------------------------------------------------"<<std::endl;
year_vec[diaplay_year_number - 2023].get_month_arr()[display_month_number - 1].display_month();
return command;
}
else if(command == "dialogue"||command=="d")
{
dialogue_interface(user_vec, user_name);
system("cls");
std::string text = '*' + user_name + '*';
// 计算文本两侧的空格数,使文本居中
int padding = (139 - text.length()) / 2;
// 设置填充字符
std::cout << std::setfill(' ');
// 输出居中的文本
std::cout << std::setw(padding + text.length()) << text << std::endl;
std::cout << "键入help/h获取帮助..." << std::endl;
std::cout << " ---------------------------------------------------------------------------------------------------------------------------------" << std::endl;
print_daiban_schedule();
std::cout << " ---------------------------------------------------------------------------------------------------------------------------------" << std::endl;
year_vec[diaplay_year_number - 2023].get_month_arr()[display_month_number - 1].display_month();
return command;
}
else if(string_is_number(command))
{
std::cin.ignore();
auto command_number = string_to_unsigned(command);
if(command_number >= 1 && command_number <= year_vec[diaplay_year_number - 2023].get_month_arr()[display_month_number - 1].get_day_vec_size())
{
day_interface(diaplay_year_number, display_month_number, command_number, u);
return command;
}
else
{
std::cout << f_red << "操作失败:输入格式不正确!" << reset << std::endl;
return command;
}
}
else if(command == "today"||command=="t")
{
std::cin.ignore();
day_interface(now_year, now_month, now_day,u);
return command;
}
else if(command == "back"||command=="b")
{
return command;
}
else if(command == "exit"||command=="e")
{
return command;
}
else
{
std::cin.ignore();
std::cout << f_red << "操作失败:未找到该指令!" << reset << std::endl;
return command;
}
}
else if(u.get_user_shenfen() == "管理员"|| u.get_user_shenfen() == "群成员")
{
if(string_is_space(command))
{
return command;
}
else if(command == "help"||command=="h")
{
std::cin.ignore();
main_interface_guanliyuan_qunchengyuan_help();
return command;
}
else if(command == "dialogue"||command=="d")
{
dialogue_interface(user_vec, user_name);
system("cls");
std::string text = '*' + user_name + '*';
// 计算文本两侧的空格数,使文本居中
int padding = (139 - text.length()) / 2;
// 设置填充字符
std::cout << std::setfill(' ');
// 输出居中的文本
std::cout << std::setw(padding + text.length()) << text << std::endl;
std::cout << "键入help/h获取帮助..." << std::endl;
std::cout << " ---------------------------------------------------------------------------------------------------------------------------------" << std::endl;
print_daiban_schedule();
std::cout << " ---------------------------------------------------------------------------------------------------------------------------------" << std::endl;
year_vec[diaplay_year_number - 2023].get_month_arr()[display_month_number - 1].display_month();
return command;
}
else if(string_is_number(command))
{
std::cin.ignore();
auto command_number = string_to_unsigned(command);
if(command_number >= 1 && command_number <= year_vec[diaplay_year_number - 2023].get_month_arr()[display_month_number - 1].get_day_vec_size())
{
day_interface(diaplay_year_number, display_month_number, command_number, u);
return command;
}
else
{
std::cout << f_red << "操作失败:输入格式不正确!" << reset << std::endl;
return command;
}
}
else if(command == "today"||command=="t")
{
std::cin.ignore();
day_interface(now_year, now_month, now_day, u);
return command;
}
else if(command == "back"||command=="b")
{
return command;
}
else if(command == "exit"||command=="e")
{
return command;
}
else
{
std::cin.ignore();
std::cout << f_red << "操作失败:未找到该指令!" << reset << std::endl;
return command;
}
}
}
//主界面
std::string main_interface(user u)
{
std::string user_name = u.get_user_name();
std::string text = '*' + user_name + '*';
// 计算文本两侧的空格数,使文本居中
int padding = (139 - text.length()) / 2;
// 设置填充字符
std::cout << std::setfill(' ');
// 输出居中的文本
std::cout << std::setw(padding + text.length()) << text << std::endl;
std::cout << "键入help/h获取帮助..." << std::endl;
std::cout << " ---------------------------------------------------------------------------------------------------------------------------------"<<std::endl;
print_daiban_schedule();
std::cout << " ---------------------------------------------------------------------------------------------------------------------------------" << std::endl;
//展示本月日历
skip_default();
std::array<unsigned int, 2>arr = {now_year,now_month};
//接受命令
std::string com;
std::cout << "@" << user_name << ":~$ ";
while(true)
{
while(std::cin.peek() == '\n')
{
std::cout << "@" << user_name << ":~$ ";
std::cin.ignore();
}
std::cin >> com;
if(com == "skip")
{
arr = skip(arr[0], arr[1],user_name);
std::cout << "@" << user_name << ":~$ ";
continue;
}
std::string command = acceptcommand(com, arr[0], arr[1], u);
if(command != "back"&&command!="b" && command != "exit" && command != "e")
{
std::cout << "@" << user_name << ":~$ ";
continue;
}
return command;
}
std::cout << f_red << "程序异常退出!" << reset << std::endl;
exit(7);
}
#endif // !MAIN_H
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/yxyc-137/Team_collaboration_calendar.git
git@gitee.com:yxyc-137/Team_collaboration_calendar.git
yxyc-137
Team_collaboration_calendar
Team collaboration calendar
master

搜索帮助