diff --git a/CheongBuk_MegaPark_Key_Management/Cheongbuk_MegaPark_Key_Management.csproj b/CheongBuk_MegaPark_Key_Management/Cheongbuk_MegaPark_Key_Management.csproj
index 8068719..e7455fa 100644
--- a/CheongBuk_MegaPark_Key_Management/Cheongbuk_MegaPark_Key_Management.csproj
+++ b/CheongBuk_MegaPark_Key_Management/Cheongbuk_MegaPark_Key_Management.csproj
@@ -53,6 +53,9 @@
..\packages\System.Buffers.4.4.0\lib\netstandard2.0\System.Buffers.dll
+
+ ..\packages\System.CodeDom.7.0.0\lib\net462\System.CodeDom.dll
+
@@ -64,6 +67,7 @@
..\packages\System.Data.SQLite.Linq.1.0.116.0\lib\net46\System.Data.SQLite.Linq.dll
+
..\packages\System.Memory.4.5.3\lib\netstandard2.0\System.Memory.dll
@@ -88,6 +92,7 @@
+
Form
diff --git a/CheongBuk_MegaPark_Key_Management/DB.cs b/CheongBuk_MegaPark_Key_Management/DB.cs
index 2bbcd56..217cf56 100644
--- a/CheongBuk_MegaPark_Key_Management/DB.cs
+++ b/CheongBuk_MegaPark_Key_Management/DB.cs
@@ -1,24 +1,65 @@
using System;
using System.Collections.Generic;
using System.Data.SQLite;
+using System.IO;
namespace Cheongbuk_MegaPark_Key_Management
{
internal class DB
{
+ private SQLiteConnection _sqLiteConnection;
private SQLiteCommand _sqLiteCommand;
-
- private readonly SQLiteConnection _sqLiteConnection;
private SQLiteDataReader _sqLiteDataReader;
+ private static readonly string CONNECTION_STRING = $"Data Source={Setting.DbLocation}; Version=3; Integrated Security=true;";
public DB()
{
- if(!System.IO.File.Exists(Setting.DbLocation))
- {
- System.IO.File.WriteAllBytes(Setting.DbLocation, Properties.Resources.data);
- }
- _sqLiteConnection = new SQLiteConnection("Data Source=" + Setting.DbLocation + ";Version=3;");
+ CreateDatabaseIfNotExist();
+ }
+
+ private SQLiteConnection OpenConnection()
+ {
+ _sqLiteConnection = new SQLiteConnection(CONNECTION_STRING);
_sqLiteConnection.Open();
+
+ return _sqLiteConnection;
+ }
+
+ private void CreateDatabaseIfNotExist()
+ {
+ if (!File.Exists(Setting.DbLocation))
+ {
+ SQLiteConnection.CreateFile(Setting.DbLocation);
+ _sqLiteConnection = OpenConnection();
+
+ var createKeyTable = @"
+ CREATE TABLE Key(KeyCode INTEGER NOT NULL, Activation NUMERIC NOT NULL,PRIMARY KEY(KeyCode));
+
+ CREATE TABLE ProfitData (ID INTEGER NOT NULL UNIQUE,
+ KeyCode INTEGER NOT NULL,
+ Category INTEGER NOT NULL,
+ StartDateTime TEXT NOT NULL,
+ People INTEGER NOT NULL,
+ EndDateTime INTEGER NOT NULL,
+ UseTime INTEGER,
+ ProfitBase INTEGER NOT NULL,
+ ProfitAdd INTEGER,
+ ProfitDiscount INTEGER,
+ DeleteData INTEGER DEFAULT 0,
+ PRIMARY KEY(ID AUTOINCREMENT));
+
+ CREATE TABLE RentData (KeyCode INTEGER NOT NULL UNIQUE, Category INTEGER NOT NULL, StartDateTime TEXT NOT NULL, People INTEGER NOT NULL);";
+
+ using (var command = _sqLiteConnection.CreateCommand())
+ {
+ command.CommandText = createKeyTable;
+ var excute = command.ExecuteNonQuery();
+ }
+ }
+ else
+ {
+ OpenConnection();
+ }
}
public void LoadData()
@@ -28,10 +69,11 @@ namespace Cheongbuk_MegaPark_Key_Management
var query = "Select * FROM RentData";
_sqLiteCommand = new SQLiteCommand(query, _sqLiteConnection);
_sqLiteDataReader = _sqLiteCommand.ExecuteReader();
+
while (_sqLiteDataReader.Read())
{
var rentData = new RentData();
-
+
int.TryParse(_sqLiteDataReader["KeyCode"].ToString(), out rentData.KeyCode);
int.TryParse(_sqLiteDataReader["Category"].ToString(), out rentData.Category);
rentData.StartDateTime = Convert.ToDateTime(_sqLiteDataReader["StartDateTime"]);
@@ -42,13 +84,16 @@ namespace Cheongbuk_MegaPark_Key_Management
_sqLiteDataReader.Close();
var startDateTime = DateTime.Now;
var endDateTime = DateTime.Now.AddDays(1);
+
query = "Select * FROM ProfitData Where EndDateTime >= '" + startDateTime.Year.ToString("0000") + "-" +
- startDateTime.Month.ToString("00") +
- "-" + startDateTime.Day.ToString("00") + "' And EndDateTime < '" +
- endDateTime.Year.ToString("0000") + "-" + endDateTime.Month.ToString("00") +
- "-" + endDateTime.Day.ToString("00") + "' And DeleteData = 0";
+ startDateTime.Month.ToString("00") +
+ "-" + startDateTime.Day.ToString("00") + "' And EndDateTime < '" +
+ endDateTime.Year.ToString("0000") + "-" + endDateTime.Month.ToString("00") +
+ "-" + endDateTime.Day.ToString("00") + "' And DeleteData = 0";
+
_sqLiteCommand = new SQLiteCommand(query, _sqLiteConnection);
_sqLiteDataReader = _sqLiteCommand.ExecuteReader();
+
while (_sqLiteDataReader.Read())
{
var profitData = new ProfitData();
@@ -72,6 +117,7 @@ namespace Cheongbuk_MegaPark_Key_Management
{
var query = "Insert INTO RentData VALUES(" + rentData.KeyCode + "," + rentData.Category + ", '" +
rentData.StartDateTime.ToString("yyyy/MM/dd HH:mm:ss") + "'," + rentData.People + ")";
+
_sqLiteCommand = new SQLiteCommand(query, _sqLiteConnection);
_sqLiteCommand.ExecuteNonQuery();
}
@@ -88,13 +134,13 @@ namespace Cheongbuk_MegaPark_Key_Management
profitData.ProfitBase + ", " +
profitData.ProfitAdd + ", " +
profitData.ProfitDiscount + "); SELECT last_insert_rowid()";
+
_sqLiteCommand = new SQLiteCommand(query, _sqLiteConnection);
_sqLiteDataReader = _sqLiteCommand.ExecuteReader();
- int id = 0;
+ var id = 0;
+
while (_sqLiteDataReader.Read())
- {
int.TryParse(_sqLiteDataReader[0].ToString(), out id);
- }
query = "Delete From RentData Where KeyCode=" + profitData.KeyCode;
_sqLiteCommand = new SQLiteCommand(query, _sqLiteConnection);
diff --git a/CheongBuk_MegaPark_Key_Management/LicenseChecker.cs b/CheongBuk_MegaPark_Key_Management/LicenseChecker.cs
new file mode 100644
index 0000000..f93f2a2
--- /dev/null
+++ b/CheongBuk_MegaPark_Key_Management/LicenseChecker.cs
@@ -0,0 +1,74 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Management;
+using System.Security.Cryptography;
+using System.Net;
+
+namespace Cheongbuk_MegaPark_Key_Management
+{
+ public class LicenseChecker
+ {
+ public bool CheckLicense()
+ {
+ string webDatas;
+ using (WebClient webClient = new WebClient())
+ {
+ try
+ {
+ webDatas = webClient.DownloadString("https://raw.githubusercontent.com/crudelis/CMPKM/main/license");
+ }
+ catch
+ {
+ webDatas = "";
+ }
+ }
+ string[] certifiedLicenses = webDatas.Split(new string[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
+ certifiedLicenses = certifiedLicenses.Where(x => !string.IsNullOrEmpty(x)).ToArray();
+ string localLicenseCode = GetLocalLicense();
+ foreach (var certified in certifiedLicenses)
+ {
+ if (certified == localLicenseCode)
+ return true;
+ }
+ return false;
+ }
+ private string GetLocalLicense()
+ {
+ string localBoardCode = GetBaseBoardCode();
+ string md5LocalBoardCode = GetMD5(localBoardCode);
+ System.IO.File.WriteAllText("license", md5LocalBoardCode);
+ return md5LocalBoardCode;
+ }
+ private string GetBaseBoardCode()
+ {
+ string query = "SELECT * FROM Win32_BaseBoard";
+ ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
+ List serialNumbers = new List();
+ foreach (var mObject in searcher.Get())
+ {
+ serialNumbers.Add(mObject.GetPropertyValue("SerialNumber").ToString());
+ }
+ return serialNumbers[0];
+ }
+ private string GetMD5(string data)
+ {
+ using (MD5 md5 = MD5.Create())
+ {
+ byte[] input = Encoding.ASCII.GetBytes(data);
+ byte[] hash = md5.ComputeHash(input);
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < hash.Length; i++)
+ {
+ sb.Append(hash[i].ToString("X2"));
+ }
+ return sb.ToString();
+ }
+ }
+ }
+
+
+
+}
diff --git a/CheongBuk_MegaPark_Key_Management/Program.cs b/CheongBuk_MegaPark_Key_Management/Program.cs
index bc86fdf..5948455 100644
--- a/CheongBuk_MegaPark_Key_Management/Program.cs
+++ b/CheongBuk_MegaPark_Key_Management/Program.cs
@@ -14,6 +14,15 @@ namespace Cheongbuk_MegaPark_Key_Management
[STAThread]
static void Main()
{
+ LicenseChecker licenseChecker = new LicenseChecker();
+ bool licenseResult = licenseChecker.CheckLicense();
+ if(!licenseResult)
+ {
+ MessageBox.Show("A very crtical fatal error has occurred.\r\nContact your administrator.", "Crtical Fata Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+
+ }
+
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
diff --git a/CheongBuk_MegaPark_Key_Management/Setting.cs b/CheongBuk_MegaPark_Key_Management/Setting.cs
index ef10ff2..4ee6009 100644
--- a/CheongBuk_MegaPark_Key_Management/Setting.cs
+++ b/CheongBuk_MegaPark_Key_Management/Setting.cs
@@ -29,10 +29,10 @@ namespace Cheongbuk_MegaPark_Key_Management
};
public static int OverTime = 10;
- public static int OverAmount = 1000;
+ public static int OverAmount = 2000;
}
-
+
public struct ChargesStruct
{
diff --git a/CheongBuk_MegaPark_Key_Management/packages.config b/CheongBuk_MegaPark_Key_Management/packages.config
index e19c3a7..83c3fe8 100644
--- a/CheongBuk_MegaPark_Key_Management/packages.config
+++ b/CheongBuk_MegaPark_Key_Management/packages.config
@@ -3,10 +3,12 @@
+
+