************************************************** *-- Class: maatotalgrid (i:\desarrol\@wlib5\maaclass.vcx) *-- ParentClass: maagrid (i:\desarrol\@wlib5\maaclass.vcx) *-- BaseClass: grid *-- Time Stamp: 07/27/00 10:58:05 AM *-- Grid con línea de totales. * DEFINE CLASS maatotalgrid AS maagrid Name = "maatotalgrid" *-- Arma el grid y el cursor de los totales. Reduce el grid inicial para que el *-- grid de totales se encuentre dentro del rango especificado. PROCEDURE armatotales LParameter tcFieldsSum if param() = 0 or empty( tcFieldsSum ) && No hay campos para sumar return endif Local lcNameGridTot, lcRefGridTot, lcRecSourceMain, lcRecSourceTot, ; lnSeparacion, lnHeightGridTot *-- El nombre del grid y del recordSource de totales es igual *-- a los correspondientes del grid inicial + "T" lcNameGridTot = allt(this.name) + "T" && Nombre del grid de totales lcRefGridTot = "thisform." + lcNameGridTot && referencia al grid de totales thisform.lockScreen = .t. lnSeparacion = 1 && Separación entre grids lnHeightGridTot = 25 && Alto del Grid de Totales if type( lcRefGridTot ) = "O" thisform.RemoveObject( lcNameGridTot ) lnTopTotales = this.height + this.top + lnSeparacion else lnTopTotales = this.height + this.top - lnHeightGridTot this.height = this.height - lnHeightGridTot - lnSeparacion endif thisform.AddObject( lcNameGridTot , "maagrid" ) && agrega el grid al form ** Inicializa datos del grid de totales with &lcRefGridTot .RecordSource = "" .left = this.left .top = lnTopTotales .height = lnHeightGridTot .headerHeight = 0 lnSuprime = iif( this.scrollBars = 0, 0 , 17 ) .ColumnCount = this.columnCount .width = this.width - lnSuprime .scrollBars = 0 endwith lcRecSourceMain = this.recordSource lcRecSourceTot = allt(this.recordSource) + "T" *-- Arma las columnas del grid de totales for lnCol = 1 to this.columnCount with &lcRefGridTot with .Columns(lnCol) .name = this.Columns(lnCol).name .RemoveObject( "text1" ) && Elimina el control por default .dynamicForeColor = this.Columns(lnCol).dynamicForeColor .visible = this.Columns(lnCol).visible .sparse = this.Columns(lnCol).sparse .width = this.Columns(lnCol).width lcControlCol = this.columns(lnCol).controls(2).name lcClassObj = this.columns(lnCol).controls(2).class .addObject( lcControlCol , lcClassObj ) with .Controls(1) .FontSize = this.columns(lnCol).Controls(1).FontSize .Alignment = this.columns(lnCol).Controls(1).Alignment .FontName = this.columns(lnCol).Controls(1).FontName .FontBold = this.columns(lnCol).Controls(1).FontBold .caption = "" .name = this.columns(lnCol).Controls(1).name endwith with .Controls(2) .visible = this.columns(lnCol).Controls(2).visible .format = this.columns(lnCol).Controls(2).format .InputMask = this.columns(lnCol).Controls(2).InputMask endwith endwith endwith next *-- Crea el cursor de totales y realiza la suma de los campos indicados tcFieldsSum = allt(tcFieldsSum) lcFieldsMem = "m." + strTran( tcFieldsSum , "," , ",m." ) =AFields( laFields , lcRecSourceMain ) create cursor (lcRecSourceTot) from array laFields scatter memvar blank select (lcRecSourceMain) sum &tcFieldsSum to &lcFieldsMem insert into (lcRecSourceTot) from memvar with &lcRefGridTot .visible = .t. .recordSource = lcRecSourceTot endwith select (lcRecSourceMain) locate thisform.lockScreen = .f. thisform.refresh() ENDPROC PROCEDURE AfterRowColChange LPARAMETERS nColIndex Local lcNameGridTot, lcRefGridTot lcNameGridTot = allt(this.name) + "T" && Nombre del grid de totales lcRefGridTot = "thisform." + lcNameGridTot && referencia al grid de totales if type( lcRefGridTot ) = "O" *-- Método: Verifica que la primer columna del grid de datos sea *-- igual a la del grid. Si no llegara a ser la misma desplaza el grid *-- de totales hasta que la columna sea la misma with &lcRefGridTot lnLeftColMain = this.LeftColumn lnLeftColTotal = .LeftColumn lnDifAbs = abs( lnLeftColMain - lnLeftColTotal ) if lnLeftColMain # lnLeftColTotal if lnDifAbs > 2 thisform.LockScreen = .t. endif if lnLeftColMain > lnLeftColTotal for f = 1 to lnDifAbs .doScroll( 5 ) if lnLeftColMain = .LeftColumn exit endif next else for f = 1 to lnDifAbs .doScroll( 4 ) if lnLeftColMain = .LeftColumn exit endif next endif if lnDifAbs > 2 thisform.LockScreen = .f. endif endif endwith endif ENDPROC ENDDEFINE * *-- EndDefine: maatotalgrid **************************************************Espero que te sea útil.