Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Best way to re-factor
Message
De
14/02/2013 07:46:07
Thomas Ganss (En ligne)
Main Trend
Frankfurt, Allemagne
 
 
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Divers
Thread ID:
01565967
Message ID:
01565992
Vues:
44
IMO getting the pairs of current/close [operators,salespoint] should be refactored as well...
Esp in Dotnet, where method call cost is minimal compared to vfp (or any other script language)

>I changed the top part (up to OK to close drawer) into a separate method. The question now is - can I re-use this piece somehow in two places?
>
>
>String currentOperator, currentSalespoint, closeOperator, closeSalespoint, cDetails;
>                        currentOperator = GetParameterValue(parameters, "tcOperator");
>                        currentSalespoint = GetParameterValue(parameters, "tcSalespoint");
>                        cDetails = GetParameterValue(parameters, "tcDetails");
>                        closeOperator = cDetails.ParseStringFromSqml("CLOSE_OP");
>                        if (String.IsNullOrWhiteSpace(closeOperator))
>                            closeOperator = currentOperator;
>                        closeSalespoint = cDetails.ParseStringFromSqml("CLOSE_SP");
>                        if (String.IsNullOrWhiteSpace(closeSalespoint))
>                            closeSalespoint = currentSalespoint;
>                        DateTime startTime, endTime;
>                        startTime = cDetails.ParseDateTimeFromSqml("START_TIME");
>                        endTime = cDetails.ParseDateTimeFromSqml("END_TIME");
>
>
>?
>
>I guess I can pass back all parameters by reference, but is it a good solution?
>
>
>>Hi everybody,
>>
>>Recently I decided to use one exit point from my methods even though it leads to complicated code (sometimes) with multiple if else statements.
>>
>>I need to re-factor this code:
>>
>>
>>SqlCommand sqlCommand = new SqlCommand();
>>
>>                    sqlCommand.CommandType = CommandType.Text;
>>                    sqlCommand.CommandText = "select closedrwrs from dbo.prefs_sl;";
>>
>>                    if (database.ExecuteSqlCommand(sqlCommand, ref messageText, ref statusCode))
>>                    {
>>                        Int16 closeDrawers;
>>                        if (Int16.TryParse(messageText, out closeDrawers))
>>                        {
>>                            if (closeDrawers < 2)
>>                            {
>>                                statusCode = 610;
>>                                messageText = "System is not set up to close cash drawers";
>>                            }
>>                            // Ok to close a drawer
>>                            else
>>                            {
>>                                sqlCommand.Parameters.Clear();
>>                                String currentOperator, currentSalespoint, closeOperator, closeSalespoint, cDetails;
>>                                currentOperator = GetParameterValue(parameters, "tcOperator");
>>                                currentSalespoint = GetParameterValue(parameters, "tcSalespoint");
>>                                cDetails = GetParameterValue(parameters, "tcDetails");
>>                                closeOperator = cDetails.ParseStringFromSqml("CLOSE_OP");
>>                                if (String.IsNullOrWhiteSpace(closeOperator))
>>                                    closeOperator = currentOperator;
>>                                closeSalespoint = cDetails.ParseStringFromSqml("CLOSE_SP");
>>                                if (String.IsNullOrWhiteSpace(closeSalespoint))
>>                                    closeSalespoint = currentSalespoint;
>>                                DateTime startTime, endTime;
>>                                startTime = cDetails.ParseDateTimeFromSqml("START_TIME");
>>                                endTime = cDetails.ParseDateTimeFromSqml("END_TIME");
>>                                String closeType;
>>
>>
>>There are many lines of code below, but that first part is what is common between two different methods in VFP (where it's repeated as is in both methods).
>>
>>So, my question is - how can I make the above a separate method, but be able to re-use all these variables such as startTime, etc.
>>?
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform