Skip to content

Commit

Permalink
Event autofill implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
Thales1330 committed May 10, 2020
1 parent 91577d6 commit b63f43a
Show file tree
Hide file tree
Showing 13 changed files with 435 additions and 48 deletions.
4 changes: 4 additions & 0 deletions AvaliadorCAAC/AvaliadorCAAC.project
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
<Description/>
<Dependencies/>
<VirtualDirectory Name="src">
<File Name="Utils.cpp"/>
<File Name="EventList.cpp"/>
<File Name="FormatValues.cpp"/>
<File Name="SearchInDrive.cpp"/>
<File Name="XMLParser.cpp"/>
Expand All @@ -25,6 +27,8 @@
<File Name="wxcrafter_bitmaps.cpp"/>
</VirtualDirectory>
<VirtualDirectory Name="include">
<File Name="Utils.h"/>
<File Name="EventList.h"/>
<File Name="FormatValues.h"/>
<File Name="SearchInDrive.h"/>
<File Name="XMLParser.h"/>
Expand Down
98 changes: 98 additions & 0 deletions AvaliadorCAAC/EventList.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#include "EventList.h"
#include "Utils.h"

EventList::EventList() {}

bool EventList::Load(wxWindow* parent)
{
wxBusyInfo busy(Utils::Get().BusyInfo(parent, wxT("Avaliador CAAC"), wxT("Atualizando lista de eventos...")));
// Get ID from Drive
wxExecute(wxString::Format("%s FindInfolder \"%s\"", m_runDriveAPI, "EventList.xml"),
wxEXEC_SYNC | m_consoleStatus);
// Get ID in file
wxTextFile txtFileIDs;
wxString fileID = "";
if(txtFileIDs.Open("foundIDs.txt")) {
fileID = txtFileIDs.GetFirstLine();
txtFileIDs.Clear();
txtFileIDs.Write();
} else
return false;

if(fileID == "") return false;

wxExecute(wxString::Format("%s Download \"%s\" \"%s\"", m_runDriveAPI, fileID, "EventList.xml"),
wxEXEC_SYNC | m_consoleStatus);

if(!LoadEventList()) return false;

return true;
}

bool EventList::LoadEventList()
{
rapidxml::xml_document<> doc;
rapidxml::file<> xmlFile("EventList.xml");

m_eventList.Clear();

doc.parse<0>(xmlFile.data());

auto rootNode = doc.first_node("Lista");
if(!rootNode) return false;
auto eventNode = rootNode->first_node("Evento");
while(eventNode) {
m_eventList.Add(wxString::FromUTF8(eventNode->value()));
eventNode = eventNode->next_sibling("Evento");
}

return true;
}

void EventList::Save(wxWindow* parent, wxArrayString eventList)
{
for(auto it = eventList.begin(), itEnd = eventList.end(); it != itEnd; ++it) {
wxString newEvent = *it;
bool isNewEvent = true;
for(auto itB = m_eventList.begin(), itEndB = m_eventList.end(); itB != itEndB; ++itB) {
wxString oldEvent = *itB;
if(newEvent == oldEvent) {
isNewEvent = false;
break;
}
}
if(isNewEvent) m_eventList.Add(newEvent);
}

// Save event file

// Erase the file (if exists or not) and write the initial data
std::ofstream writeEventList("EventList.xml");
writeEventList.close();

rapidxml::xml_document<> doc;
rapidxml::file<> xmlFile("EventList.xml");
doc.parse<0>(xmlFile.data());

rapidxml::xml_node<>* decl = doc.allocate_node(rapidxml::node_declaration);
rapidxml::xml_attribute<>* ver = doc.allocate_attribute("version", "1.0");
rapidxml::xml_attribute<>* encoding = doc.allocate_attribute("encoding", "utf-8");
decl->append_attribute(ver);
decl->append_attribute(encoding);
doc.append_node(decl);

rapidxml::xml_node<>* rootNode = doc.allocate_node(rapidxml::node_element, "Lista");
doc.append_node(rootNode);

for(auto it = m_eventList.begin(), itEnd = m_eventList.end(); it != itEnd; ++it) {
rapidxml::xml_node<>* eventName = XMLParser::AppendNode(doc, rootNode, "Evento");
XMLParser::SetNodeValue(doc, eventName, *it);
}

std::ofstream writeXML("EventList.xml");
writeXML << doc;
writeXML.close();

//SaveAtDrive("EventList.xml", "EventList.xml");
Utils::Get().SaveAtDrive(parent, "EventList.xml", "EventList.xml", false, wxT("Atualizando lista de eventos..."));
}
33 changes: 33 additions & 0 deletions AvaliadorCAAC/EventList.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#ifndef EVENTLIST_H
#define EVENTLIST_H

