Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在首次运行和试用期结束后显示应用程序注册对话框_C#_Wpf_Mvvm_Trial - Fatal编程技术网

C# 在首次运行和试用期结束后显示应用程序注册对话框

C# 在首次运行和试用期结束后显示应用程序注册对话框,c#,wpf,mvvm,trial,C#,Wpf,Mvvm,Trial,我正在使用此库创建一个WPF应用程序来实现试用期此库在SystemFile上写入注册数据,但当我在项目中实现它时,它会在每次应用程序运行时显示注册对话框。 我只想在两种情况下显示注册对话框: 1-首次运行:在用户设置我的应用程序之后。我发现这两个问题和答案都在使用应用程序。设置并在那里添加bool变量,但在我的情况下,我想使用我的试用版库,我也不能使用设置。默认值[]在我的main中,因为它是非静态的,并且我没有调用特定的视图模型。我正在调用App.Run,如下所示。 2-当试用期或运行到期时

我正在使用此库创建一个WPF应用程序来实现试用期此库在
SystemFile
上写入注册数据,但当我在项目中实现它时,它会在每次应用程序运行时显示注册对话框。
我只想在两种情况下显示注册对话框:
1-首次运行:在用户设置我的应用程序之后。我发现这两个问题和答案都在使用
应用程序。设置
并在那里添加
bool
变量,但在我的情况下,我想使用我的
试用版
库,我也不能使用
设置。默认值[]
在我的main中,因为它是非静态的,并且我没有调用特定的视图模型。我正在调用
App.Run
,如下所示。
2-当试用期或运行到期时

这是我的
App.xaml.cs
课程:

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using SoftwareLocker;
using System.Globalization;
using System.Threading;

namespace PharmacyManagementSystem
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
    /// <summary>
    /// Application Entry Point.
    /// </summary>
    [System.STAThreadAttribute()]
    [System.Diagnostics.DebuggerNonUserCodeAttribute()]
    [System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "4.0.0.0")]
    public static void Main()
    {

        CultureInfo ci = CultureInfo.CreateSpecificCulture(CultureInfo.CurrentCulture.Name);
        ci.DateTimeFormat.ShortDatePattern = "yyyy-MM-dd";
        ci.DateTimeFormat.LongTimePattern = "HH:mm:ss";
        Thread.CurrentThread.CurrentCulture = Thread.CurrentThread.CurrentUICulture = ci;

        TrialMaker t = new TrialMaker("Pharmacy Management System",
        System.AppDomain.CurrentDomain.BaseDirectory + "\\RegFile.reg",
        Environment.GetFolderPath(Environment.SpecialFolder.System) +
        "\\TMSetp.dbf",
        "Mobile: +249 914 837664",
        15, 1000, "745");

        byte[] MyOwnKey = { 97, 250,  1,  5,  84, 21,   7, 63,
                     4,  54, 87, 56, 123, 10,   3, 62,
                     7,   9, 20, 36,  37, 21, 101, 57};
        t.TripleDESKey = MyOwnKey;


        bool is_trial;
        TrialMaker.RunTypes RT = t.ShowDialog();
        if (RT != TrialMaker.RunTypes.Expired)
        {
            if (RT == TrialMaker.RunTypes.Full)
                is_trial = false;
            else
                is_trial = true;

            PharmacyManagementSystem.App app = new PharmacyManagementSystem.App();
            app.InitializeComponent();
            /// as i said am just calling App.Run 
            app.Run();
        }
    }
}
}
我已经为
试用期添加了
getter
,以利用它。
在其他情况下,我希望我的应用程序直接运行,而不需要注册对话框。其他情况是当它是完整版本或未过期试用版时,首次不运行。

有什么办法可以做到这一点吗?

我建议您在Windows注册表中写入必要的数据



您可以使用此引用:

我建议您在Windows注册表中写入必要的数据



您可以使用此参考资料:

感谢以上与@Akram Mashni的讨论。我提出了这个解决方案,它适合我的场景。
我将
DaysToEnd()
方法修改为
public
,这样我就可以从其他任何地方用
TrialMaker
类的实例调用它(例如,我的
Main()
):

