#pragma once #include "uart/ProtocolSender.h" #include "core/utilities.h" #include "base/strings.hpp" #include "service/BusinessConfig.h" #include "restclient-cpp/restclient.h" /* *此文件由GUI工具生成 *文件功能:用于处理用户的逻辑相应代码 *功能说明: *========================onButtonClick_XXXX 当页面中的按键按下后系统会调用对应的函数,XXX代表GUI工具里面的[ID值]名称, 如Button1,当返回值为false的时候系统将不再处理这个按键,返回true的时候系统将会继续处理此按键。比如SYS_BACK. *========================onSlideWindowItemClick_XXXX(int index) 当页面中存在滑动窗口并且用户点击了滑动窗口的图标后系统会调用此函数,XXX代表GUI工具里面的[ID值]名称, 如slideWindow1;index 代表按下图标的偏移值 *========================onSeekBarChange_XXXX(int progress) 当页面中存在滑动条并且用户改变了进度后系统会调用此函数,XXX代表GUI工具里面的[ID值]名称, 如SeekBar1;progress 代表当前的进度值 *========================ogetListItemCount_XXXX() 当页面中存在滑动列表的时候,更新的时候系统会调用此接口获取列表的总数目,XXX代表GUI工具里面的[ID值]名称, 如List1;返回值为当前列表的总条数 *========================oobtainListItemData_XXXX(ZKListView::ZKListItem *pListItem, int index) 当页面中存在滑动列表的时候,更新的时候系统会调用此接口获取列表当前条目下的内容信息,XXX代表GUI工具里面的[ID值]名称, 如List1;pListItem 是贴图中的单条目对象,index是列表总目的偏移量。具体见函数说明 *========================常用接口=============== *LOGD(...) 打印调试信息的接口 *mTextXXXPtr->setText("****") 在控件TextXXX上显示文字**** *mButton1Ptr->setSelected(true); 将控件mButton1设置为选中模式,图片会切换成选中图片,按钮文字会切换为选中后的颜色 *mSeekBarPtr->setProgress(12) 在控件mSeekBar上将进度调整到12 *mListView1Ptr->refreshListView() 让mListView1 重新刷新,当列表数据变化后调用 *mDashbroadView1Ptr->setTargetAngle(120) 在控件mDashbroadView1上指针显示角度调整到120度 * * 在Eclipse编辑器中 使用 “alt + /” 快捷键可以打开智能提示 */ Json::Value clerk; Json::Value clerkList; static string frameFullName; static string frameBedNameList = ""; static bool isPosition = false; static bool isRoomPatrol = false; static bool isNursing = false; static int positionItId = 0; static int roomCheckItId = 0; static int authItId = 0; static int chooseId = 0; static bool isChoose = false; static void getClerkList() { string url = getHttpGateway() + "/deviceRoom/get_clerk_by_part_id/" + StoragePreferences::getString(STORE_PARTID, ""); LOGD("请求科室所有员工. url = %s", url.c_str()); //发起HTTP GET请求 RestClient::Response r = RestClient::get(url); LOGD("获得科室所有员工列表. result = %s", r.body.c_str()); //解析json Json::Reader reader; Json::Value root; if (reader.parse(r.body, root, false)){ if (root.size() > 0) { Json::Value clerks; for (int i = 0; i < root.size(); i++) { if (root[i]["pass_no"].asString() != "") { clerks.append(root[i]); } } clerkList = clerks; } } } static bool getClerkByPartIdAndPassNo(std::string passNo) { string url = getHttpGateway() + "/deviceRoom/get_clerk_by_part_id_and_pass_no/" + StoragePreferences::getString(STORE_PARTID, "") + "/" + passNo; LOGD("根据科室id和卡号查询员工. url = %s", url.c_str()); //发起HTTP GET请求 RestClient::Response r = RestClient::get(url); LOGD("根据科室id和卡号查询员工. result = %s", r.body.c_str()); //解析json Json::Reader reader; Json::Value root; if (reader.parse(r.body, root, false)){ if (root.isMember("clerk_id")) { clerk = root; return true; } } return false; } std::string getClerkPassNo() { return clerk["pass_no"].asCString(); } void setClerk(std::string clerk_name, std::string pass_no, int _authItid) { isChoose = true; clerk["clerk_name"] = clerk_name; clerk["pass_no"] = pass_no; authItId = _authItid; } int getAuthItId() { return authItId; } void setAuthItId(int id) { authItId = id; } void setPosistionItId(int id) { positionItId = id; } void setRoomCheckItId(int id) { roomCheckItId = id; } void setPositionButton(bool setPosition) { isPosition = setPosition; if (mActivityPtr == NULL) { return; } if (setPosition) { mPositionPainterPtr->setBackgroundPic("medicalCare/ding-y.png"); mPositionButtonPtr->setButtonStatusPic(ZK_CONTROL_STATUS_NORMAL, "medicalCare/yellow_199x281.png"); mPositionButtonPtr->setText(LANGUAGEMANAGER->getValue("Positioned")); mPositionButtonPtr->setTextColor(0xFFFFFFFF); mPositionTextViewPtr->setTextColor(0xFFFFFFFF); mPositionButtonPtr->setTouchable(false); } else { mPositionPainterPtr->setBackgroundPic("medicalCare/ding.png"); mPositionButtonPtr->setButtonStatusPic(ZK_CONTROL_STATUS_NORMAL, "medicalCare/white_199x281.png"); mPositionButtonPtr->setText(LANGUAGEMANAGER->getValue("Position")); mPositionButtonPtr->setTextColor(0xFF000000); mPositionTextViewPtr->setTextColor(0xFF7D7D7D); mPositionButtonPtr->setTouchable(true); } } void setPosition(bool setPosition) { if (setPosition) { setPositionButton(setPosition); Json::Value json; json["passNo"] = clerk["pass_no"].asCString(); json["operationData"] = ""; TcpModel tcpModel; tcpModel.tid = base::format("t%d", TimeHelper::getCurrentTime()); tcpModel.type = TcpType::POSITION; tcpModel.action = PositionAction::POSITION_START; tcpModel.from_id = StoragePreferences::getInt(STORE_DEVICE_ID,0); tcpModel.to_id = 0; tcpModel.json = json; sendTcpModel(tcpModel); } else { setPositionButton(setPosition); if (positionItId != 0) { // TcpModel tcpModel; // tcpModel.tid = base::format("t%d", TimeHelper::getCurrentTime()); // tcpModel.type = TcpType::POSITION; // tcpModel.action = PositionAction::POSITION_END; // tcpModel.from_id = StoragePreferences::getInt(STORE_DEVICE_ID,0); // tcpModel.to_id = 0; // tcpModel.data = to_string(positionItId); // sendTcpModel(tcpModel); positionItId = 0; } } } void setRoomPatrolButton(bool setRoomPatrol) { isRoomPatrol = setRoomPatrol; if (mActivityPtr == NULL) { return; } if (setRoomPatrol) { mRoomPatrolPainterPtr->setBackgroundPic("medicalCare/xun-y.png"); mRoomPatrolButtonPtr->setButtonStatusPic(ZK_CONTROL_STATUS_NORMAL, "medicalCare/green_199x281.png"); mRoomPatrolButtonPtr->setText(LANGUAGEMANAGER->getValue("RoomPatrolCompleted")); mRoomPatrolButtonPtr->setTextColor(0xFFFFFFFF); mRoomPatrolTextViewPtr->setTextColor(0xFFFFFFFF); mRoomPatrolButtonPtr->setTouchable(false); } else { mRoomPatrolPainterPtr->setBackgroundPic("medicalCare/xun.png"); mRoomPatrolButtonPtr->setButtonStatusPic(ZK_CONTROL_STATUS_NORMAL, "medicalCare/white_199x281.png"); mRoomPatrolButtonPtr->setText(LANGUAGEMANAGER->getValue("RoomPatrol")); mRoomPatrolButtonPtr->setTextColor(0xFF000000); mRoomPatrolTextViewPtr->setTextColor(0xFF7D7D7D); mRoomPatrolButtonPtr->setTouchable(true); } } void setRoomPatrol(bool setRoomPatrol) { if (setRoomPatrol) { setRoomPatrolButton(setRoomPatrol); Json::Value json; json["passNo"] = clerk["pass_no"].asCString(); json["operationData"] = ""; TcpModel tcpModel; tcpModel.tid = base::format("t%d", TimeHelper::getCurrentTime()); tcpModel.type = TcpType::ROOMCHECK; tcpModel.action = RoomCheckAction::START; tcpModel.from_id = StoragePreferences::getInt(STORE_DEVICE_ID,0); tcpModel.to_id = 0; tcpModel.json = json; sendTcpModel(tcpModel); } else { setRoomPatrolButton(setRoomPatrol); if (roomCheckItId != 0) { // TcpModel tcpModel; // tcpModel.tid = base::format("t%d", TimeHelper::getCurrentTime()); // tcpModel.type = TcpType::ROOMCHECK; // tcpModel.action = RoomCheckAction::END; // tcpModel.from_id = StoragePreferences::getInt(STORE_DEVICE_ID,0); // tcpModel.to_id = 0; // tcpModel.data = to_string(roomCheckItId); // sendTcpModel(tcpModel); // roomCheckItId = 0; } } } void setNursingEnd() { StoragePreferences::putBool(STORE_NURSING_TYPE, false); if (StoragePreferences::getString(STORE_NURSING_INTERACTION_ID, "") != "") { // 对比一下,json里面不为空的时候 // 发送tcp, tcp_type = SIDE, tcp_action = NURSING_END TcpModel tcpModel; tcpModel.tid = base::format("t%d", TimeHelper::getCurrentTime()); tcpModel.type = TcpType::SIDE; tcpModel.action = SideAction::NURSING_END; tcpModel.from_id = StoragePreferences::getInt(STORE_DEVICE_ID,0); tcpModel.data = StoragePreferences::getString(STORE_NURSING_INTERACTION_ID, ""); // 获取nursingTcpModel里,id字段的数据 sendTcpModel(tcpModel); // 需要把护理的interactionId清空 StoragePreferences::putString(STORE_NURSING_INTERACTION_ID, ""); } } void setNursingButton(bool setNursing) { isNursing = setNursing; if (mActivityPtr == NULL) { return; } if (setNursing) { mNursingPainterPtr->setBackgroundPic("medicalCare/hu-y.png"); mNursingButtonPtr->setButtonStatusPic(ZK_CONTROL_STATUS_NORMAL, "medicalCare/pink_199x281.png"); mNursingButtonPtr->setText(LANGUAGEMANAGER->getValue("InNursing")); mNursingButtonPtr->setTextColor(0xFFFFFFFF); mNursingTextViewPtr->setTextColor(0xFFFFFFFF); } else { mNursingPainterPtr->setBackgroundPic("medicalCare/hu.png"); mNursingButtonPtr->setButtonStatusPic(ZK_CONTROL_STATUS_NORMAL, "medicalCare/white_199x281.png"); mNursingButtonPtr->setText(LANGUAGEMANAGER->getValue("Nursing")); mNursingButtonPtr->setTextColor(0xFF000000); mNursingTextViewPtr->setTextColor(0xFF7D7D7D); } } void setNursing(bool setNursing) { if (setNursing) { setNursingButton(setNursing); // 门灯控制 std::string color = StoragePreferences::getString(STORE_NURSING_COLOR_RGB, "010"); if (color != "" && color.size() == 3) { color = color + "F"; } else { color = "010F"; } lightControl("DOORLED", color); // 发送tcp, tcp_type = SIDE, tcp_action = NURSING TcpModel tcpModel; tcpModel.tid = base::format("t%d",TimeHelper::getCurrentTime()); tcpModel.type = TcpType::SIDE; tcpModel.action = SideAction::NURSING; tcpModel.from_id = StoragePreferences::getInt(STORE_DEVICE_ID,0); tcpModel.to_id = 0; sendTcpModel(tcpModel); // 把护理状态缓存起来 StoragePreferences::putBool(STORE_NURSING_TYPE, true); } else { setNursingButton(setNursing); lightControl("DOORLED", "000F"); setNursingEnd(); } } void logoutMedicalCare() { isChoose = false; setPosition(false); setRoomPatrol(false); setNursing(false); clerk.clear(); if (mActivityPtr != NULL) { mPasswordEditTextPtr->setText(""); mMedicalCareWindowPtr->hideWnd(); mChooseClerkWindowPtr->hideWnd(); mLoginWindowPtr->showWnd(); } if (authItId != 0) { // 发送tcp, tcp_type = AUTH, tcp_action = LOGOUT TcpModel tcpModel; tcpModel.tid = base::format("t%d",TimeHelper::getCurrentTime()); tcpModel.type = TcpType::AUTH; tcpModel.action = AuthAction::LOGOUT; tcpModel.from_id = StoragePreferences::getInt(STORE_DEVICE_ID,0); tcpModel.to_id = 0; tcpModel.data = to_string(authItId); sendTcpModel(tcpModel); authItId = 0; } } void loginMedicalCare() { mLoginWindowPtr->hideWnd(); mChooseClerkWindowPtr->hideWnd(); mMedicalCareWindowPtr->showWnd(); Json::Value json; json["passNo"] = clerk["pass_no"].asCString(); json["operationData"] = ""; // 发送tcp, tcp_type = AUTH, tcp_action = LOGIN TcpModel tcpModel; tcpModel.tid = base::format("t%d",TimeHelper::getCurrentTime()); tcpModel.type = TcpType::AUTH; tcpModel.action = AuthAction::LOGIN; tcpModel.from_id = StoragePreferences::getInt(STORE_DEVICE_ID,0); tcpModel.to_id = 0; tcpModel.json = json; sendTcpModel(tcpModel); if (StoragePreferences::getInt(STORE_AUTO_POSITION, 0)) { setPosition(true); } } void nfcLogin(std::string revStr) { if (mActivityPtr == NULL) { LOGD("不在医护界面"); return; } if (isChoose) { LOGD("已经存在员工"); return; } bool reslut = getClerkByPartIdAndPassNo(revStr); if (reslut) { isChoose = true; mClerkNameTextViewPtr->setText(clerk["clerk_name"].asString() + " " + clerk["role_name"].asString()); loginMedicalCare(); } else { Intent* intent = new Intent(); intent->putExtra(functionWindows, "warn"); intent->putExtra(warnText, LANGUAGEMANAGER->getValue("PassNoError")); EASYUICONTEXT->openActivity("functionActivity", intent); } } /** * 注册定时器 * 填充数组用于注册定时器 * 注意:id不能重复 */ static S_ACTIVITY_TIMEER REGISTER_ACTIVITY_TIMER_TAB[] = { //{0, 6000}, //定时器id=0, 时间间隔6秒 //{1, 1000}, }; /** * 当界面构造时触发 */ static void onUI_init(){ //Tips :添加 UI初始化的显示代码到这里,如:mText1Ptr->setText("123"); Json::Value frameRoom = getFrame(); frameFullName = frameRoom["frame_room"]["full_name"].asString(); mPositionTextViewPtr->setText(frameFullName); mRoomPatrolTextViewPtr->setText(frameFullName); Json::Value frameBedList = frameRoom["frame_bed_list"]; if (frameBedList.size() > 0) { for (int i = 0; i < frameBedList.size(); i++) { string frameBedName = frameBedList[i]["frame_bed"]["full_name"].asString(); int nPos = frameBedName.find("-"); if (nPos != -1) { frameBedName = frameBedName.substr(nPos + 1, frameBedName.length()); } frameBedNameList += frameBedName; frameBedNameList += "、"; } } frameBedNameList.substr(0, frameBedNameList.length() - 1); } /** * 当切换到该界面时触发 */ static void onUI_intent(const Intent *intentPtr) { if (intentPtr != NULL) { //TODO } } /* * 当界面显示时触发 */ static void onUI_show() { if (isChoose) { mClerkNameTextViewPtr->setText(clerk["clerk_name"].asString() + " " + clerk["role_name"].asString()); mLoginWindowPtr->hideWnd(); mChooseClerkWindowPtr->hideWnd(); mMedicalCareWindowPtr->showWnd(); setPositionButton(isPosition); setRoomPatrolButton(isRoomPatrol); setNursingButton(isNursing); } else { chooseId = 0; mLoginWindowPtr->showWnd(); mChooseClerkWindowPtr->hideWnd(); mMedicalCareWindowPtr->hideWnd(); } } /* * 当界面隐藏时触发 */ static void onUI_hide() { } /* * 当界面完全退出时触发 */ static void onUI_quit() { } /** * 串口数据回调接口 */ static void onProtocolDataUpdate(const SProtocolData &data) { } /** * 定时器触发函数 * 不建议在此函数中写耗时操作,否则将影响UI刷新 * 参数: id * 当前所触发定时器的id,与注册时的id相同 * 返回值: true * 继续运行当前定时器 * false * 停止运行当前定时器 */ static bool onUI_Timer(int id){ switch (id) { default: break; } return true; } /** * 有新的触摸事件时触发 * 参数:ev * 新的触摸事件 * 返回值:true * 表示该触摸事件在此被拦截,系统不再将此触摸事件传递到控件上 * false * 触摸事件将继续传递到控件上 */ static bool onmedicalCareActivityTouchEvent(const MotionEvent &ev) { switch (ev.mActionStatus) { case MotionEvent::E_ACTION_DOWN://触摸按下 //LOGD("时刻 = %ld 坐标 x = %d, y = %d", ev.mEventTime, ev.mX, ev.mY); break; case MotionEvent::E_ACTION_MOVE://触摸滑动 break; case MotionEvent::E_ACTION_UP: //触摸抬起 break; default: break; } return false; } static void onEditTextChanged_JobNumberEditText(const std::string &text) { //LOGD(" onEditTextChanged_ JobNumberEditText %s !!!\n", text.c_str()); } static void onEditTextChanged_PasswordEditText(const std::string &text) { //LOGD(" onEditTextChanged_ PasswordEditText %s !!!\n", text.c_str()); } static bool onButtonClick_EnteringMedicalCareButton(ZKButton *pButton) { LOGD(" ButtonClick EnteringMedicalCareButton !!!\n"); string password = mPasswordEditTextPtr->getText(); //密码为当前日时 struct tm *t = TimeHelper::getDateTime(); char cpwd[10]; sprintf(cpwd,"%02d%02d",t->tm_mday,t->tm_hour); LOGD("cpwd is %s", cpwd); if (password == cpwd) { getClerkList(); if (clerkList.size() > 0) { mLoginWindowPtr->hideWnd(); mChooseClerkWindowPtr->showWnd(); } else { Intent* intent = new Intent(); intent->putExtra(functionWindows, "warn"); intent->putExtra(warnText, LANGUAGEMANAGER->getValue("ConfigureEmployeeID")); EASYUICONTEXT->openActivity("functionActivity", intent); } } else { Intent* intent = new Intent(); intent->putExtra(functionWindows, "warn"); intent->putExtra(warnText, LANGUAGEMANAGER->getValue("WrongPassword")); EASYUICONTEXT->openActivity("functionActivity", intent); } return false; } static bool onButtonClick_PositionButton(ZKButton *pButton) { LOGD(" ButtonClick PositionButton !!!\n"); setPosition(true); Intent* intent = new Intent(); intent->putExtra(functionWindows, "position"); intent->putExtra(functionText, frameFullName); EASYUICONTEXT->openActivity("functionActivity", intent); return false; } static bool onButtonClick_RoomPatrolButton(ZKButton *pButton) { LOGD(" ButtonClick RoomPatrolButton !!!\n"); setRoomPatrol(true); Intent* intent = new Intent(); intent->putExtra(functionWindows, "roomPatrol"); intent->putExtra(functionText, frameFullName); EASYUICONTEXT->openActivity("functionActivity", intent); return false; } static bool onButtonClick_NursingButton(ZKButton *pButton) { LOGD(" ButtonClick NursingButton !!!\n"); if (!isNursing) { Intent* intent = new Intent(); intent->putExtra(functionWindows, "nursing"); intent->putExtra(functionText, frameBedNameList); intent->putExtra(nursingText, frameFullName); EASYUICONTEXT->openActivity("functionActivity", intent); } else { Intent* intent = new Intent(); intent->putExtra(functionWindows, "nursingEnd"); intent->putExtra(functionText, frameBedNameList); EASYUICONTEXT->openActivity("functionActivity", intent); } return false; } static bool onButtonClick_PromptButton(ZKButton *pButton) { LOGD(" ButtonClick PromptButton !!!\n"); EASYUICONTEXT->openActivity("promptActivity"); return false; } static bool onButtonClick_LogoutButton(ZKButton *pButton) { LOGD(" ButtonClick LogoutButton !!!\n"); Intent* intent = new Intent(); intent->putExtra(functionWindows, "logoutMedicalCare"); intent->putExtra(goActivity, ""); EASYUICONTEXT->openActivity("functionActivity", intent); return false; } static int getListItemCount_ClerkListView(const ZKListView *pListView) { //LOGD("getListItemCount_ClerkListView !\n"); return clerkList.size(); } static void obtainListItemData_ClerkListView(ZKListView *pListView,ZKListView::ZKListItem *pListItem, int index) { //LOGD(" obtainListItemData_ ClerkListView !!!\n"); pListItem->setText(clerkList[index]["clerk_name"].asCString()); if (index == chooseId) { pListItem->setSelected(true); clerk = clerkList[index]; LOGD("clerk pass no == %s", clerk["pass_no"].asCString()); } else { pListItem->setSelected(false); } } static void onListItemClick_ClerkListView(ZKListView *pListView, int index, int id) { //LOGD(" onListItemClick_ ClerkListView !!!\n"); chooseId = index; } static bool onButtonClick_EnteringButton(ZKButton *pButton) { LOGD(" ButtonClick EnteringButton !!!\n"); isChoose = true; mClerkNameTextViewPtr->setText(clerk["clerk_name"].asString() + " " + clerk["role_name"].asString()); mChooseClerkWindowPtr->hideWnd(); mMedicalCareWindowPtr->showWnd(); loginMedicalCare(); return false; }