From 81f3e69513cfddcd2e9c323d9b718ad526c2a826 Mon Sep 17 00:00:00 2001 From: Crudelis Date: Sun, 24 Sep 2023 01:03:18 +0900 Subject: [PATCH] =?UTF-8?q?=ED=99=98=EB=B6=88=EC=B2=98=EB=A6=AC=20?= =?UTF-8?q?=EC=9E=91=EC=97=85=20=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CustomForm/Refund.Designer.cs | 147 ++++++++++++++++++ .../CustomForm/Refund.cs | 50 ++++++ .../CustomForm/Refund.resx | 120 ++++++++++++++ .../CustomUserControl/UserList.cs | 97 +++++++++++- .../DataModel.cs | 13 ++ .../Database.cs | 88 ++++++++++- .../Extends.cs | 27 +++- ...SUCO_Cargo_Garage_Operation_Program.csproj | 9 ++ 8 files changed, 538 insertions(+), 13 deletions(-) create mode 100644 HSUCO_Cargo_Garage_Operation_Program/CustomForm/Refund.Designer.cs create mode 100644 HSUCO_Cargo_Garage_Operation_Program/CustomForm/Refund.cs create mode 100644 HSUCO_Cargo_Garage_Operation_Program/CustomForm/Refund.resx diff --git a/HSUCO_Cargo_Garage_Operation_Program/CustomForm/Refund.Designer.cs b/HSUCO_Cargo_Garage_Operation_Program/CustomForm/Refund.Designer.cs new file mode 100644 index 0000000..339f35b --- /dev/null +++ b/HSUCO_Cargo_Garage_Operation_Program/CustomForm/Refund.Designer.cs @@ -0,0 +1,147 @@ +namespace HSUCO_Cargo_Garage_Operation_Program.CustomForm +{ + partial class Refund + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.metroLabel1 = new MetroFramework.Controls.MetroLabel(); + this.metroDateTime_Refund = new MetroFramework.Controls.MetroDateTime(); + this.metroButton_Refund = new MetroFramework.Controls.MetroButton(); + this.metroButton_Cancel = new MetroFramework.Controls.MetroButton(); + this.metroLabel_DateStart = new MetroFramework.Controls.MetroLabel(); + this.metroLabel_DateEnd = new MetroFramework.Controls.MetroLabel(); + this.metroLabel4 = new MetroFramework.Controls.MetroLabel(); + this.metroLabel5 = new MetroFramework.Controls.MetroLabel(); + this.SuspendLayout(); + // + // metroLabel1 + // + this.metroLabel1.AutoSize = true; + this.metroLabel1.Location = new System.Drawing.Point(58, 146); + this.metroLabel1.Name = "metroLabel1"; + this.metroLabel1.Size = new System.Drawing.Size(83, 19); + this.metroLabel1.TabIndex = 0; + this.metroLabel1.Text = "환불 시작일"; + // + // metroDateTime_Refund + // + this.metroDateTime_Refund.Location = new System.Drawing.Point(183, 159); + this.metroDateTime_Refund.MinimumSize = new System.Drawing.Size(0, 29); + this.metroDateTime_Refund.Name = "metroDateTime_Refund"; + this.metroDateTime_Refund.Size = new System.Drawing.Size(200, 29); + this.metroDateTime_Refund.TabIndex = 1; + // + // metroButton_Refund + // + this.metroButton_Refund.FontSize = MetroFramework.MetroButtonSize.Tall; + this.metroButton_Refund.Location = new System.Drawing.Point(44, 212); + this.metroButton_Refund.Name = "metroButton_Refund"; + this.metroButton_Refund.Size = new System.Drawing.Size(170, 50); + this.metroButton_Refund.TabIndex = 37; + this.metroButton_Refund.Text = "환 불"; + this.metroButton_Refund.UseSelectable = true; + this.metroButton_Refund.Click += new System.EventHandler(this.metroButton_Refund_Click); + // + // metroButton_Cancel + // + this.metroButton_Cancel.FontSize = MetroFramework.MetroButtonSize.Tall; + this.metroButton_Cancel.Location = new System.Drawing.Point(258, 221); + this.metroButton_Cancel.Name = "metroButton_Cancel"; + this.metroButton_Cancel.Size = new System.Drawing.Size(170, 50); + this.metroButton_Cancel.TabIndex = 38; + this.metroButton_Cancel.Text = "취 소"; + this.metroButton_Cancel.UseSelectable = true; + this.metroButton_Cancel.Click += new System.EventHandler(this.metroButton_Cancel_Click); + // + // metroLabel_DateStart + // + this.metroLabel_DateStart.AutoSize = true; + this.metroLabel_DateStart.Location = new System.Drawing.Point(197, 74); + this.metroLabel_DateStart.Name = "metroLabel_DateStart"; + this.metroLabel_DateStart.Size = new System.Drawing.Size(83, 19); + this.metroLabel_DateStart.TabIndex = 39; + this.metroLabel_DateStart.Text = "환불 시작일"; + // + // metroLabel_DateEnd + // + this.metroLabel_DateEnd.AutoSize = true; + this.metroLabel_DateEnd.Location = new System.Drawing.Point(197, 93); + this.metroLabel_DateEnd.Name = "metroLabel_DateEnd"; + this.metroLabel_DateEnd.Size = new System.Drawing.Size(83, 19); + this.metroLabel_DateEnd.TabIndex = 40; + this.metroLabel_DateEnd.Text = "환불 시작일"; + // + // metroLabel4 + // + this.metroLabel4.AutoSize = true; + this.metroLabel4.Location = new System.Drawing.Point(50, 74); + this.metroLabel4.Name = "metroLabel4"; + this.metroLabel4.Size = new System.Drawing.Size(83, 19); + this.metroLabel4.TabIndex = 41; + this.metroLabel4.Text = "환불 시작일"; + // + // metroLabel5 + // + this.metroLabel5.AutoSize = true; + this.metroLabel5.Location = new System.Drawing.Point(50, 93); + this.metroLabel5.Name = "metroLabel5"; + this.metroLabel5.Size = new System.Drawing.Size(83, 19); + this.metroLabel5.TabIndex = 42; + this.metroLabel5.Text = "환불 시작일"; + // + // Refund + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.metroLabel5); + this.Controls.Add(this.metroLabel4); + this.Controls.Add(this.metroLabel_DateEnd); + this.Controls.Add(this.metroLabel_DateStart); + this.Controls.Add(this.metroButton_Cancel); + this.Controls.Add(this.metroButton_Refund); + this.Controls.Add(this.metroDateTime_Refund); + this.Controls.Add(this.metroLabel1); + this.Name = "Refund"; + this.Text = "Refund"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private MetroFramework.Controls.MetroLabel metroLabel1; + private MetroFramework.Controls.MetroDateTime metroDateTime_Refund; + private MetroFramework.Controls.MetroButton metroButton_Refund; + private MetroFramework.Controls.MetroButton metroButton_Cancel; + private MetroFramework.Controls.MetroLabel metroLabel_DateStart; + private MetroFramework.Controls.MetroLabel metroLabel_DateEnd; + private MetroFramework.Controls.MetroLabel metroLabel4; + private MetroFramework.Controls.MetroLabel metroLabel5; + } +} \ No newline at end of file diff --git a/HSUCO_Cargo_Garage_Operation_Program/CustomForm/Refund.cs b/HSUCO_Cargo_Garage_Operation_Program/CustomForm/Refund.cs new file mode 100644 index 0000000..3bc5e62 --- /dev/null +++ b/HSUCO_Cargo_Garage_Operation_Program/CustomForm/Refund.cs @@ -0,0 +1,50 @@ +using MetroFramework; +using MetroFramework.Forms; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace HSUCO_Cargo_Garage_Operation_Program.CustomForm +{ + public partial class Refund : MetroForm + { + public DateTime RefundDateTime { get; set; } + private GetRefundInformation _getRefundInformation; + public Refund(GetRefundInformation getRefundInformation) + { + InitializeComponent(); + _getRefundInformation = getRefundInformation; + metroLabel_DateStart.Text = _getRefundInformation.DateStart.ToString("yyyy-MM- dd"); + metroLabel_DateEnd.Text = _getRefundInformation.DateEnd.ToString("yyyy-MM- dd"); + } + + private void metroButton_Refund_Click(object sender, EventArgs e) + { + if(metroDateTime_Refund.Value > _getRefundInformation.DateEnd) + { + MetroMessageBox.Show(this, "환불일이 종료일 보다 큽니다.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + metroDateTime_Refund.Focus(); + return; + } + if(metroDateTime_Refund.Value < DateTime.Now.Date) + { + MetroMessageBox.Show(this, "환불일이 현재시간보다 이릅니다.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + metroDateTime_Refund.Focus(); + return; + } + RefundDateTime = metroDateTime_Refund.Value.Date; + DialogResult = DialogResult.OK; + } + + private void metroButton_Cancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + } + } +} diff --git a/HSUCO_Cargo_Garage_Operation_Program/CustomForm/Refund.resx b/HSUCO_Cargo_Garage_Operation_Program/CustomForm/Refund.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/HSUCO_Cargo_Garage_Operation_Program/CustomForm/Refund.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/HSUCO_Cargo_Garage_Operation_Program/CustomUserControl/UserList.cs b/HSUCO_Cargo_Garage_Operation_Program/CustomUserControl/UserList.cs index c38be22..f3fc42a 100644 --- a/HSUCO_Cargo_Garage_Operation_Program/CustomUserControl/UserList.cs +++ b/HSUCO_Cargo_Garage_Operation_Program/CustomUserControl/UserList.cs @@ -187,14 +187,97 @@ namespace HSUCO_Cargo_Garage_Operation_Program.CustomUserControl private void metroButton_Refund_Click(object sender, EventArgs e) { - var allCount = dataGridView_List.SelectedRows.Count; - if (allCount == 0) return; + var count = dataGridView_List.SelectedRows.Count; + if (count == 0) return; + string no = dataGridView_List.SelectedRows[0].Cells[0].Value.ToString(); + GetRefundInformation getRefundInformation = Database.GetRefundData(no); + if (getRefundInformation.RefundStatus) + { + MetroMessageBox.Show(this, "이미 환불된 사용자 입니다.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + Refund refund = new Refund(getRefundInformation); + refund.ShowDialog(); + if(refund.DialogResult != DialogResult.OK) + { + return; + + } + DateTime refundDateTime = refund.RefundDateTime; + + int totalAmount = 0; + + // 연장여부 + // 이용 전 이면 + if(getRefundInformation.DateStart > refundDateTime) + { + refundDateTime = getRefundInformation.DateStart; + + totalAmount += getRefundInformation.BaseFee; + if(getRefundInformation.ExtensionStatus) + { + totalAmount += getRefundInformation.ExtensionFee; + } + } + else if(getRefundInformation.ExtensionStatus) + { + //연장일 보다 환불일이 늦는경우(연장에 부분만 일자 계산후 정산) + if (getRefundInformation.ExtensionStart < refundDateTime) + { + // 연장 시작 부와 비교 + var leftDays = (getRefundInformation.DateEnd - refundDateTime).TotalDays + 1; + int leftAmount = (getRefundInformation.ExtensionFee / 365) * (int)leftDays; + if (leftAmount > 0) + { + leftAmount = leftAmount / 10 * 10; + } + totalAmount += leftAmount; + // 연장부분만 계산 + + } + else + { + // 최초 이용일에서 남은 이용일 게산 + var leftDays = (getRefundInformation.ExtensionStart.AddDays(-1) - refundDateTime).TotalDays + 1; + int leftAmount = (getRefundInformation.BaseFee / 365) * (int)leftDays; + if(leftAmount > 0) + { + leftAmount = leftAmount / 10 * 10; + } + totalAmount += leftAmount; + totalAmount += getRefundInformation.ExtensionFee; + } + // 연장한 경우 + } + else + { + + // 연장안한경우 + var leftDays = (getRefundInformation.DateEnd - refundDateTime).TotalDays + 1; + int leftAmount = (getRefundInformation.ExtensionFee / 365) * (int)leftDays; + if (leftAmount > 0) + { + leftAmount = leftAmount / 10 * 10; + } + totalAmount += leftAmount; + } + + DialogResult dialogResult = MetroMessageBox.Show(this, $"환불 처리 하시겟습니까?\r\n 환불 금액 : {String.Format("{0:n0}", totalAmount)}원", "환불", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); + + if(dialogResult == DialogResult.OK) + { + bool result = Database.SetRefund(no, refundDateTime, totalAmount); + if(result) + { + MetroMessageBox.Show(this, "환불처리가 완료되었습니다.", "환불", MessageBoxButtons.OK, MessageBoxIcon.Information); + DataChange(); + } + else + { + MetroMessageBox.Show(this, "환불처리가 실패하였습니다.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } - // 연장 Y N - // 연장일을 사용중인가 Y N - 사용중이면 일반 금액은 계산하지 않음, - // - // TODO: 환불시 금액은 남은 이용일 일활 계산 - // 이 사람의 결제 금액 가져오기 -> 남은 일수 만큼 나누고 원단위 올림처리 연장 되었을경우 까지 처리 } private void metroButton_Certificate_Click(object sender, EventArgs e) diff --git a/HSUCO_Cargo_Garage_Operation_Program/DataModel.cs b/HSUCO_Cargo_Garage_Operation_Program/DataModel.cs index d864e2b..f017d63 100644 --- a/HSUCO_Cargo_Garage_Operation_Program/DataModel.cs +++ b/HSUCO_Cargo_Garage_Operation_Program/DataModel.cs @@ -123,6 +123,19 @@ namespace HSUCO_Cargo_Garage_Operation_Program public string Phone { get; set; } // 연락처 public string Address { get; set; } // 주소 } + public struct GetRefundInformation + { + + public bool RefundStatus { get; set; } + public DateTime DateStart { get; set; } + public DateTime DateEnd { get; set; } + public bool ExtensionStatus { get; set; } + public DateTime ExtensionStart { get; set; } + public int BaseFee { get; set; } + public int ExtensionFee { get; set; } + + } + public struct Settings { public string GarageName { get; set; } diff --git a/HSUCO_Cargo_Garage_Operation_Program/Database.cs b/HSUCO_Cargo_Garage_Operation_Program/Database.cs index 9a430d7..7cde611 100644 --- a/HSUCO_Cargo_Garage_Operation_Program/Database.cs +++ b/HSUCO_Cargo_Garage_Operation_Program/Database.cs @@ -189,7 +189,7 @@ namespace HSUCO_Cargo_Garage_Operation_Program string no = $"{year}-{suffix}{lastNo}"; var query = - $"INSERT INTO ApplicantList VALUES('{no}, {applicant.ApplicantType.BoolToInt()}','{applicant.CargoVehicleNumber}','{applicant.CargoVehicleName}','{applicant.PassengerVehicleNumber}','{applicant.PassengerVehicleName}','{(int)applicant.VehicleType}','{applicant.Name}','{applicant.PersonalNumber}','{applicant.Phone}','{applicant.Address}','{applicant.DateOfApplication.DateTimeDatabase()}',0) "; + $"INSERT INTO ApplicantList VALUES('{no}', '{applicant.ApplicantType.BoolToInt()}','{applicant.CargoVehicleNumber}','{applicant.CargoVehicleName}','{applicant.PassengerVehicleNumber}','{applicant.PassengerVehicleName}','{(int)applicant.VehicleType}','{applicant.Name}','{applicant.PersonalNumber}','{applicant.Phone}','{applicant.Address}','{applicant.DateOfApplication.DateTimeDatabase()}', 0)"; int insertResult; using (var command = _sqLiteConnection.CreateCommand()) @@ -440,11 +440,7 @@ namespace HSUCO_Cargo_Garage_Operation_Program public static void UpdateExtended(string no, int amount) { - // Userlist ExtensionStatus, ExtensionStart - // UserListHistor "UserNo" TEXT NOT NULL, "HistoryCode" INTEGER NOT NULL, "HistoryDate" TEXT NOT NULL, "HistoryAmount" INTEGER NOT NULL, - //CREATE TABLE "LedgerProceeds" ( "UserNo" TEXT NOT NULL, "Type" INTEGER NOT NULL, "Amount" INTEGER NOT NULL, "Date" TEXT NOT NULL, - // 일단 EndDate var query = $"SELECT DateEnd From UserList Where No='{no}'"; DateTime endDateTime = DateTime.Now; using (var command = _sqLiteConnection.CreateCommand()) @@ -496,7 +492,89 @@ namespace HSUCO_Cargo_Garage_Operation_Program } return; } + public static GetRefundInformation GetRefundData(string no) + { + GetRefundInformation getRefundInformation = new GetRefundInformation(); + // RefundStatus DateStart DateEnd ExtensionStatus ExtensionStart BaseFee ExtensionFee + var query = $"SELECT RefundStatus, DateStart, DateEnd, ExtensionStatus, ExtensionStart From UserList Where No='{no}'"; + using (var command = _sqLiteConnection.CreateCommand()) + { + command.CommandText = query; + using (var reader = command.ExecuteReader()) + { + while (reader.Read()) + { + getRefundInformation.RefundStatus = reader["RefundStatus"].ToString() == "1"; + getRefundInformation.DateStart = DateTime.Parse(reader["DateStart"].ToString()); + getRefundInformation.DateEnd = DateTime.Parse(reader["DateEnd"].ToString()); + getRefundInformation.ExtensionStatus = reader["ExtensionStatus"].ToString() == "1"; + if (getRefundInformation.ExtensionStatus) + { + getRefundInformation.ExtensionStart = DateTime.Parse(reader["ExtensionStart"].ToString()); + } + } + } + } + query = $"SELECT Type, Amount From LedgerProceeds Where UserNo='{no}'"; + using (var command = _sqLiteConnection.CreateCommand()) + { + command.CommandText = query; + using (var reader = command.ExecuteReader()) + { + while (reader.Read()) + { + EProceedsType eProceedsType = (EProceedsType)int.Parse(reader["Type"].ToString()); + int amount = int.Parse(reader["Amount"].ToString()); + if (eProceedsType == EProceedsType.Fees) + { + getRefundInformation.BaseFee = amount; + } + if (eProceedsType == EProceedsType.ExtensionFees) + { + getRefundInformation.ExtensionFee = amount; + } + } + } + } + return getRefundInformation; + } + public static bool SetRefund(string no, DateTime refundDate, int amount) + { + var query = $"UPDATE UserList Set DateEnd='{refundDate.AddDays(-1).EndDateTime()}', RefundStatus={true.BoolToInt()} Where No='{no}'"; + using (var command = _sqLiteConnection.CreateCommand()) + { + command.CommandText = query; + int result = command.ExecuteNonQuery(); + if (result < 1) + { + return false; + } + } + + query = $"INSERT INTO UserListHistory(UserNo, HistoryCode, HistoryDate, HistoryAmount) VALUES('{no}',{(int)EHistoryCode.Refund},'{DateTime.Now.DateTimeDatabase()}',{-amount})"; + using (var command = _sqLiteConnection.CreateCommand()) + { + command.CommandText = query; + int result = command.ExecuteNonQuery(); + if (result < 1) + { + return false; + } + } + query = $"INSERT INTO LedgerProceeds(UserNo, Type, Amount, Date) Values('{no}',{(int)EProceedsType.Refunds},{-amount},'{DateTime.Now}')"; + using (var command = _sqLiteConnection.CreateCommand()) + { + command.CommandText = query; + int result = command.ExecuteNonQuery(); + if (result < 1) + { + return false; + } + } + + return true; + } public static List GetApplicantList(List CargoVehicleNumber) { var applicants = new List(); diff --git a/HSUCO_Cargo_Garage_Operation_Program/Extends.cs b/HSUCO_Cargo_Garage_Operation_Program/Extends.cs index 99f6453..6b2e2d4 100644 --- a/HSUCO_Cargo_Garage_Operation_Program/Extends.cs +++ b/HSUCO_Cargo_Garage_Operation_Program/Extends.cs @@ -4,30 +4,55 @@ namespace HSUCO_Cargo_Garage_Operation_Program { public static class Extends { + /// + /// Database 저장용 Date와 Time 존재 + /// + /// + /// public static string DateTimeDatabase(this DateTime dateTime) { return dateTime.ToString("yyyy-MM-dd hh:mm:ss"); } + /// + /// 시간이 00:00:00 으로 된 버전 + /// + /// + /// public static string DateOnly(this DateTime date) { return date.ToString("yyyy-MM-dd 00:00:00"); } + /// + /// 시간이 00:00:00 으로 변경하여 출력 + /// + /// + /// public static string StartDateTime(this DateTime date) { return $"{date.Year:D4}-{date.Month:D2}-{date.Day:D2} 00:00:00"; } - + /// + /// 시간이 23:59:59 으로 변경하여 출력 + /// + /// + /// public static string EndDateTime(this DateTime date) { return $"{date.Year:D4}-{date.Month:D2}-{date.Day:D2} 23:59:59"; } + public static int BoolToInt(this bool value) { return value ? 1 : 0; } + + public static int LeftArea(int count, DateTime dateTime) + { + + } } } diff --git a/HSUCO_Cargo_Garage_Operation_Program/HSUCO_Cargo_Garage_Operation_Program.csproj b/HSUCO_Cargo_Garage_Operation_Program/HSUCO_Cargo_Garage_Operation_Program.csproj index a5374fe..3850260 100644 --- a/HSUCO_Cargo_Garage_Operation_Program/HSUCO_Cargo_Garage_Operation_Program.csproj +++ b/HSUCO_Cargo_Garage_Operation_Program/HSUCO_Cargo_Garage_Operation_Program.csproj @@ -92,6 +92,12 @@ Promotion.cs + + Form + + + Refund.cs + Form @@ -164,6 +170,9 @@ Promotion.cs + + Refund.cs + UpdateUserData.cs