然后我在
Main()
方法中使用它来检查我的场景。当我调用
DaysToEnd()
时,它将通过调用
CheckHideFile()
来更新存储在
系统文件中的信息。
我先调用了
DaysToEnd()
,以便更新
系统文件中的信息
DaysToEnd()
将返回
int
值,表示试用期内剩余的天数。我还调用了
get
,用于
TrialPeriodRuns
,我在前面添加到库中,它表示试用期内的剩余运行

我还实现了嵌套的
if-else
语句来检查我的场景:

        int daystoend = t.DaysToEnd();
        int trialperiodruns = t.TrialPeriodRuns;
        /// Check if it is first run here 
        if (dte == 15 && tpr == 1000)
        {
            bool is_trial;
            /// then show the Registration dialog
            TrialMaker.RunTypes RT = t.ShowDialog();
            if (RT != TrialMaker.RunTypes.Expired)
            {
                if (RT == TrialMaker.RunTypes.Full)
                    is_trial = false;
                else
                    is_trial = true;

                PharmacyManagementSystem.App app = new PharmacyManagementSystem.App();
                app.InitializeComponent();
                app.Run();
            }
        }
        /// Check if it is trial but not first run
        /// no Registration Dialog will show in this case
        else if (dte > 0 && tpr > 0)
        {
            PharmacyManagementSystem.App app = new PharmacyManagementSystem.App();
            app.InitializeComponent();
            app.Run();
        }
        /// Check if it is expired trial
        else if (dte == 0 || tpr == 0)
        {
            bool is_trial;
            /// then show the Registration Dialog here
            TrialMaker.RunTypes RT = t.ShowDialog();
            if (RT != TrialMaker.RunTypes.Expired)
            {
                if (RT == TrialMaker.RunTypes.Full)
                    is_trial = false;
                else
                    is_trial = true;

                PharmacyManagementSystem.App app = new PharmacyManagementSystem.App();
                app.InitializeComponent();
                app.Run();
            }
        }
        /// the full version scenario remain and it comes here 
        /// no need to show Registration Dialog
        else
        {
            bool is_trial;
            TrialMaker.RunTypes RT = t.ShowDialog();
            if (RT != TrialMaker.RunTypes.Expired)
            {
                if (RT == TrialMaker.RunTypes.Full)
                    is_trial = false;
                else
                    is_trial = true;

                PharmacyManagementSystem.App app = new PharmacyManagementSystem.App();
                app.InitializeComponent();
                app.Run();
            }
        }  
最后,它对我来说就像一种魅力

再次感谢@Akram Mashni激发我的灵感

感谢与@Akram Mashni的上述讨论。我提出了这个解决方案,它适合我的场景。
我将
DaysToEnd()
方法修改为
public
,这样我就可以从其他任何地方用
TrialMaker
类的实例调用它(例如,我的
Main()
):

然后我在
Main()
方法中使用它来检查我的场景。当我调用
DaysToEnd()
时,它将通过调用
CheckHideFile()
来更新存储在
系统文件中的信息。
我先调用了
DaysToEnd()
,以便更新
系统文件中的信息
DaysToEnd()
将返回
int
值,表示试用期内剩余的天数。我还调用了
get
,用于
TrialPeriodRuns
,我在前面添加到库中,它表示试用期内的剩余运行

