Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0
This is the forum to discuss the Wrox book ASP.NET 2.0 Website Programming: Problem - Design - Solution by Marco Bellinaso; ISBN: 9780764584640
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 25th, 2008, 04:49 PM
Authorized User
 
Join Date: Jul 2007
Location: , , .
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem in understanding EnsureValidSortExp syntax

protected virtual string EnsureValidSortExpression(string sortExpression)
{
   if (string.IsNullOrEmpty(sortExpression))
      return "LastPostDate DESC";

   string sortExpr = sortExpression.ToLower();
   if (!sortExpr.Equals("lastpostdate") && !sortExpr.Equals("lastpostdate asc") &&
      !sortExpr.Equals("lastpostdate desc") && !sortExpr.Equals("viewcount") &&
      !sortExpr.Equals("viewcount asc") && !sortExpr.Equals("viewcount desc") &&
      !sortExpr.Equals("replycount") && !sortExpr.Equals("replycount asc") &&
      !sortExpr.Equals("replycount desc") && !sortExpr.Equals("addeddate") &&

      !sortExpr.Equals("addeddate asc") && !sortExpr.Equals("addeddate desc") &&
      !sortExpr.Equals("addedby") && !sortExpr.Equals("addedby asc") &&
      !sortExpr.Equals("addedby desc") && !sortExpr.Equals("title") &&
      !sortExpr.Equals("title asc") && !sortExpr.Equals("title desc") &&
      !sortExpr.Equals("lastpostby") && !sortExpr.Equals("lastpostby asc") &&
      !sortExpr.Equals("lastpostby desc"))
   {
      return "LastPostDate DESC";
   }
   else
   {
      if (sortExpr.StartsWith("title"))
         sortExpr = sortExpr.Replace("title", "tbh_posts.title");
      if (!sortExpr.StartsWith("lastpostdate"))
         sortExpr += ", LastPostDate DESC";
      return sortExpr;
   }
}

i have to ask two questions...

First, In the else part why this sort expression title or
title desc or title asc is converted into tbh_posts.title while this LastPostDate or LastPostDate DESC LastPostDate DESC is not converted into tbh_posts.lastpostdate. Except the sort expression containing title, none other sortexpression is convert into the string like tbh_post_columnname (even in case of null LastPostDate DESC is returned). sortExpression contains column name of post table then, why we just do this conversion in case of title.


Second, What is meant by this last check
if (!sortExpr.StartsWith("lastpostdate"))
         sortExpr += ", LastPostDate DESC";

if sortExpression start this lastpostdate convert it into
sortExpression = sortExpression + , LastPostDate DESC;

sortexpression will become lastpostdate,LastPostDate DESC
or lastpostdate ASC,LastPostDate DESC
or lastpostdate DESC,LastPostDate DESC

now what is this and it will be true in wut conditions?

-Thanks in advance!





Similar Threads
Thread Thread Starter Forum Replies Last Post
problem in XMlserialization understanding. Theone84 ASP.NET 2.0 Professional 1 August 26th, 2007 01:20 PM
Problem understanding how to arrange the project alexanderH BOOK: ASP.NET Website Programming Problem-Design-Solution 6 January 29th, 2007 12:50 AM
problem with syntax MarkMingLuy ASP.NET 1.0 and 1.1 Basics 1 November 30th, 2006 07:42 AM
Syntax Problem Please i need your help haron_Master VB Databases Basics 4 February 2nd, 2005 01:56 PM
Problem understanding Object creation cdplayer Classic ASP Basics 4 March 18th, 2004 07:04 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.