Frage

Hi everyone I have developed an application using c# and I wish to restrict its use to 30days and after 30 days the user should not be able to use the application.I got the following code online.What code should I add in elseif(days<30) to restrict its use

#region Using directives
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
#endregion

namespace Coder24
{
    class TrialTimeManager
    {
        /// <summary>
        /// A Temporary variable.
        /// </summary>
        private string temp = "";

        /// <summary>
        /// The constructor.
        /// </summary>
        public TrialTimeManager()
        {

        }

        /// <summary>
        /// Sets the new date +31 days add for trial.
        /// </summary>
        public void SetNewDate()
        {
            DateTime newDate = DateTime.Now.AddDays(31);
            temp = newDate.ToLongDateString();
            StoreDate(temp);
        }

        /// <summary>
        /// Checks if expire or NOT.
        /// </summary>
        public void Expired()
        {
            string d = "";
            using (Microsoft.Win32.RegistryKey key =
                Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Test"))
            {
                 d = (String)key.GetValue("Date");
            }
            DateTime now = DateTime.Parse(d);
            int day = (now.Subtract(DateTime.Now)).Days;
            if (day > 30){}
            else if (0 < day && day <= 30){
                 string daysLeft = string.Format("{0} days more to expire", now.Subtract(DateTime.Now).Days);
                 MessageBox.Show(daysLeft);
            }
            else if (day <= 0){
                /* Fill with more code, once it has expired, what will happen nex! */
            }
        }

        /// <summary>
        /// Stores the new date value in registry.
        /// </summary>
        /// <param name="value"></param>
        private void StoreDate(string value)
        {
            try
            {
                using (Microsoft.Win32.RegistryKey key =
                    Microsoft.Win32.Registry.LocalMachine.CreateSubKey(@"SOFTWARE\Test"))
                {
                    key.SetValue("Date", value, Microsoft.Win32.RegistryValueKind.String);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}
War es hilfreich?

Lösung

This depends entirely on what you want to have happen when a trial expires.

You probably want to immediately end the program. You could also give them the option of visiting your website to purchase a license. Maybe something like this:

if (day > 30)
{
    if (MessageBox.Show("Trial expired. Visit site to purchase license?",
        "Trial Expired!", MessageBoxButtons.YesNo) == DialogResult.Yes)
    {
        Process.Start("http://www.yourwebsite.com");
    }

    Environment.Exit(0);
}

If you have something else in mind, or other requirements, update your question with more details.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top