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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

765 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