how to ensure that a single entity can be created per day

Posts   
 
    
yogiberr
User
Posts: 432
Joined: 29-Jun-2005
# Posted on: 24-Apr-2006 10:17:53   

version 1.0.2005.1 final (self-servicing) VS2005 winforms


hiya,

I have a "van load" entity. A "van load" entity consists of a driver filling up their van at the start of the day. A van load will only happen once a day for each driver.

The van load entity has a datetime field. I am guessing that I have to somehow start messing about with sub strings, so that I can tell if a driver has already loaded his van?

Can llblGenPro give me anything that will make it easier?

Hope this post made sense sunglasses

cheers,

yogi

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 24-Apr-2006 15:08:22   

A simple database table structure would help us understand your issue better.

Anyway, I guess a database constraint (over the date & driver fields I guess) will be the adequate thing to use, or you might do a select before the Insert to check if the driver had loaded his van yet or not.

yogiberr
User
Posts: 432
Joined: 29-Jun-2005
# Posted on: 24-Apr-2006 15:57:33   

OK Walaa,

tblDelivery deliveryId driverId deliveryDate

I think i'd prefer to use LlblGenPro, rather than use constraints.

So, I believe I should use predicates that will return a bool value indicating whether the driver has loaded his van?

many thanks,

yogi

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 24-Apr-2006 16:08:12   

So, I believe I should use predicates that will return a bool value indicating whether the driver has loaded his van?

Yes that's the select I've been talking about.

With that query.., you may also use a database constraint as a second line of defence, just for the sake of a good database design and data integrity.

Good Luck

hlesesne avatar
hlesesne
User
Posts: 47
Joined: 22-Jul-2004
# Posted on: 25-Apr-2006 09:27:40   

Couldn't a new van look something like the following then:


Function GetTodaysDelivery(DriverID as integer) as Entity
' Sync this for multiple threads
    Dim Pred as new predicateexpression(predicatefactory.comparevalue(DeliveryFieldIndex.DriverID, Equals, DriverID)
    ' assuming you just want the whole date tracked, not hours/min/sec/ms,etc...
    Pred.AddWithAnd(Predicatefactory.comparevalue(DeliveryFieldIndex.DeliveryDate, Equals, Now.Today)
    dim Delivery as new DeliveryEntity
    da.FetchEntityByUniqueConstraint(Delivery, Pred)
' if the van hasn't been created, create it
    if Delivery.isNew then
        Delivery.DriverID = DriverID
        Delivery.DeliveryDate = now.today
        da.saveentity(Delivery,True)
    end if 
    return Delivery
' End sync
End Function

I may be misunderstanding what exactly you are looking for - if so, sorry...

Best regards,

Hal Lesesne http://hal.lco.net

yogiberr
User
Posts: 432
Joined: 29-Jun-2005
# Posted on: 26-Apr-2006 22:06:27   

hiya,

I think you've got it. the only hassle that I hav is the following


da.FetchEntityByUniqueConstraint(Delivery, Pred)

I'm using selfService.I think that the nearest method would be:


Delivery.FetchUsingPK(.....

But I don't think that the overloads are correct for my scenario. Maybe the selService has an equivalent?

thanks for the help.

yogi

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 27-Apr-2006 08:16:10   

Please refer to the LLBLGen Pro manual "Using the generated code -> SelfServicing -> Using the entity collection classes" goto the section titeled "Using a unique constraint's value".

You may also use DeliveryColection.GetMulti(Filter), with the appropriate filtering predicate.

yogiberr
User
Posts: 432
Joined: 29-Jun-2005
# Posted on: 29-Apr-2006 12:28:13   

thanks Walaa,

I am going down the "DeliveryColection.GetMulti(Filter), with the appropriate filtering predicate. " route.

however, I am having problems filtring the deliveries for a particular date:


IPredicateExpression deliveryFilter = new PredicateExpression();
            deliveryFilter.Add(PredicateFactory.CompareValue(TblDeliveryFieldIndex.DeliveryDate, ComparisonOperator.Equal, DateTime.Today));

deliveries.GetMulti(deliveryFilter);    
int delCount;
            delCount = deliveries.Count;    

however, NO deliveries are returned, depite the fact that:

1) there is a delivery for this particular date 2) the datetime on my machine is correct (everything is on the SAME machine)

I'm not sure why it doesn't work. The datatype of the sqlSever coumn that it refernces is "datetime"

Can anyone help?

many thanks,

yogi

JimHugh
User
Posts: 191
Joined: 16-Nov-2005
# Posted on: 29-Apr-2006 17:16:27   

Any chance that you specified DateTime.Now (which includes time) when you saved the delivery?

If so, then #4/29/2006 12:28:13# will not be equal to #4/29/2006 00:00:00#.

So you will either need to use Today when assigning delivery.deliverydate (which uses midnight) or change your predicate to use FieldBetweenPredicate and compare midnight today and midnight tomorrow.

yogiberr
User
Posts: 432
Joined: 29-Jun-2005
# Posted on: 29-Apr-2006 18:27:30   

nice one Jim.

thanks,

yogi