#include <wx/process.h>
#include <wx/textfile.h>
#include <wx/utils.h>
#include <wx/wfstream.h>
#include <wx/msgdlg.h>

#include "XMLParser.h"

class Utils;

class EventList
{
public:
EventList();
~EventList() {}

const wxArrayString& GetEventList() const { return m_eventList; }
bool Load(wxWindow* parent);
void Save(wxWindow* parent, wxArrayString eventList);

private:
bool LoadEventList();

wxArrayString m_eventList;

const wxString m_runDriveAPI = "cmd.exe /c py googleDiveAPI.py";
const int m_consoleStatus = wxEXEC_HIDE_CONSOLE;
};

#endif // EVENTLIST_H
53 changes: 41 additions & 12 deletions AvaliadorCAAC/MainFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "MainFrame.h"
#include "PdfPage.h"
#include "SearchInDrive.h"
#include "Utils.h"

MainFrame::MainFrame(wxWindow* parent) : MainFrameBaseClass(parent) { InitFrame(); }

Expand All @@ -26,10 +27,15 @@ void MainFrame::InitFrame()
m_ifIcon.LoadFile("logo128.png", wxBITMAP_TYPE_PNG);
EnableAll(false);
BuildGrid();
m_pgPropIFGEvent->SetAttribute(wxPG_BOOL_USE_CHECKBOX, true);
m_pgPropIFGEvent->SetAttribute(wxPG_BOOL_USE_CHECKBOX, true);
m_pgPropInvalidate->SetAttribute(wxPG_BOOL_USE_CHECKBOX, true);
m_pgPropShowInReport->SetAttribute(wxPG_BOOL_USE_CHECKBOX, true);
m_pgPropIgnoreRestrictions->SetAttribute(wxPG_BOOL_USE_CHECKBOX, true);

// Load Event list from drive
if(m_eventList.Load(this)) {
m_pgPropEvent->SetAttribute(wxPG_ATTR_AUTOCOMPLETE, m_eventList.GetEventList());
}
}

void MainFrame::OnExit(wxCommandEvent& event)
Expand Down Expand Up @@ -141,6 +147,11 @@ bool MainFrame::OpenProcess(wxString path)
auto eventName = activityNode->first_node("Evento");
if(!eventName) return false;
activity->SetEventName(wxString::FromUTF8(eventName->value()));
// Descricao evento
auto eventDesc = activityNode->first_node("DescricaoEvento");
if(eventDesc){
activity->SetEventDescription(wxString::FromUTF8(eventDesc->value()));
}
// Num shifts
activity->SetShiftNumber(XMLParser::GetNodeValueDouble(activityNode, "NumTurnos"));
// Evento IFG
Expand Down Expand Up @@ -197,6 +208,13 @@ void MainFrame::OnSave(wxCommandEvent& event)
if(saveFileDialog.ShowModal() == wxID_CANCEL) return;

SaveProcess(saveFileDialog.GetPath(), saveFileDialog.GetFilename());

// Get event list to save
wxArrayString eventListArray;
for(auto it = m_activityList.begin(), itEnd = m_activityList.end(); it != itEnd; ++it) {
eventListArray.Add((*it)->GetEventName());
}
m_eventList.Save(this, eventListArray);
}

