crud de variante terminado, tal vez con detalles
This commit is contained in:
+105
-2
@@ -1,8 +1,11 @@
|
||||
using System;
|
||||
using compabetov2.database;
|
||||
using compabetov2.database.modelos;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@@ -12,14 +15,114 @@ namespace compabetov2.admin
|
||||
{
|
||||
public partial class editarvariante : Form
|
||||
{
|
||||
public editarvariante()
|
||||
private Variante variante;
|
||||
private Variantes ventanaPadre;
|
||||
private string imagePath;
|
||||
public editarvariante(Variante variante, Variantes ventanaPadre)
|
||||
{
|
||||
InitializeComponent();
|
||||
this.variante = variante;
|
||||
this.ventanaPadre = ventanaPadre;
|
||||
llenarCampos();
|
||||
}
|
||||
|
||||
private void llenarCampos()
|
||||
{
|
||||
txtNombre.Text = variante.nombre;
|
||||
txtCantidad.Text = variante.cantidad.ToString();
|
||||
txtPrecio.Text = variante.precio.ToString();
|
||||
txtPrecioCompra.Text = variante.precioCompra.ToString();
|
||||
lbImg.Text = "Imagen: " + variante.img.ToString();
|
||||
imagePath = variante.img;
|
||||
}
|
||||
|
||||
private void editarvariante_Load(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void button1_Click(object sender, EventArgs e)
|
||||
{
|
||||
OpenFileDialog openFileDialog1 = new OpenFileDialog();
|
||||
|
||||
openFileDialog1.Filter = "Archivos de imagen (*.jpg, *.jpeg, *.png, *.bmp)|*.jpg;*.jpeg;*.png;*.bmp";
|
||||
openFileDialog1.Title = "Seleccionar imagen";
|
||||
|
||||
if (openFileDialog1.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
imagePath = openFileDialog1.FileName;
|
||||
lbImg.Text = $"Imagen: {Path.GetFileName(imagePath)}";
|
||||
}
|
||||
}
|
||||
|
||||
private void pictureBox1_Click(object sender, EventArgs e)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
private static bool isInt(string cadena)
|
||||
{
|
||||
try
|
||||
{
|
||||
int.Parse(cadena);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
MessageBox.Show("Por favor introduzca un precio valido", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool isDecimal(string cadena)
|
||||
{
|
||||
try
|
||||
{
|
||||
Decimal.Parse(cadena);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
MessageBox.Show("Por favor introduzca un precio valido", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void pictureBox2_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (isInt(txtCantidad.Text) && isDecimal(txtPrecio.Text) && isDecimal(txtPrecioCompra.Text))
|
||||
{
|
||||
Variante NuevaVariante = new Variante(
|
||||
variante.idVariante,
|
||||
txtNombre.Text,
|
||||
Decimal.Parse(txtPrecio.Text),
|
||||
int.Parse(txtCantidad.Text),
|
||||
imagePath,
|
||||
variante.fkProducto,
|
||||
Decimal.Parse(txtPrecioCompra.Text)
|
||||
);
|
||||
|
||||
if (service.editarVariante(NuevaVariante))
|
||||
{
|
||||
if (!NuevaVariante.img.Equals(variante.img))
|
||||
{
|
||||
string destinationFolder = Path.Combine(Application.StartupPath, "Resources");
|
||||
string destinationFile = Path.Combine(destinationFolder, Path.GetFileName(imagePath));
|
||||
File.Copy(imagePath, destinationFile, true);
|
||||
}
|
||||
Close();
|
||||
ventanaPadre.llenarLayout();
|
||||
//borrar imagen
|
||||
//
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void label3_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user