C# “理解错误”;该名称在当前上下文中不存在;

C# “理解错误”;该名称在当前上下文中不存在;,c#,visual-studio-2015,C#,Visual Studio 2015,我用的是C#。我得到一个错误: 当前上下文中不存在名称“DateAndTime”、“DateInterval”、“FirstDayOfWeek”、“FirstWeekOfYear” 我不明白。我尝试了很多解决方案,但都不起作用 using System; using System.Collections.Generic; using System.Text; using Microsoft.Win32; using System.IO; using Microsoft.VisualBasic;

我用的是C#。我得到一个错误:

当前上下文中不存在名称“DateAndTime”、“DateInterval”、“FirstDayOfWeek”、“FirstWeekOfYear”

我不明白。我尝试了很多解决方案,但都不起作用

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Win32;
using System.IO;
using Microsoft.VisualBasic;
using System.Windows.Forms;

namespace SoftwareLocker
{
    // Activate Property
    public class TrialMaker
    {
        #region -> Private Variables 

        private string _BaseString;
        private string _Password;
        private string _SoftName;
        private string _RegFilePath;
        private string _HideFilePath;
        private int _DefDays;
        private int _Runed;
        private string _Text;
        private string _Identifier;

        #endregion

        #region -> Constructor 

        /// <summary>
        /// Make new TrialMaker class to make software trial
        /// </summary>
        /// <param name="SoftwareName">Name of software to make trial</param>
        /// <param name="RegFilePath">File path to save password(enrypted)</param>
        /// <param name="HideFilePath">file path for saving hidden information</param>
        /// <param name="Text">A text for contacting to you</param>
        /// <param name="TrialDays">Default period days</param>
        /// <param name="TrialRunTimes">How many times user can run as trial</param>
        /// <param name="Identifier">3 Digit string as your identifier to make password</param>
        public TrialMaker(string SoftwareName,
            string RegFilePath, string HideFilePath,
            string Text, int TrialDays, int TrialRunTimes,
            string Identifier)
        {
            _SoftName = SoftwareName;
            _Identifier = Identifier;

            SetDefaults();

            _DefDays = TrialDays;
            _Runed = TrialRunTimes;

            _RegFilePath = RegFilePath;
            _HideFilePath = HideFilePath;
            _Text = Text;
        }

        private void SetDefaults()
        {
            SystemInfo.UseBaseBoardManufacturer = false;
            SystemInfo.UseBaseBoardProduct = true;
            SystemInfo.UseBiosManufacturer = false;
            SystemInfo.UseBiosVersion = true;
            SystemInfo.UseDiskDriveSignature = true;
            SystemInfo.UsePhysicalMediaSerialNumber = false;
            SystemInfo.UseProcessorID = true;
            SystemInfo.UseVideoControllerCaption = false;
            SystemInfo.UseWindowsSerialNumber = false;

            MakeBaseString();
            MakePassword();
        }

        #endregion

        // Make base string (Computer ID)
        private void MakeBaseString()
        {
            _BaseString = Encryption.Boring(Encryption.InverseByBase(SystemInfo.GetSystemInfo(_SoftName), 10));
        }

        private void MakePassword()
        {
            _Password = Encryption.MakePassword(_BaseString, _Identifier);
        }

        /// <summary>
        /// Show registering dialog to user
        /// </summary>
        /// <returns>Type of running</returns>
        public RunTypes ShowDialog()
        {
            // check if registered before
            if (CheckRegister() == true)
                return RunTypes.Full;

            frmDialog PassDialog = new frmDialog(_BaseString, _Password, DaysToEnd(), _Runed, _Text);

            MakeHideFile();

            DialogResult DR = PassDialog.ShowDialog();

            if (DR == System.Windows.Forms.DialogResult.OK)
            {
                MakeRegFile();
                return RunTypes.Full;
            }
            else if (DR == DialogResult.Retry)
                return RunTypes.Trial;
            else
                return RunTypes.Expired;
        }

        // save password to Registration file for next time usage
        private void MakeRegFile()
        {
            FileReadWrite.WriteFile(_RegFilePath, _Password);
        }

        // Control Registeration file for password
        // if password saved correctly return true else false
        private bool CheckRegister()
        {
            string Password = FileReadWrite.ReadFile(_RegFilePath);

            if (_Password == Password)
                return true;
            else
                return false;
        }

        // from hidden file
        // indicate how many days can user use program
        // if the file does not exists, make it
        private int DaysToEnd()
        {
            FileInfo hf = new FileInfo(_HideFilePath);
            if (hf.Exists == false)
            {
                MakeHideFile();
                return _DefDays;
            }
            return CheckHideFile();
        }

