static TaxFormModel() { if (WPFHelpers.DesignMode) { return; } //piggyback the TransactionType code table load with the TaxForm to ExtendedFields by TransactionType master-detail tables var tableNames = CacheTables("TaxForm_init"); //among other things, this query will initialize an empty "TaxForm" DataTable in dsCache ... since this is a static constructor which fires before everything else, it is safe to assume TaxFormTable property will be non null in all other contexts TransactionTypes = new DataView(DsCache.Tables["TransactionType"]); tableNames.Where(name => name.Left(8) == "taxform_"). //nugget: // ReSharper disable ReturnValueOfPureMethodIsNotUsed Select(extTableName => { DsCache.AddRelation(extTableName, TaxFormTable.Columns["RowGUID"], DsCache.Tables[extTableName].Columns["TaxFormGUID"]); return(false); }).Count(); //nugget: // ReSharper restore ReturnValueOfPureMethodIsNotUsed //nugget: wrapping a void function in an inline method which returns something makes LINQ Select happy //nugget: make sure to include something like .Count() at the end to short circuit LINQ's deferred execution behavior TaxFormViolationTypes = new DataView(DsCache.Tables["RemarkType"]) { RowFilter = "CategoryId = 'FORM_VIOLATION'" }; TaxFormPackageServiceFees = new DataView(DsCache.Tables["TaxFormPackageServiceFee"]) { Sort = "FormTypeId, FormCount" }; TaxFormOrderNumberView = new DataView(TaxFormTable) { Sort = "OrderNumber" }; }
protected override void LoadSubClass() { Fields = EntityLookup(GUID, "TaxForm", "TaxForm_s"); GUID = Fields["RowGUID"].ToString(); //for the case where TaxForm_s can lookup on OrderNumber as well as GUID //currently comes back with the following tables loaded: TaxForm, (optional) TaxForm_Weapon or (optional) TaxForm_Vehicle Fields.PropertyChanged += FieldChange; SetExtendedFields(); _isLocked = IsFormStatusClosed || !IsFormFromMyOffice; //create the logical lookup field for "Location" via TaxForm.LocationCode to TaxOffice.TaxOfficeCode DsCache.AddRelation("Location", TaxOfficeModel.TaxOfficeTable.Columns["OfficeCode"], TaxFormTable.Columns["LocationCode"], false); if (!TaxFormTable.Columns.Contains("Location")) { TaxFormTable.Columns.Add("Location", typeof(string), "Parent(Location).Office"); } //create the TaxForm_Remark relationship DsCache.AddRelation("TaxForm_Remark", TaxFormTable.Columns["RowGUID"], TaxFormRemarksTable.Columns["FKRowGUID"], false); TaxFormRemarks = Fields.CreateChildView("TaxForm_Remark"); ShowDeletedRemarks = false; RemarkModel.CommonRemarkTableSettings(TaxFormRemarks); TaxFormRemarks.Table.RowChanged += TaxFormRemarksRowChanged; if (IsIncomplete) { Validate(); //flip on all the red boxes so the user is prompted to resolve right away } }
protected override void LoadSubClass() { if (Transactions == null) { Transactions = new TransactionList(this, "Transactions"); } //assumption we're taking with caching with Sponsor entities in particular: // the corresponding sproc returns the whole household of sponsor + dependent clients records // and also the "household" (sponsor) address/phone record // then this lookup method returns a cached model of the specific type // and the GUI can then pull what it needs off that object via basic properties //the specified GUID passed in is for the Sponsor's *Sponsor*table* RowGUID Fields = EntityLookup(GUID, "Sponsor", "Sponsor_s"); var sponsorTable = DsCache.Tables["Sponsor"]; sponsorTable.Columns["DutyPhoneDSN1"].AllowDBNull = false; //sucks to have to fix these but they're 'generated' from a real field so they lose their NOT NULL metadata sponsorTable.Columns["DutyPhoneDSN2"].AllowDBNull = false; ClientTable.ColumnChanged += ClientTableColumnChanged; ClientTable.RowChanged += ClientTableRowChanged; UTAPFields = RowLookup("Sponsor_UTAP", GUID); //create the logical lookup field for SuspensionTaxOffice via Sponsor.SuspensionTaxOfficeId to Office.TaxOfficeId DsCache.AddRelation("SuspensionTaxOffice", DsCache.Tables["TaxOffice"].Columns["TaxOfficeId"], sponsorTable.Columns["SuspensionTaxOfficeId"]); if (!sponsorTable.Columns.Contains("SuspensionTaxOffice")) { sponsorTable.Columns.Add("SuspensionTaxOffice", typeof(string), "Parent(SuspensionTaxOffice).Office"); } //map the parent-child relationships hanging off Sponsor ... DataColumn sponsorTableRowGUID = sponsorTable.Columns["RowGUID"]; //SponsorTable tweaks: if (!sponsorTable.Columns.Contains("CanSellForms")) { sponsorTable.Columns.Add("CanSellForms", typeof(bool), "Active AND ISNULL(SuspensionExpiry, #1/1/01#) = #1/1/01#"); sponsorTable.Columns["Active"].ReadOnly = true; //block access to this field from the UI, elsewhere in this class we temporarily open it up to make validated changes (see CheckClientActiveRules method) } //Dependents: DsCache.AddRelation("Sponsor_Client", sponsorTableRowGUID, ClientTable.Columns["SponsorGUID"]); HouseMembers = Fields.CreateChildView("Sponsor_Client"); HouseMembers.Sort = "IsSponsor desc, IsSpouse desc, LName, FName"; //if brand new sponsor, add a default row to fill out for convenience if (HouseMembers.Count == 0) { AddMember(); } //set ShowDeactive to true, if there's not an Active Sponsor ShowDeactiveMembers = !HouseMembers[0].Field <bool>("Active") || !HouseMembers[0].Field <bool>("IsSponsor"); if (!ClientTable.Columns.Contains("IsSponsorOrSpouse")) { ClientTable.Columns.Add("IsSponsorOrSpouse", typeof(bool), "IsSponsor OR IsSpouse"); ClientTable.Columns["Active"].ReadOnly = true; //block access to this field from the UI, elsewhere in this class we temporarily open it up to make validated changes (see CheckClientActiveRules method) } //TaxForms: DsCache.AddRelation("Sponsor_TaxForm", sponsorTableRowGUID, DsCache.Tables["Sponsor_TaxForm"].Columns["SponsorGUID"]); RefreshTaxFormsList(false); //Remarks: var remarkTable = DsCache.Tables["Sponsor_Remark"]; DsCache.AddRelation("Sponsor_Remark", sponsorTableRowGUID, remarkTable.Columns["SponsorGUID"]); SponsorRemarks = Fields.CreateChildView("Sponsor_Remark"); ShowDeletedRemarks = false; RemarkModel.CommonRemarkTableSettings(SponsorRemarks); SponsorRemarks.Table.RowChanged += SponsorRemarksRowChanged; SponsorRemarks.Table.ColumnChanging += SponsorRemarksColumnChanging; _potentialClientMatchesBgWorker.OnExecute = PotentialMatchesSearchExecute; _potentialClientMatchesBgWorker.OnCompleted = PotentialMatchesSearchCompleted; }