bool MainFrame::SaveProcess(wxString path, wxString fileName)
Expand Down Expand Up @@ -244,6 +262,9 @@ bool MainFrame::SaveProcess(wxString path, wxString fileName)
// Evento
rapidxml::xml_node<>* eventName = XMLParser::AppendNode(doc, activityNode, "Evento");
XMLParser::SetNodeValue(doc, eventName, activity->GetEventName());
// Descricao do evento
rapidxml::xml_node<>* eventDesc = XMLParser::AppendNode(doc, activityNode, "DescricaoEvento");
XMLParser::SetNodeValue(doc, eventDesc, activity->GetEventDescription());
// Turnos/apresentação/participação
rapidxml::xml_node<>* numShift = XMLParser::AppendNode(doc, activityNode, "NumTurnos");
XMLParser::SetNodeValue(doc, numShift, activity->GetShiftNumber());
Expand Down Expand Up @@ -289,6 +310,7 @@ void MainFrame::EnableAll(bool enable)
m_pgMgr->Enable(enable);
m_pgPropItem->Enable(enable);
m_pgPropEvent->Enable(enable);
m_pgPropEventDesc->Enable(enable);
m_pgPropShiftN->Enable(enable);
m_pgPropIFGEvent->Enable(enable);
m_pgPropInstitution->Enable(enable);
Expand Down Expand Up @@ -496,6 +518,10 @@ void MainFrame::ValidateCH(Activity* activity)
}

} break;
case 18: {
activity->SetChValidated(0.0);
activity->SetChPresented(activity->GetChPresented());
} break;
default:
break;
}
Expand Down Expand Up @@ -541,6 +567,7 @@ void MainFrame::FillPG(int id)
if(activity->GetId() == id) {
m_pgPropItem->SetValueFromInt(activity->GetItemCode());
m_pgPropEvent->SetValueFromString(activity->GetEventName());
m_pgPropEventDesc->SetValueFromString(activity->GetEventDescription());
m_pgPropShiftN->SetValueFromInt(activity->GetShiftNumber());
m_pgPropIFGEvent->SetValueFromInt(activity->IsIFGEvent());
m_pgPropInstitution->SetValueFromString(activity->GetInstitutionName());
Expand Down Expand Up @@ -615,6 +642,10 @@ void MainFrame::UpdateChangedPG()
m_pgPropShiftN->Enable(true);
shiftN = true;
} break;
case 18: {
m_pgPropCH->Enable(true);
ch = true;
}
default:
break;
}
Expand All @@ -635,6 +666,7 @@ void MainFrame::UpdateChangedPG()
// Fill the current activity with new informations
currentActivity->SetItemCode(m_pgPropItem->GetValue().GetInteger());
currentActivity->SetEventName(m_pgPropEvent->GetValue().GetString());
currentActivity->SetEventDescription(m_pgPropEventDesc->GetValue().GetString());
currentActivity->SetShiftNumber(m_pgPropShiftN->GetValue().GetDouble());
currentActivity->SetIfgEvent(m_pgPropIFGEvent->GetValue().GetBool());
currentActivity->SetInstitutionName(m_pgPropInstitution->GetValue().GetString());
Expand Down Expand Up @@ -933,7 +965,9 @@ void MainFrame::GenerateReport(wxCommandEvent& event)
Activity* activity = *it;
if(activity->IsShownInReport()) {
wxString activityStr = fTBtxt;
activityStr.Replace("\\event", activity->GetEventName());
wxString eventName = activity->GetEventName();
if(activity->GetEventDescription() != "") eventName += " - " + activity->GetEventDescription();
activityStr.Replace("\\event", eventName);
activityStr.Replace("\\institution", activity->GetInstitutionName());
activityStr.Replace("\\date", activity->GetDate());
activityStr.Replace("\\requiredCH", wxString::FromDouble(activity->GetChPresented()));
Expand Down Expand Up @@ -1062,6 +1096,9 @@ void MainFrame::FillAllRows()
case 17: {
shiftN = true;
} break;
case 18: {
ch = true;
} break;
default:
break;
}
Expand Down Expand Up @@ -1144,16 +1181,8 @@ bool MainFrame::ShowSaveDialog()
void MainFrame::OnPanelKeyDown(wxKeyEvent& event)
{
if(event.ShiftDown() && event.GetUnicodeKey() == 'E') {
wxExecute(wxT("cmd.exe /c py googleDiveAPI.py FindInFolder teste"), wxEXEC_SYNC);
wxTextFile txtFile;
if(txtFile.Open("foundIDs.txt")) {
wxString ids = txtFile.GetFirstLine() + '\n';
while(!txtFile.Eof()) { ids += txtFile.GetNextLine() + '\n'; }

wxMessageBox(wxString::Format("Num IDs: %d\n%s", ids.Freq('\n') - 1, ids));
txtFile.Clear();
txtFile.Write();
}
EventList eventList;
eventList.Load(this);
}
event.Skip();
}
Expand Down
9 changes: 8 additions & 1 deletion AvaliadorCAAC/MainFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@

