Functionnal version of ImportPanel
This commit is contained in:
@@ -19,11 +19,12 @@
|
||||
|
||||
#include "ImportPanel.h"
|
||||
|
||||
enum {OPEN_FILE_ID=1, BUTTON_OPEN_ID, NAME_ID, BUTTON_LOAD_ID, BUTTON_INTEGRATE_ID, OPS_GRID_ID};
|
||||
enum {OPEN_FILE_ID=1, BUTTON_OPEN_ID, NAME_ID, BUTTON_LOAD_ID, BUTTON_INTEGRATE_ID, CHECK_SAVE_ID, OPS_GRID_ID};
|
||||
|
||||
BEGIN_EVENT_TABLE(ImportPanel, wxPanel)
|
||||
EVT_GRID_CMD_CELL_CHANGE(OPS_GRID_ID, ImportPanel::OnOperationModified)
|
||||
EVT_BUTTON(BUTTON_OPEN_ID, ImportPanel::OnFile)
|
||||
EVT_BUTTON(BUTTON_INTEGRATE_ID, ImportPanel::OnIntegrate)
|
||||
EVT_TEXT_ENTER(OPEN_FILE_ID, ImportPanel::OnFileEnter)
|
||||
EVT_BUTTON(BUTTON_LOAD_ID, ImportPanel::OnLoadOperations)
|
||||
EVT_SHOW(ImportPanel::OnShow)
|
||||
@@ -33,7 +34,7 @@ ImportPanel::ImportPanel(KissCount* kiss, wxUI *parent) : KissPanel(kiss, parent
|
||||
{
|
||||
wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL);
|
||||
wxBoxSizer *hbox = new wxBoxSizer(wxHORIZONTAL);
|
||||
wxBoxSizer *hbox2 = new wxBoxSizer(wxHORIZONTAL);
|
||||
_hbox = new wxBoxSizer(wxHORIZONTAL);
|
||||
wxButton* buttonOpen;
|
||||
wxRect rect = wxDisplay().GetGeometry();
|
||||
int w, h;
|
||||
@@ -54,10 +55,13 @@ ImportPanel::ImportPanel(KissCount* kiss, wxUI *parent) : KissPanel(kiss, parent
|
||||
_buttonIntegrate = new wxButton(this, BUTTON_INTEGRATE_ID, wxT("Integrate operations"));
|
||||
_buttonIntegrate->Disable();
|
||||
|
||||
_checkSaveImportPatterns = new wxCheckBox(this, CHECK_SAVE_ID, wxT("Save import patterns"));
|
||||
|
||||
hbox->Add(_fileTxt, 0, wxGROW|wxALL, 5);
|
||||
hbox->Add(buttonOpen, 0, wxALL, 5);
|
||||
hbox->Add(_buttonLoadOperations, 0, wxALL, 5);
|
||||
hbox->Add(_buttonIntegrate, 0, wxALL, 5);
|
||||
hbox->Add(_checkSaveImportPatterns, 0, wxALL, 5);
|
||||
|
||||
vbox->Add(hbox, 0);
|
||||
|
||||
@@ -73,10 +77,10 @@ ImportPanel::ImportPanel(KissCount* kiss, wxUI *parent) : KissPanel(kiss, parent
|
||||
|
||||
_operationsGrid = new GridAccount(kiss, this, OPS_GRID_ID, false, false, false);
|
||||
|
||||
hbox2->Add(staticBoxSizer, 0, wxGROW|wxALL, 15);
|
||||
hbox2->Add(_operationsGrid, 0, wxGROW|wxALL, 15);
|
||||
_hbox->Add(staticBoxSizer, 0, wxGROW|wxALL, 15);
|
||||
_hbox->Add(_operationsGrid, 0, wxGROW|wxALL, 15);
|
||||
|
||||
vbox->Add(hbox2, wxGROW);
|
||||
vbox->Add(_hbox, wxGROW);
|
||||
|
||||
Fit();
|
||||
|
||||
@@ -93,7 +97,7 @@ KissPanel* ImportPanel::CreatePanel()
|
||||
wxBitmapButton* ImportPanel::GetButton(int id)
|
||||
{
|
||||
if (!_KissButton)
|
||||
_KissButton = new wxBitmapButton(_wxUI, id, wxBitmap(wxT(PREFS_ICON), wxBITMAP_TYPE_PNG), wxDefaultPosition, wxSize(128, 128));
|
||||
_KissButton = new wxBitmapButton(_wxUI, id, wxBitmap(wxT(IMPORT_ICON), wxBITMAP_TYPE_PNG), wxDefaultPosition, wxSize(128, 128));
|
||||
|
||||
return _KissButton;
|
||||
}
|
||||
@@ -195,8 +199,9 @@ void ImportPanel::ProcessFile()
|
||||
void ImportPanel::OnLoadOperations(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
std::map<wxString, wxString> resolvedAccounts;
|
||||
int i;
|
||||
int i, nbAccounts;
|
||||
User* user = _kiss->GetUser();
|
||||
Account account;
|
||||
|
||||
for(i=0; i<_accountsGrid->GetNumberRows(); i++)
|
||||
{
|
||||
@@ -204,13 +209,57 @@ void ImportPanel::OnLoadOperations(wxCommandEvent& WXUNUSED(event))
|
||||
user->GetAccountId(_accountsGrid->GetCellValue(i, 1));
|
||||
}
|
||||
|
||||
nbAccounts = 0;
|
||||
for(i=0; i<_accountsGrid->GetNumberRows(); i++)
|
||||
{
|
||||
if (_accountsGrid->GetCellValue(i, 1) == _("Create one"))
|
||||
nbAccounts++;
|
||||
}
|
||||
|
||||
if (nbAccounts)
|
||||
{
|
||||
wxString message = wxString::Format(wxT("%d"), nbAccounts);
|
||||
message += _(" account(s) will be created, is it ok ?");
|
||||
|
||||
wxMessageDialog dialog(_wxUI, message, wxT("KissCount"), wxYES_NO);
|
||||
if (dialog.ShowModal() == wxID_NO)
|
||||
return;
|
||||
|
||||
for(i=0; i<_accountsGrid->GetNumberRows(); i++)
|
||||
{
|
||||
if (_accountsGrid->GetCellValue(i, 1) == _("Create one"))
|
||||
{
|
||||
account.name = _accountsGrid->GetCellValue(i, 0);
|
||||
account.number = _accountsGrid->GetCellValue(i, 0);
|
||||
account.shared = false;
|
||||
account.blocked = false;
|
||||
account._default = false;
|
||||
account.is_owner = true;
|
||||
account._virtual = false;
|
||||
|
||||
resolvedAccounts[_accountsGrid->GetCellValue(i, 0)] = _kiss->AddAccount(account);
|
||||
}
|
||||
}
|
||||
|
||||
_accountsGrid->DeleteRows(0, _accountsGrid->GetNumberRows ());
|
||||
|
||||
_wxUI->NeedReload();
|
||||
}
|
||||
|
||||
_operations = _importEngine->GetOperations(resolvedAccounts);
|
||||
|
||||
if (_operations->size())
|
||||
{
|
||||
_hbox->Detach(_operationsGrid);
|
||||
delete _operationsGrid;
|
||||
_operationsGrid = new GridAccount(_kiss, this, OPS_GRID_ID, false, false, false);
|
||||
_hbox->Add(_operationsGrid, 0, wxGROW|wxALL, 15);
|
||||
|
||||
_operationsGrid->LoadOperations(_operations, 0, 0);
|
||||
_buttonIntegrate->Enable();
|
||||
|
||||
_buttonLoadOperations->Disable();
|
||||
|
||||
Fit();
|
||||
}
|
||||
else
|
||||
@@ -219,6 +268,32 @@ void ImportPanel::OnLoadOperations(wxCommandEvent& WXUNUSED(event))
|
||||
}
|
||||
}
|
||||
|
||||
void ImportPanel::OnIntegrate(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
int i;
|
||||
|
||||
if (!_operations->size()) return;
|
||||
|
||||
wxMessageDialog dialog(_wxUI, _("Are you sure want to integrate these operations ?"), wxT("KissCount"), wxYES_NO);
|
||||
if (dialog.ShowModal() == wxID_NO)
|
||||
return;
|
||||
|
||||
_buttonIntegrate->Disable();
|
||||
|
||||
for(i=0; i<(int)_operations->size(); i++)
|
||||
_kiss->AddOperation((*_operations)[i]);
|
||||
|
||||
// if (_checkSaveImportPatterns->IsChecked())
|
||||
_kiss->UpdateImportPattern();
|
||||
|
||||
_operations->clear();
|
||||
_operationsGrid->ClearGrid();
|
||||
|
||||
wxMessageBox(_("Operations successfully imported"), wxT("KissCount"), wxICON_INFORMATION | wxOK);
|
||||
|
||||
_wxUI->NeedReload();
|
||||
}
|
||||
|
||||
void ImportPanel::OnOperationModified(wxGridEvent& event)
|
||||
{
|
||||
int col = event.GetCol();
|
||||
@@ -238,8 +313,6 @@ void ImportPanel::OnOperationModified(wxGridEvent& event)
|
||||
if (_importEngine->UpdatePattern(row-1) > 1)
|
||||
_operationsGrid->LoadOperations(_operations, 0, 0);
|
||||
|
||||
// sleep(1);
|
||||
|
||||
Fit();
|
||||
|
||||
update = false;
|
||||
|
Reference in New Issue
Block a user