Procedimiento para cargar los datos de una tabla recibida como parámetro, filtrando por el where, también recibido


Código VB6:

Sub CargaHistoricoArticulo ( aNomTabla,aWhere, aCaption )
' Formulario de mantenimiento
Set lfrm = gcn.AhoraProceso("NewfrmMantenimiento",False,gCn)
     lfrm.Form.Width = 10000
     lfrm.Form.Height = 7000
     lfrm.Form.Caption= aCaption
 Set lGrid= lFrm.Grid("HistoricoArticulo")
 With lGrid
 If Not .Preparada Then
     .Agregar = False
     .Editar = False
     .Eliminar = False 
     .RowDivider = 6
     .ColDivider = 6
     .Grid.HeadLines = 1
.CargaObjetos = False
.EditarPorObjeto = False
lsql="Select sc.name Campo , REPLACE (CASE WHEN LEFT (sc.name,2)='D_' THEN RIGHT(sc.name,Len( sc.name)-2) ELSE sc.name END ,'_' ,' ') nombre , " & _
" stB.name tipocampo, st.length long from Sys.syscolumns Sc inner Join sys.systypes St On Sc.xusertype = st.xusertype " & _
" inner Join systypes stB On st.xtype = stb.xtype And st.xtype = stb.xusertype " & _
" WHERE object_id('" & aNomTabla & "') = id " & _
" And Sc.name Not In ('FechaInsertUpdate','IdDoc', 'InsertUpdate')"

Set lr1 = gcn.OpenResultSet (lSQL)
While Not lr1.EOF
lCampo = CStr(lr1("Campo"))
ldescrip = CStr(lr1("nombre"))
lTipo = CStr(lr1("tipocampo"))
lLong = CStr(lr1("long"))
 Select Case ltipo
     Case "int","smallint" .AgregaColumna "" & lCampo & "" , 800, "" & ldescrip & "", False,,,"#,##0"
     Case "varchar","nvarchar" .AgregaColumna "" & lCampo & "" , 3000, "" & ldescrip & "", False
     Case "datetime" .AgregaColumna "" & lCampo & "" , 2000, "" & ldescrip & "", False,,,"dd/mm/yyyy hh:mm"
     Case "float" ,"decimal" ,"real" ,"money" ,"smallmoney" .AgregaColumna "" & lCampo & "" , 1000, "" & ldescrip & "", False,,,"#,##0.00"
     Case "date" ,"smalldatetime" .AgregaColumna "" & lCampo & "" , 1000, "" & ldescrip & "", False,,,"dd/mm/yyyy"
     Case Else .AgregaColumna "" & lCampo & "" , 2000, "" & ldescrip & "", False
End Select
    lr1.MoveNext
    Wend
    Set lr1=Nothing
     .From = aNomTabla 
     .Where = aWhere
     .Refresca = True
     End If

     End With 

         lFrm.Form.Caption = "Historico de modificaciones del articulo "
         lFrm.Carga , True, 4 
         Set lFrm = Nothing
End Sub

Código C#:

using AhoraSistema;
using AhoraCore;
using AhoraOCX;
using AhoraAsistentes;

namespace AhoraScriptsPantalla
{
  public class AhoraCl_frmArticulos : AhoraOCX.AhoraBaseScript
  {

    public void Show()
        {
            CargaHistoricoArticulo("Articulos", "", "Histórico de modificaciones del artículo");
        }


        private void CargaHistoricoArticulo(string aNomTabla, string aWhere, string aCaption)
        {
            IFrmMantenimientos lFrm = (IFrmMantenimientos)gCn.AhoraProceso("NewFrmMantenimiento", out _, gCn);
            lFrm.NombreForm = "Pers_CargaHistoricoArticulo";
            lFrm.Form.Width = 667;
            lFrm.Form.Height = 467;
            ICntGridUsuario lGrid = lFrm["HistoricoArticulo"];

            if (!lGrid.Preparada)
            {
                lGrid.Agregar = false;
                lGrid.Editar = false;
                lGrid.Eliminar = false;

                lGrid.RowDivider = DividerStyleConstants.dbgLightGrayLine;
                lGrid.ColDivider = DividerStyleConstants.dbgLightGrayLine;
                lGrid.GridHeadLines = 1;

                lGrid.CargaObjetos = false;
                lGrid.EditarPorObjeto = false;

                string lSql = "Select sc.name Campo , REPLACE (CASE WHEN LEFT (sc.name,2)='D_' THEN RIGHT(sc.name,Len( sc.name)-2) ELSE sc.name END ,'_' ,' ') nombre, stB.name tipocampo, st.length long from Sys.syscolumns Sc inner Join sys.systypes St On Sc.xusertype = st.xusertype inner Join systypes stB On st.xtype = stb.xtype And st.xtype = stb.xusertype " + " WHERE object_id('" + aNomTabla + "') = id And Sc.name Not In ('FechaInsertUpdate','IdDoc', 'InsertUpdate')";

                string lCampo = "";
                string lDescrip = "";
                string lTipo = "";
                string lLong = "";

                IRecordSet lr1 = gCn.OpenResultSet(lSql);
                while (!lr1.EOF)
                {
                    lCampo = lr1["Campo"].Value;
                    lDescrip = lr1["nombre"].Value;
                    lTipo = lr1["tipocampo"].Value;
                    lLong = lr1["long"].Value;
                    switch (lTipo)
                    {
                        case "int":
                        case "smallint":
                            {
                                lGrid.AgregaColumna("" + lCampo + "", 53, "" + lDescrip + "", false, "", false, "#,##0");
                                break;
                            }
                        case "varchar":
                        case "nvarchar":
                            {
                                lGrid.AgregaColumna("" + lCampo + "", 200, "" + lDescrip + "", false);
                                break;
                            }
                        case "datetime":
                            {
                                lGrid.AgregaColumna("" + lCampo + "", 133, "" + lDescrip + "", false, "", false, "dd/MM/yyyy hh:mm");
                                break;
                            }
                        case "float":
                        case "decimal":
                        case "real":
                        case "money":
                        case "smallmoney":
                            {
                                lGrid.AgregaColumna("" + lCampo + "", 67, "" + lDescrip + "", false, "", false, "#,##0");
                                break;
                            }
                        case "date":
                        case "smalldatetime":
                            {
                                lGrid.AgregaColumna("" + lCampo + "", 133, "" + lDescrip + "", false, "", false, "dd/MM/yyyy");
                                break;
                            }
                        default:
                            {
                                lGrid.AgregaColumna("" + lCampo + "", 133, "" + lDescrip + "", false);
                                break;
                            }
                    }

                    lr1.MoveNext();
                }

                lr1 = null;

                lGrid.From = aNomTabla;
                lGrid.Where = aWhere;
                lGrid.Refresca = true;
            }

            lFrm.Form.Text = aCaption;
            lFrm.Carga(null, true, EBotonesMant.eBotMant_Cerrar);

            lFrm = null;

        }

    }
}