7 Replies - 695 Views - Last Post: 25 January 2019 - 12:41 PM Rate Topic: -----

#1 Steve7419   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 34
  • Joined: 19-November 18

Stop working after a certain date or after a week

Posted 21 January 2019 - 12:35 AM

Hello All,


I want my code to stop working after a certain date, I mean after my client pays my invoice full amount.
I use a certain checkbox in the application window and disable it but still visible. I name it Trial.

How do I write this in my code at the best way? I appreciate your help so much. Thank you


Regards,
Steve
Is This A Good Question/Topic? 0
  • +

Replies To: Stop working after a certain date or after a week

#2 Steve7419   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 34
  • Joined: 19-November 18

Re: Stop working after a certain date or after a week

Posted 21 January 2019 - 12:54 AM

I have read this link but in page 2, there was a question but no answer. So, I think there was still a problem in the code.
https://www.dreaminc...od/page__st__15

Regards,
Steve
Was This Post Helpful? 0
  • +
  • -

#3 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14854
  • View blog
  • Posts: 59,272
  • Joined: 12-June 08

Re: Stop working after a certain date or after a week

Posted 21 January 2019 - 08:35 AM

I would think you would check as far up in the app flow as possible. The constructor or load event. If after the date then exit the app.

Though the real doozie will be what if they just change their computer's clock time. ;)
Was This Post Helpful? 2
  • +
  • -

#4 Sheepings   User is offline

  • Senior Programmer
  • member icon

Reputation: 201
  • View blog
  • Posts: 1,126
  • Joined: 05-December 13

Re: Stop working after a certain date or after a week

Posted 21 January 2019 - 04:43 PM

One of the best ways to do this would be to use a web client to download a string from a text file you have access to online to change the values from tru to false. This link for the DownloadString will be useful :: https://docs.microso...framework-4.7.2

Because the form.load event can hide code issues, I've used form.shown instead. You could use it like this ::

Option Strict On
Option Explicit On

Imports System.Net

Public Class Form1
    Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles MyBase.Shown
        If ExpireOn() = True Then
            MessageBox.Show("This is trial software. Please contact the developer for a licence.", "Important Information", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
            Application.Exit()
        Else
            'Run something for the user
        End If
        'If they get around this by setting the date back to previous allowed month, then this will get them :)/>/>
        If DLS("https://textuploader.com/1a2uf") = True Then
            MessageBox.Show("This is trial software. Please contact the developer for a licence.", "Important Information", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
            Application.Exit()
        Else
            'Run something for the user
        End If
    End Sub
    Public Shared Function DLS(Optional ByVal result As String = Nothing) As Boolean

        Dim wClient As WebClient = New WebClient()
        Dim responseString As String = wClient.DownloadString(result)

        If responseString.Contains("<pre><code class='no-highlight'>false</code></pre>") Then
            Return True
        Else
            Return False
        End If
        Return False
    End Function
    Public Shared Function ExpireOn() As Boolean
        If Not System.DateTime.Today.ToString.Contains("01/2019") Then
            Return True
        Else
            Return False
        End If
        Return False
    End Function
End Class

The URL i used should never expire, so you can use the code as it is. Or if you have your own website, upload a txt file to it, and add only the word false to it, then change the url from the string to your own. You can then change this ::
If responseString.Contains("<pre><code class='no-highlight'>false</code></pre>")

to this ::
If responseString.Contains("false")

Edited, added missing keyword

This post has been edited by Sheepings: 22 January 2019 - 12:31 PM

Was This Post Helpful? 2
  • +
  • -

#5 Sheepings   User is offline

  • Senior Programmer
  • member icon

Reputation: 201
  • View blog
  • Posts: 1,126
  • Joined: 05-December 13

Re: Stop working after a certain date or after a week

Posted 21 January 2019 - 05:13 PM

I should have also mentioned that you should look into Obfucation software to protect your code. While it is not 100% protected, since hackers and cheaters of the system are now reverse engineering obfuscation software to learn to deobfucate software after its been protected. So there are no fool proof ways to protect your code from them reverse engineering it to change the values of your source and recompiling it to their own liking, but with that said; obfucation is better than not using anything at all. At least, you can make it very difficult for them. ;)
Was This Post Helpful? 1
  • +
  • -

#6 Steve7419   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 34
  • Joined: 19-November 18

Re: Stop working after a certain date or after a week

Posted 24 January 2019 - 12:01 AM

Hi Guys..

Thanks a lot for your kindness to help me.

The solution is really great and I will comeback with the result.
Currently I'm using date validation as follows:
....
 Dim dtDate As DateTime
                    dtDate = Convert.ToDateTime("2019-01-23")
                    If (dtDate.Year >= DateTime.Now.Year) Then
                        If (dtDate.Day >= 27) And (dtDate.Month >= 1) Then
                            Throw New Exception("Date and month should not more than  27 January")
                            Return
                        End If
                    Else
                        Throw New Exception("Year should be in the present Year ")
                        Return
                    End If
                    Dim oSO As SAPbobsCOM.Documents
                    oSO = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oInventoryGenEntry)
                    'oSO.DocDate = Date.Now.ToString("yyyy-MM-dd")
                    oSO.DocDate = dtDate.ToString("yyyy-MM-dd")

