Exemplo n.º 1
0
 ///<summary>Registers an IGridBehavior for one or more Singularity schemas.</summary>
 ///<param name="schemas">The schemas to apply the behavior to.</param>
 ///<param name="behavior">The IGridBehavior instance.</param>
 public static void RegisterBehavior(IEnumerable <TableSchema> schemas, IGridBehavior behavior)
 {
     if (schemas == null)
     {
         throw new ArgumentNullException("schemas");
     }
     RegisterBehavior(t => schemas.Contains(TableSchema.GetSchema(t)), behavior);
 }
Exemplo n.º 2
0
 ///<summary>Registers an IGridBehavior for a Singularity schema.</summary>
 ///<param name="schema">The schema to apply the behavior to.</param>
 ///<param name="behavior">The IGridBehavior instance.</param>
 public static void RegisterBehavior(TableSchema schema, IGridBehavior behavior)
 {
     if (schema == null)
     {
         throw new ArgumentNullException("schema");
     }
     RegisterBehavior(t => TableSchema.GetSchema(t) == schema, behavior);
 }
Exemplo n.º 3
0
        static Column GetColumn(Binding binding)
        {
            var schema = TableSchema.GetSchema(binding.DataSource);

            if (schema == null)
            {
                return(null);
            }
            return(schema.Columns[binding.BindingMemberInfo.BindingField]);
        }
Exemplo n.º 4
0
        ///<summary>Gets an IEditorSettings to use for the given column, or null if there is no preset for that column.</summary>
        public static IEditorSettings GetSettings(object dataSource, string columnName)
        {
            UIThread.Verify();

            var schema = TableSchema.GetSchema(dataSource);

            if (schema == null)
            {
                return(null);
            }
            var column = schema.Columns[columnName];

            if (column == null)
            {
                return(null);                                   //eg, unbound columns
            }
            return(GetSettings(column));
        }
Exemplo n.º 5
0
        private void Initialize()
        {
            // Get Schema
            _schema = TableSchema <TValue> .GetSchema();

            if (_schema.Keys.Count != 1)
            {
                throw new ArgumentException("The specified type does not have a valid Schema.  The KeyList class requires a single-part key");
            }

            // Get LoadNew Method
            _loadNewMethod = (typeof(TValue)).GetMethod("LoadNew", BindingFlags.NonPublic | BindingFlags.Static);
            if (_loadNewMethod == null)
            {
                throw new ArgumentException("The specified type does not have a compatible static LoadNew method.");
            }

            // Get database name of key column
            foreach (var col in _schema.Keys)
            {
                _keyColumn = col.Value;
                break;
            }

            // Check for SelectCommand in type, if it is there use it!
            System.Reflection.FieldInfo fi = (typeof(TValue)).GetField("SelectCommand", BindingFlags.NonPublic | BindingFlags.Static);
            if (fi != null)
            {
                _selectValuesTemplate  = (string)fi.GetValue(null);
                _selectKeyListTemplate = CrudFactory.MakeSelectKeyTemplate(_schema, _selectValuesTemplate);
            }
            else
            {
                _selectValuesTemplate  = CrudFactory.MakeSelectTemplate(_schema);
                _selectKeyListTemplate = CrudFactory.MakeSelectKeyTemplate(_schema);
            }

            // Get select templates
            _selectOneCommand = CreateSelectOneCommand();
            _selectOneCommand.Prepare();
            _selectBlockCommand = CreateSelectBlockCommand();
            _selectBlockCommand.Prepare();
        }
Exemplo n.º 6
0
        ///<summary>Gets the TableSchema for the table bound to a grid view.</summary>
        ///<remarks>This method even supports detail pattern views at design
        ///time.  (Even though they don't have a data source)</remarks>
        public static TableSchema GetSourceSchema(this BaseView view)
        {
            if (view == null)
            {
                throw new ArgumentNullException("view");
            }

            if (view.DataSource != null)
            {
                return(TableSchema.GetSchema(view.DataSource));
            }
            if (view == view.GridControl.MainView)              //And there's no datasource
            {
                return(null);
            }

            return(view.GetLevelNode().GetSchema());

            //var parentSchema = view.ParentView.GetSourceSchema();
            //if (parentSchema != null)
            //    return parentSchema.ChildRelations[view.LevelName].ChildSchema;

            //return null;
        }
Exemplo n.º 7
0
 /// <summary>
 /// Gets the table schema for item type C.  The table schema is created by using the
 /// ColumnAttributes and TableAttributes defined in the item type.
 /// </summary>
 /// <returns>A TableSchema that describes the items in the list.</returns>
 public TableSchema <C> GetSchema()
 {
     return(TableSchema <C> .GetSchema());
 }
