All pastes #267392 Raw Edit

Unnamed

public text v1 · immutable
·published 2006-12-04 20:52 UTC
rendered paste body
 this.ugCategories.DataSource = clsCategory.GetCategoryData( CompNo, Convert.ToInt32( CategoryListSortBtn.Tag ) );			
           

Object dataSource;

String dataMember;

BindingSource bindingSource = new BindingSource( dataSource, dataMember );

this.ultraGrid1.DataSource = bindingSource;


   public static DataSet GetCategoryData(int CompNo, int iSortOrder)
            {
            m_objDs = new DataSet();
            DataTable dtCat = new DataTable();
            DataTable dtSub = new DataTable();
            DataRow drCat;

            dtCat.Columns.Add( "CategoryID", typeof( string ) );    // 0
            dtCat.Columns.Add( "CatDescription", typeof( string ) );    // 1 

            dtSub.Columns.Add( "MainCategoryID", typeof( string ) );    // 0
            dtSub.Columns.Add( "SubCategoryID", typeof( string ) );    // 1
            dtSub.Columns.Add( "SubCatDescription", typeof( string ) );    // 2 

            try
                {
                clsTBLK.TBType = "Select"; // DeleteRow , UpDate, Select, Insert			
                clsTBLK.TBSelect = " CategoryID , CatDescription ";
                clsTBLK.TBName = "  ProductCategory  ";
                clsTBLK.TBWhere = "(CompanyID = " + "'" + CompNo + "'" + ")" + " AND " + " ( CatSort  = " + 1 + ")";
                if( iSortOrder == 0 )
                    clsTBLK.TBOrdBy = "CompanyID , CatSort ";
                else
                    clsTBLK.TBOrdBy = "CompanyID , CatDescription ";

                clsTBLK.clsTBUp();

                SqlDataReader oRd = clsTBLK.TBSql.ExecuteReader( CommandBehavior.CloseConnection );
                if( oRd.HasRows )
                    {
                    while( oRd.Read() )
                        {
                        drCat = dtCat.NewRow();

                        drCat[ 0 ] = oRd[ 0 ].ToString();
                        drCat[ 1 ] = oRd[ 1 ].ToString();

                        dtCat.Rows.Add( drCat );

                        clsTLK.TLType = "Select"; // DeleteRow , UpDate, Select, Insert			
                        clsTLK.TLSelect = " SubCatMainCategoryID ,SubCategoryID , SubCatDescription ";
                        clsTLK.TLName = "  ProductCategorySub  ";
                        if( iSortOrder == 0 )
                            clsTLK.TLOrdBy = "CompanyID , SubCatMainCategoryID, SubCatSortOrder ";
                        else
                            clsTLK.TLOrdBy = "CompanyID , SubCatMainCategoryID, SubCatDescription ";
                        clsTLK.TLWhere = "(CompanyID = " + "'" + CompNo + "'" + ")" + " AND " + " ( SubCatMainCategoryID  = " + oRd[ 0 ].ToString() + ")";
                        clsTLK.clsTLUp();

                        SqlDataReader oRdS = clsTLK.TLSql.ExecuteReader( CommandBehavior.CloseConnection );
                        if( oRdS.HasRows )
                            {
                            //	 strHaveItems = "8";
                            while( oRdS.Read() )
                                {
                                drCat = dtSub.NewRow();

                                drCat[ 0 ] = oRdS[ 0 ].ToString();
                                drCat[ 1 ] = oRdS[ 1 ].ToString();
                                drCat[ 2 ] = oRdS[ 2 ].ToString();

                                dtSub.Rows.Add( drCat );
                                }
                            }
                        oRdS.Close();

                        }
                    }
                oRd.Close();
                }
            catch( SqlException ex )
                {
                MessageBox.Show( "Database error has occurred: " + ex.ToString() );
                //System.Diagnostics.Debug.WriteLine( ex.ToString() );
                }

            m_objDs.Tables.Add( dtCat );
            m_objDs.Tables.Add( dtSub );

            m_objDs.Relations.Add( "Cat_Sub", objDs.Tables[ 0 ].Columns[ 0 ], objDs.Tables[ 1 ].Columns[ 0 ] );

            return objDs;
            }
        }