....



After the commercial is finished, I will delete the code and recompile it. Maybe too simple but becoz currently it is really urgent, I have no other choice.

Regards,
Steve
Was This Post Helpful? 0
  • +
  • -

#7 Sheepings   User is offline

  • Senior Programmer
  • member icon

Reputation: 201
  • View blog
  • Posts: 1,126
  • Joined: 05-December 13

Re: Stop working after a certain date or after a week

Posted 24 January 2019 - 10:52 AM

Some problems with your method. First, date validation is not foolproof. Also this ::
If (dtDate.Year >= DateTime.Now.Year) Then
Should be ::
        If (DateTime.Now.Year <> dtDate.Year) Then 
Since dtDate year is greater than the PC time; I can avoid your first check. IF (I set my clock to 2018) because the condition is still greater, whereas I feel you might want this going to your else? This is what Modi was pointing out to you above. ;)

Lets step through my changes ::
Console.WriteLine(DateTime.Now.Year <> dtDate.Year) 'Read the "output", is this year the current one in your string? 

In this section, check with is equal operators <> instead of >= one direction. This way, the year must be the present one and not just greater than but not less than something else.
If (DateTime.Now.Year <> dtDate.Year) Then 

Your else section wasn't going to execute if the person using your app was to set their date year to be before 2019. The check above now makes sure it does.
        Else 'How do you evaluate the year if its from before 2019? The user you supplied your app to, changed their PC time/clock to 2018 avoiding your first check. Using not equal operators fixes that <>

Are the user using your app using it during the allowed time-frame of the month of January?
Console.WriteLine(DateTime.Now.Month <> dtDate.Month)
If they are not in the correct month, and trying to avoid your checks, they will get exception.
If (dtDate.Month <> DateTime.Now.Month) Then
                Throw New Exception("It is not the month of January.")
Otherwise, we allow them to continue on, and then we check the days properly. Like this ::
Else 'Month is correct, are the days?
                Console.WriteLine(DateTime.Now.Day >= dtDate.Day) 'Is it greater or equal?
                Console.WriteLine(DateTime.Now.Day < 19) 'Is it less than? Check the output tab...
If the dates are not right, they will get an error. I've checked the dates like this ::
If (DateTime.Now.Day >= dtDate.Day) OrElse (DateTime.Now.Day <= 19) Then 'By setting the date to the 28th I was able to avoid your exception. 
                    'If you provide this software on the 19th they can still use it afterwards if they set their clock to between the two conditions you've set. 
                    'If date is less than 27, (your deadline), also if the date is also more than this date; the 19th.
                    Throw New Exception("Date and month should not be more than 27th January or less than the 19th of January")
                End If
Lastly ending both statements ::
                ' Your stuff here

            End If
        End If


I've made some changes to your code to make it more fool proof, but you need to note, that the DateTimeNow comes from the users PC, and so when they change the date or time on the PC where your application runs, this effects the conditions you set, and thus allows them to be avoided. Here are the quick changes I made ::
        Dim dtDate As DateTime
        dtDate = Convert.ToDateTime("2019-01-27")
        Console.WriteLine(DateTime.Now.Year <> dtDate.Year) 
        If (DateTime.Now.Year <> dtDate.Year) Then 
            Throw New Exception("Year should be in the present Year")
        Else 
            Console.WriteLine(DateTime.Now.Month <> dtDate.Month)
            If (dtDate.Month <> DateTime.Now.Month) Then
                Throw New Exception("It is not the month of January.")
            Else 'Month is correct, are the days?
                Console.WriteLine(DateTime.Now.Day >= dtDate.Day) 
                Console.WriteLine(DateTime.Now.Day < 19) 
                If (DateTime.Now.Day >= dtDate.Day) OrElse (DateTime.Now.Day <= 19) Then 
                    Throw New Exception("Date and month should not be more than 27th January or less than the 19th of January")
                End If
                ' Your stuff here
                oSO = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oInventoryGenEntry)
                'oSO.DocDate = Date.Now.ToString("yyyy-MM-dd")
                oSO.DocDate = dtDate.ToString("yyyy-MM-dd")
            End If
        End If


All in all, you'd be better using the DLS function I provided you with.

Edited out a typo in code since the first time I changed it. All good now

Also, fixed an inline comment error of something i changed.

This post has been edited by Sheepings: 24 January 2019 - 11:03 AM

Was This Post Helpful? 1
  • +
  • -

#8 Steve7419   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 34
  • Joined: 19-November 18

Re: Stop working after a certain date or after a week

Posted 25 January 2019 - 12:41 PM

Dear Sheepings,


Thanks a lot for your brilliant changes.
I will try it and will come back with result.

I missed that in my code. I tried in today, my doc date is still Jan. 23, 2019. I expects the doc date should be today and when the system date is Jan 28, 2019, my application won't work.

I shouldn't know it from the start but it does anyway...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1