/// <summary> /// Creates a site referencing the provided client. /// </summary> /// <param name="pClient"></param> public SiteView(Client pClient) { try { mSite = new Site(db); foreman = new SiteContact(SiteContact.ContactTypes.Foreman, mSite.GetSiteID()); SuperVisor1 = new SiteContact(SiteContact.ContactTypes.Supervisor1, mSite.GetSiteID()); SuperVisor2 = new SiteContact(SiteContact.ContactTypes.Supervisor2, mSite.GetSiteID()); SupplyAuth = new SiteContact(SiteContact.ContactTypes.SupplyAuth, mSite.GetSiteID()); mSite.SetClientID(pClient.GetClientID()); mClient = pClient; } catch (Exception ex) { MessageBox.Show("Site Object - " + msgCodes.GetString("M2101") + ex.Message, "Error - 2102", MessageBoxButton.OK, MessageBoxImage.Error); } InitializeComponent(); isModified = false; this.Name = "SiteNewSite"; newSite = true; }
/// <summary> /// Loads an existing site and allows for reference to client. /// </summary> /// <param name="pSite"></param> /// <param name="pClient"></param> public SiteView(Site pSite, Client pClient) { mSite = pSite; mClient = pClient; try { foreman = mSite.GetSiteContact(SiteContact.ContactTypes.Foreman); SuperVisor1 = mSite.GetSiteContact(SiteContact.ContactTypes.Supervisor1); SuperVisor2 = mSite.GetSiteContact(SiteContact.ContactTypes.Supervisor2); SupplyAuth = mSite.GetSiteContact(SiteContact.ContactTypes.SupplyAuth); } catch (Exception ex) { MessageBox.Show("Loading Site Contacts - " + msgCodes.GetString("M2102") + ex.Message, "Error - 2102", MessageBoxButton.OK, MessageBoxImage.Error); } InitializeComponent(); lockFields(); this.Name = "SiteView" + mSite.GetSiteID(); PopulateAllFields(); cmdSaveEdit.IsEnabled = true; isModified = false; }
/// <summary> /// Retrieves the contact object from the database. /// </summary> /// <param name="type"></param> /// <returns></returns> public SiteContact GetSiteContact(SiteContact.ContactTypes type) { int contactNum = 0; switch (type) { case SiteContact.ContactTypes.Foreman: contactNum = 0; break; case SiteContact.ContactTypes.Supervisor1: contactNum = 1; break; case SiteContact.ContactTypes.Supervisor2: contactNum = 2; break; case SiteContact.ContactTypes.SupplyAuth: contactNum = 3; break; } DataSet serviceData = Database.Instance.Select("*", SiteContact.Table, SiteContact.Fields.siteID.ToString() + " = '" + GetSiteID() + "' AND " + SiteContact.Fields.contactType.ToString() + " = " + contactNum); if (serviceData.NumberOfRows() > 0) { serviceData.Read(); return new SiteContact(serviceData.GetRecordDataSet()); } return null; }