in
Forums
Blogs
Files
Devexpress.Com
Client Center
Support Center
DevExpress Channel

Validation and others made me skip lunch!

Last post 7/14/2007 3:26 PM by Jascha. 16 replies.
Page 1 of 2 (17 items) 1 2 Next >
Sort Posts:
Previous Next
  • 7/6/2007 11:31 AM

    Validation and others made me skip lunch!

    Hi Guys,

    I actually managed to hammer out my app within a really short time, only to get stuck with validation. I have two peculiar scenarios:

    1. I need to ensure a record is unique based on two or more fields.

    2. I have an 'Master' object 'A' with a one to many relationship with 'B'. I need exactly two* objects of  type 'B' for each unique type 'A'.

    a) How do I ensure the above conditions are met?

    *I have an enum with two values and an object of type 'B' is required for each of these values along with other fields.

     b) Also, I would like to have a Save and Create New action (I wonder how DX guys missed this). How and where do I hook it up for all detail views?

    c) Finally, as with every other windows app I want to put an About box via Help-> About. I cant seem to be able to put any action in the main menu. How do I do this?

    Oh, and the Dirty flag doesn't seem to work. All detail views still ask to cancel even without touching anything! 

    Sample code would be really appreciated.

    Regards,

    Keith. 

  • 7/6/2007 9:31 PM In reply to

    Re: Validation and others made me skip lunch!

    Hi Keith,

    If I understand your scenario - object A has an object's collection of type B which must contains 2 elements.
    You can decorate MasterA class with following attribute(Note: It works for Aggregated collections only...):
    [RuleCriteria("MasterA.CollectionOfB.Count", DefaultContexts.Save, "CollectionOfB.Count==2", "B collection must have 2 elements.")]
    When using NonAggregated collection object A is saved just before adding a new B object, so validation fails. I wonder how the solution should look like...

    MasterA class has defined 3 properties which must be unique - this property should do the trick:
    [RuleFromBoolProperty("MasterA.IsUnique", DefaultContexts.Save, "U1, U2, and U3 are not unique")]
    [System.ComponentModel.
    Browsable(false)]
    [
    NonPersistent]
    public
    bool IsUnique {
      get{
       
    if (Session.IsNewObject(this)){
          //looking for other objects with the same u1, u2 and u3 values - it should be 0
          
    if (new XPCollection<MasterA>(PersistentCriteriaEvaluationBehavior.BeforeTransaction, Session, Fields.Unique1 == Unique1 & Fields.Unique2 == Unique2 & Fields.Unique3 == Unique3).Count == 0)
           
    return true;
        }
    else {
         
    //looking for objects (including this object with it's current value) with the same u1, u2 and u3 values - it should be 1 (this object)
          if (new XPCollection<MasterA>(PersistentCriteriaEvaluationBehavior.InTransaction, Session, Fields.Unique1 == Unique1 & Fields.Unique2 == Unique2 & Fields.Unique3 == Unique3).Count == 1)
           
    return true;
        }
       
    return false;
      }
    }

    Take a look at the attachment.

    b) I've got no idea why this action is not included :)  it's interesting. You could post a suggestion to add this feature to the framework.

    c) By default all actions you define in ViewController are put in MainMenu and in MainToolbar (if specific category is included Menu or Toolbar). To add Help menu, you need customize MainForm template. Well, I've never done this before, so I can't say what steps needs to be taken.

    Regards,
    Michal

    Filed under:
  • 7/7/2007 2:50 AM In reply to

    Re: Validation and others made me skip lunch!

    Wow, Thanks Michal, you always save the day. I'll try out the validation in a moment. I'll also make sure to drop in a suggestion concerning the Save and Create New action. Aaah, and as for the custom menus... I'll live. I can't wait to show off my new 'over the weekend' app :).

    Cheers,

    Keith.

     PS: Have you seen my other post about the strange error? If you can make the time, please do investigate. I doubt Its unique to me.
     

  • 7/7/2007 3:58 AM In reply to

    Save and Create New

     Hi,

    I'm not sure I got this right but would you believe it, DX rejected a standard Save and Create New action on detail views.

    Regards,

    Keith. 

  • 7/7/2007 4:27 AM In reply to

    Re: Save and Create New

    Hi,

    Keith M. Dennis wrote:

    > I'm not sure I got this right but would you believe it, DX rejected a
    > standard Save and Create New action on detail views.

    I wasn't aware of this issue before, so thanks for pointing it out - but I
    do support the position Plato is taking.

    Our plans for the future include development of batch data entry
    functionality for XAF, but this is quite a bit more complex than just a
    "Save and New" button - when entering loads of data, you'll also want to
    take fields over from one record to the next, or pre-populate field values
    according to certain rules.

    Until we introduce this feature, it should really be pretty easy to create
    a controller that does just what you were suggesting. If you want some help
    doing this, please feel free to get back to Plato and ask him for an
    example.

    --
    Regards,
    Oliver Sturm
    Developer Express Inc.
    MVP C#
    --
    Regards,
    Oliver Sturm
    Developer Express Inc.
    MVP C#
  • 7/7/2007 4:51 AM In reply to

    Re: Save and Create New

    Thanks Oliver, I'm already working on it.

    Regards, 

    Keith. 

  • 7/7/2007 5:42 AM In reply to

    Re: Save and Create New

    Keith,
     
    If you get it done, any chance of sharing it?
     
    Thanks,
     
    Jascha
    <Keith M. Dennis> wrote in message news:187869@community.devexpress.com...

    Thanks Oliver, I'm already working on it.

    Regards, 

    Keith. 


    If we knew what it was we were doing, it would not be called research, Would it? - Albert Einstein

    http://community.devexpress.com//forums/p/55736/187869.aspx#187869

  • 7/7/2007 5:52 AM In reply to

    Re: Save and Create New

    Jascha,

    No problem.

    Keith. 

  • 7/7/2007 10:00 AM In reply to

    Re: Save and Create New

    Hi Guys,

    I've got it Wink

    private

    void closeAndNewAction_Execute(object sender, SimpleActionExecuteEventArgs e){
      DetailViewController detailViewController;
      detailViewController = Frame.GetController<DetailViewController>();
     
    if (detailViewController != null){
       
    //we must ensure that currnet view is saved and validated
       
    if (ObjectSpace.IsModified){
          detailViewController.SaveAction.DoExecute();
        }
       
    //if object is dirty, there was validation errors so we do nothing
       
    if (!ObjectSpace.IsModified){
          NewObjectViewController newObjectViewController = Frame.GetController<NewObjectViewController>();
         
    if (newObjectViewController != null){
            newObjectViewController.NewObjectAction.DoExecute(newObjectViewController.NewObjectAction.SelectedItem);
          }
          detailViewController.SaveAndCloseAction.DoExecute();
        }
      }
    }

    The attachment contains working example.

    Regards,
    Michal

  • 7/7/2007 10:43 AM In reply to

    Re: Save and Create New

    Fantastic! I'll make sure to spread the gospel. I think you should put it in a new post (with an new topic) so guys can find it easily.

    Regards,

    Keith
     

  • 7/7/2007 12:06 PM In reply to

    Re: AboutBoxController

    Keith - good news!

    The AboutBox task was simpler then I thought. You don't need to modify MainForm template. There is Help menu already defined and About category too. Only thing which needs to be done is to create WindowController with your AboutAction assigned to About category - and that's all!

    As usually :) you can find a working example inside the attachment.

    Michal

    PS. I've labeled my posts, so SaveAndNewController and AboutBoxController will be shown in the tag cloud on front page, so it could be easily found :)

    Filed under:
  • 7/7/2007 2:56 PM In reply to

    Re: Save and Create New

    Thanks Michal
     
    Jascha
    <Michal Korsak> wrote in message news:187881@community.devexpress.com...

    Hi Guys,

    I've got it Wink

    private

    void closeAndNewAction_Execute(object sender, SimpleActionExecuteEventArgs e){
      DetailViewController detailViewController;
      detailViewController = Frame.GetController<DetailViewController>();
     
    if (detailViewController != null){
       
    //we must ensure that currnet view is saved and validated
       
    if (ObjectSpace.IsModified){
          detailViewController.SaveAction.DoExecute();
        }
       
    //if object is dirty, there was validation errors so we do nothing
       
    if (!ObjectSpace.IsModified){
          NewObjectViewController newObjectViewController = Frame.GetController<NewObjectViewController>();
         
    if (newObjectViewController != null){
            newObjectViewController.NewObjectAction.DoExecute(newObjectViewController..NewObjectAction.SelectedItem);
          }
          detailViewController.SaveAndCloseAction.DoExecute();
        }
      }
    }

    The attachment contains working example.

    Regards,
    Michal



    http://community.devexpress.com//forums/p/55736/187881.aspx#187881

  • 7/8/2007 5:42 AM In reply to

    Re: Save and Create New

     Hi,

    That's really good news Michal. Keep up the good work and thanks again. By the way how did you discover the 'About' category and why it doesn't it show up on the drop down? Seems there is so much more to dig out!

    Regards,

    Keith.

    PS: These posts are extremely helpful to beginners, they should probably be included in an How To topic here. What do you think guys? 

  • 7/8/2007 10:08 AM In reply to

    Re: MainForm template action categories

    You should include MainForm template to any project and review it (it is located in: C:\Program Files\Developer Express Inc\eXpressApp Framework v7.1\Sources\FrameTemplates)

    To be able to compile it you need to add:
    using DevExpress.ExpressApp.Win.Templates;
    (looks like guys forgot to do it)

    go to designer and look at MainMenu and MainToolbar for defined categories and where are they located (screenshot attached).

    Regards,
    Michal


  • 7/12/2007 5:55 PM In reply to

    Re: Save and Create New

    Hi Michal,
     
    Is there a reason why you have not enabled this controller for non-root views?
     
    Thanks,
     
    Jascha
    <Michal Korsak> wrote in message news:187881@community.devexpress.com...

    Hi Guys,

    I've got it Wink

    private

    void closeAndNewAction_Execute(object sender, SimpleActionExecuteEventArgs e){
      DetailViewController detailViewController;
      detailViewController = Frame.GetController<DetailViewController>();
     
    if (detailViewController != null){
       
    //we must ensure that currnet view is saved and validated
       
    if (ObjectSpace.IsModified){
          detailViewController.SaveAction.DoExecute();
        }
       
    //if object is dirty, there was validation errors so we do nothing
       
    if (!ObjectSpace.IsModified){
          NewObjectViewController newObjectViewController = Frame.GetController<NewObjectViewController>();
         
    if (newObjectViewController != null){
            newObjectViewController.NewObjectAction.DoExecute(newObjectViewController..NewObjectAction.SelectedItem);
          }
          detailViewController.SaveAndCloseAction.DoExecute();
        }
      }
    }

    The attachment contains working example.

    Regards,
    Michal



    http://community.devexpress.com//forums/p/55736/187881.aspx#187881

Page 1 of 2 (17 items) 1 2 Next >
Copyright © 1998-2008 Developer Express Inc.
ALL RIGHTS RESERVED