From c364c0a90421f7c3ad9c487914f51e67ed06022a Mon Sep 17 00:00:00 2001 From: Crudelis Date: Tue, 17 Oct 2023 21:32:45 +0900 Subject: [PATCH] =?UTF-8?q?=EC=B6=94=EC=B2=A8=20=EB=B0=8F=20=EB=8C=80?= =?UTF-8?q?=EA=B8=B0=EC=9E=90=20=EC=88=9C=EB=B2=88=20=ED=95=A0=EB=8B=B9?= =?UTF-8?q?=EC=8B=9C=20=ED=99=94=EC=84=B1=EC=8B=9C=20=EC=9A=B0=EC=84=A0=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CustomUserControl/WaitingList.cs | 2 +- .../DataModel.cs | 1 + .../Database.cs | 234 +++++++++++------- .../Properties/AssemblyInfo.cs | 4 +- 4 files changed, 144 insertions(+), 97 deletions(-) diff --git a/HSUCO_Cargo_Garage_Operation_Program/CustomUserControl/WaitingList.cs b/HSUCO_Cargo_Garage_Operation_Program/CustomUserControl/WaitingList.cs index 4d8b139..99deed1 100644 --- a/HSUCO_Cargo_Garage_Operation_Program/CustomUserControl/WaitingList.cs +++ b/HSUCO_Cargo_Garage_Operation_Program/CustomUserControl/WaitingList.cs @@ -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++; diff --git a/HSUCO_Cargo_Garage_Operation_Program/DataModel.cs b/HSUCO_Cargo_Garage_Operation_Program/DataModel.cs index cd6173f..9080d2c 100644 --- a/HSUCO_Cargo_Garage_Operation_Program/DataModel.cs +++ b/HSUCO_Cargo_Garage_Operation_Program/DataModel.cs @@ -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 diff --git a/HSUCO_Cargo_Garage_Operation_Program/Database.cs b/HSUCO_Cargo_Garage_Operation_Program/Database.cs index acc2790..09b80b8 100644 --- a/HSUCO_Cargo_Garage_Operation_Program/Database.cs +++ b/HSUCO_Cargo_Garage_Operation_Program/Database.cs @@ -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 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(); - 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 SetUserListForApplicant(LeftAreaInformation leftAreaInformation, DateTime endDate) { - List setUserListInformations = new List(); + List tempUserList = new List(); + 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 setUserListInformationLarge = new List(); List setUserListInformationOversized = new List(); - 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 setUserListInformationFinal = new List(); @@ -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 oList = new List(); + 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 SetUserListForApplicantWait(LeftAreaInformation leftAreaInformation, DateTime endDate) { List setUserListInformations = new List(); + 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 setUserListInformationLarge = new List(); List setUserListInformationOversized = new List(); 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) diff --git a/HSUCO_Cargo_Garage_Operation_Program/Properties/AssemblyInfo.cs b/HSUCO_Cargo_Garage_Operation_Program/Properties/AssemblyInfo.cs index 7bdf103..188e53c 100644 --- a/HSUCO_Cargo_Garage_Operation_Program/Properties/AssemblyInfo.cs +++ b/HSUCO_Cargo_Garage_Operation_Program/Properties/AssemblyInfo.cs @@ -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.*")]