1 private void Authentication(){
2
3 string regKey = Properties.Settings.Default.ApplicationId;
4
5 DateTime dt = DateTime.Now; //当日日付の取得
6
7 Microsoft.Win32.RegistryKey regkey =
8 Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"Software\test\subU2", true);
9
10 //初回起動時の処理
11 if (regkey == null)
12 {
13 Microsoft.Win32.RegistryKey regkey2 =
14 Microsoft.Win32.Registry.CurrentUser.CreateSubKey(@"Software\test\subU2");
15
16
17 //レジストリへの書き込み
18 //使用年月日
19 regkey2.SetValue("siyoYear", dt.Year);
20 regkey2.SetValue("siyoMonth", dt.Month);
21 regkey2.SetValue("siyoDay", dt.Day);
22
23 //30日使用可能
24 DateTime dt2 = dt.AddDays(30);
25
26 //レジストリへの書き込み
27 regkey2.SetValue("siyoKigenYear", dt2.Year);
28 regkey2.SetValue("siyoKigenMonth", dt2.Month);
29 regkey2.SetValue("siyoKigenDay", dt2.Day);
30
31 regkey2.Close();
32
33 }
34 //二回目
35 else
36 {
37 //使用期限年月日をレジストリより取得
38 int wkSiyoKigenYear = (int)regkey.GetValue("siyoKigenYear");
39 int wkSiyoKigenMonth = (int)regkey.GetValue("siyoKigenMonth");
40 string wkStSiyoKigenMonth = "";
41
42 if (wkSiyoKigenMonth < 10)
43 {
44 wkStSiyoKigenMonth = "0" + wkSiyoKigenMonth.ToString();
45 }
46 else
47 {
48 wkStSiyoKigenMonth = wkSiyoKigenMonth.ToString();
49 }
50
51 int wkSiyoKigenDay = (int)regkey.GetValue("siyoKigenDay");
52 string wkStSiyoKigenDay = "";
53 if (wkSiyoKigenDay < 10)
54 {
55 wkStSiyoKigenDay = "0" + wkSiyoKigenDay.ToString();
56 }
57 else
58 {
59 wkStSiyoKigenDay = wkSiyoKigenDay.ToString();
60 }
61
62 string strSiyoKigenYMD = wkSiyoKigenYear.ToString() + wkStSiyoKigenMonth + wkStSiyoKigenDay;
63
64 //使用年月日をレジストリより取得
65 int wkSiyoYear = (int)regkey.GetValue("siyoYear");
66 int wkSiyoMonth = (int)regkey.GetValue("siyoMonth");
67 string wkStSiyoMonth = "";
68 if (wkSiyoMonth < 10)
69 {
70 wkStSiyoMonth = "0" + wkSiyoMonth.ToString();
71 }
72 else
73 {
74 wkStSiyoMonth = wkSiyoMonth.ToString();
75 }
76
77 int wkSiyoDay = (int)regkey.GetValue("siyoDay");
78 string wkStSiyoDay = "";
79 if (wkSiyoDay < 10)
80 {
81 wkStSiyoDay = "0" + wkSiyoDay.ToString();
82 }
83 else
84 {
85 wkStSiyoDay = wkSiyoDay.ToString();
86 }
87
88 int wkSystemMonth = dt.Month;
89 int wkSystemDay = dt.Day;
90
91 string wkStSystemMonth = "";
92 string wkStSystemDay = "";
93
94 if (wkSystemMonth < 10)
95 {
96 wkStSystemMonth = "0" + wkSystemMonth.ToString();
97 }
98 else
99 {
100 wkStSystemMonth = wkSystemMonth.ToString();
101 }
102
103 if (wkSystemDay < 10)
104 {
105 wkStSystemDay = "0" + wkSystemDay.ToString();
106 }
107 else
108 {
109 wkStSystemDay = wkSystemDay.ToString();
110 }
111
112 string strSiyoYMD = wkSiyoYear.ToString() + wkStSiyoMonth + wkStSiyoDay;
113
114 string strSystemYMD = dt.Year.ToString() + wkStSystemMonth + wkStSystemDay;
115
116 //システム日付と使用期限年月日の比較
117 //システム日付が使用期限年月日より大きい場合(期限超過)
118 if (int.Parse(strSiyoKigenYMD) < int.Parse(strSystemYMD))
119 {
120 MessageBox.Show("使用期限日を超過しております。延伸の手続きをお願いします。使用期限日:" + strSiyoKigenYMD);
121
122 //価格チェックボタンを非活性化
123 goButton.Enabled = false;
124 }
125 //期限超過していない場合
126 else
127 {
128 MessageBox.Show("利用可能です。使用期限は" + wkSiyoKigenYear.ToString() + "/" + wkSiyoKigenMonth.ToString() + "/" + wkSiyoKigenDay.ToString() + "です。");
129
130 //レジストリへの書き込み
131 //使用年月日にシステム日付をセットする
132 regkey.SetValue("siyoYear", dt.Year);
133 regkey.SetValue("siyoMonth", dt.Month);
134 regkey.SetValue("siyoDay", dt.Day);
135 }
136
137 //閉じる
138 regkey.Close();
139 }
140 }
|