Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to lock some record in BROWSE window ?

Status
Not open for further replies.

johan3000

MIS
Dec 17, 2010
18
ID
Hi All,

I wrote an General Ledger program, browsing a list of record (date,refno,accno,info,Debet,Credit). While browsing that data, it would be nice to protect all the previous month entries not to be modified.

1. Is they any easy way to protect some of the record in browsing (specify by the user for certain date at any time) ?

(note:the table has relation and many indexes and
the user allow to change the protection date as wish)

thanks you and Merry Crhistmanst.
 
Well, locking records will lock them for all. Just don't display them. Or display them in a readonly grid.

Don't use browse in GUI, use a grid.

Actually in a grid you could use the dynamiccurrentcontrol feature switching between a normal and a readonly textbox on the condition of some date field being from the actual month or earlier.

Bye, Olaf.
 
The way I would do this is to use a grid rather than a browse. Make the entire grid read-only.

To allow the user to edit the current month's data, let them double-click on the row they want to edit. Or, let them select that row, and then click an "edit" button. Either way, it would open a modal form for editing that one record. (Or, instead of a modal form, the text boxes could be on the same form as the grid.)

As well as solving the problem of locking out the old entries, this would be an overall better user interface.

The point is that a grid is not a good tool for editing. It's better to use the grid to permit record selection, and do the actual editing in text boxes, etc.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
I'd take two grids, a normal one for the current month and a readonly one for previous data.

