Solved

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

Posted on 2006-07-06
15
203 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
ID: 17050409
The description of the problem is not clear enough to help.

Bob
0
 

Author Comment

by:Tech_Men
ID: 17050800
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
ID: 17051241
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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

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

Expert Comment

by:Bob Learned
ID: 17054557
Can you tell me what it is not doing?  Exceptions?

Bob
0
 

Author Comment

by:Tech_Men
ID: 17055028
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
ID: 17055161
Can you show me the complete code of what you came up with, please?

Bob
0
 

Author Comment

by:Tech_Men
ID: 17056758
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
ID: 17057535
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
ID: 17060547
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
ID: 17062355
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
ID: 17064118
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
ID: 17064148
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
ID: 17064980
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
ID: 17068913
thanks u Very mush ..........Love u :))
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 article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

837 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