Solved

i need to run over my DB table and check if the continuity are o.k

Posted on 2006-07-06
15
199 Views
Last Modified: 2010-04-16
hi there ,

i have an order table in my db i want to run over the orderNum row
and chesk the continuity if something worng and there is duplicity or lack or miss number i want to poll out the
number or the relative number into a listBox

i am on SQl 2000 db WinForm pro on c# 1.1.

thanks all ....
0
Comment
Question by:Tech_Men
  • 8
  • 7
15 Comments
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
The description of the problem is not clear enough to help.

Bob
0
 

Author Comment

by:Tech_Men
Comment Utility
i have an order table in my DB

orderID
1
2
3
4
-
6
7
7
8
i want to know that in my table the ordernum=5 are miising
i want to know that order num=7 haz 2 orders in the same number i need to chek the succession  in my DB
0
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
using System.Collections;
using System.Data;
using System.Text;

...

  public bool ValidateOrders(DataTable table, out string errors)
  {
    Hashtable validation = new Hashtable();

    StringBuilder errorBuilder = new StringBuilder();
    foreach (DataRow row in table.Rows)
    {
      string orderID = row["orderID"].ToString();

      if (validation.ContainsKey(orderID))
      {
        errorBuilder.Append("Duplicate order:  " + orderID + "\r\n");
      }
      else if (orderID == "-")
      {
        errorBuilder.Append("Missing order:  " + orderID + "\r\n");
      }
      else
      {
        validation.Add(orderID, orderID);
      }
    }

    errors = errorBuilder.ToString();

    return (errors.Length == 0);
  }

}

Bob
0
 

Author Comment

by:Tech_Men
Comment Utility
its work fine but the miising part are not working
0
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
Can you tell me what it is not doing?  Exceptions?

Bob
0
 

Author Comment

by:Tech_Men
Comment Utility
there is no exsption
but he dosent visit in this code

      else if (HesID == "-")
                              {
                                    errorBuilder.Append("Missing invoice:  " + HesID +" "+"\r\n\n");
                                    listBox1.Items.Add(errorBuilder.ToString());
                              }

even that i have a missing order
1
2
-
4

thanks ...BOb

0
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
Can you show me the complete code of what you came up with, please?

Bob
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

Author Comment

by:Tech_Men
Comment Utility
sure
foreach (DataRow row in table.Rows)
                  {
                        bool temp = bool.Parse(row["OutOrIn"].ToString());

                        if(temp==true)
                        {
                              string HesID = row["HasbonitNum"].ToString();

                              if (validation.ContainsKey(HesID))
                              {
                                    errorBuilder.Append("Duplicate invoice:  " + HesID + " " +"\r\n\n");
                                    listBox1.Items.Add(errorBuilder.ToString());
                              }
                              else if (HesID == "-")
                              {
                                    errorBuilder.Append("Missing invoice:  " + HesID +" "+"\r\n\n");
                                    listBox1.Items.Add(errorBuilder.ToString());
                              }
                              else
                              {
                                    validation.Add(HesID, HesID);

                              }
                        }
0
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
I got to thinking about something, and it seems like a silly assumption that I made.  Are you saying that a missing invoice is a '-' or a null/empty string?  

If so, then you need something like this:

                    else if (HesID.Length == 0)
 
Bob
0
 

Author Comment

by:Tech_Men
Comment Utility
not working
i the table there is orders
1
2
4

3 is deleted
there is no row in 3

thanks ...
0
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
Try a little different approach with a SortedList instead of a Hashtable:

using System.Collections;
using System.Data;
using System.Text;

...

  public void ValidateOrders(DataTable table, out string errors)
  {

    // Clear the errors.
    errors = "";

    // Collect all the IDs
    SortedList validation = new SortedList();

    // Get all the table rows, looking for duplicate invoice numbers.
    foreach (DataRow row in table.Rows)
    {
      bool outOrIn = bool.Parse(row["OutOrIn"].ToString());

      if (outOrIn)
      {
        string HesID = row["HasbonitNum"].ToString();

        if (validation.ContainsKey(HesID))
        {
          listBox1.Items.Add("Duplicate invoice:  " + HesID);
        }
        else
        {
          validation.Add(HesID, HesID);
        }
      }

    }

    // Look at the difference between two invoice numbers.  Any value
    // greater than 1 indicates a missing invoice number.
    string current = "";
    foreach (string val in validation.Values)
    {
      if (current.Length != 0 && (int.Parse(val) - int.Parse(current) > 1))
      {
        listBox1.Items.Add("Missing invoice:  " + current.ToString());
      }
      // Store the current ID to compare to the next ID
      current = val;
    }

  }

Bob
0
 

Author Comment

by:Tech_Men
Comment Utility
its not working
i dont get any worning abhot the duplicated  invoice

and there is a problem whit the missing invoice
like :
1
2
4

i get meesage that number 2 is misiing insted of 3 ...

sooryyy .... i hope that every thing works....


0
 

Author Comment

by:Tech_Men
Comment Utility
soooryyy

the duplicated is working fine +++
only this :
and there is a problem whit the missing invoice
like :
1
2
4

i get meesage that number 2 is misiing insted of 3 ...

0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 400 total points
Comment Utility
Sorry, there wasn't any way for me to test that code, so I left that up to you:

    listBox1.Items.Add("Missing invoice:  " + val.ToString());

The 'current' value is the previous element, and 'val' is the current.  I think those are misnamed variables--in retrospect they should be 'previous' and 'current' instead of 'current' and 'val'.

Bob
0
 

Author Comment

by:Tech_Men
Comment Utility
thanks u Very mush ..........Love u :))
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

771 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

12 Experts available now in Live!

Get 1:1 Help Now