[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 186
  • Last Modified:

code conversion from vb.net to c#

Here is the vb.net 1.1 code, I want to convert it to c#2.0 , I don't know vb.net.
Please help me.It's extremely urgent.Thanks a million in advance.I'd be grateful to u.

Private Sub GetPaymentHoldIndicator(ByVal sAcctNo As String)
        Dim bRetVal As Boolean = False
        Dim sPymtHoldInd As String = "N"
        Dim sPymtScore As String = ""
        Dim sPymtStartDt As String = ""
        Dim sPymtStopDt As String = ""
        Dim oConn As New tsysConnect
        Dim oCIFS As New TSYS2.TS2.CIFS     'Inquire Payment & Fraud Scores

        Try
            oCIFS.RequestedAccount = sAcctNo
            bRetVal = oConn.PerformInquire(oCIFS)

            If bRetVal Then
                sPymtScore = oCIFS.Payment_Score.Trim
                sPymtStartDt = oCIFS.Payment_Score_Start_Date.Trim
                sPymtStopDt = oCIFS.Payment_Score_Stop_Date.Trim

                If Not IsNumeric(sPymtScore) Then Exit Sub

                If CLng(sPymtScore) > 0 Then                                                                    ' If Payment Score is not "000"
                    If CLng(sPymtScore) <> 999 And CLng(sPymtScore) <> 213 And CLng(sPymtScore) <> 217 Then     ' Exception Case - Ignore
                        If Not IsDate(sPymtStartDt) Then Exit Sub
                        If Not IsDate(sPymtStopDt) Then Exit Sub

                        ' If current date falls between start date and stop date
                        If CDate(sPymtStartDt) <= DateTime.Today Then
                            If CDate(sPymtStopDt) >= DateTime.Today Then
                                sPymtHoldInd = "Y"
                            End If
                        End If
                    End If
                End If

                If sPymtHoldInd = "Y" Then
                    lbPymtHoldInd.Visible = True
                    lPymtHldInd.Visible = False
                    lPymtHoldInd.Text = sPymtHoldInd
                    lPymtScore.Text = sPymtScore
                    lPymtStartDt.Text = sPymtStartDt
                    lPymtStopDt.Text = sPymtStopDt
                Else
                    lbPymtHoldInd.Visible = False
                    lPymtHldInd.Visible = True
                    lPymtHldInd.Text = sPymtHoldInd
                End If
            End If
        Catch ex As Exception
            Dim oError As New Blast2.Errors
            oError.LogToEvent(ex.ToString)
            Throw New Exception(ex.ToString())
        End Try
    End Sub
0
amukta
Asked:
amukta
  • 4
  • 3
1 Solution
 
Joel CoehoornDirector of Information TechnologyCommented:
I may have missed something here or there, but since you have some 3rd party components I can't test it against the compiler.  However,  this should get you 90% or more:


void GetPaymentHoldIndicator(string sAcctNo)
{
        bool RetVal = false;
        string PymtHoldInd = "N";
        string PymtScore;
        string PymtStartDt;
        string PymtStopDt;
        tsysConnect oConn = new tsysConnect();
        TSYS2.TS2.CIFS oCIFS = new TSYS2.TS2.CIFS();    //Inquire Payment & Fraud Scores

        try
        {
            oCIFS.RequestedAccount = sAcctNo;
            RetVal = oConn.PerformInquire(oCIFS);

            if (RetVal)
            {
                PymtScore  = oCIFS.Payment_Score.Trim();
                PymtStartDt = oCIFS.Payment_Score_Start_Date.Trim();
                PymtStopDt = oCIFS.Payment_Score_Stop_Date.Trim();

                int z;
                if (!int.TryParse(PymtScore,out z)) return;

                if (Convert.ToInt64(PymtScore) > 0)                             // If Payment Score is not "000"
                {
                    if (Convert.ToInt64(PymtScore) != 999 && Convert.ToInt64(PymtScore) != 213 && Convert.ToInt64(PymtScore) != 217 )  // Exception Case - Ignore
                    {
                        DateTime Start, Stop;
                        if (!DateTime.TryParse(PymtStartDt,out Start)) return;
                        if (!DateTime.TryParse(PymtStopDt,out Stop)) return;

                        // If current date falls between start date and stop date
                        if ( Start <= DateTime.Today &&Stop >= DateTime.Today)
                                PymtHoldInd = "Y";
                       
                    }
                }

                if (PymtHoldInd == "Y")
                {
                    lbPymtHoldInd.Visible = true;
                    lPymtHldInd.Visible = false;
                    lPymtHoldInd.Text = PymtHoldInd;
                    lPymtScore.Text = PymtScore;
                    lPymtStartDt.Text = PymtStartDt;
                    lPymtStopDt.Text = PymtStopDt;
                }
                else
                {
                    lbPymtHoldInd.Visible = false;
                    lPymtHldInd.Visible = true;
                    lPymtHldInd.Text = PymtHoldInd;
               }
            }
        }
        catch (Exception ex )
        {
            Blast2.Errors oError = new Blast2.Errors();
            oError.LogToEvent(ex.ToString());
            throw new Exception(ex.ToString(), ex);
        }
    }
0
 
amuktaAuthor Commented:
Hi!
Thank you very much!
Instead of
 DateTime Start;
if (!DateTime.TryParse(PymtStartDt,out Start)) return;
                       Can I use
Try{
if(PymtStartDt==DateTime.Parse(PymtStartDt)
}
catch{
return;
}
 ;
and similarly for
DateTime Start;
if (!DateTime.TryParse(PymtStopDt,out Stop)) return
and also for
 int z;
  if (!int.TryParse(PymtScore,out z)) return;
Can I do this s done above?
Please let me know ASAP!
IT'S EXTREMELY URGENT!

THANKS A MILLION IN ADVANCE!
0
 
amuktaAuthor Commented:
Hi!
Thank you very much!
Instead of
 DateTime Start;
if (!DateTime.TryParse(PymtStartDt,out Start)) return;
                       Can I use
Try{
if(PymtStartDt==DateTime.Parse(PymtStartDt)
}
catch{
return;
}
 ;
and similarly for
DateTime Start;
if (!DateTime.TryParse(PymtStopDt,out Stop)) return
and also for
 int z;
  if (!int.TryParse(PymtScore,out z)) return;
Can I do this as done above?
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
Joel CoehoornDirector of Information TechnologyCommented:
Looking at this line:
    if(PymtStartDt==DateTime.Parse(PymtStartDt)
You're missing a parentheses at the end, and you're comparing a string type to a datetime type, so you might not get the results you expect.  Also, looking back at the original code it converted PymtScore to a number no fewer than five times, and I should have used a long anyway.  You could simplify that whole section like this:

    long score=0;
    try {
        score = long.Parse(PymtScore);

        // If Payment Score is not "000"
        if (score > 0 && score != 999 && score != 213 && score != 217) //exception cases
        {
             // If current date falls between start date and stop date
            if ( DateTime.Parse(PymtStartDt) <= DateTime.Today && DateTime.Parse(PymtStopDt) >= DateTime.Today)
                    PymtHoldInd = "Y";
        }
    }
    catch {
        return;
    }







0
 
amuktaAuthor Commented:
DateTime Start;
if (!DateTime.TryParse(PymtStartDt,out Start)) return;
  Can I use
Try{
if(PymtStartDt==DateTime.Parse(PymtStartDt).ToString())
}
catch{
return;
}
 ;
and similarly for
DateTime Stop;
if (!DateTime.TryParse(PymtStopDt,out Stop)) return
can i use
try{
if(PymtStopDt==DateTime.Parse(PymtStopDt).ToString())
}
catch{
return;}
and instead of
int z;
  if (!int.TryParse(PymtScore,out z)) return;

Can I use
try{
if(PymtScore==double.Parse(PymtScore))
}
catch{
return;}


Can I do this as done above?
Please let me know.

I didn't undertstand y we need to change the code to the latest oen u've sen tme
Thanks
0
 
Joel CoehoornDirector of Information TechnologyCommented:
The new code means you only have to convert PymtScore to a numeric type one time instead of five, you only need one try/catch block instead of three, and get's rid of an extra layer of nesting your {} braces.

Now let's look again at this line:
  if(PymtStartDt==DateTime.Parse(PymtStartDt).ToString())

It still won't work, because the .ToString() method is not guaranteed to generate the same string as PymtStartDt.  In fact, by specifying different format options I could create many different versions of the string that all represent that same date.  For example, if PymtStartDt is "11/15/2007" you could tell .ToString() to output "November 15, 2007" instead, as just one example.  What will be used by default depends on the datetime settings in the control panel of the computer where the code runs.  Here's a version that would work:

    DateTime.Parse(PymtStartDt)

No if() statement, no comparison.  It will work because if PymtStartDt cannot be converted to a datetime an exception will be thrown for the enclosing try/catch block.  This will also work for PymtStopDt and PymtScore, though in the case of the latter I would use long.Parse() rather than double.Parse(), since that more closely matches the original.
0
 
Joel CoehoornDirector of Information TechnologyCommented:
One more thing I thought of:
I can only presume your initial reluctance to use TryParse() results either because you're using .Net 1.1, which doesn't have TryParse(), or because you want the code to match the original vb.  Since you were reluctant to go with my 2nd version, which meets the first hypothesis, I'm inclined to believe it's the latter.  In that case, this being C#, I'd put the try/catch all on one line like this so it more closely resembles the vb line for line:
try {DateTime.Parse(PymtStartDt)} catch {return;}
try {DateTime.Parse(PymtStopDt} catch {return;}
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now