        // store hidden information to hidden file
        // Date,DaysToEnd,HowManyTimesRuned,BaseString(ComputerID)
        private void MakeHideFile()
        {
            string HideInfo;
            HideInfo = DateTime.Now.Ticks + ";";
            HideInfo += _DefDays + ";" + _Runed + ";" + _BaseString;
            FileReadWrite.WriteFile(_HideFilePath, HideInfo);
        }

        // Get Data from hidden file if exists
        private int CheckHideFile()
        {
            string[] HideInfo;
            HideInfo = FileReadWrite.ReadFile(_HideFilePath).Split(';');
            long DiffDays;
            int DaysToEnd;

            if (_BaseString == HideInfo[3])
            {
                DaysToEnd = Convert.ToInt32(HideInfo[1]);
                if (DaysToEnd <= 0)
                {
                    _Runed = 0;
                    _DefDays = 0;
                    return 0;
                }
                DateTime dt = new DateTime(Convert.ToInt64(HideInfo[0]));
                DiffDays = DateAndTime.DateDiff(DateInterval.Day,
                    dt.Date, DateTime.Now.Date,
                    FirstDayOfWeek.Saturday,
                    FirstWeekOfYear.FirstFullWeek);

                DaysToEnd = Convert.ToInt32(HideInfo[1]);
                _Runed = Convert.ToInt32(HideInfo[2]);
                _Runed -= 1;

                DiffDays = Math.Abs(DiffDays);

                _DefDays = DaysToEnd - Convert.ToInt32(DiffDays);
            }
            return _DefDays;
        }

        public enum RunTypes
        {
            Trial = 0,
            Full,
            Expired,
            UnKnown
        }

        #region -> Properties 

        /// <summary>
        /// Indicate File path for storing password
        /// </summary>
        public string RegFilePath
        {
            get
            {
                return _RegFilePath;
            }
            set
            {
                _RegFilePath = value;
            }
        }

        /// <summary>
        /// Indicate file path for storing hidden information
        /// </summary>
        public string HideFilePath
        {
            get
            {
                return _HideFilePath;
            }
            set
            {
                _HideFilePath = value;
            }
        }

        /// <summary>
        /// Get default number of days for trial period
        /// </summary>
        public int TrialPeriodDays
        {
            get
            {
                return _DefDays;
            }
        }

        /// <summary>
        /// Get or Set TripleDES key for encrypting files to save
        /// </summary>
        public byte[] TripleDESKey
        {
            get
            {
                return FileReadWrite.key;
            }
            set
            {
                FileReadWrite.key = value;
            }
        }

        #endregion

        #region -> Usage Properties 

        public bool UseProcessorID
        {
            get
            {
                return SystemInfo.UseProcessorID;
            }
            set
            {
                SystemInfo.UseProcessorID = value;
            }
        }

        public bool UseBaseBoardProduct
        {
            get
            {
                return SystemInfo.UseBaseBoardProduct;
            }
            set
            {
                SystemInfo.UseBaseBoardProduct = value;
            }
        }

        public bool UseBaseBoardManufacturer
        {
            get
            {
                return SystemInfo.UseBiosManufacturer;
            }
            set
            {
                SystemInfo.UseBiosManufacturer = value;
            }
        }

        public bool UseDiskDriveSignature
        {
            get
            {
                return SystemInfo.UseDiskDriveSignature;
            }
            set
            {
                SystemInfo.UseDiskDriveSignature = value;
            }
        }

        public bool UseVideoControllerCaption
        {
            get
            {
                return SystemInfo.UseVideoControllerCaption;
            }
            set
            {
                SystemInfo.UseVideoControllerCaption = value;
            }
        }

        public bool UsePhysicalMediaSerialNumber
        {
            get
            {
                return SystemInfo.UsePhysicalMediaSerialNumber;
            }
            set
            {
                SystemInfo.UsePhysicalMediaSerialNumber = value;
            }
        }

        public bool UseBiosVersion
        {
            get
            {
                return SystemInfo.UseBiosVersion;
            }
            set
            {
                SystemInfo.UseBiosVersion = value;
            }
        }

        public bool UseBiosManufacturer
        {
            get
            {
                return SystemInfo.UseBiosManufacturer;
            }
            set
            {
                SystemInfo.UseBiosManufacturer = value;
            }
        }

        public bool UseWindowsSerialNumber
        {
            get
            {
                return SystemInfo.UseWindowsSerialNumber;
            }
            set
            {
                SystemInfo.UseWindowsSerialNumber = value;
            }
        }