Exemplo n.º 8
0
        //TODO: Group summaries
        #region Behaviors
        static void RegisterBehaviors()
        {
            //TODO: Delete LoggedStatements?
            GridManager.RegisterBehavior(JournalAd.Schema,
                                         DeletionBehavior.WithMessages <JournalAd>(
                                             singular: a => "CAUTION! Only delete an ad if its shape is gone.\r\nTo delete a healthy ad, double-click it, then click the Delete Ad button in the ribbon.\r\nEither way, any pledges, payments, or seating reservations will NOT be deleted.\r\n\r\nAre you sure you want to delete the row for ad #" + a.ExternalId + "?",
                                             plural: set => "CAUTION! Only delete an ad if its shape is gone.\r\nTo delete a healthy ad, double-click it, then click the Delete Ad button in the ribbon.\r\nEither way, any pledges, payments, or seating reservations will NOT be deleted.\r\n\r\nAre you sure you want to delete the rows for ads #" + set.Join(", ", j => j.ExternalId.ToString()) + "?"
                                             )
                                         );

            GridManager.RegisterBehavior(RelativeLink.Schema,
                                         DeletionBehavior.WithMessages(
                                             "relative link",
                                             "relative links"
                                             )
                                         );
            GridManager.RegisterBehavior(Person.Schema,
                                         DeletionBehavior.Disallow("You cannot delete rows from the master directory.\r\nIf you really want to delete someone, call Schabse.")
                                         );
            GridManager.RegisterBehavior(RaffleTicket.Schema,
                                         DeletionBehavior.WithMessages <RaffleTicket>(
                                             singular: t => "Are you sure you want to delete ticket #" + t.TicketId + "?",
                                             plural: set => "Are you sure you want to delete " + set.Count() + " tickets?"
                                             )
                                         );
            GridManager.RegisterBehavior(Caller.Schema,
                                         DeletionBehavior.WithMessages(
                                             "Melave Malka caller",
                                             "Melave Malka callers"
                                             )
                                         );
            GridManager.RegisterBehavior(EmailAddress.Schema,
                                         DeletionBehavior.WithMessages(
                                             "email address from the email list",
                                             "email addresses from the email list"
                                             )
                                         );
            GridManager.RegisterBehavior(MelaveMalkaSeat.Schema,
                                         DeletionBehavior.WithMessages(
                                             "seating reservation",
                                             "seating reservations"
                                             )
                                         );
            GridManager.RegisterBehavior(MelaveMalkaInfo.Schema,
                                         DeletionBehavior.WithMessages <MelaveMalkaInfo>(
                                             singular: m => "Are you sure you want to delete the info about the " + m.Year + " Melave Malka?\r\nNo other data will be deleted.",
                                             plural: mms => "Are you sure you want to delete  info about " + mms.Count() + " Melave Malkas?\r\nNo other data will be deleted."
                                             )
                                         );
            GridManager.RegisterBehavior(MelaveMalkaInvitation.Schema,
                                         DeletionBehavior.WithMessages <MelaveMalkaInvitation>(
                                             singular: mmi => "Are you sure you want to uninvite " + mmi.Person.FullName + "?",
                                             plural: mmis => "Are you sure you want to uninvite " + mmis.Count() + " people?"
                                             )
                                         );
            GridManager.RegisterBehavior(Pledge.Schema,
                                         DeletionBehavior.WithMessages <Pledge>(
                                             singular: p => "Are you sure you want to delete this " + p.Amount.ToString("c", CultureInfo.CurrentCulture) + " pledge?",
                                             plural: pledges => "Are you sure you want to delete "
                                             + (pledges.Count().ToString(CultureInfo.InvariantCulture) + " pledges totaling "
                                                + pledges.Sum(p => p.Amount).ToString("c", CultureInfo.CurrentCulture) + "?")
                                             )
                                         );
            GridManager.RegisterBehavior(Payment.Schema,
                                         DeletionBehavior.WithMessages <Payment>(
                                             singular: p => "Are you sure you want to delete this " + p.Amount.ToString("c", CultureInfo.CurrentCulture) + " payment?",
                                             plural: payments => "Are you sure you want to delete "
                                             + (payments.Count().ToString(CultureInfo.InvariantCulture) + " payments totaling "
                                                + payments.Sum(p => p.Amount).ToString("c", CultureInfo.CurrentCulture) + "?")
                                             )
                                         );
            GridManager.RegisterBehavior(
                new TableSchema[] { Pledge.Schema, Payment.Schema },
                new AdvancedColumnsBehavior("modifier columns", new[] { "Modified", "Modifier" })
                );
            //The predicate will only be called after views are created,
            //after the client application has registered its activators
            GridManager.RegisterBehavior(
                ds => {
                var schema = TableSchema.GetSchema(ds);
                return(schema != null && AppFramework.Current.CanShowDetails(schema));
            },
                new RowDetailBehavior()
                );
        }