476 lines
20 KiB
C#
476 lines
20 KiB
C#
using compabetov2.database;
|
|
using compabetov2.database.modelos;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Drawing.Printing;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using compabetov2.admin;
|
|
|
|
namespace compabetov2
|
|
{
|
|
public partial class envios : Form
|
|
{
|
|
|
|
private Point lastPoint;
|
|
private LoginModel loginPrincipal;
|
|
public envios(LoginModel loginPrincipal)
|
|
{
|
|
|
|
|
|
InitializeComponent();
|
|
llenarPanel();
|
|
this.loginPrincipal = loginPrincipal;
|
|
|
|
txtTelefono.KeyPress += new KeyPressEventHandler(txtTelefono_KeyPress);
|
|
}
|
|
|
|
private void InitializePanelEnvio()
|
|
{
|
|
// Asegúrate de que panelEnvio ya está creado en tu formulario
|
|
|
|
// Habilitar eventos táctiles simulados
|
|
panelEnvio.MouseDown += PanelEnvio_MouseDown;
|
|
panelEnvio.MouseMove += PanelEnvio_MouseMove;
|
|
panelEnvio.MouseUp += PanelEnvio_MouseUp;
|
|
}
|
|
|
|
private void PanelEnvio_MouseDown(object sender, MouseEventArgs e)
|
|
{
|
|
lastPoint = new Point(e.X, e.Y);
|
|
panelEnvio.Capture = true;
|
|
}
|
|
|
|
private void PanelEnvio_MouseMove(object sender, MouseEventArgs e)
|
|
{
|
|
if (e.Button == MouseButtons.Left)
|
|
{
|
|
int deltaX = lastPoint.X - e.X;
|
|
int deltaY = lastPoint.Y - e.Y;
|
|
|
|
// Ajustar la dirección del desplazamiento
|
|
panelEnvio.AutoScrollPosition = new Point(panelEnvio.AutoScrollPosition.X + deltaX, panelEnvio.AutoScrollPosition.Y - deltaY);
|
|
|
|
lastPoint = new Point(e.X, e.Y);
|
|
}
|
|
}
|
|
|
|
private void PanelEnvio_MouseUp(object sender, MouseEventArgs e)
|
|
{
|
|
panelEnvio.Capture = false;
|
|
}
|
|
|
|
private void llenarPanel()
|
|
{
|
|
panelEnvio.Controls.Clear();
|
|
List<Dictionary<string, dynamic>> envios_importes_list = service.conseguirEnvio();
|
|
foreach(Dictionary<string, dynamic> envio_importes in envios_importes_list)
|
|
{
|
|
Envio envio = envio_importes["envio"];
|
|
if (envio.estado.Equals("EN PROCESO"))
|
|
{
|
|
TableLayoutPanel carta = new TableLayoutPanel();
|
|
carta.ColumnCount = 1;
|
|
carta.RowCount = 2;
|
|
carta.RowStyles.Add(new RowStyle(SizeType.Percent, 75F));
|
|
carta.RowStyles.Add(new RowStyle(SizeType.Percent, 25F));
|
|
carta.Width = 700;
|
|
carta.Height = 170;
|
|
|
|
FlowLayoutPanel infoPanel = new FlowLayoutPanel();
|
|
infoPanel.FlowDirection = FlowDirection.TopDown;
|
|
infoPanel.Dock = DockStyle.Fill;
|
|
|
|
Label lbFecha = new Label();
|
|
lbFecha.Text = $"Fecha: {envio.fecha}";
|
|
lbFecha.Font = new Font(lbFecha.Font.FontFamily, 12);
|
|
lbFecha.Width = 700;
|
|
|
|
Label lbDireaccion = new Label();
|
|
lbDireaccion.Text = $"Direccion: {envio.direccion}";
|
|
lbDireaccion.Font = new Font(lbDireaccion.Font.FontFamily, 12);
|
|
lbDireaccion.Width = 700;
|
|
|
|
Label lbTelefono = new Label();
|
|
lbTelefono.Text = $"Telefono: {envio.telefono} Estado: {envio.estado}";
|
|
lbTelefono.Font = new Font(lbTelefono.Font.FontFamily, 12);
|
|
lbTelefono.Width = 700;
|
|
|
|
|
|
Label lbCliente = new Label();
|
|
lbCliente.Text = $"Cliente: {envio.cliente}";
|
|
lbCliente.Font = new Font(lbCliente.Font.FontFamily, 12);
|
|
lbCliente.Width = 700;
|
|
|
|
Label lbResponzable = new Label();
|
|
lbResponzable.Text = $"Responzable: {envio.responsable}";
|
|
lbResponzable.Font = new Font(lbResponzable.Font.FontFamily, 12);
|
|
lbResponzable.Width = 700;
|
|
|
|
TableLayoutPanel botonesPanel = new TableLayoutPanel();
|
|
botonesPanel.RowCount = 1;
|
|
botonesPanel.ColumnCount = 4;
|
|
botonesPanel.Dock = DockStyle.Fill;
|
|
botonesPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 25F));
|
|
botonesPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 25F));
|
|
botonesPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 25F));
|
|
botonesPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 25F));
|
|
botonesPanel.RowStyles.Add(new RowStyle(SizeType.Percent, 100F));
|
|
|
|
Button btnDetalles = new Button();
|
|
btnDetalles.Text = "Detalles";
|
|
btnDetalles.Dock = DockStyle.Fill;
|
|
btnDetalles.FlatStyle = FlatStyle.Flat;
|
|
btnDetalles.FlatAppearance.BorderSize = 0;
|
|
btnDetalles.BackColor = Color.FromArgb(33, 90, 255);
|
|
btnDetalles.Font = new Font(btnDetalles.Font.FontFamily, 16);
|
|
btnDetalles.ForeColor = Color.White;
|
|
btnDetalles.Click += new EventHandler(delegate (object sender, EventArgs e)
|
|
{
|
|
List<DetalleEnvioModel> detalles = service.conseguirDetalleEnvio(envio.id);
|
|
string mensaje = "";
|
|
decimal cantidadImportes = 0;
|
|
foreach (DetalleEnvioModel detalle in detalles)
|
|
{
|
|
mensaje += $"{detalle.producto.nombre} - {detalle.cantidad}\n";
|
|
|
|
foreach(DetalleImporteEnvio importe in envio_importes["importes"])
|
|
{
|
|
cantidadImportes = importe.cantidad * importe.precioImporte;
|
|
}
|
|
|
|
}
|
|
mensaje += $"Importe: {cantidadImportes}\n";
|
|
mensaje += $"Total: {envio.total}";
|
|
|
|
MessageBox.Show(mensaje);
|
|
});
|
|
|
|
Button btnConcluir = new Button();
|
|
btnConcluir.Text = "Concluir";
|
|
btnConcluir.Dock = DockStyle.Fill;
|
|
btnConcluir.FlatStyle = FlatStyle.Flat;
|
|
btnConcluir.FlatAppearance.BorderSize = 0;
|
|
btnConcluir.BackColor = Color.FromArgb(33, 90, 255);
|
|
btnConcluir.Font = new Font(btnDetalles.Font.FontFamily, 16);
|
|
btnConcluir.ForeColor = Color.White;
|
|
btnConcluir.Click += new EventHandler(delegate (object sender, EventArgs e)
|
|
{
|
|
DialogResult result = MessageBox.Show($"¿Está seguro de que desea concluir este envio?",
|
|
"Confirmación", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
|
|
if (result == DialogResult.Yes)
|
|
{
|
|
List<DetalleEnvioModel> detalles = service.conseguirDetalleEnvio(envio.id);
|
|
if (service.concluirEnvio(envio, detalles, envio_importes["importes"]))
|
|
{
|
|
llenarPanel();
|
|
ImprimirTicketConcluido(envio);
|
|
}
|
|
}
|
|
});
|
|
|
|
Button btnCancelar = new Button();
|
|
btnCancelar.Text = "Cancelar";
|
|
btnCancelar.Dock = DockStyle.Fill;
|
|
btnCancelar.FlatStyle = FlatStyle.Flat;
|
|
btnCancelar.FlatAppearance.BorderSize = 0;
|
|
btnCancelar.BackColor = Color.Red;
|
|
btnCancelar.Font = new Font(btnDetalles.Font.FontFamily, 16);
|
|
btnCancelar.Click += new EventHandler(delegate (object sender, EventArgs e)
|
|
{
|
|
DialogResult result = MessageBox.Show($"¿Está seguro de que desea eliminar este envio?",
|
|
"Confirmación", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
|
|
List<DetalleEnvioModel> detalles = service.conseguirDetalleEnvio(envio.id);
|
|
if (result == DialogResult.Yes)
|
|
{
|
|
if (service.cancelarEnvio(envio, detalles))
|
|
{
|
|
llenarPanel();
|
|
}
|
|
}
|
|
|
|
});
|
|
|
|
Button btnAgregar = new Button();
|
|
btnAgregar.Text = "Agregar";
|
|
btnAgregar.Dock = DockStyle.Fill;
|
|
btnAgregar.FlatStyle = FlatStyle.Flat;
|
|
btnAgregar.FlatAppearance.BorderSize = 0;
|
|
btnAgregar.BackColor = Color.FromArgb(33, 90, 255);
|
|
btnAgregar.Font = new Font(btnDetalles.Font.FontFamily, 16);
|
|
btnAgregar.ForeColor = Color.White;
|
|
btnAgregar.Click += new EventHandler(delegate (object sender, EventArgs e)
|
|
{
|
|
Envio envioEditado = new Envio(envio.id, "",
|
|
txtDireccion.Text == "" ? envio.direccion : txtDireccion.Text,
|
|
txtTelefono.Text == "" ? envio.telefono : txtTelefono.Text
|
|
, "", "",
|
|
txtCliente.Text == "" ? envio.cliente : txtCliente.Text
|
|
, 0);
|
|
if (service.editarEnvio(envioEditado))
|
|
{
|
|
llenarPanel();
|
|
txtCliente.Text = "";
|
|
txtDireccion.Text = "";
|
|
txtTelefono.Text = "";
|
|
}
|
|
});
|
|
|
|
|
|
infoPanel.Controls.Add(lbFecha);
|
|
infoPanel.Controls.Add(lbResponzable);
|
|
infoPanel.Controls.Add(lbCliente);
|
|
infoPanel.Controls.Add(lbDireaccion);
|
|
infoPanel.Controls.Add(lbTelefono);
|
|
|
|
botonesPanel.Controls.Add(btnDetalles, 0, 0);
|
|
botonesPanel.Controls.Add(btnConcluir, 1, 0);
|
|
botonesPanel.Controls.Add(btnAgregar, 2, 0);
|
|
botonesPanel.Controls.Add(btnCancelar, 3, 0);
|
|
|
|
carta.Controls.Add(infoPanel, 0, 0);
|
|
carta.Controls.Add(botonesPanel, 0, 1);
|
|
|
|
panelEnvio.Controls.Add(carta);
|
|
}
|
|
else
|
|
{
|
|
TableLayoutPanel carta = new TableLayoutPanel();
|
|
carta.ColumnCount = 1;
|
|
carta.RowCount = 2;
|
|
carta.RowStyles.Add(new RowStyle(SizeType.Percent, 75F));
|
|
carta.RowStyles.Add(new RowStyle(SizeType.Percent, 25F));
|
|
carta.Width = 700;
|
|
carta.Height = 170;
|
|
|
|
FlowLayoutPanel infoPanel = new FlowLayoutPanel();
|
|
infoPanel.FlowDirection = FlowDirection.TopDown;
|
|
infoPanel.Dock = DockStyle.Fill;
|
|
|
|
Label lbFecha = new Label();
|
|
lbFecha.Text = $"Fecha: {envio.fecha}";
|
|
lbFecha.Font = new Font(lbFecha.Font.FontFamily, 12);
|
|
lbFecha.Width = 700;
|
|
|
|
Label lbDireaccion = new Label();
|
|
lbDireaccion.Text = $"Direccion: {envio.direccion}";
|
|
lbDireaccion.Font = new Font(lbDireaccion.Font.FontFamily, 12);
|
|
lbDireaccion.Width = 700;
|
|
|
|
Label lbTelefono = new Label();
|
|
lbTelefono.Text = $"Telefono: {envio.telefono} Estado: {envio.estado}";
|
|
lbTelefono.Font = new Font(lbTelefono.Font.FontFamily, 12);
|
|
lbTelefono.Width = 700;
|
|
|
|
|
|
Label lbCliente = new Label();
|
|
lbCliente.Text = $"Cliente: {envio.cliente}";
|
|
lbCliente.Font = new Font(lbCliente.Font.FontFamily, 12);
|
|
lbCliente.Width = 700;
|
|
|
|
Label lbResponzable = new Label();
|
|
lbResponzable.Text = $"Responzable: {envio.responsable}";
|
|
lbResponzable.Font = new Font(lbResponzable.Font.FontFamily, 12);
|
|
lbResponzable.Width = 700;
|
|
|
|
TableLayoutPanel botonesPanel = new TableLayoutPanel();
|
|
botonesPanel.RowCount = 1;
|
|
botonesPanel.ColumnCount = 4;
|
|
botonesPanel.Dock = DockStyle.Fill;
|
|
botonesPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 25F));
|
|
botonesPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 25F));
|
|
botonesPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 25F));
|
|
botonesPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 25F));
|
|
botonesPanel.RowStyles.Add(new RowStyle(SizeType.Percent, 100F));
|
|
|
|
Button btnDetalles = new Button();
|
|
btnDetalles.Text = "Detalles";
|
|
btnDetalles.Dock = DockStyle.Fill;
|
|
btnDetalles.FlatStyle = FlatStyle.Flat;
|
|
btnDetalles.FlatAppearance.BorderSize = 0;
|
|
btnDetalles.BackColor = Color.FromArgb(33, 90, 255);
|
|
btnDetalles.Font = new Font(btnDetalles.Font.FontFamily, 16);
|
|
btnDetalles.ForeColor = Color.White;
|
|
btnDetalles.Click += new EventHandler(delegate (object sender, EventArgs e)
|
|
{
|
|
List<DetalleEnvioModel> detalles = service.conseguirDetalleEnvio(envio.id);
|
|
string mensaje = "";
|
|
foreach (DetalleEnvioModel detalle in detalles)
|
|
{
|
|
mensaje += $"{detalle.producto.nombre} - {detalle.cantidad}\n" +
|
|
$"Total: {envio.total}";
|
|
}
|
|
MessageBox.Show(mensaje);
|
|
});
|
|
|
|
infoPanel.Controls.Add(lbFecha);
|
|
infoPanel.Controls.Add(lbResponzable);
|
|
infoPanel.Controls.Add(lbCliente);
|
|
infoPanel.Controls.Add(lbDireaccion);
|
|
infoPanel.Controls.Add(lbTelefono);
|
|
|
|
botonesPanel.Controls.Add(btnDetalles, 0, 0);
|
|
|
|
carta.Controls.Add(infoPanel, 0, 0);
|
|
carta.Controls.Add(botonesPanel, 0, 1);
|
|
|
|
panelEnvio.Controls.Add(carta);
|
|
}
|
|
}
|
|
|
|
}
|
|
public static class ImpresionHelper
|
|
{
|
|
public static void ImprimirContenido(string contenido)
|
|
{
|
|
PrintDocument pd = new PrintDocument();
|
|
pd.PrintPage += (sender, e) =>
|
|
{
|
|
Font fuente = new Font("Arial", 10);
|
|
PointF posicion = new PointF(0, e.MarginBounds.Top);
|
|
e.Graphics.DrawString(contenido, fuente, Brushes.Black, posicion);
|
|
};
|
|
|
|
PrintDialog printDialog = new PrintDialog();
|
|
printDialog.Document = pd;
|
|
|
|
if (printDialog.ShowDialog() == DialogResult.OK)
|
|
{
|
|
pd.Print();
|
|
}
|
|
}
|
|
}
|
|
private string CrearContenidoImprimir(Envio envio)
|
|
{
|
|
// Aquí deberías construir el contenido del ticket según tus necesidades
|
|
// Puedes usar StringBuilder para construir el contenido eficientemente
|
|
StringBuilder contenido = new StringBuilder();
|
|
contenido.AppendLine($"Fecha: {envio.fecha}");
|
|
contenido.AppendLine($"Responsable: {envio.responsable}");
|
|
contenido.AppendLine($"Cliente: {envio.cliente}");
|
|
contenido.AppendLine($"Direccion: {envio.direccion}");
|
|
contenido.AppendLine($"Telefono: {envio.telefono}");
|
|
// ... Agrega más información según sea necesario
|
|
|
|
return contenido.ToString();
|
|
}
|
|
|
|
private void ImprimirTicketConcluido(Envio envio)
|
|
{
|
|
string contenido = CrearContenidoImprimir(envio);
|
|
contenido += "Estado: CONCLUIDO\n"; // Añade el estado concluido al final del ticket
|
|
ImpresionHelper.ImprimirContenido(contenido);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void button1_Click(object sender, EventArgs e)
|
|
{
|
|
// Cerrar el formulario de ventas
|
|
this.Close();
|
|
|
|
// Verificar si ya hay una instancia del formulario principal
|
|
MenuPrincipal menuprincipalForm = Application.OpenForms.OfType<MenuPrincipal>().FirstOrDefault();
|
|
|
|
if (menuprincipalForm == null)
|
|
{
|
|
// Si no hay una instancia, crear una nueva
|
|
menuprincipalForm = new MenuPrincipal(loginPrincipal);
|
|
|
|
// Establecer el formulario principal como el formulario MDI padre
|
|
menuprincipalForm.MdiParent = this.MdiParent;
|
|
|
|
// Mostrar el formulario principal
|
|
menuprincipalForm.Show();
|
|
}
|
|
else
|
|
{
|
|
// Si ya hay una instancia, simplemente llevarlo al frente
|
|
menuprincipalForm.BringToFront();
|
|
}
|
|
}
|
|
|
|
private void horafecha_Tick(object sender, EventArgs e)
|
|
{
|
|
|
|
lblhora.Text = DateTime.Now.ToString("h:mm:ss");
|
|
lblfecha.Text = DateTime.Now.ToLongDateString();
|
|
|
|
}
|
|
|
|
private void label10_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void envios_Load(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void label4_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void panelEnvio_Paint(object sender, PaintEventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void button2_Click(object sender, EventArgs e)
|
|
{
|
|
if (loginPrincipal.tipo.Equals("empleado"))
|
|
{
|
|
MessageBox.Show("Usted no tiene permisos de acceder a este apartado");
|
|
}
|
|
else
|
|
{
|
|
Estadiscticas estadiscticas = new Estadiscticas();
|
|
estadiscticas.Owner = this;
|
|
estadiscticas.Show();
|
|
};
|
|
}
|
|
|
|
private void txtTelefono_TextChanged(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
private void txtTelefono_KeyPress(object sender, KeyPressEventArgs e)
|
|
{
|
|
// Verificar si la tecla presionada no es un número o la tecla de retroceso
|
|
if (!char.IsDigit(e.KeyChar) && e.KeyChar != 8)
|
|
{
|
|
e.Handled = true; // Ignorar la tecla presionada
|
|
|
|
// Mostrar un mensaje indicando que solo se permiten números
|
|
MessageBox.Show("Por favor, ingrese solo números en el teléfono.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
|
|
private void button3_Click(object sender, EventArgs e)
|
|
{
|
|
if (loginPrincipal.tipo.Equals("empleado"))
|
|
{
|
|
MessageBox.Show("Usted no tiene permisos de acceder a este apartado");
|
|
}
|
|
else
|
|
{
|
|
crud crud = new crud();
|
|
crud.Owner = this;
|
|
crud.Show();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|