@@ -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 . A pplicantType = ( E ApplicantType ) int . Parse ( reader [ "ApplicantType" ] . ToString ( ) ) ;
applicant . Owenr = ( EOwner ) int . Parse ( reader [ "Owner " ] . ToString ( ) ) ;
applicant . Name = reader [ "Nam e" ] . ToString ( ) ;
applicant . PersonalNumber = reader [ "PersonalNumb er" ] . ToString ( ) ;
applicant . Phon e = reader [ "Phon e" ] . ToString ( ) ;
applicant . Address = reader [ "Address " ] . ToString ( ) ;
applicant . VehicleType = ( EVehicleType ) int . Parse ( reader [ "VehicleTyp e" ] . ToString ( ) ) ;
applicant . CargoVehicleNumber = reader [ "CargoVehicleNumber " ] . ToString ( ) ;
applicant . Cargo VehicleNam e = reader [ "Cargo VehicleNam e" ] . ToString ( ) ;
applicant . Passenger VehicleNumber = reader [ "Passenger VehicleNumber" ] . ToString ( ) ;
applicant . Passenger VehicleName = reader [ "Passenger VehicleName" ] . ToString ( ) ;
while ( reader . Read ( ) )
{
var a pplicant = new ApplicantInformation ( ) ;
applicant . No = reader [ "No " ] . ToString ( ) ;
applicant . ApplicantType = ( EApplicantType ) int . Parse ( reader [ "ApplicantTyp e" ] . ToString ( ) ) ;
applicant . Owenr = ( EOwner ) int . Parse ( reader [ "Own er" ] . ToString ( ) ) ;
applicant . Nam e = reader [ "Nam e" ] . ToString ( ) ;
applicant . PersonalNumber = reader [ "PersonalNumber " ] . ToString ( ) ;
applicant . Phone = reader [ "Phon e" ] . ToString ( ) ;
applicant . Address = reader [ "Address " ] . ToString ( ) ;
applicant . VehicleTyp e = ( EVehicleType ) int . Parse ( reader [ "VehicleTyp e" ] . ToString ( ) ) ;
applicant . Cargo VehicleNumber = reader [ "Cargo VehicleNumber" ] . ToString ( ) ;
applicant . Cargo VehicleName = reader [ "Cargo VehicleName" ] . 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 > set UserListInformations = new List < SetUserListInformation > ( ) ;
List < SetUserListInformation > temp UserList = 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 ( setUserList Informations . Wher e( x = > x . VehicleType = = EVehicleType . Oversized_Down | | x . VehicleType = = EVehicleType . Oversized_Up ) . Take ( leftAreaInformation . OverSized . Count ) ) ;
// Large 차량들이 남은 자리보다 작을때
if ( leftArea Information. Larg e. 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 ( ) ;
s etUserListInformation. 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 ( ) )
{
S etUserListInformation 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 )