Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Jeuxjieta Address Book System
- Version 1.0
- By:
- Denz Del Villar (101205)
- Jojee Dumayaca (101329)
- Chi Punzalan (103043)
- Special Thanks To:
- The Kuyas at CTC314 (I forgot their names :C -Chi)
- Google
- wxFormBuilder - for sparing us from the pain of studying how to build forms
- */
- #include <wx/wxprec.h>
- #ifndef WX_PRECOMP
- #include <wx/wx.h>
- #endif
- #include "base.h"
- IMPLEMENT_APP(MainApp)
- //This declares what happens once the program is executed.
- bool MainApp::OnInit()
- {
- MainFrame *win = new MainFrame(_("Jeuxjieta Address Book System"), wxPoint (100, 100),
- wxSize(600, 400));
- win->Show(TRUE);
- SetTopWindow(win);
- return TRUE;
- }
- BEGIN_EVENT_TABLE(MainFrame, wxFrame)
- EVT_CLOSE(MainFrame::OnClose)
- END_EVENT_TABLE()
- //This defines the Main Window of the program, from its layout, contents to the events
- MainFrame::MainFrame(const wxString &title, const wxPoint &pos, const wxSize &size)
- : wxFrame((wxFrame *) NULL, -1, title, pos, size)
- {
- this->SetSizeHints( wxDefaultSize, wxDefaultSize );
- this->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT ) );
- wxBoxSizer* bSizer9;
- bSizer9 = new wxBoxSizer( wxVERTICAL );
- m_staticText21 = new wxStaticText( this, wxID_ANY, wxT("JEUXJIETA ADDRESS BOOK SYSTEM"), wxDefaultPosition, wxDefaultSize, 0 );
- m_staticText21->SetFont( wxFont( 20, 74, 90, 92, false, wxT("Tahoma") ) );
- bSizer9->Add( m_staticText21, 0, wxALL|wxALIGN_CENTER_HORIZONTAL, 5 );
- wxBoxSizer* bSizer10;
- bSizer10 = new wxBoxSizer( wxHORIZONTAL );
- nameslist = new wxListBox( this, wxID_nameslist, wxDefaultPosition, wxSize( 400,320 ), 0, NULL, wxLB_SORT );
- bSizer10->Add( nameslist, 0, wxALL, 5 );
- //This part here is the function used to get the previously stored data.
- startup();
- wxBoxSizer* bSizer14;
- bSizer14 = new wxBoxSizer( wxVERTICAL );
- //Buttons
- addButton = new wxButton( this, ADD_BUTTON, wxT("Add New Contact"), wxDefaultPosition, wxSize( 150,50 ), 0 );
- bSizer14->Add( addButton, 0, wxALL|wxALIGN_CENTER_HORIZONTAL, 5 );
- edtButton = new wxButton( this, EDT_BUTTON, wxT("Edit Contact"), wxDefaultPosition, wxSize( 150,50 ), 0 );
- bSizer14->Add( edtButton, 0, wxALL|wxALIGN_CENTER_HORIZONTAL, 5 );
- delButton = new wxButton( this, DEL_BUTTON, wxT("Delete Contact"), wxDefaultPosition, wxSize( 150,50 ), 0 );
- bSizer14->Add( delButton, 0, wxALL|wxALIGN_CENTER_HORIZONTAL, 5 );
- clrButton = new wxButton( this, CLR_BUTTON, wxT("Clear List"), wxDefaultPosition, wxSize( 150,50 ), 0 );
- bSizer14->Add( clrButton, 0, wxALL|wxALIGN_CENTER_HORIZONTAL, 5 );
- sveButton = new wxButton( this, SVE_BUTTON, wxT("Save Data"), wxDefaultPosition, wxSize( 150,50 ), 0 );
- bSizer14->Add( sveButton, 0, wxALL|wxALIGN_CENTER_HORIZONTAL, 5 );
- //Connection of Buttons to Events (instead of using the switch method)
- Connect(ADD_BUTTON, wxEVT_COMMAND_BUTTON_CLICKED,
- wxCommandEventHandler(MainFrame::OnNew) );
- Connect(EDT_BUTTON, wxEVT_COMMAND_BUTTON_CLICKED,
- wxCommandEventHandler(MainFrame::OnRename) );
- Connect(CLR_BUTTON, wxEVT_COMMAND_BUTTON_CLICKED,
- wxCommandEventHandler(MainFrame::OnClear) );
- Connect(DEL_BUTTON, wxEVT_COMMAND_BUTTON_CLICKED,
- wxCommandEventHandler(MainFrame::OnDelete) );
- Connect(SVE_BUTTON, wxEVT_COMMAND_BUTTON_CLICKED,
- wxCommandEventHandler(MainFrame::OnSave) );
- bSizer10->Add( bSizer14, 1, wxEXPAND, 5 );
- bSizer9->Add( bSizer10, 1, wxEXPAND, 5 );
- this->SetSizer( bSizer9 );
- this->Layout();
- this->Centre( wxBOTH );
- }
- //Function for getting user input for new contact entry
- void MainFrame::OnNew(wxCommandEvent& event)
- {
- wxString str = wxGetTextFromUser(wxT("Enter Last Name"));
- wxString str2 = wxGetTextFromUser(wxT("Enter First Name"));
- wxString str3 = wxGetTextFromUser(wxT("Enter Contact Number"));
- wxString str4 = wxGetTextFromUser(wxT("Enter E-Mail Address"));
- wxString str5 = wxGetTextFromUser(wxT("Enter Address"));
- wxString *comma = new wxString(wxT(", "));
- wxString *space = new wxString(wxT(" | "));// this, wxID_ANY, wxT(" "), wxDefaultPosition, wxDefaultSize, 0 );
- wxString strgr = str + *comma + str2 + *space + str3 + *space + str4 + *space + str5;
- if (str.Len() > 0)
- nameslist->Append(strgr);
- }
- //Function for deleting all contact entries
- void MainFrame::OnClear(wxCommandEvent& event)
- {
- nameslist->Clear();
- }
- //Function for editing details of a selected contact entry
- void MainFrame::OnRename(wxCommandEvent& event)
- {
- wxString text;
- wxString newLast = wxGetTextFromUser(wxT("Enter New Last Name"));
- wxString newFirst = wxGetTextFromUser(wxT("Enter New First Name"));
- wxString newNum = wxGetTextFromUser(wxT("Enter New Number"));
- wxString newMail = wxGetTextFromUser(wxT("Enter New E-Mail"));
- wxString newAdd = wxGetTextFromUser(wxT("Enter New Address"));
- wxString *comma = new wxString(wxT(", "));
- wxString *space = new wxString(wxT(" | "));
- wxString renamed = newLast + *comma + newFirst + *space + newNum + *space + newMail + *space + newAdd;
- int sel = nameslist->GetSelection();
- if (sel != -1) {
- text.Printf(nameslist->GetString(sel));
- renamed;
- }
- if (!renamed.IsEmpty()) {
- nameslist->Delete(sel);
- nameslist->Insert(renamed, sel);
- }
- }
- //Function for deleting a contact entry
- void MainFrame::OnDelete(wxCommandEvent& event)
- {
- int sel = nameslist->GetSelection();
- if (sel != -1) {
- nameslist->Delete(sel);
- }
- }
- //Function for saving data on data.txt
- void MainFrame::OnSave(wxCommandEvent& event)
- {
- int listCount = nameslist->GetCount();
- wxTextFile file( wxT("data.txt") );
- file.Open();
- file.Clear();
- for (int h=0; h<=listCount; h++) {
- const wxChar* listItem = nameslist->GetString(h);
- file.AddLine(listItem);
- }
- file.Write();
- file.Close();
- }
- //Function for retrieving previously stored data from data.txt and storing it in the contact list
- bool MainFrame::startup() {
- wxString str;
- nameslist->Deselect(0);
- nameslist->SetFirstItem(wxT("Last Name, First Name | Contact Number | E-mail Address | Address"));
- wxTextFile file( wxT("data.txt") );
- //Checks if data.txt exists & creates a new file if data.txt does not exist
- if (!file.Exists()){
- file.Create();
- }
- else {
- file.Open();
- str = file.GetFirstLine();
- nameslist->Append(str);
- while(!file.Eof())
- {
- str = file.GetNextLine();
- nameslist->Append(str);
- }
- }
- }
- //Just in case the user forgets to save his/her data, it will automatically save when closed.
- void MainFrame::OnClose (wxCloseEvent& event) {
- int listCount = nameslist->GetCount();
- wxTextFile file( wxT("data.txt") );
- file.Open();
- file.Clear();
- for (int h=0; h<=listCount; h++) {
- const wxChar* listItem = nameslist->GetString(h);
- file.AddLine(listItem);
- }
- file.Write();
- file.Close();
- Destroy();
- }
Add Comment
Please, Sign In to add comment