Ticket Q515471
Visible to All Users

XAF replace current object Onsaving

created 12 years ago

Hi !

I've got 2 table : 1: Measurement 2: Puffer.

I XAF, when I fill datas in detailview of measurement, I will save the data.
So here are my problems :

I use Measurement Onsaving method.
In first time I would like to save data to Puffer, and NO SAVE into Measurement,- second time I get back the data from Puffer, save to the Measurement, then delete from the Puffer.

  1. How can I prevent in Measurement Onsaving method the save the actual datas into the table ? (I would like to no save !!!).
  2. How can I save data In Measurement Onsaving method to save datas into Puffer ?

I think something lik this, but I know, this code is not correct :
Measurement Onsaving method()
{
var firstmeasurement = new PUFFER(Session);
firstmeasurement.kg = 35;
firstmeasurement.save();
//Disable save into measurement table ??
// base.OnSaving();
}

Any explanation :
I have a scale. Every record in Measurement table includes 2 measurements,
e.g. Measrement 1: 20 kilogramm, Measurement 2 : 5400 kilogramm.
After, the first measurement I save the data to the temporary table, after the second measurement I delete the data from the Puffer table, I create an ID for this measurement, and I save it into Measurement table.

Thanks for the help,
Zoltan

Show previous comments (7)
DevExpress Support Team 12 years ago

    Hi Zoltan.
    If you wish to modify an existing record, do not create a new measurement via the New action. Instead, use the FullTextSearch action to find an existing measure, for example.
    If the user does not know whether a previous measurement exists, you can create a custom action to simplify the process as follows. Create a ParametrizedAction to accept the ID or a PopupWindowShowAction to show a dialog if you need a complex search. When this action is executed, search for a previous measurement record. If it is found, open the detail view of the measurement record, otherwise create a new measurement instance and open its detail view.

      Hi Michael !
      In my project induced a lot of problem, to finish it. If I review my questions that asked from the support, it is about 80% about about this project. The project, and the task, that I have to implemet it, is very simple, but the realization in XAF is hard many times.
      There are many specialities,- like this problem,- these are NOT exist in any other project, only in this project.
      Sorry for this long prolog.

      1. "If you wish to modify an existing record, do not create a new measurement via the New action."
        O.K. Is not any other way, workaround for this ?
        Explanation : when the user enters the licence plate number = LPN into the first field, he does not know, that exist or not a measurement for this LPN. There are more than 100 measurement per day, and more than 30 1st measurement at the same time. Please see the attavhement.
        The users enter the LPN, if exist, it will be a new measurement with finished-flag=false, if the next measurement enter the same LPN, it will modify the record. (that's why I wanted to use the PUFFER table, but if You reread the ticket, I reject using the PUFFER table, because I cannot implement it for my needs, based upon your suggetion.)
        I want simplify the user's job : everytime he want to measure, click new measurement button, enter the LPN, if this LPN does not exist save the 1st measurement, if exist, modify the record. I hope it is clear. I have to implement it this way, this is my BOSS command.
        I've got an idea, not the best, but fits my needs, I think :
        In the 1st measurement save the datas, O.K.
        In the 2nd measurement, save the datas, and delete the record, that is same like this, except for the unefinished flag, and the 2nd measurement datas.
        How can I implement it, e.g in OnSaving() ? (I need a short sample code, saving…create a new object, find it, and delete…).
        2."Instead, use the FullTextSearch action to find an existing measure, for example."
        This is not option. Please see the 1.
        3."If the user does not know whether a previous measurement exists, you can create a custom action to simplify the process as follows. Create a ParametrizedAction to accept the ID or a PopupWindowShowAction to show a dialog if you need a complex search. When this action is executed, search for a previous measurement record. If it is found, open the detail view of the measurement record, otherwise create a new measurement instance and open its detail view."
        Huh…, I will implement this, way only, if I will not any chance to solve this problem, that write it above.
        Thanks for the help,
        Zoltan

        Answers approved by DevExpress Support

        created 12 years ago (modified 11 years ago)

        Hello Zoltan,
        Deleting the current object and replacing it with the another one is definitely not a good practice. I suggest that you try to find another approach. For example, note that it is not necessary to use the Measurement DetailView as a form where measurement details are entered. You can use a DetailView of another object. For example, you can use a TrackMeasurement class that contains the Measurement1 and Measurement2 properties, and operate measurements in this class' business logic. In this case, it will be easy to understand what measurement was the first, and what was the second. If your business model cannot be extended this way, you can use a DetailView of a non-persistent class to enter measurement details. I have attached a sample project demonstrating this approach. Launch it, click the Measure action and enter LPN in the displayed window. Then click OK to execute the business logic. If you do not wish to use an additional button, you can place the business logic directly to the LPN's setter, as shown in the commented code.
        I hope you will find this information helpful.

          Show previous comments (32)
          Anatol (DevExpress) 11 years ago

            Would you please provide a sample project? I have not managed to reproduce the problem on the Main Demo. See the attached video.
            P.S. I have used version 13.1.8. If the Address1 and Address2 properties do not show different detail views in the MainDemo application after the same steps on your machine, most probably the version update will be helpful.

              Hi Anatol !

              Before I create a sample project, I atteched a video again.In the MERESPARAMETERS class there are 2 items default : LPN, MERES. I cloned the MERES item to MERES_Copy, and I setup that as you can see in video. It works this way.
              If it is ot enough, I will attach a code sample.
              Thanks for the help,
              Zoltan

              Anatol (DevExpress) 11 years ago

                I see that the View property works fine in your last video. It is unclear what the difference between this case and the case demonstrated in the 2013-10-29_1448.swf video is. Probably the MERES item's View property is modified somewhere else, for example, in the higher-level model. If you do not find such a place, provide a sample project.

                Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

                Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.