This repository has been archived by the owner on Dec 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRegistrarPagosDeEventos.cs
176 lines (152 loc) · 6.26 KB
/
RegistrarPagosDeEventos.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Windows.Forms;
namespace ShowTime_DatabseProject
{
public partial class RegistrarPagosDeEventos : Form
{
private readonly string connectionString = ConfigurationManager.ConnectionStrings["connection_S"].ConnectionString;
public RegistrarPagosDeEventos()
{
InitializeComponent();
LoadEventosData();
LoadMetodosPago();
ConfigureUI();
}
/// <summary>
/// Configura la interfaz de usuario (botones y posiciones).
/// </summary>
private void ConfigureUI()
{
this.StartPosition = FormStartPosition.CenterScreen;
Color baseColor = Color.FromArgb(18, 29, 36);
Color hoverColor = Color.FromArgb(10, 180, 180, 180);
Utils.AgregarBordeInferiorConHover(btnRealizarPagos, baseColor, 3, hoverColor, Color.Black);
Utils.AgregarBordeInferiorConHover(CloseButton, baseColor, 3, hoverColor, Color.Black);
}
/// <summary>
/// Cierra el formulario.
/// </summary>
private void CloseButton_Click(object sender, EventArgs e)
{
this.Close();
}
/// <summary>
/// Carga los eventos junto con el monto pendiente de pago en el DataGridView.
/// </summary>
private void LoadEventosData()
{
const string query = @"
SELECT
e.Id_evento,
c.Nombre AS Cliente,
e.Fecha_inicio,
e.Detalles_adicionales,
e.Costo_total,
dbo.CalcularPagoRestante(e.Id_evento) AS PagoRestante
FROM
Eventos e
INNER JOIN
Clientes c ON e.Id_cliente = c.Id_cliente
ORDER BY
e.Fecha_reserva DESC";
try
{
using (var connection = new SqlConnection(connectionString))
{
connection.Open();
var adapter = new SqlDataAdapter(query, connection);
var dataTable = new DataTable();
adapter.Fill(dataTable);
// Asignar los datos al DataGridView
dgvEventos.DataSource = dataTable;
if (dgvEventos.Columns["Id_evento"] != null)
dgvEventos.Columns["Id_evento"].Visible = false;
}
}
catch (Exception ex)
{
MessageBox.Show($"Error al cargar los eventos: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
/// <summary>
/// Registra un pago para el evento seleccionado y actualiza el DataGridView.
/// </summary>
private void btnRealizarPagos_Click(object sender, EventArgs e)
{
if (dgvEventos.SelectedRows.Count == 0)
{
MessageBox.Show("Seleccione un evento para registrar el pago.", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
try
{
// Obtener datos del evento seleccionado
var selectedRow = dgvEventos.SelectedRows[0];
int idEvento = Convert.ToInt32(selectedRow.Cells["Id_evento"].Value);
decimal montoPago = numericMontoPago.Value;
string metodoPago = comboBoxMetodoPago.SelectedItem?.ToString();
if (string.IsNullOrEmpty(metodoPago))
{
MessageBox.Show("Seleccione un método de pago.", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
// Registrar el pago en la base de datos
using (var connection = new SqlConnection(connectionString))
{
connection.Open();
string insertQuery = @"
INSERT INTO Pagos (Id_evento, Monto, Metodo_pago, Fecha_pago)
VALUES (@IdEvento, @Monto, @MetodoPago, GETDATE())";
using (var command = new SqlCommand(insertQuery, connection))
{
command.Parameters.AddWithValue("@IdEvento", idEvento);
command.Parameters.AddWithValue("@Monto", montoPago);
command.Parameters.AddWithValue("@MetodoPago", metodoPago);
command.ExecuteNonQuery();
}
}
MessageBox.Show("Pago registrado correctamente.", "Éxito", MessageBoxButtons.OK, MessageBoxIcon.Information);
// Actualizar el DataGridView
LoadEventosData();
}
catch (Exception ex)
{
MessageBox.Show($"Error al registrar el pago: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
/// <summary>
/// Carga una lista básica de métodos de pago en el comboBoxMetodoPago.
/// </summary>
private void LoadMetodosPago()
{
try
{
// Definir una lista básica de métodos de pago
var metodosPago = new List<string>
{
"Efectivo",
"Tarjeta de Crédito",
"Transferencia Bancaria",
"Cheque"
};
// Limpiar elementos existentes en el ComboBox
comboBoxMetodoPago.Items.Clear();
// Agregar los métodos de pago al ComboBox
comboBoxMetodoPago.Items.AddRange(metodosPago.ToArray());
// Seleccionar el primer método como predeterminado
if (comboBoxMetodoPago.Items.Count > 0)
{
comboBoxMetodoPago.SelectedIndex = 0;
}
}
catch (Exception ex)
{
MessageBox.Show($"Error al cargar los métodos de pago: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}