public ViewContact(string title, clsContact contact) { InitializeComponent(); //Set caption to the person's name Text = title; buildForm(contact); }
public UpdateContact(string title, string mode, clsContact contact) { InitializeComponent(); Text = title; mFormMode = mode; clsContact mContact = contact; if (mode == "Update") { //Populate the form with existing data populate(contact); } }
private void populate(clsContact contact) { //Build values into the form here. txtContactFirstName.Text = contact.ContactFirstName; txtContactMiddleName.Text = contact.ContactMiddleName; txtContactLastName.Text = contact.ContactLastName; txtContactJobTitle.Text = contact.ContactJobTitle; txtContactCompany.Text = contact.ContactCompany; //Email addresses txtContactEmail1.Text = contact.ContactEmail1; txtContactEmail2.Text = contact.ContactEmail2; txtContactEmail3.Text = contact.ContactEmail3; //Addresses txtContactAddressHome.Text = contact.ContactAddressHome; txtContactAddressWork.Text = contact.ContactAddressWork; txtContactAddressVacation.Text = contact.ContactAddressVacation; txtContactAddressOther.Text = contact.ContactAddressOther; //Phone Numbers txtContactPhoneWork.Text = contact.ContactPhoneBusiness; txtContactPhoneHome.Text = contact.ContactPhoneHome; txtContactPhoneCell.Text = contact.ContactPhoneCell; txtContactPhoneFax.Text = contact.ContactPhoneFax; txtContactPhoneOther.Text = contact.ContactPhoneOther; //Notes txtContactNotes.Text = contact.ContactNotes; //Dept, Office, Prof. txtContactDepartment.Text = contact.ContactDepartment; txtContactOffice.Text = contact.ContactOffice; txtContactProfession.Text = contact.ContactProfession; //Nickname, Title, Suffix txtContactNickname.Text = contact.ContactNickname; txtContactTitle.Text = contact.ContactTitle; txtContactSuffix.Text = contact.ContactSuffix; //Manager, Assistant, Spouse names txtContactManagerName.Text = contact.ContactManagersName; txtContactAssistantName.Text = contact.ContactAssistantsName; txtContactSpouseName.Text = contact.ContactSpousesName; //Birthday and Anniversary if (contact.ContactBirthday.Year < 1000) { txtContactBirthday.Text = ""; } else { txtContactBirthday.Text = contact.ContactBirthday.ToShortDateString(); } if (contact.ContactAnniversary.Year < 1000) { txtContactAnniversary.Text = ""; } else { txtContactAnniversary.Text = contact.ContactAnniversary.ToShortDateString(); } //Set Hidden ID Field to Contact ID lblHiddenID.Text = contact.ContactID.ToString(); }
private void buildForm(clsContact contact) { //Build values into the form here. lblContactName.Text = contact.ContactFirstName + " " + contact.ContactMiddleName + " " + contact.ContactLastName; lblContactJobTitle.Text = contact.ContactJobTitle; lblContactCompany.Text = contact.ContactCompany; //Email addresses lblContactEmail1.Text = contact.ContactEmail1; mContactEmail1 = contact.ContactEmail1; lblContactEmail2.Text = contact.ContactEmail2; mContactEmail2 = contact.ContactEmail2; lblContactEmail3.Text = contact.ContactEmail3; mContactEmail3 = contact.ContactEmail3; //Addresses lblContactAddressHome.Text = contact.ContactAddressHome; lblContactAddressWork.Text = contact.ContactAddressWork; lblContactAddressVacation.Text = contact.ContactAddressVacation; lblContactAddressOther.Text = contact.ContactAddressOther; //Phone Numbers lblContactPhoneBusiness.Text = contact.ContactPhoneBusiness; lblContactPhoneHome.Text = contact.ContactPhoneHome; lblContactPhoneCell.Text = contact.ContactPhoneCell; lblContactPhoneFax.Text = contact.ContactPhoneFax; lblContactPhoneOther.Text = contact.ContactPhoneOther; //Notes txtContactNotes.Text = contact.ContactNotes; //Dept, Office, Prof. lblContactDepartment.Text = contact.ContactDepartment; lblContactOffice.Text = contact.ContactOffice; lblContactProfession.Text = contact.ContactProfession; //Nickname, Title, Suffix lblContactNickname.Text = contact.ContactNickname; lblContactTitle.Text = contact.ContactTitle; lblContactSuffix.Text = contact.ContactSuffix; //Manager, Assistant, Spouse names lblContactManagerName.Text = contact.ContactManagersName; lblContactAssistantName.Text = contact.ContactAssistantsName; lblContactSpouseName.Text = contact.ContactSpousesName; //Birthday, Anniversary if (contact.ContactBirthday.Year < 1000) { lblContactBirthday.Text = ""; } else { lblContactBirthday.Text = contact.ContactBirthday.ToShortDateString(); } if (contact.ContactAnniversary.Year < 1000) { lblContactAnniversary.Text = ""; } else { lblContactAnniversary.Text = contact.ContactAnniversary.ToShortDateString(); } //Added, Modified lblDateAdded.Text = contact.ContactDateAdded.ToShortDateString(); lblDateModified.Text = contact.ContactModified.ToString(); }
private void readUsers() { OleDbConnection db = null; OleDbDataReader dataReader = null; try { // Open a connection to the DBMS. db = new OleDbConnection(); db.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" + mFileName; db.Open(); string sql = "SELECT * FROM Contacts ORDER BY ContactLastName ASC"; OleDbCommand command = new OleDbCommand(sql, db); dataReader = command.ExecuteReader(); // Format each message returned from the query. mContacts = new ArrayList(); while (dataReader.Read() == true) { //Build a class object and add it to the array //Make a new clsPost object each time. clsContact contact = new clsContact(); contact.createObject(dataReader); //Pass the reader to create the object. mContacts.Add(contact); //Add the object to the ArrayList } } catch (Exception ex) { showErrorMessage(ex.Message); Close(); //Close if you get an error here, because there is a database issue. } finally { if (dataReader != null) { dataReader.Close(); } if (db != null) { db.Close(); } } }
private void deleteContact(clsContact contact) { OleDbConnection db = null; try { db = new OleDbConnection(); db.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" + mFileName; db.Open(); string sql = "DELETE FROM Contacts WHERE ContactID=" + contact.ContactID; OleDbCommand command = new OleDbCommand(sql, db); command.ExecuteNonQuery(); } catch (Exception ex) { showErrorMessage(ex.Message); } finally { if (db != null) { db.Close(); } } }
private void addContact() { clsContact contact = new clsContact(); UpdateContact updateContact = new UpdateContact("Add a new User", "Add", contact); updateContact.ShowDialog(); //Rebuild table after adding or updating a user. readUsers(); showUsers(); }