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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
asp web application 3 54
Create a Dropdown list with sub group 10 38
Put File 6 33
XML Constructor Throwing Incorrectly Structured Document Error 4 18
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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

739 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