大家好,我已经使用 c# 开发了一个应用程序,我希望将其使用限制为 30 天,30 天后用户应该无法使用该应用程序。我在线获得了以下代码。我应该在 elseif(days<30) 中添加什么代码来限制它的使用
#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);
}
}
}
}