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
236 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

705 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now