HatchKeeper  0.90
The Free Open-Source Egg Incubation Software
ReminderDialog.cpp
Go to the documentation of this file.
1 /*******************************************************************/
8 #include <wx/wx.h>
9 #include <wx/listctrl.h>
10 
17 class AddReminderDialog : public wxDialog
18 {
19  private:
20  wxTextCtrl* RNameCtrl;
21  wxStaticText* RNameText;
22  wxDatePickerCtrl* RDateCtrl;
23  wxStaticText* RDateText;
24  wxTextCtrl* RTextCtrl;
25  wxButton* RSave;
26  wxButton* RCancel;
27 
28  void OnSaveButton(wxCommandEvent& );
29  void OnCancelButton(wxCommandEvent& );
30  public:
31  AddReminderDialog( wxWindow* parent, wxWindowID id = 500, const wxString& title = wxT("Add Reminder"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxCAPTION|wxCLOSE_BOX|wxSYSTEM_MENU );
32 };
33 
35 AddReminderDialog::AddReminderDialog( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxDialog( parent, id, title, pos, size, style )
36 {
37  wxTextValidator textVal(wxFILTER_INCLUDE_CHAR_LIST,NULL);
38  textVal.SetCharIncludes(Info.GetValidChars().c_str());
39 
40  this->SetSizeHints( wxDefaultSize, wxDefaultSize );
41 
42  //Colors
43  vector<int> ColorRed = Settings.GetIntArray("ColorRed");
44  vector<int> ColorGreen = Settings.GetIntArray("ColorGreen");
45  vector<int> ColorBlue = Settings.GetIntArray("ColorBlue");
46 
47  this->SetForegroundColour( wxColor(ColorRed[8],ColorGreen[8],ColorBlue[8]) );
48  this->SetBackgroundColour( wxColor(ColorRed[7],ColorGreen[7],ColorBlue[7]) );
49 
50  wxBoxSizer* bSizer3;
51  bSizer3 = new wxBoxSizer( wxVERTICAL );
52 
53  bSizer3->SetMinSize( wxSize( -1,10 ) );
54  wxGridSizer* gSizer2;
55  gSizer2 = new wxGridSizer( 2, 2, 0, 0 );
56 
57  RNameCtrl = new wxTextCtrl( this, 501, wxEmptyString, wxDefaultPosition, wxSize(-1,-1), 0 , textVal);
58  gSizer2->Add( RNameCtrl, 0, wxALL|wxEXPAND, 5 );
59 
60  RNameText = new wxStaticText( this, wxID_ANY, l("Name"), wxDefaultPosition, wxDefaultSize, 0 );
61  RNameText->Wrap( -1 );
62  gSizer2->Add( RNameText, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxALIGN_CENTER_HORIZONTAL, 5 );
63 
64  RDateCtrl = new wxDatePickerCtrl( this, wxID_ANY, wxDefaultDateTime, wxDefaultPosition, wxDefaultSize, wxDP_DROPDOWN );
65  gSizer2->Add( RDateCtrl, 0, wxALL|wxEXPAND, 5 );
66 
67  RDateText = new wxStaticText( this, wxID_ANY, l("Date"), wxDefaultPosition, wxDefaultSize, 0 );
68  RDateText->Wrap( -1 );
69  gSizer2->Add( RDateText, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxALIGN_CENTER_HORIZONTAL, 5 );
70 
71  bSizer3->Add( gSizer2, 0, wxEXPAND, 5 );
72 
73  RTextCtrl = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 , textVal);
74  bSizer3->Add( RTextCtrl, 1, wxALL|wxEXPAND, 5 );
75 
76  wxGridSizer* gSizer3;
77  gSizer3 = new wxGridSizer( 1, 2, 0, 0 );
78 
79  RCancel = new wxButton( this, wxID_ANY, l("Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
80  gSizer3->Add( RCancel, 0, wxALL|wxEXPAND, 5 );
81 
82  RSave = new wxButton( this, wxID_ANY, l("Save"), wxDefaultPosition, wxDefaultSize, 0 );
83  gSizer3->Add( RSave, 0, wxALL|wxEXPAND, 5 );
84 
85  bSizer3->Add( gSizer3, 0, wxEXPAND, 5 );
86  bSizer3->SetSizeHints(this);
87 
88  RSave->Bind(wxEVT_BUTTON, &AddReminderDialog::OnSaveButton, this );
89  RCancel->Bind(wxEVT_BUTTON, &AddReminderDialog::OnCancelButton, this );
90 
91  this->SetSizer( bSizer3 );
92  this->Layout();
93 }
94 
95 
97 void AddReminderDialog::OnCancelButton(wxCommandEvent& ){EndModal(0);}
98 
100 void AddReminderDialog::OnSaveButton(wxCommandEvent& )
101 {
102  //Get Reminder Name
103  string curRName = RNameCtrl->GetLineText(0).ToStdString();
104 
105  if(curRName == "") {
106  wxMessageDialog* dialog = new wxMessageDialog(this,
107  l("Please Enter A Name!"));
108  dialog->ShowModal();
109  dialog->Destroy();
110  return;
111  }
112 
113  for( int a = 0; a < Remind.GetCount(); a++) {
114  if(curRName == Remind.GetName(a)) {
115  wxMessageDialog* dialog = new wxMessageDialog(this,
116  l("Please Enter A Different Name!\nThis One Exists Already!"));
117  dialog->ShowModal();
118  dialog->Destroy();
119  return;
120  }
121  }
122  //Get Reminder Text
123  string curRText = RTextCtrl->GetLineText(0).ToStdString();
124 
125  //Get Reminder Date
126  wxDateTime selDate;
127 
128  selDate = RDateCtrl->GetValue();
129 
130  HK_Date Date(
131  selDate.GetDay(wxDateTime::Local),
132  selDate.GetMonth(wxDateTime::Local) + 1,
133  selDate.GetYear(wxDateTime::Local)
134  );
135 
136  /* Create SQL statement */
137  string SQL = "INSERT INTO Reminders VALUES(" + to_string(Remind.GetValidID()) + ", '";
138  SQL += curRName + "','" + Date.ToSortable("/") + "','" + curRText + "',0);";
139 
140  if(!Database.Execute(SQL)) {
141  wxMessageDialog* dialog = new wxMessageDialog(this,
142  "Sqlite Error: " + Database.GetErrors());
143  dialog->ShowModal();
144  dialog->Destroy();
145  return;
146  }
147 
148  RNameCtrl->Clear();
149  RTextCtrl->Clear();
150  RDateCtrl->SetValue(wxDateTime::Today());
151  EndModal(0);
152 }
153 
160 class ReminderDialog : public wxDialog
161 {
162  private:
163  wxButton* RAdd;
164  wxButton* RRemv;
165  wxButton* RClose;
166  wxListView* RListView;
167 
168  void OnRSelect(wxListEvent& evt);
169  void OnRUnselect(wxListEvent& evt);
170  void OnRAddButton(wxCommandEvent& );
171  void OnRCloseButton(wxCommandEvent& );
172  void OnRRemvButton(wxCommandEvent& );
173  void ShowRemind(bool Scan);
174  public:
175  ReminderDialog( wxWindow* parent, wxWindowID id = 500, const wxString& title = wxT("Reminders"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 500,500 ), long style = wxCAPTION|wxCLOSE_BOX|wxSYSTEM_MENU|wxRESIZE_BORDER );
176 };
177 
179 ReminderDialog::ReminderDialog( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxDialog( parent, id, title, pos, size, style )
180 {
181  this->SetSizeHints( wxDefaultSize, wxDefaultSize );
182 
183  //Colors
184  vector<int> ColorRed = Settings.GetIntArray("ColorRed");
185  vector<int> ColorGreen = Settings.GetIntArray("ColorGreen");
186  vector<int> ColorBlue = Settings.GetIntArray("ColorBlue");
187 
188  this->SetForegroundColour( wxColor(ColorRed[8],ColorGreen[8],ColorBlue[8]) );
189  this->SetBackgroundColour( wxColor(ColorRed[7],ColorGreen[7],ColorBlue[7]) );
190 
191  wxBoxSizer* bSizer3;
192  bSizer3 = new wxBoxSizer( wxVERTICAL );
193 
194  bSizer3->SetMinSize( wxSize( -1,10 ) );
195 
196  RListView = new wxListView( this, 1254, wxDefaultPosition, wxDefaultSize, wxLC_REPORT );
197  bSizer3->Add( RListView, 1, wxALL|wxEXPAND, 5 );
198 
199  wxGridSizer* gSizer3;
200  gSizer3 = new wxGridSizer( 1, 3, 0, 0 );
201 
202  RRemv = new wxButton( this, wxID_ANY, l("Remove"), wxDefaultPosition, wxDefaultSize, 0 );
203  gSizer3->Add( RRemv, 0, wxALL|wxEXPAND, 5 );
204 
205  RAdd = new wxButton( this, wxID_ANY, l("Add"), wxDefaultPosition, wxDefaultSize, 0 );
206  gSizer3->Add( RAdd, 0, wxALL|wxEXPAND, 5 );
207 
208  RClose = new wxButton( this, wxID_ANY, l("Close"), wxDefaultPosition, wxDefaultSize, 0 );
209  gSizer3->Add( RClose, 0, wxALL|wxEXPAND, 5 );
210 
211  bSizer3->Add( gSizer3, 0, wxEXPAND, 5 );
212 
213  RListView->Bind(wxEVT_COMMAND_LIST_ITEM_SELECTED, &ReminderDialog::OnRSelect, this);
214  RListView->Bind(wxEVT_COMMAND_LIST_ITEM_DESELECTED, &ReminderDialog::OnRUnselect, this);
215  RAdd->Bind(wxEVT_BUTTON, &ReminderDialog::OnRAddButton, this );
216  RRemv->Bind(wxEVT_BUTTON, &ReminderDialog::OnRRemvButton, this );
217  RClose->Bind(wxEVT_BUTTON, &ReminderDialog::OnRCloseButton, this );
218 
219  this->SetSizer( bSizer3 );
220  this->Layout();
221 
222  ShowRemind(false);
223 }
224 
226 void ReminderDialog::OnRCloseButton(wxCommandEvent& ){EndModal(0);}
227 
229 void ReminderDialog::OnRAddButton(wxCommandEvent& )
230 {
231  AddReminderDialog *dialog = new AddReminderDialog(this,906,l("Add Reminder"));
232  dialog->ShowModal();
233  dialog->Destroy();
234 
235  ShowRemind(true);
236 }
237 
239 void ReminderDialog::OnRRemvButton(wxCommandEvent& )
240 {
241  int sel = RListView->GetFirstSelected();
242 
243  if(sel == -1) {
244  wxMessageDialog* dialog = new wxMessageDialog(this,
245  l("No Item Is Selected!"));
246  dialog->ShowModal();
247  dialog->Destroy();
248  return;
249  }
250  //Unselect
251  RListView->Select(sel,false);
252 
253  int really = wxMessageBox(wxString::Format(wxT("Delete %s ?"),Remind.GetName(sel).c_str()), l("Delete?"),wxOK| wxCANCEL);
254 
255  if (really == 4) {
256  if(!Database.Execute("DELETE FROM Reminders where ID = " + to_string(Remind.GetID(sel)) + ";")) {
257  wxMessageDialog* dialog = new wxMessageDialog(this,
258  "Sqlite Error: " + Database.GetErrors());
259  dialog->ShowModal();
260  dialog->Destroy();
261  return;
262  }
263  ShowRemind(true);
264  }
265 }
266 
272 {
273  if(Scan)
275 
276  HK_Date Date;
277 
278  RListView->ClearAll();//Clear the previous list items
279  RListView->InsertColumn(0,l("Date" ), wxLIST_FORMAT_LEFT, 80);
280  RListView->InsertColumn(1,l("Name" ), wxLIST_FORMAT_LEFT, 180);
281  RListView->InsertColumn(2,l("Text" ), wxLIST_FORMAT_LEFT, 300);
282 
283  for(int count1 = 0; count1 < Remind.GetCount(); count1++) {
284  Date = Remind.GetDate(count1);
285  RListView->InsertItem(count1,wxString::Format(wxT("%s"), Date.ToReadable("/",Settings.GetInt("DateMode"))) );
286  RListView->SetItem(count1,1,wxString::Format(wxT("%s"), Remind.GetName(count1).c_str()));
287  RListView->SetItem(count1,2,wxString::Format(wxT("%s"), Remind.GetText(count1).c_str()));
288  }
289  RRemv->Disable();
290 }
291 
292 void ReminderDialog::OnRSelect(wxListEvent& evt) {
293  RRemv->Enable(true);
294 }
295 
296 void ReminderDialog::OnRUnselect(wxListEvent& evt) {
297  RRemv->Disable();
298 }
HK_KeyValue Settings
Definition: Declare.h:36
HK_Info Info
Definition: Declare.h:34
HK_Date Today
Definition: Declare.h:33
HK_Storage Remind
Definition: Declare.h:40
HK_Database Database(HATCHKEEPER_DATA+"HatchKeeper.db")
std::string l(std::string Text)
A Helper Function For HK_Language.
Definition: Declare.h:52
A Dialog For Adding Reminders.
wxTextCtrl * RTextCtrl
void OnSaveButton(wxCommandEvent &)
Adds A Reminder To The Database.
AddReminderDialog(wxWindow *parent, wxWindowID id=500, const wxString &title=wxT("Add Reminder"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxCAPTION|wxCLOSE_BOX|wxSYSTEM_MENU)
Constructor.
wxStaticText * RNameText
void OnCancelButton(wxCommandEvent &)
Closes Dialog.
wxDatePickerCtrl * RDateCtrl
wxTextCtrl * RNameCtrl
wxStaticText * RDateText
bool Execute(string SQL)
Executes SQL Statments.
HK_Storage ReadRemind()
Reads Reminders Table Into HK_Storage Object.
string GetErrors()
Returns sqlite3_errmsg(HK_DB))
A Class For Managing Dates.
Definition: Date.h:25
std::string ToSortable(std::string Separator)
Generate A Sortable String For Database.
Definition: HK_Date.cpp:163
std::string ToReadable(std::string Separator, int Mode)
Generate A Readable String.
Definition: HK_Date.cpp:132
std::string GetValidChars()
Returns Chars That Are Allowed In Text Controls.
Definition: HK_Info.cpp:12
vector< int > GetIntArray(int Selection)
Returns The Selected Value As An Array Of Integers.
int GetInt(int Selection)
Returns The Selected Setting Value As An Integer.
Definition: HK_KeyValue.cpp:49
HK_Date GetDate(int Select)
Returns The Selected Stored Date.
Definition: HK_Storage.cpp:71
int GetValidID()
Returns A Valid ID For Adding Entries To The Database.
Definition: HK_Storage.cpp:106
int GetCount()
Returns The Number Of Elements Stored.
Definition: HK_Storage.cpp:101
string GetName(int Select)
Returns The Selected Stored Name.
Definition: HK_Storage.cpp:61
string GetText(int Select)
Returns The Selected Stored Text.
Definition: HK_Storage.cpp:91
int GetID(int Select)
Returns The Selected Stored ID.
Definition: HK_Storage.cpp:66
A Dialog For Managing Reminders.
void OnRCloseButton(wxCommandEvent &)
Closes Dialog.
ReminderDialog(wxWindow *parent, wxWindowID id=500, const wxString &title=wxT("Reminders"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(500, 500), long style=wxCAPTION|wxCLOSE_BOX|wxSYSTEM_MENU|wxRESIZE_BORDER)
Constructor.
void ShowRemind(bool Scan)
void OnRUnselect(wxListEvent &evt)
wxListView * RListView
void OnRAddButton(wxCommandEvent &)
Adds A Reminder To The Database.
void OnRRemvButton(wxCommandEvent &)
Deletes The Selected Reminder From The Database.
void OnRSelect(wxListEvent &evt)