Καλώς ορίσατε στο dotNETZone.gr - Σύνδεση | Εγγραφή | Βοήθεια
σε

 

Αρχική σελίδα Ιστολόγια Συζητήσεις Εκθέσεις Φωτογραφιών Αρχειοθήκες

ResultSet utility

Îåêßíçóå áðü ôï ìÝëïò anjelinio. Τελευταία δημοσίευση από το μέλος anjelinio στις 16-02-2006, 12:27. Υπάρχουν 0 απαντήσεις.
Ταξινόμηση Δημοσιεύσεων: Προηγούμενο Επόμενο
  •  16-02-2006, 12:27 9778

    ResultSet utility

    Συνημμένα: ResultSet.rar
    Κοιτώντας χτές την "αποθήκη" κώδικά μου ( τι ψώνιο ε; :D ), βρήκα ένα μικρό utility class, το οποίο λειτουργεί σαν ένας page-able read-ony navigable  Reader.
    Το λέω BaseResultSet, και βασικά μιμείται το ResultSet class της Java ( αχ ... μου ξανάρχονται ένα-ένα, χρόνια δοξασμένα ... ).

    Χρησιμοποιείται κάπως έτσι:

        static void TestResultSet(){

                         IDbConnection objConn = _sourceMan.GetConnectionByName("local_odbc");
     

                         BaseResultSet rs = new BaseResultSet("select * from users", objConn);

                         rs.Open();

                         while(rs.Next()){

                               Console.WriteLine("User ID: {0}", rs.Get("uname"));

                         }

                         rs.Close();
                  }

     

                  static void TestResultSetPaged(int pageSize){

                         IDbConnection objConn = _sourceMan.GetConnectionByName("local_odbc");
          

                         BaseResultSet rs = new BaseResultSet("select * from users", objConn, pageSize);

                         rs.Open();

                         while(rs.NextPage()){

                               Console.WriteLine("Page: {0}", rs.CurrentPage);

                               while(rs.Next()){

                                      Console.WriteLine("User ID: {0}", rs.Get("uname"));

                               }

                         }

                         rs.Close();
                  }

      ... αυτές είναι οι δύο μέθοδοι με τις οποίες έκανα τότε debug  προφανώς, και δείχνουν τη χρήση του σε paged / non-paged mode.

    Το interface το οποίο υλοποιεί, είναι το παρακάτω:

           public interface IResultSet : IListSource, IEnumerable
          
    {

                  /* Row Count */
                  int Count {get;}

                  /* Current page index */
                  int CurrentPage {get;}

                  /* Total Page Count */
                  int PageCount {get;}

                  /* Size of each page */
                  int PageSize {get; set;}

                  /* Moves the r/set cursor to the specified page */
                  bool MoveToPage(int intPageNo); 

                  /* Move to first row ( or first row in the current page ) */
                  void First();

                  /* Move to the last row ( or last row in the current page ) */
                  void Last();

                  /* Move to the next row ( or the next row in the current page ) */
                  bool Next();

                  /* Move to the previous row ( or the previous row in the current page ) */
                  bool Previous();

                  /* Get the value in the current row, at the specified index */
                  object Get(int index);

                  /* The value of column columnName at the current row */
                  object Get(string columnName);             

                  /* Fill the recordset */
                  bool Open();
                  bool Close();

                  /* Return the ResultSet ( or current page ) as an Xml string */
                  string XmlString {get;}

                  /* Return the ResultSet ( or current page ) as an XmlDocument */
                  System.Xml.XmlDocument XmlDocument {get;}
     

                  // IListSource members
                  bool ContainsListCollection {get;}
                  IList GetList();

                  // IEnumerable members
                  IEnumerator GetEnumerator();
          
    }

    Στα συνημμένα έχω τα sources, για όποιον θέλει αν το δεί λίγο, γιατί είμαι σίγουρος οτι γίνεται χαμός εκει μέσα αλλά ίσως φανεί χρήσιμο σε κάποιον.

    Πολύ καλή μέρα μας



    Angel
    O:]
Προβολή Τροφοδοσίας RSS με μορφή XML
Με χρήση του Community Server (Commercial Edition), από την Telligent Systems