Solved

Rewrite the following code so we don't have to speficy the same thing over and over again.

Posted on 2008-06-18
1
242 Views
Last Modified: 2013-12-16
I have the following;

// Look at errors 'E'
                            if (GradeCodeDetailID == -1)
                            {
                                PLEO.price_list_hdr_id = PLHO.price_list_hdr_id;
                                PLEO.err_line_num = rowCount + 1;
                                PLEO.grade_name = gradeName;
                                PLEO.strght_price_amt = Price;
                                PLEO.err_warng_indr_flag = 'E';
                                PLEO.err_msg_desc = "Grade Code not found in Grade Code Details table.";
  Insert_Price_List_Detail(gradeName, Price); //  insert the prices
                            }
                           
                            if ((double)(Price) < 0.00)
                            {
                                PLEO.price_list_hdr_id = PLHO.price_list_hdr_id;
                                PLEO.err_line_num = rowCount + 1;
                                PLEO.grade_name = gradeName;
                                PLEO.strght_price_amt = Price;
                                PLEO.err_warng_indr_flag = 'E';
                                PLEO.err_msg_desc = "Price cannot be negative.";
  Insert_Price_List_Detail(gradeName, Price); //  insert the prices
                            }

                            for (int i = 0; i < 4; i++)
                            {
                                for (int j = 0; j < 3; j++)
                                {
                                    if ((double)(discounts[i, j]) >= 0.00)
                                    {
                                        if ((i == 2) && (j == 2)) break;
                                        PLEO.price_list_hdr_id = PLHO.price_list_hdr_id;
                                        PLEO.err_line_num = rowCount + 1;
                                        PLEO.grade_name = discountnames[i, j]; // put the string of the discount name.
                                        PLEO.strght_price_amt = discounts[i, j];
                                        PLEO.err_warng_indr_flag = 'E';
                                        PLEO.err_msg_desc = "Discount cannot be positive.";
  Insert_Price_List_Detail(gradeName, Price); //  insert the prices
                                    }
                                }

                            }
                            ///////////////////////
                           

                            // Look at warnings 'W'
                            if ((double)(Price) > 1000.00)
                            {
                                PLEO.price_list_hdr_id = PLHO.price_list_hdr_id;
                                PLEO.err_line_num = rowCount + 1;
                                PLEO.grade_name = gradeName;
                                PLEO.strght_price_amt = Price;
                                PLEO.err_warng_indr_flag = 'W';
                                PLEO.err_msg_desc = "Price is over $1000.00.  Please confirm with SP&P.";
  Insert_Price_List_Detail(gradeName, Price); //  insert the prices
                            }
                            if ((double)(Price) == 0.00)
                            {
                                PLEO.price_list_hdr_id = PLHO.price_list_hdr_id;
                                PLEO.err_line_num = rowCount + 1;
                                PLEO.grade_name = gradeName;
                                PLEO.strght_price_amt = (decimal)(0.00);
                                PLEO.err_warng_indr_flag = 'W';
                                PLEO.err_msg_desc = "Grade has no price.  Please confirm with SP&P.";
  Insert_Price_List_Detail(gradeName, Price); //  insert the prices
                            }
                           
                                       
                         
0
Comment
Question by:mathieu_cupryk
1 Comment
 
LVL 16

Accepted Solution

by:
burakiewicz earned 500 total points
ID: 21812994
have a method that accepts all the params that you are setting
private void or PLEO whatever type it is SetValues(int id,int num,string gradeName.......
{
                                PLEO.price_list_hdr_id = id;
                                PLEO.err_line_num = num;
                                PLEO.grade_name = gradeName;
                                PLEO.strght_price_amt = Price;
                                PLEO.err_warng_indr_flag = 'E';
                                PLEO.err_msg_desc = "Grade Code not found in Grade Code Details table.";
  Insert_Price_List_Detail(gradeName, Price); //  insert the prices
}

then when you call it pass all the params
SetValues(PLHO.price_list_hdr_id,rowCount + 1,gradeName,.......

if you need the full example let me know
0

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB.NET Textbox input validation 4 60
Why use this lambda? 12 60
linq .concat equivalent with expression syntax 4 21
Trigger C# code inside the SQL Server 6 23
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question