72 lines
2.3 KiB
C#
72 lines
2.3 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.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace compabetov2.admin
|
|
{
|
|
public partial class agregarproducto : Form
|
|
{
|
|
private crud ventanaPadre;
|
|
private string imagePath = "";
|
|
public agregarproducto(crud ventanaPadre)
|
|
{
|
|
this.ventanaPadre = ventanaPadre;
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void pictureBox2_Click(object sender, EventArgs e)
|
|
{
|
|
string nombre = txtNombre.Text;
|
|
decimal precio = 0;
|
|
//valida que se haya colocado alguna imagen
|
|
if (!imagePath.Equals("")) {
|
|
Producto producto = new Producto(-1, nombre, "", precio, Path.GetFileName(imagePath), 0);
|
|
if (service.insertarProducto(producto))
|
|
{
|
|
string destinationFolder = Path.Combine(Application.StartupPath, "Resources");
|
|
string destinationFile = Path.Combine(destinationFolder, Path.GetFileName(imagePath));
|
|
File.Copy(imagePath, destinationFile, true);
|
|
|
|
Close();
|
|
ventanaPadre.llenarLayout();
|
|
|
|
}
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show("Por favor seleccione alguna imagen", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
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();
|
|
}
|
|
}
|
|
}
|