        #endregion
    }
}
使用系统;
使用System.Collections.Generic;
使用系统文本;
使用Microsoft.Win32;
使用System.IO;
使用Microsoft.VisualBasic;
使用System.Windows.Forms;
命名空间软件锁
{
//激活属性
公营试飞员
{
#区域->私有变量
私有字符串_基串;
私有字符串\u密码;
私有字符串_SoftName;
私有字符串_RegFilePath;
私有字符串_HideFilePath;
私人国际日;
私人内部运行;
私有字符串_文本;
私有字符串_标识符;
#端区
#区域->构造函数
/// 
///创建新的TrialMaker类以进行软件试用
/// 
///要进行试用的软件的名称
///保存密码的文件路径(加密)
///用于保存隐藏信息的文件路径
///与您联系的文本
///默认期间天数
///用户可以作为试用版运行多少次
///3位字符串作为您的标识符,用于生成密码
公共TrialMaker(字符串SoftwareName,
字符串RegFilePath,字符串HideFilePath,
字符串文本、int TrialDays、int TrialRunTimes、,
字符串标识符)
{
_SoftName=SoftwareName;
_标识符=标识符;
SetDefaults();
_DefDays=试验日;
_Runed=试验时间;
_RegFilePath=RegFilePath;
_HideFilePath=HideFilePath;
_文本=文本;
}
私有void SetDefaults()
{
SystemInfo.UseBaseBoardManufacturer=false;
SystemInfo.UseBaseBoardProduct=true;
SystemInfo.UseBiosManufacturer=假;
SystemInfo.UseBiosVersion=true;
SystemInfo.UseDiskDriveSignature=true;
SystemInfo.UsePhysicalMediaSerialNumber=false;
SystemInfo.UseProcessorID=true;
SystemInfo.UseVideoControllerCaption=false;
SystemInfo.UseWindowsSerialNumber=false;
MakeBaseString();
MakePassword();
}
#端区
//生成基本字符串(计算机ID)
私有void MakeBaseString()
{
_BaseString=Encryption.Boring(Encryption.InverseByBase(SystemInfo.GetSystemInfo(_SoftName),10));
}
私有密码()
{
_Password=Encryption.MakePassword(_BaseString,_Identifier);
}
/// 
///向用户显示注册对话框
/// 
///运行类型
公共运行类型ShowDialog()
{
//检查之前是否注册过
if(CheckRegister()==true)
返回RunTypes.Full;
frmDialog PassDialog=新的frmDialog(_BaseString,_Password,DaysToEnd(),_Runed,_Text);
MakeHideFile();
DialogResult DR=PassDialog.ShowDialog();
if(DR==System.Windows.Forms.DialogResult.OK)
{
MakeRegFile();
返回RunTypes.Full;
}
else if(DR==对话框结果。重试)
返回运行类型。试用;
其他的
返回RunTypes.Expired;
}
//将密码保存到注册文件以备下次使用
私有void MakeRegFile()
{
WriteFile(_RegFilePath,_Password);
}
//控制密码的注册文件
//如果密码保存正确,则返回true,否则返回false
私有布尔校验寄存器()
{
字符串密码=FileReadWrite.ReadFile(_RegFilePath);
如果(_Password==密码)
返回true;
其他的
返回false;
}
//从隐藏文件
//指出用户可以使用程序的天数
//如果文件不存在,请将其设置为
private int DaysToEnd()
{
FileInfo hf=新的FileInfo(_HideFilePath);
if(hf.Exists==false)
{
MakeHideFile();
返回日期(天);;
}
返回CheckHideFile();
}
//将隐藏信息存储到隐藏文件
//日期,日期结束,HowmanyTimeRuned,基本字符串(ComputerID)
私有void MakeHideFile()
{
字符串隐藏信息;
HideInfo=DateTime.Now.Ticks+“;”;
HideInfo+=\u DefDays+“;”+\u Runed+“;”+\u BaseString;
WriteFile(_HideFilePath,HideInfo);
}
//从隐藏文件(如果存在)获取数据
私有int CheckHideFile()
{
字符串[]HideInfo;
HideInfo=FileReadWrite.ReadFile(_HideFilePath).Split(“;”);
漫长的白天;
最后一天;
if(_BaseString==HideInfo[3])
{
DaysToEnd=Convert.ToInt32(HideInfo[1]);
if(DaysToEnd属性
/// 
///指示用于存储密码的文件路径
/// 
公共字符串RegFilePath
{
得到
{
返回_RegFilePath;
}
设置
{
_RegFilePath=value;
}
}
/// 
///指示用于存储隐藏信息的文件路径
/// 
公共字符串隐藏路径
{
得到
{
return\u HideFilePath;
}
设置
{
_HideFilePath=值;
}
}
/// 
///获取试用的默认天数