我还实现了嵌套的
if-else
语句来检查我的场景:

        int daystoend = t.DaysToEnd();
        int trialperiodruns = t.TrialPeriodRuns;
        /// Check if it is first run here 
        if (dte == 15 && tpr == 1000)
        {
            bool is_trial;
            /// then show the Registration dialog
            TrialMaker.RunTypes RT = t.ShowDialog();
            if (RT != TrialMaker.RunTypes.Expired)
            {
                if (RT == TrialMaker.RunTypes.Full)
                    is_trial = false;
                else
                    is_trial = true;

                PharmacyManagementSystem.App app = new PharmacyManagementSystem.App();
                app.InitializeComponent();
                app.Run();
            }
        }
        /// Check if it is trial but not first run
        /// no Registration Dialog will show in this case
        else if (dte > 0 && tpr > 0)
        {
            PharmacyManagementSystem.App app = new PharmacyManagementSystem.App();
            app.InitializeComponent();
            app.Run();
        }
        /// Check if it is expired trial
        else if (dte == 0 || tpr == 0)
        {
            bool is_trial;
            /// then show the Registration Dialog here
            TrialMaker.RunTypes RT = t.ShowDialog();
            if (RT != TrialMaker.RunTypes.Expired)
            {
                if (RT == TrialMaker.RunTypes.Full)
                    is_trial = false;
                else
                    is_trial = true;

                PharmacyManagementSystem.App app = new PharmacyManagementSystem.App();
                app.InitializeComponent();
                app.Run();
            }
        }
        /// the full version scenario remain and it comes here 
        /// no need to show Registration Dialog
        else
        {
            bool is_trial;
            TrialMaker.RunTypes RT = t.ShowDialog();
            if (RT != TrialMaker.RunTypes.Expired)
            {
                if (RT == TrialMaker.RunTypes.Full)
                    is_trial = false;
                else
                    is_trial = true;

                PharmacyManagementSystem.App app = new PharmacyManagementSystem.App();
                app.InitializeComponent();
                app.Run();
            }
        }  
最后,它对我来说就像一种魅力

再次感谢@Akram Mashni激发了我的灵感

我使用的库已经通过调用
MakeHideFile()
CheckHideFile()
将数据写入了
SystemFile
中。因此,如果您已经获得了第一次运行的日期时间信息,你可以制作一个表单,在这里你可以显示用户在到期之前有多少时间,如果到期,他需要添加许可证,否则当表单关闭时它将关闭应用程序。我也有这个窗口。它显示每次我运行应用程序时,我只想在我在问题中提到的上述场景中显示它@Akram Mashnit我使用的库已经通过调用
MakeHideFile()
CheckHideFile()
SystemFile
上写入了数据。因此,如果您已经有了关于第一次运行的日期时间的信息,您可以制作一个表单,在该表单中可以显示用户在过期之前有多少时间,如果过期,他需要添加一个许可证,否则它会在表单关闭时关闭应用程序。我也有这个窗口。它显示每次我运行应用程序时,我只想在我在问题中提到的上述场景中显示它@阿克兰马什尼
        int daystoend = t.DaysToEnd();
        int trialperiodruns = t.TrialPeriodRuns;
        /// Check if it is first run here 
        if (dte == 15 && tpr == 1000)
        {
            bool is_trial;
            /// then show the Registration dialog
            TrialMaker.RunTypes RT = t.ShowDialog();
            if (RT != TrialMaker.RunTypes.Expired)
            {
                if (RT == TrialMaker.RunTypes.Full)
                    is_trial = false;
                else
                    is_trial = true;

                PharmacyManagementSystem.App app = new PharmacyManagementSystem.App();
                app.InitializeComponent();
                app.Run();
            }
        }
        /// Check if it is trial but not first run
        /// no Registration Dialog will show in this case
        else if (dte > 0 && tpr > 0)
        {
            PharmacyManagementSystem.App app = new PharmacyManagementSystem.App();
            app.InitializeComponent();
            app.Run();
        }
        /// Check if it is expired trial
        else if (dte == 0 || tpr == 0)
        {
            bool is_trial;
            /// then show the Registration Dialog here
            TrialMaker.RunTypes RT = t.ShowDialog();
            if (RT != TrialMaker.RunTypes.Expired)
            {
                if (RT == TrialMaker.RunTypes.Full)
                    is_trial = false;
                else
                    is_trial = true;

                PharmacyManagementSystem.App app = new PharmacyManagementSystem.App();
                app.InitializeComponent();
                app.Run();
            }
        }
        /// the full version scenario remain and it comes here 
        /// no need to show Registration Dialog
        else
        {
            bool is_trial;
            TrialMaker.RunTypes RT = t.ShowDialog();
            if (RT != TrialMaker.RunTypes.Expired)
            {
                if (RT == TrialMaker.RunTypes.Full)
                    is_trial = false;
                else
                    is_trial = true;

                PharmacyManagementSystem.App app = new PharmacyManagementSystem.App();
                app.InitializeComponent();
                app.Run();
            }
        }