YATiSh
Yet Another TIme SHeet
yatishDlgActivity.cpp
Go to the documentation of this file.
1 #include "wx_pch.h"
2 #include "yatishDlgActivity.h"
3 
4 #ifndef WX_PRECOMP
5  //(*InternalHeadersPCH(yatishDlgActivity)
6  #include <wx/string.h>
7  #include <wx/intl.h>
8  //*)
9 #endif
10 //(*InternalHeaders(yatishDlgActivity)
11 //*)
12 
13 //(*IdInit(yatishDlgActivity)
14 const long yatishDlgActivity::idChoiceProject = wxNewId();
15 const long yatishDlgActivity::idChoiceTask = wxNewId();
16 const long yatishDlgActivity::idChoiceTool = wxNewId();
17 //*)
18 
19 BEGIN_EVENT_TABLE (yatishDlgActivity, wxDialog)
20  //(*EventTable(yatishDlgActivity)
21  //*)
22 END_EVENT_TABLE()
23 
24 
26  BuildContent();
27  pdb = p_db;
28  id = sql_id;
29  bool choiceOK;
30  choiceOK = pdb->FillChoice (choiceProject, project_tid);
31  choiceOK = pdb->FillChoice (choiceTask, task_tid);
32  choiceOK = pdb->FillChoice (choiceTool, tool_tid);
33  if (!choiceOK) wxLogError ("Initialization of choices failed (yatishDlgActivity)");
34  project = pdb->ChoiceSelector (project_tid, id);
35  task = pdb->ChoiceSelector (task_tid, id);
36  tool = pdb->ChoiceSelector (tool_tid, id);
37  choiceProject->SetValidator ( wxGenericValidator (&project) );
38  choiceTask ->SetValidator ( wxGenericValidator (&task) );
39  choiceTool ->SetValidator ( wxGenericValidator (&tool) );
40  Fit(); SetMaxSize ( GetSize() );
41 }
42 
45  BuildContent();
46  staticBoxSizer->GetStaticBox()->SetLabel (_("New row") );
47  pdb = p_db;
48  buttonSave->Disable();
49  bool choiceOK;
50  choiceOK = pdb->FillChoice (choiceProject, project_tid);
51  choiceOK = pdb->FillChoice (choiceTask, task_tid);
52  choiceOK = pdb->FillChoice (choiceTool, tool_tid);
53  if (!choiceOK) wxLogError ("Initialization of choices failed (yatishDlgActivity)");
54  project = 0;
55  task = 0;
56  tool = 0;
57  choiceProject->SetValidator ( wxGenericValidator (&project) );
58  choiceTask ->SetValidator ( wxGenericValidator (&task) );
59  choiceTool ->SetValidator ( wxGenericValidator (&tool) );
60  Fit(); SetMaxSize ( GetSize() );
61  if ( choiceProject->IsEmpty() || choiceTask->IsEmpty() || choiceTool->IsEmpty() )
62  buttonNew->Disable(); // in case we get here while some tables are still empty
63 }
64 
66  //(*Initialize(yatishDlgActivity)
67  wxBoxSizer* BoxSizer1;
68  wxBoxSizer* BoxSizer2;
69  wxButton* buttonCancel;
70  wxFlexGridSizer* FlexGridSizer1;
71  wxStaticText* StaticText1;
72  wxStaticText* StaticText2;
73  wxStaticText* StaticText3;
74 
75  Create(0, wxID_ANY, _("Table: yatish_activity"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE, _T("wxID_ANY"));
76  BoxSizer1 = new wxBoxSizer(wxVERTICAL);
77  staticBoxSizer = new wxStaticBoxSizer(wxHORIZONTAL, this, _("(previously selected row)"));
78  FlexGridSizer1 = new wxFlexGridSizer(3, 2, 0, 0);
79  StaticText1 = new wxStaticText(this, wxID_ANY, _("Project:"), wxDefaultPosition, wxDefaultSize, 0, _T("wxID_ANY"));
80  FlexGridSizer1->Add(StaticText1, 1, wxALL|wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 5);
81  choiceProject = new wxChoice(this, idChoiceProject, wxDefaultPosition, wxDefaultSize, 0, 0, 0, wxDefaultValidator, _T("idChoiceProject"));
82  FlexGridSizer1->Add(choiceProject, 1, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
83  StaticText2 = new wxStaticText(this, wxID_ANY, _("Task:"), wxDefaultPosition, wxDefaultSize, 0, _T("wxID_ANY"));
84  FlexGridSizer1->Add(StaticText2, 1, wxALL|wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 5);
85  choiceTask = new wxChoice(this, idChoiceTask, wxDefaultPosition, wxDefaultSize, 0, 0, 0, wxDefaultValidator, _T("idChoiceTask"));
86  FlexGridSizer1->Add(choiceTask, 1, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
87  StaticText3 = new wxStaticText(this, wxID_ANY, _("Tool:"), wxDefaultPosition, wxDefaultSize, 0, _T("wxID_ANY"));
88  FlexGridSizer1->Add(StaticText3, 1, wxALL|wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 5);
89  choiceTool = new wxChoice(this, idChoiceTool, wxDefaultPosition, wxDefaultSize, 0, 0, 0, wxDefaultValidator, _T("idChoiceTool"));
90  FlexGridSizer1->Add(choiceTool, 1, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
91  staticBoxSizer->Add(FlexGridSizer1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
92  BoxSizer1->Add(staticBoxSizer, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
93  BoxSizer2 = new wxBoxSizer(wxHORIZONTAL);
94  buttonCancel = new wxButton(this, wxID_CANCEL, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("wxID_CANCEL"));
95  BoxSizer2->Add(buttonCancel, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
96  buttonSave = new wxButton(this, wxID_SAVE, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("wxID_SAVE"));
97  BoxSizer2->Add(buttonSave, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
98  buttonNew = new wxButton(this, wxID_NEW, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("wxID_NEW"));
99  BoxSizer2->Add(buttonNew, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
100  BoxSizer1->Add(BoxSizer2, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
101  SetSizer(BoxSizer1);
102  BoxSizer1->Fit(this);
103  BoxSizer1->SetSizeHints(this);
104 
105  Connect(wxID_SAVE,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&yatishDlgActivity::OnButtonSaveClick);
106  Connect(wxID_NEW,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&yatishDlgActivity::OnButtonNewClick);
107  //*)
108 }
109 
111  //(*Destroy(yatishDlgActivity)
112  //*)
113 }
114 
115 void yatishDlgActivity::OnButtonSaveClick (wxCommandEvent& event) {
116  TransferDataFromWindow();
117  if ( pdb->RecordActivity (id, project, task, tool) )
118  EndModal (wxID_SAVE);
119  else
120  EndModal (wxID_CANCEL);
121 }
122 
123 void yatishDlgActivity::OnButtonNewClick (wxCommandEvent& event) {
124  TransferDataFromWindow();
125  if ( pdb->RecordActivity (wxNOT_FOUND, project, task, tool) )
126  EndModal (wxID_NEW);
127  else
128  EndModal (wxID_CANCEL);
129 }
Interacts with yatish tables in a SQLite database.
bool FillChoice(wxChoice *, tableID)
Fills a wxChoice.
bool RecordActivity(long, int, int, int)
Modifies or creates a record in the yatish_activity table.
static const long idChoiceProject
static const long idChoiceTool
static const long idChoiceTask
wxChoice * choiceProject
yatishDlgActivity(yatishDBsqlite *, long)
This constructor initializes the dialog box with data from the SQL record identified by sql_id.
yatishDBsqlite * pdb
void OnButtonSaveClick(wxCommandEvent &event)
wxStaticBoxSizer * staticBoxSizer
void OnButtonNewClick(wxCommandEvent &event)
@ tool_tid
Definition: yatishDB.h:16
@ task_tid
Definition: yatishDB.h:15
@ project_tid
Definition: yatishDB.h:17