#include "NewProcess.h"
#include "XMLParser.h"
#include "EventList.h"

#define MY_APP_VERSION_STRING "0.1-beta"
#define MY_APP_VERSION_STRING "0.2-beta"

class Utils;
class PdfPage;
class SearchInDrive;
class FormatValues;
Expand All @@ -34,6 +36,7 @@ class Activity
void SetChValidated(double chValidated) { this->m_chValidated = chValidated; }
void SetDate(const wxString& date) { this->m_date = date; }
void SetEventName(const wxString& eventName) { this->m_eventName = eventName; }
void SetEventDescription(const wxString& eventDesc) { this->m_eventDesc = eventDesc; }
void SetIfgEvent(bool ifgEvent) { this->m_ifgEvent = ifgEvent; }
void SetInstitutionName(const wxString& institutionName) { this->m_institutionName = institutionName; }
void SetItemCode(int itemCode) { this->m_itemCode = itemCode; }
Expand All @@ -42,6 +45,7 @@ class Activity
double GetChValidated() const { return m_chValidated; }
const wxString& GetDate() const { return m_date; }
const wxString& GetEventName() const { return m_eventName; }
const wxString& GetEventDescription() const { return m_eventDesc; }
bool IsIFGEvent() const { return m_ifgEvent; }
const wxString& GetInstitutionName() const { return m_institutionName; }
int GetItemCode() const { return m_itemCode; }
Expand All @@ -62,6 +66,7 @@ class Activity
int m_id = 0;
int m_itemCode = 0;
wxString m_eventName = wxT("Nome do evento...");
wxString m_eventDesc = "";
double m_shiftNumber = 1.0;
bool m_ifgEvent = true;
wxString m_institutionName = wxT("Nome da instituição...");
Expand Down Expand Up @@ -154,6 +159,8 @@ class MainFrame : public MainFrameBaseClass
double m_totalValCH = 0.0;

bool m_saveNeeded = false;

EventList m_eventList;

const wxString m_runDriveAPI = "cmd.exe /c py googleDiveAPI.py";
const int m_consoleStatus = wxEXEC_HIDE_CONSOLE;
Expand Down
33 changes: 28 additions & 5 deletions AvaliadorCAAC/SearchInDrive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ wxBusyInfoFlags SearchInDrive::GetBusyInfoFlags(wxWindow* parent, wxString messa

void SearchInDrive::DoSearch()
{

wxString protocolNum = m_textCtrlProcessNumber->GetValue();
wxString studentName = m_textCtrlStudentName->GetValue();

Expand All @@ -74,17 +73,41 @@ void SearchInDrive::DoSearch()

wxTextFile txtFileNames;
wxTextFile txtFileIDs;
int numEventList = -1;
int count = 0;

// Skip EventList file
m_foundNames.Clear();
if(txtFileNames.Open("foundNames.txt")) {
m_foundNames.Add(txtFileNames.GetFirstLine());
while(!txtFileNames.Eof()) { m_foundNames.Add(txtFileNames.GetNextLine()); }
wxString name = txtFileNames.GetFirstLine();
if(name == "EventList.xml")
numEventList = count;
else
m_foundNames.Add(name);
count++;
while(!txtFileNames.Eof()) {
name = txtFileNames.GetNextLine();
if(name == "EventList.xml")
numEventList = count;
else
m_foundNames.Add(name);
count++;
}
txtFileNames.Clear();
txtFileNames.Write();
wxString names = "";
}
m_foundIDs.Clear();
count = 0;
if(txtFileIDs.Open("foundIDs.txt")) {
m_foundIDs.Add(txtFileIDs.GetFirstLine());
while(!txtFileIDs.Eof()) { m_foundIDs.Add(txtFileIDs.GetNextLine()); }
wxString id = txtFileIDs.GetFirstLine();
if(count != numEventList) m_foundIDs.Add(id);
count++;
while(!txtFileIDs.Eof()) {
id = txtFileIDs.GetNextLine();
if(count != numEventList) m_foundIDs.Add(id);
count++;
}
txtFileIDs.Clear();
txtFileIDs.Write();
}
Expand Down
Loading

0 comments on commit b63f43a

Please sign in to comment.