Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
VFP inlist() in c#
Message
De
27/01/2013 08:21:37
 
 
À
27/01/2013 04:40:59
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01320903
Message ID:
01564297
Vues:
42
>>>>>Declaring the type for the generic in the function call also works:
closeDrawers.InList< short >(2, 4)
>>>>
>>>>Do you know if there is something similar to VFP Case statement in C# where we can analyze different conditions?
>>>>
>>>>Say,
>>>>
>>>>I just wrote this part:
>>>>
>>>>
>>>> if (startTime > defaultDate && endTime > defaultDate)
>>>>                                    {
>>>>                                        whereClause.AppendLine(" AND date_time between @StartTime and @EndTime");
>>>>                                        sqlCommand.Parameters.Add("@StartTime", SqlDbType.DateTime).Value = startTime;
>>>>                                        sqlCommand.Parameters.Add("@EndTime", SqlDbType.DateTime).Value = endTime;
>>>>                                    }
>>>>
>>>>I need 2 more cases for only startTime defined or only endTime defined. If I will use if I again need to check both variables.
>>>
>>>What do you want to do if startTime or endTime are not defined ?
>>>
>>>>
>>>>Wondering if there is something in C# that makes this decision choice easier. I believe there is nothing in C# that is like VFP case where we can test various expressions - quick Google search also confirms it.
>>
>>That's my code - I just hoped there is something I can do to make it easier:
>>
>>
>> if (closeDrawers.InList<short>(2, 4))
>>                                {
>>                                    DateTime defaultDate = Functions.DTSqlMinDate;
>>                                    sqlStatement.AppendLine("salespoint = @Salespoint");
>>                                    sqlCommand.Parameters.Add("@Salespoint", SqlDbType.Char, 6).Value = closeSalespoint.PadRight(6);
>>                                    if (startTime > defaultDate && endTime > defaultDate)
>>                                    {
>>                                        sqlStatement.AppendLine(" AND date_time between @StartTime and @EndTime");
>>                                        sqlCommand.Parameters.Add("@StartTime", SqlDbType.DateTime).Value = startTime;
>>                                        sqlCommand.Parameters.Add("@EndTime", SqlDbType.DateTime).Value = endTime;
>>                                    }
>>                                    if (startTime > defaultDate && endTime == defaultDate)
>>                                    {
>>                                        sqlStatement.AppendLine(" AND date_time>= @StartTime");
>>                                        sqlCommand.Parameters.Add("@StartTime", SqlDbType.DateTime).Value = startTime;
>>                                    }
>>                                    if (startTime == defaultDate && endTime > defaultDate)
>>                                    {
>>                                        sqlStatement.AppendLine(" AND date_time <= @EndTime");
>>                                        sqlCommand.Parameters.Add("@EndTime", SqlDbType.DateTime).Value = endTime;
>>                                    }
>>                                }
Did you miss out some "else"'s ? Would this work:
if (endTime == defaultDate) endTime = DateTime.MaxValue;
>sqlStatement.AppendLine("salespoint = @SalesPoint AND date_time between @StartTime and @EndTime");
>sqlCommand.Parameters.Add("@StartTime", SqlDbType.DateTime).Value = startTime;
>sqlCommand.Parameters.Add("@EndTime", SqlDbType.DateTime).Value = endTime;
or will it be less efficient on the SQL side ?


That is the way I would do it. Never mind the efficiency hit, if any - there should be an index on date_time
Gregory
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform