Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • The replacement of VB On Error Goto with Structured try-catch exception handling,
  • The replacement of a legacy ADO wrapper function (ExecProc) with a call to our standard ADO.NET data access component (DataMeister). Note that DataMeister is a slightly modified version of the SQLHelper application block.
  • The translation requires stored proc parameters information to setup the SqlParameter array. The translation tool is able to determine lookup and integrate the names of stored proc parameters dynamically at translation time from metadata pulled from SQL server – a huge time saver.


Code Block
languagevb
titleOriginal VB code
Public Function GetLessee(Acct As String) As String
    'Returns name of accountholder, if no last name then use company name.
    If gbErrorTrapOn Then On Error GoTo ErrorTrap
    Dim rs As ADODB.Recordset
    If ExecProc("cash", "cash_GetLessee", rs, -1, Acct, gsCountry) Then
        If Not rs.EOF Then
            If Len(Trim(rs!last_nme)) > 0 Then
                GetLessee = IIf(IsNull(rs!first_nme), "", Trim(rs!first_nme)) & " " & _
                IIf(IsNull(rs!last_nme), "", Trim(rs!last_nme))
            Else
                GetLessee = IIf(IsNull(rs!company_nme), "", Trim(rs!company_nme))
            End If
        End If
    Else
        GetLessee = "Unavailable"
    End If
    Exit Function
ErrorTrap:
        ShowError("GetLessee", Err.Number, Err.Description)
End Function
Code Block
languagecpp
titleGenerated C# code
public static string GetLessee(string Acct)
{
    string GetLessee = "";
    // Returns name of accountholder, if no last name then use company name.
    SqlParameter[] sqlParms = new SqlParameter[2];
    try
    {
        SqlDataReader rs = null;
        sqlParms[0] = DesktopDataMeister.SetProcParameter("@account_no",ParameterDirection.Input, false, Acct.ToString(), 10);
        sqlParms[1] = DesktopDataMeister.SetProcParameter("@country_cde",ParameterDirection.Input, false, Cash_Globals.gsCountry.ToString(), 3);
        rs = DesktopDataMeister.ExecuteReader(DesktopConfigurator.EDBServer,
        CommandType.StoredProcedure, "Cash.dbo.cash_GetLessee", sqlParms);
        if (rs.Read())
        {
            if ((rs["last_nme"].ToString().Trim()).Length > 0)
            {
                GetLessee = (VBNET.Information.IsDBNull(rs["first_nme"]) ? "" :
                rs["first_nme"].ToString().Trim()) + " "
                + (VBNET.Information.IsDBNull(rs["last_nme"]) ? "" :
                rs["last_nme"].ToString().Trim());
            }
            else
            {
                GetLessee = (VBNET.Information.IsDBNull(rs["company_nme"]) ? "" :
                rs["company_nme"].ToString().Trim());
            }
        }
        else
        {
            GetLessee = "Unavailable";
        }
        return GetLessee;
    }
    catch (Exception exc)
    {
        ShowError("GetLessee", ABCFSException.MapExceptionToErrNumber(exc),
        exc.Message);
    }
}

...