Current month can be filtered by eg SET FILTER TO datefield between date(year(date(),month(date),1) and gomonth(date(year(date(),month(date),1),1)-1

prevous data can be filtered by SET FILTER TO datefield<date(year(date(),month(date),1)

Bye, Olaf.
 
John,
The advice I am about to give you is from me and only me, I am sure that there are others (most?) that may say that what I am suggesting is full of *(&@*^# but for me this is a best practice. ( I suspect some will post later in this thread saying something to that effect (or is that affect?))

Only use a grid in a read only fashion! Do not try to have pull downs, checkboxes etc in the grid. The FVP grid for editing is a pig, and if you try and get a pig to dance it will only make the pig mad and you frustrated.

Why do I say that? Well because I have spent many a day trying to get grids to do what my boss/clients have asked me to and I can get it to do what is needed 95%+ of the time, but then the user clicks on a grid element in at a certain time, or presses the backspace key, or or or and then the data does not get updated, or the element from the current cell gets copied to the new cell, or the cell one to the left or or or. I spent more time getting grids to work 98% (Never could get them to work 100% user always found new ways to break the grids) of the time than any other control! Now this was back in VFP 5, 6 days. Some may say: “Anthony VFP 9.0 handles grids perfectly come embrace the light!” To that I say NO! I have been tricked once too often> <Smile>

OK so what do I do instead? First of all I love grids use them on the majority of my screens, but I use them in read only fashion. I add to the screen a set of edit controls, normally one for every grid column. I allow the user to the data changes/input etc via this edit area and the changes are reflected in the grid. This is my personal best practice and what I recommend to you.

Use grids in a read/write mode at your own risk.

BTW I agree do not use browse in production code the few times that I have in VFP I have gotten my self burned. Now FPW that is another story.


Lion Crest Software Services
Anthony L. Testi
President
 
I don't object and I won't say suggesting to use grids read only is a too restrictive use.

But actually the grid is also marvellous for entering values in a fast fashin, moving from record to record with arrow keys for example. As long as you don't force it do display fancy stuff and also act as a data entry control, that's bad.

That said I strongly suggest you rather use the two grid approach than the dynamiccurrentcontrol approach.

Bye, Olaf.
 
MikeLewis:
let them double-click on the row they want to edit
johan3000: doubleClick will decrease the efficiency

OlafDoschke:
I'd take two grids, a normal one for the current month and a readonly one for previous data.
johan3000: this would be a good idea... I just thinking only one grid with previeous date in a different foreGround/background color...

mrDataGuy:
The FVP grid for editing is a pig, and if you try and get a pig to dance it will only make the pig mad and you frustrated.
johan3000: I enjoy your comments, this sentence just make my day..

question:
so how is the dynamiccurrentcontrol for specific date in a grid not to be MODIFY ? (if using filter, the records will not shown!)


thanks agian...
 
doubleClick will decrease the efficiency

Maybe. But the question isn't one of efficiency; it's about user interface.

so how is the dynamiccurrentcontrol for specific date in a grid not to be MODIFY ? (if using filter, the records will not shown!)

Using DynamicCurrentControl is an alternative to using two grids with the filters. There's no point in doing both.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Johan,

in regard to dynamiccurrentcontrol, this would be a solution for one grid, reread what I said earlier: "dynamiccurrentcontrol feature switching between a normal and a readonly textbox on the condition of some date field being from the actual month or earlier."

So this requires to add controls to the grid, a textbox for each row, and set these controls readonly. Each column by default has a readwrite textbox called text1, eg grid.column1.text1 is the control showing the table field value in column1. You can add eg Text2 and make that readonly.

Then you can switch between Text1 (readwrite) and Text2 (readonly) by condition.

But forget about that, as you don't seem to be very familiar with grids and their dynamic... features, it would be rather much to explain.

Rather go for the solution with two grids, then it's only the readonly setting you need to set .T. on the previous data grid and .T. on the current month grid.

Bye, Olaf.
 
* get the date begining of last month 01-lastMonth-YY
zdBOL = DATE( YEAR(zdJnlLast),MONTH(zdJnlLast ),1)
* Current month in zebra color (diff ref_no diff color)
* any other month with white color (to prevent miss input)
thisform.grid1.SetAll("DynamicBackColor", ;
"IIF(EMPTY(journal.ref_no) .or. EMPTY(journal.acc_no) .or. ;
(journal.date_enter<zdBOL),RGB(255,255,255) ,"+;
"IIF("+;
"MOD(VAL(RIGHT(' '+journal.ref_no,1)),2)=0"+;
",RGB(230,254,255),RGB(230,255,231))"+; && two color here
")","Column")
* for sunday , display fore color in RED; 1=sunday
thisform.grid1.SetAll("dynamicforecolor", ;
"IIF(DOW(journal.date_enter)=1, RGB(255,0,0), RGB(0,0,0))", "Column")

that is part of my grid to display different color...

thanks to mikeLewis and
OlafDoschke you have helped me much... to clear up the cloud!

so I just need to add protection for previous data on the grid not to be modify....

thanks all....
 
So I should set all the object in the grid as follow ?

thisform.grid1.oAccNo.txtAccNo.ReadOnly=currentMonth(journalDate)

where :

function currentMonth(xDate)
return year(now())=year(xDate) .and. ;
moth(now())=month(xDate)

please help!
 
No, the grid readonly is working for the whole grid and no DYNAMIC Proeprty, which works per record.

Have two grids, one showing data of previous months and one showing current data, make the first one readonly and leave the second enabled.

Bye, Olaf.
 
thisform.grid1.ReadOnly

bro Olaf,
your suggestion is there will 2 grid object on the form ?
and the grid will split by 2
1. upper part grid1 old data
2. bottom part grid2 editing current data

But is there possible just to have one grid doing the job? so the user will have bigger area of grid ?

some example of the code would be very welcome...hahahaa

thanks for your kindness
 
Sorry johann,

Take the two grid solution as a first solution, which you can change later. If this has time and you insist on the other solution, then reread and do as I said, or wait. My time is running short.

Bye, Olaf.
 
bro Olaf,

I had been trying but still not working...

Is there a way to set the journal.dbf such that
the only last 100 records can be modify in a grid ?

would you mind to show me some hint (code) ?

thanks...
 
Is there a way to set the journal.dbf such that
the only last 100 records can be modify in a grid ?

I think Olaf and others have gone out of their way to answer your question.

The simplest solution would be to create two grids, along the lines that have already been suggested.

If you definitely want a single grid, then you should use the DynamicCurrentControl method:

1. Create the grid as usual.

2. In each of the editable columns, place an additional textbox. Name it, say, Text1_X. Set its ReadOnly property to .T.

3. Assign a field (in the underlying cursor or table) to hold a flag to say whether the corresponding record is editable. For example, if you want to make the last 100 records read-only, the flag would be .F. for those 100 records and .T. for the others. Name the flag, say, Editable.

4. In the grid's Init, execute code similar to the following:

Code:
This.Column1.DynamicCurrentControl = ;
  "IIF(Editable, 'Text1', 'Text1_X')"

* Repeat for each editable column

That should do what you want.

However, I would still advise against using a grid for editing. Better to use the grid to let the user locate the record to be edited, and provide other controls for the actual editing. Not only would that give you greater control, it would be more convenient for the user.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Thanks so much, MikeLewis

I will try to work it out....(although that is hard for me)

Happy new Year 2011. and Merry X'mas too


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top