추첨 및 대기자 순번 할당시 화성시 우선 기능 추가

This commit is contained in:
2023-10-17 21:32:45 +09:00
parent 483aef2741
commit c364c0a904
4 changed files with 144 additions and 97 deletions

View File

@@ -65,7 +65,7 @@ namespace HSUCO_Cargo_Garage_Operation_Program.CustomUserControl
int countOversized = 1;
for (int i = 0; i < applicants.Count; i++)
{
if (applicants[i].VehicleType == 0)
if (applicants[i].VehicleType == EVehicleType.Large_Up || applicants[i].VehicleType == EVehicleType.Large_Down)
{
order = $"대형-{countLarge}";
countLarge++;

View File

@@ -168,6 +168,7 @@ namespace HSUCO_Cargo_Garage_Operation_Program
public string CargoVehicleNumber { get; set; }
public DateTime Date { get; set; }
public EVehicleType VehicleType { get; set; }
public bool Inside { get; set; }
}
public struct ResultSetUserListInformation

View File

@@ -1,9 +1,11 @@
using System;
using System.Collections.Generic;
using System.Data.SQLite;
using System.Drawing.Printing;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Windows;
namespace HSUCO_Cargo_Garage_Operation_Program
{
@@ -41,6 +43,7 @@ namespace HSUCO_Cargo_Garage_Operation_Program
""Date"" TEXT NOT NULL,
""RegistrationStatus"" INTEGER NOT NULL,
""DropDate"" TEXT,
""DropOrder"" INTEGER,
FOREIGN KEY(""UID"") REFERENCES ""UserInformation""(""UID""),
PRIMARY KEY(""No"")
);
@@ -124,7 +127,8 @@ namespace HSUCO_Cargo_Garage_Operation_Program
UI.PassengerVehicleName,
AL.Date,
AL.RegistrationStatus,
AL.DropDate
AL.DropDate,
AL.DropOrder
FROM main.ApplicantList AL INNER JOIN main.UserInformation UI ON AL.UID = UI.UID;
CREATE VIEW ViewUserList AS SELECT
@@ -355,66 +359,43 @@ namespace HSUCO_Cargo_Garage_Operation_Program
public static List<ApplicantInformation> GetApplicantWait()
{
string[] querys = new string[4];
querys[0] = $"SELECT * From ViewApplicantList Where ApplicantType={(int)EApplicantType.LotsOut} And RegistrationStatus={(int)ERegistrationStatus.Wait} AND Address LIKE '%화성시%' Order By DropDate, DropOrder, Date ASC";
querys[1] = $"SELECT * From ViewApplicantList Where ApplicantType={(int)EApplicantType.Wait} And RegistrationStatus={(int)ERegistrationStatus.Wait} AND Address LIKE '%화성시%' Order By Date ASC";
querys[2] = $"SELECT * From ViewApplicantList Where ApplicantType={(int)EApplicantType.LotsOut} And RegistrationStatus={(int)ERegistrationStatus.Wait} AND Address NOT LIKE '%화성시%' Order By DropDate, DropOrder, Date ASC";
querys[3] = $"SELECT * From ViewApplicantList Where ApplicantType={(int)EApplicantType.Wait} And RegistrationStatus={(int)ERegistrationStatus.Wait} AND Address NOT LIKE '%화성시%' Order By Date ASC";
var applicants = new List<ApplicantInformation>();
var query = $"SELECT * From ViewApplicantList Where ApplicantType={(int)EApplicantType.LotsOut} And RegistrationStatus={(int)ERegistrationStatus.Wait} Order By DropDate, Date ASC";
using (var command = _sqLiteConnection.CreateCommand())
foreach (var query in querys)
{
command.CommandText = query;
using (var reader = command.ExecuteReader())
using (var command = _sqLiteConnection.CreateCommand())
{
while (reader.Read())
command.CommandText = query;
using (var reader = command.ExecuteReader())
{
var applicant = new ApplicantInformation();
applicant.No = reader["No"].ToString();
applicant.ApplicantType = (EApplicantType)int.Parse(reader["ApplicantType"].ToString());
applicant.Owenr = (EOwner)int.Parse(reader["Owner"].ToString());
applicant.Name = reader["Name"].ToString();
applicant.PersonalNumber = reader["PersonalNumber"].ToString();
applicant.Phone = reader["Phone"].ToString();
applicant.Address = reader["Address"].ToString();
applicant.VehicleType = (EVehicleType)int.Parse(reader["VehicleType"].ToString());
applicant.CargoVehicleNumber = reader["CargoVehicleNumber"].ToString();
applicant.CargoVehicleName = reader["CargoVehicleName"].ToString();
applicant.PassengerVehicleNumber = reader["PassengerVehicleNumber"].ToString();
applicant.PassengerVehicleName = reader["PassengerVehicleName"].ToString();
while (reader.Read())
{
var applicant = new ApplicantInformation();
applicant.No = reader["No"].ToString();
applicant.ApplicantType = (EApplicantType)int.Parse(reader["ApplicantType"].ToString());
applicant.Owenr = (EOwner)int.Parse(reader["Owner"].ToString());
applicant.Name = reader["Name"].ToString();
applicant.PersonalNumber = reader["PersonalNumber"].ToString();
applicant.Phone = reader["Phone"].ToString();
applicant.Address = reader["Address"].ToString();
applicant.VehicleType = (EVehicleType)int.Parse(reader["VehicleType"].ToString());
applicant.CargoVehicleNumber = reader["CargoVehicleNumber"].ToString();
applicant.CargoVehicleName = reader["CargoVehicleName"].ToString();
applicant.PassengerVehicleNumber = reader["PassengerVehicleNumber"].ToString();
applicant.PassengerVehicleName = reader["PassengerVehicleName"].ToString();
applicant.Date = DateTime.Parse(reader["Date"].ToString());
applicant.Date = DateTime.Parse(reader["Date"].ToString());
applicants.Add(applicant);
applicants.Add(applicant);
}
}
}
}
query = $"SELECT * From ViewApplicantList Where ApplicantType={(int)EApplicantType.Wait} And RegistrationStatus={(int)ERegistrationStatus.Wait} Order By Date ASC";
using (var command = _sqLiteConnection.CreateCommand())
{
command.CommandText = query;
using (var reader = command.ExecuteReader())
{
while (reader.Read())
{
var applicant = new ApplicantInformation();
applicant.No = reader["No"].ToString();
applicant.ApplicantType = (EApplicantType)int.Parse(reader["ApplicantType"].ToString());
applicant.Owenr = (EOwner)int.Parse(reader["Owner"].ToString());
applicant.Name = reader["Name"].ToString();
applicant.PersonalNumber = reader["PersonalNumber"].ToString();
applicant.Phone = reader["Phone"].ToString();
applicant.Address = reader["Address"].ToString();
applicant.VehicleType = (EVehicleType)int.Parse(reader["VehicleType"].ToString());
applicant.CargoVehicleNumber = reader["CargoVehicleNumber"].ToString();
applicant.CargoVehicleName = reader["CargoVehicleName"].ToString();
applicant.PassengerVehicleNumber = reader["PassengerVehicleNumber"].ToString();
applicant.PassengerVehicleName = reader["PassengerVehicleName"].ToString();
applicant.Date = DateTime.Parse(reader["Date"].ToString());
applicants.Add(applicant);
}
}
}
return applicants;
}
@@ -801,7 +782,8 @@ namespace HSUCO_Cargo_Garage_Operation_Program
public static List<ResultSetUserListInformation> SetUserListForApplicant(LeftAreaInformation leftAreaInformation, DateTime endDate)
{
List<SetUserListInformation> setUserListInformations = new List<SetUserListInformation>();
List<SetUserListInformation> tempUserList = new List<SetUserListInformation>();
var query = $"SELECT * From ViewApplicantList Where ApplicantType={(int)EApplicantType.Lots} And RegistrationStatus={(int)ERegistrationStatus.Wait}";
using (var command = _sqLiteConnection.CreateCommand())
{
@@ -817,16 +799,47 @@ namespace HSUCO_Cargo_Garage_Operation_Program
setUserListInformation.Date = DateTime.Parse(reader["Date"].ToString());
setUserListInformation.VehicleType = (EVehicleType)int.Parse(reader["VehicleType"].ToString());
setUserListInformation.CargoVehicleNumber = reader["CargoVehicleNumber"].ToString();
setUserListInformations.Add(setUserListInformation);
string address = reader["Address"].ToString();
setUserListInformation.Inside = address.IndexOf("화성시") != -1;
tempUserList.Add(setUserListInformation);
}
}
}
setUserListInformations.Shuffle(); // 랜덤화 시킨다
// 사용자 랜덤
tempUserList.Shuffle();
int countInsideLarge = tempUserList.Count( x => x.Inside && x.VehicleType == EVehicleType.Large_Up || x.VehicleType == EVehicleType.Large_Down);
int countInsideOversized = tempUserList.Count(x => x.Inside && x.VehicleType == EVehicleType.Oversized_Up || x.VehicleType == EVehicleType.Oversized_Down);
List<SetUserListInformation> setUserListInformationLarge = new List<SetUserListInformation>();
List<SetUserListInformation> setUserListInformationOversized = new List<SetUserListInformation>();
setUserListInformationLarge.AddRange(setUserListInformations.Where(x => x.VehicleType == EVehicleType.Large_Down || x.VehicleType == EVehicleType.Large_Up).Take(leftAreaInformation.Large.Count));
setUserListInformationOversized.AddRange(setUserListInformations.Where(x => x.VehicleType == EVehicleType.Oversized_Down || x.VehicleType == EVehicleType.Oversized_Up).Take(leftAreaInformation.OverSized.Count));
// Large 차량들이 남은 자리보다 작을때
if(leftAreaInformation.Large.Count > countInsideLarge)
{
int tmepCount = leftAreaInformation.Large.Count - countInsideLarge;
setUserListInformationLarge.AddRange(tempUserList.Where(x => x.Inside && x.VehicleType == EVehicleType.Large_Up || x.VehicleType == EVehicleType.Large_Down));
setUserListInformationLarge.AddRange(tempUserList.Where(x => !x.Inside && x.VehicleType == EVehicleType.Large_Up || x.VehicleType == EVehicleType.Large_Down).Take(tmepCount));
}
else // 화성시만으로 자리가 꽉참
{
setUserListInformationLarge.AddRange(tempUserList.Where(x => x.Inside && x.VehicleType == EVehicleType.Large_Up || x.VehicleType == EVehicleType.Large_Down).Take(leftAreaInformation.Large.Count));
}
// OverSized 차량들이 남은 자리보다 적을때
if(leftAreaInformation.OverSized.Count > countInsideOversized)
{
int tmepCount = leftAreaInformation.OverSized.Count - countInsideOversized;
setUserListInformationOversized.AddRange(tempUserList.Where(x => x.Inside && x.VehicleType == EVehicleType.Large_Up || x.VehicleType == EVehicleType.Large_Down));
setUserListInformationOversized.AddRange(tempUserList.Where(x => !x.Inside && x.VehicleType == EVehicleType.Large_Up || x.VehicleType == EVehicleType.Large_Down).Take(tmepCount));
}
else // 화성
{
setUserListInformationOversized.AddRange(tempUserList.Where(x => x.Inside && x.VehicleType == EVehicleType.Large_Up || x.VehicleType == EVehicleType.Large_Down).Take(leftAreaInformation.OverSized.Count));
}
List<SetUserListInformation> setUserListInformationFinal = new List<SetUserListInformation>();
@@ -844,13 +857,34 @@ namespace HSUCO_Cargo_Garage_Operation_Program
}
var result = SetUserList(setUserListInformationFinal, leftAreaInformation.StartDateTime, endDate);
// 남은 사람 대기로
query = $"UPDATE ApplicantList SET ApplicantType={(int)EApplicantType.LotsOut} Where ApplicantType={(int)EApplicantType.Lots} And RegistrationStatus={(int)ERegistrationStatus.Wait}";
List<string> oList = new List<string>();
query = $"SELECT * FROM ApplicantList Where ApplicantType={(int)EApplicantType.Lots} And RegistrationStatus={(int)ERegistrationStatus.Wait}";
using (var command = _sqLiteConnection.CreateCommand())
{
command.CommandText = query;
command.ExecuteNonQuery();
using (var reader = command.ExecuteReader())
{
while (reader.Read())
{
string no = reader["No"].ToString();
oList.Add(no);
}
}
}
oList.Shuffle();
// 랜덤
DateTime dropDate = DateTime.Now;
int lastDropOrder = GetLastDropOrder(dropDate);
lastDropOrder++;
for (int i = 0; i < oList.Count; i++)
{
query = $"UPDATE ApplicantList SET ApplicantType={(int)EApplicantType.LotsOut}, DropDate='{dropDate.DateTimeDatabase()}' , DropOrder={lastDropOrder + i} WHERE No='{oList[i]}'";
using (var command = _sqLiteConnection.CreateCommand())
{
command.CommandText = query;
command.ExecuteNonQuery();
}
}
return result;
@@ -884,44 +918,38 @@ namespace HSUCO_Cargo_Garage_Operation_Program
public static List<ResultSetUserListInformation> SetUserListForApplicantWait(LeftAreaInformation leftAreaInformation, DateTime endDate)
{
List<SetUserListInformation> setUserListInformations = new List<SetUserListInformation>();
string[] querys = new string[4];
querys[0] = $"SELECT * From ViewApplicantList Where ApplicantType={(int)EApplicantType.LotsOut} And RegistrationStatus={(int)ERegistrationStatus.Wait} AND Address LIKE '%화성시%' Order By DropDate, DropOrder, Date ASC";
querys[1] = $"SELECT * From ViewApplicantList Where ApplicantType={(int)EApplicantType.Wait} And RegistrationStatus={(int)ERegistrationStatus.Wait} AND Address LIKE '%화성시%' Order By Date ASC";
querys[2] = $"SELECT * From ViewApplicantList Where ApplicantType={(int)EApplicantType.LotsOut} And RegistrationStatus={(int)ERegistrationStatus.Wait} AND Address NOT LIKE '%화성시%' Order By DropDate, DropOrder, Date ASC";
querys[3] = $"SELECT * From ViewApplicantList Where ApplicantType={(int)EApplicantType.Wait} And RegistrationStatus={(int)ERegistrationStatus.Wait} AND Address NOT LIKE '%화성시%' Order By Date ASC";
// 저번에 떨어진 사람들 리스트
var query = $"SELECT * From ViewApplicantList Where ApplicantType={(int)EApplicantType.LotsOut} And RegistrationStatus={(int)ERegistrationStatus.Wait} Order By DropDate, Date ASC ";
using (var command = _sqLiteConnection.CreateCommand())
// 순위 정립 1. 화성시 떨어짐, 2. 대기 화성시, 3. 그외 떨어짐, 4. 그외 대기
foreach (var query in querys)
{
command.CommandText = query;
using (var reader = command.ExecuteReader())
using (var command = _sqLiteConnection.CreateCommand())
{
while (reader.Read())
command.CommandText = query;
using (var reader = command.ExecuteReader())
{
SetUserListInformation setUserListInformation = new SetUserListInformation();
setUserListInformation.ApplicantNo = reader["No"].ToString();
setUserListInformation.UID = int.Parse(reader["UID"].ToString());
setUserListInformation.Date = DateTime.Parse(reader["Date"].ToString());
setUserListInformation.VehicleType = (EVehicleType)int.Parse(reader["VehicleType"].ToString());
setUserListInformations.Add(setUserListInformation);
while (reader.Read())
{
SetUserListInformation setUserListInformation = new SetUserListInformation();
setUserListInformation.ApplicantNo = reader["No"].ToString();
setUserListInformation.UID = int.Parse(reader["UID"].ToString());
setUserListInformation.Date = DateTime.Parse(reader["Date"].ToString());
setUserListInformation.VehicleType = (EVehicleType)int.Parse(reader["VehicleType"].ToString());
setUserListInformation.CargoVehicleNumber = reader["CargoVehicleNumber"].ToString();
string address = reader["Address"].ToString();
setUserListInformation.Inside = address.IndexOf("화성시") != -1;
setUserListInformations.Add(setUserListInformation);
}
}
}
}
query = $"SELECT * From ViewApplicantList Where ApplicantType={(int)EApplicantType.Wait} And RegistrationStatus={(int)ERegistrationStatus.Wait} Order By Date ASC";
using (var command = _sqLiteConnection.CreateCommand())
{
command.CommandText = query;
using (var reader = command.ExecuteReader())
{
while (reader.Read())
{
SetUserListInformation setUserListInformation = new SetUserListInformation();
setUserListInformation.ApplicantNo = reader["No"].ToString();
setUserListInformation.UID = int.Parse(reader["UID"].ToString());
setUserListInformation.Date = DateTime.Parse(reader["Date"].ToString());
setUserListInformation.VehicleType = (EVehicleType)int.Parse(reader["VehicleType"].ToString());
setUserListInformation.CargoVehicleNumber = reader["CargoVehicleNumber"].ToString();
setUserListInformations.Add(setUserListInformation);
}
}
}
List<SetUserListInformation> setUserListInformationLarge = new List<SetUserListInformation>();
List<SetUserListInformation> setUserListInformationOversized = new List<SetUserListInformation>();
setUserListInformationLarge.AddRange(setUserListInformations.Where(x => x.VehicleType == EVehicleType.Large_Down || x.VehicleType == EVehicleType.Large_Up).Take(leftAreaInformation.Large.Count));
@@ -1208,7 +1236,26 @@ namespace HSUCO_Cargo_Garage_Operation_Program
}
return lastNo;
}
public static int GetLastDropOrder(DateTime DropDate)
{
var lastDropOrder = 0;
var query = $"SELECT DropOrder FROM ApplicantList WHERE DropDate='{DropDate.DateTimeDatabase()}' ORDER BY DropOrder DESC LIMIT 1";
using (var command = _sqLiteConnection.CreateCommand())
{
command.CommandText = query;
using (var reader = command.ExecuteReader())
{
while (reader.Read())
{
var dropOrder = reader["DropOrder"].ToString();
lastDropOrder = Convert.ToInt32(dropOrder);
}
}
}
return lastDropOrder;
}
public static bool SetCertificate(SetCertificateInformation setCertificateInformation)
{
var query =
@@ -1330,10 +1377,9 @@ namespace HSUCO_Cargo_Garage_Operation_Program
LeftUserInformation leftUserInformation = new LeftUserInformation();
leftUserInformation.Large = 0;
leftUserInformation.OverSized = 0;
var query = $"SELECT VehicleType , COUNT(VehicleType) as Count From ViewApplicantList Where ApplicantType={(int)EApplicantType.LotsOut} And RegistrationStatus={(int)ERegistrationStatus.Wait} Group By VehicleType";
leftUserInformation = GetLeftUser(startDateTime, leftUserInformation, query);
query = $"SELECT VehicleType , COUNT(VehicleType) as Count From ViewApplicantList Where ApplicantType={(int)EApplicantType.Wait} And RegistrationStatus={(int)ERegistrationStatus.Wait} Group By VehicleType";
var query = $"SELECT VehicleType , COUNT(VehicleType) as Count From ViewApplicantList Where (ApplicantType={(int)EApplicantType.LotsOut} OR ApplicantType={(int)EApplicantType.Wait}) And RegistrationStatus={(int)ERegistrationStatus.Wait} Group By VehicleType";
leftUserInformation = GetLeftUser(startDateTime, leftUserInformation, query);
return leftUserInformation;
}
public static LeftUserInformation GetLeftUser(DateTime startDateTime, LeftUserInformation leftUserInformation, string query)

View File

@@ -31,5 +31,5 @@ using System.Runtime.InteropServices;
// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호를
// 기본값으로 할 수 있습니다.
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.*")]
[assembly: AssemblyFileVersion("1.1.*")]
[assembly: AssemblyVersion("1.2.*")]
[assembly: AssemblyFileVersion("1.2.*")]