RE: [perl-win32-gui-users] wrappers revisited

2005-02-23 Thread Frazier, Joe Jr
Here is what I do in my Listview.  I have a global var to keep track of
the direction of the currently sorted column and one to keep track of
the column currently sorted.  Off the top of my head, I believe this
will work for most fields.  Of course, you might need a more general
purpose convtoDate() if you use (or your database returns) a different
date format(think: Wednesday, February 23, 2005.  If using data from a
database, my best suggestion (I wrote this app before I figured this
out) is to use your databases sql formating functions to get an ISO
date: 2005-02-23.  This will always sort properly.  Of course, this may
not be an option for all databases and doesn't take other sources of
dates into account such as command shell 'dir' lists, etc.

If only dealing with a single date format, you could could also pass in
a date format mask to the "custom" sort function.  You could also use a
Date/Time package such as DateManip, but that would introduce a
dependency and would slow sorts down by half or more.

sub lvwJobposts_ColumnClick{
my $sort = shift;
my @Rows;
for(my $x = 0; $x < $win->lvwJobposts->Count();$x++){
my @Values;
for(my $y = 0; $y <= $win->lvwJobposts->{Columns};
$y++){
my %data = $win->lvwJobposts->ItemInfo($x, $y);
push @Values,$data{-text};
}
push @Rows, [EMAIL PROTECTED];
}
if ($sort == $sortCol){
if($dir eq 'f'){
$dir = 'b';
}elsif($dir eq 'b'){
$dir = 'f';
}
}else{
$sortCol = $sort;
$dir = "f";
}
my @result;
dosort ([EMAIL PROTECTED], [EMAIL PROTECTED], $sort, $dir);
$win->lvwJobposts->Clear();
for (my $d = 0; $d <= $#result;$d++){
Win32::GUI::DoEvents();
$win->lvwJobposts->InsertItem(-text =>$result[$d]);
}

}
sub dosort {# dosort [EMAIL PROTECTED], [EMAIL PROTECTED], column 0 
to n,
'f'|'r'
my ($sort, $sorted, $col, $dir) = @_;
if ($dir eq 'f') {
@$sorted = sort { convtoDate($a->[$col]) <=>
convtoDate($b->[$col]) || $a->[$col] <=> $b->[$col] || $a->[$col] cmp
$b->[$col] } @$sort;
} else {
@$sorted = sort { convtoDate($b->[$col]) <=>
convtoDate($a->[$col]) || $b->[$col] <=> $a->[$col] || $b->[$col] cmp
$a->[$col] } @$sort;
}
}

sub convtoDate
{
my $val = shift;
if ( $val =~ m|(\d+)/(\d+)/(\d+)|)
{
return sprintf "%4d%02d%02d", $3+2000,$1,$2;
}
return $val;

}


FYI: For MS SQL server 2000, I use something like:

Select username, convert(char(10), createdon, 121) as [Createdon]
>From tbl_user

This gets me :
Usernamecreatedon
-- 
Jfrazier2005-02-23

Joe Frazier, Jr.
Senior Support Engineer

Peopleclick Service Support
Tel:  +1-800-841-2365
E-Mail: [EMAIL PROTECTED] 

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On 
> Behalf Of Ariel Serbin
> Sent: Tuesday, February 22, 2005 16:42
> To: perl-win32-gui-users@lists.sourceforge.net
> Subject: [perl-win32-gui-users] wrappers revisited
> 
> I've been toying with the listview wrapper idea that I 
> brought up last week.  I threw together a module to show off 
> the basic idea, though it needs to be reworked.  I wanted to 
> make it easy to set up a listview and keep track of the items 
> by some id.  When I started writing this, I used the 
> hashref-of-hashrefs idea like DBI returns from 
> fetchall_hashref() because it seemed like a good way of 
> matching name/value pairs up with their respective ids.  The 
> problem with this is that there currently isn't a good way to 
> sort the items in the listview because of the nature of hashing.
> 
> If you're interested in having a look, I have the rough 
> module and a test script here:
> 
> http://www.serbin.org/ariel/mms.zip
> 
> I can easily fix this up to suit my immediate needs, but I 
> think that it would be nice to make it more generic so that 
> it would be helpful to others.  If anyone has any opinions as 
> to how this could be better implemented, please offer them up...
> 
> -Ariel
> 
> 
> 
> 
> ---
> SF email is sponsored by - The IT Product Guide Read honest & 
> candid reviews on hundreds of IT Products from real users.
> Discover which products truly live up to the hype. Start reading now.
> http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
> ___
> Perl-Win32-GUI-Users mailing list
> Perl-Win32-GUI-Users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users
> 



Re: [perl-win32-gui-users] wrappers revisited

2005-02-23 Thread Ariel Serbin
I made some changes to my wrapper module that I
mentioned the other day.  I had considered the sorting
issues that Joe mentioned and added sorting routines
similar to the code that he posted.  The wrapper now
has a sorting scheme that defaults to a regular cmp,
but lets you pass in a sub to convert the data if you
want.  For an example, uncomment the code in the
lv_ColumnClick event handler in my new test script:
 
http://www.serbin.org/ariel/mms.zip

So far, this seems to be a pretty handy way to manage
listviews for me.  The think that I like about it is
really easy to show the results of the query and the
wrapper can return either the relevant ID or the
underlying data.  (see the mybutton_Click handler for
an example.)

In one app that I'm working on, I'd like to let the
user decide which columns they would like to see in
the listview.  At first, I had planned to just write
something to collapse unwanted columns to 0 width, but
I think that using this module is much more intuitive.
 I also like the fact that the "rows" are not limited
to what is shown in the listview.

As always, thoughts are appreciated.

-Ariel