コード例 #1
0
    private TaxOfficeModel() { } //ensure "Current" is a singleton
    static TaxOfficeModel()
    {
      if (WPFHelpers.DesignMode) return;

      Current = new TaxOfficeModel();

      CacheTables("TaxOffice_Init");

      TaxOfficeTable.DefaultView.Sort = "TaxOfficeId";

      UserTable.PrimaryKey = new[] { UserTable.Columns["TaxOfficeId"], UserTable.Columns["RowGUID"] };
      UserTable.Columns.Add("UserNameId", typeof(string), "FirstName + ' ' + LastName");
      UserTable.DefaultView.Sort = "UserNameId";


      {// AllOffices
        AllOffices = new DataView(TaxOfficeTable) {RowFilter = "Office <> 'Any'", Sort = "Active desc, Office"};
      }

      {// AllOfficesPlusAny
        var any = TaxOfficeTable.NewRow();
        any["TaxOfficeId"] = 0; //we can't jam a DBNull in here since ADO.Net doesn't allow NULLs on Primary Keys
        any["OfficeCode"] = "__";
        any["Office"] = "Any";
        any["Active"] = true;
        TaxOfficeTable.Rows.InsertAt(any, 0);

        AllOfficesPlusAny = new DataView(TaxOfficeTable) {Sort = "Active desc, Office"};
      }

      // Current.Fields
      Current.Fields = TaxOfficeTable.DefaultView.FindRows(SettingsModel.TaxOfficeId)[0];

      {// Current.POC
        DsCache.Relations.Add("POC",
          new[] { UserTable.Columns["TaxOfficeId"], UserTable.Columns["RowGUID"] },
          new[] { TaxOfficeTable.Columns["TaxOfficeId"], TaxOfficeTable.Columns["POC_UserGUID"] }, false);
        Current.Fields.PropertyChanged += (s, e) => { if (e.PropertyName == "POC_UserGUID") Current.OnPropertyChanged("POC"); };

        TaxOfficeTable.Columns.Add("POC Name", typeof(string), "Parent(POC).UserNameId"); //nugget: syntax for pulling parent relationship columns over to the child DataTable
        TaxOfficeTable.Columns.Add("POC Phone", typeof(string), "Parent(POC).DSNPhone");
        TaxOfficeTable.Columns.Add("POC Email", typeof(string), "Parent(POC).Email");
      }

      {// Current.ActiveUsers
        DsCache.Relations.Add("OfficeUsers", TaxOfficeTable.Columns["TaxOfficeId"], UserTable.Columns["TaxOfficeId"], false);
        Current.ActiveUsers = Current.Fields.CreateChildView("OfficeUsers");
        Current.ActiveUsers.RowFilter = "Active = 1";
        Current.ActiveUsers.Sort = "UserNameId";
        UserTable.RowChanged += UserTableRowChanged;
      }

    }
コード例 #2
0
        }                        //ensure "Current" is a singleton

        static TaxOfficeModel()
        {
            if (WPFHelpers.DesignMode)
            {
                return;
            }

            Current = new TaxOfficeModel();

            CacheTables("TaxOffice_Init");

            TaxOfficeTable.DefaultView.Sort = "TaxOfficeId";

            UserTable.PrimaryKey = new[] { UserTable.Columns["TaxOfficeId"], UserTable.Columns["RowGUID"] };
            UserTable.Columns.Add("UserNameId", typeof(string), "FirstName + ' ' + LastName");
            UserTable.DefaultView.Sort = "UserNameId";


            {// AllOffices
                AllOffices = new DataView(TaxOfficeTable)
                {
                    RowFilter = "Office <> 'Any'", Sort = "Active desc, Office"
                };
            }

            {                           // AllOfficesPlusAny
                var any = TaxOfficeTable.NewRow();
                any["TaxOfficeId"] = 0; //we can't jam a DBNull in here since ADO.Net doesn't allow NULLs on Primary Keys
                any["OfficeCode"]  = "__";
                any["Office"]      = "Any";
                any["Active"]      = true;
                TaxOfficeTable.Rows.InsertAt(any, 0);

                AllOfficesPlusAny = new DataView(TaxOfficeTable)
                {
                    Sort = "Active desc, Office"
                };
            }

            // Current.Fields
            Current.Fields = TaxOfficeTable.DefaultView.FindRows(SettingsModel.TaxOfficeId)[0];

            {// Current.POC
                DsCache.Relations.Add("POC",
                                      new[] { UserTable.Columns["TaxOfficeId"], UserTable.Columns["RowGUID"] },
                                      new[] { TaxOfficeTable.Columns["TaxOfficeId"], TaxOfficeTable.Columns["POC_UserGUID"] }, false);
                Current.Fields.PropertyChanged += (s, e) => { if (e.PropertyName == "POC_UserGUID")
                                                              {
                                                                  Current.OnPropertyChanged("POC");
                                                              }
                };

                TaxOfficeTable.Columns.Add("POC Name", typeof(string), "Parent(POC).UserNameId"); //nugget: syntax for pulling parent relationship columns over to the child DataTable
                TaxOfficeTable.Columns.Add("POC Phone", typeof(string), "Parent(POC).DSNPhone");
                TaxOfficeTable.Columns.Add("POC Email", typeof(string), "Parent(POC).Email");
            }

            {// Current.ActiveUsers
                DsCache.Relations.Add("OfficeUsers", TaxOfficeTable.Columns["TaxOfficeId"], UserTable.Columns["TaxOfficeId"], false);
                Current.ActiveUsers           = Current.Fields.CreateChildView("OfficeUsers");
                Current.ActiveUsers.RowFilter = "Active = 1";
                Current.ActiveUsers.Sort      = "UserNameId";
                UserTable.RowChanged         += UserTableRowChanged;
            }
        }