기능 추가 및 수정

- DB 기본 기능 수정
- 추가 요금 2000원 수정
- 라이센스 기능 추가
This commit is contained in:
2023-01-11 09:04:41 +09:00
parent 07c71e3dc6
commit 42bbb17256
6 changed files with 153 additions and 17 deletions

View File

@@ -53,6 +53,9 @@
<Reference Include="System.Buffers, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Buffers.4.4.0\lib\netstandard2.0\System.Buffers.dll</HintPath>
</Reference>
<Reference Include="System.CodeDom, Version=7.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.CodeDom.7.0.0\lib\net462\System.CodeDom.dll</HintPath>
</Reference>
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Core" />
<Reference Include="System.Data.SQLite, Version=1.0.116.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
@@ -64,6 +67,7 @@
<Reference Include="System.Data.SQLite.Linq, Version=1.0.116.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
<HintPath>..\packages\System.Data.SQLite.Linq.1.0.116.0\lib\net46\System.Data.SQLite.Linq.dll</HintPath>
</Reference>
<Reference Include="System.Management" />
<Reference Include="System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Memory.4.5.3\lib\netstandard2.0\System.Memory.dll</HintPath>
</Reference>
@@ -88,6 +92,7 @@
<Compile Include="DB.cs" />
<Compile Include="Extends.cs" />
<Compile Include="FontLibrary.cs" />
<Compile Include="LicenseChecker.cs" />
<Compile Include="MainForm.cs">
<SubType>Form</SubType>
</Compile>

View File

@@ -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);
CreateDatabaseIfNotExist();
}
_sqLiteConnection = new SQLiteConnection("Data Source=" + Setting.DbLocation + ";Version=3;");
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,6 +69,7 @@ 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();
@@ -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";
_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);

View File

@@ -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<string> serialNumbers = new List<string>();
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();
}
}
}
}

View File

@@ -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());

View File

@@ -29,7 +29,7 @@ namespace Cheongbuk_MegaPark_Key_Management
};
public static int OverTime = 10;
public static int OverAmount = 1000;
public static int OverAmount = 2000;
}

View File

@@ -3,10 +3,12 @@
<package id="EntityFramework" version="6.4.4" targetFramework="net472" />
<package id="Stub.System.Data.SQLite.Core.NetFramework" version="1.0.116.0" targetFramework="net472" />
<package id="System.Buffers" version="4.4.0" targetFramework="net472" />
<package id="System.CodeDom" version="7.0.0" targetFramework="net472" />
<package id="System.Data.SQLite" version="1.0.116.0" targetFramework="net472" />
<package id="System.Data.SQLite.Core" version="1.0.116.0" targetFramework="net472" />
<package id="System.Data.SQLite.EF6" version="1.0.116.0" targetFramework="net472" />
<package id="System.Data.SQLite.Linq" version="1.0.116.0" targetFramework="net472" />
<package id="System.Management" version="7.0.0" targetFramework="net472" />
<package id="System.Memory" version="4.5.3" targetFramework="net472" />
<package id="System.Numerics.Vectors" version="4.4.0" targetFramework="net472" />
<package id="System.Runtime.CompilerServices.Unsafe" version="4.5.2" targetFramework="net472" />