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
246 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Quiz: What Do These Organizations Have In Common?

Hint: Their teams ended up taking quizzes, too.

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

688 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