public EditarVarianteFrm(TipoProducto tipo, ProductoVariante variante) { InitializeComponent(); this.tipo = tipo; if (variante != null) { btnEliminar.Visible = true; this.variante = variante; txtNombre.Text = variante.nombre_variante; txtDescripcion.Text = variante.descripcion; txtPrecio.Text = "" + variante.precio_variante; materialToggle1.Checked = variante.disponible; btnEliminar.Visible = true; } }
private void btnAceptar_Click(object sender, EventArgs e) { MaterialSingleLineTextField[] textField = { txtNombre, txtPrecio }; if (!Helper.Llenos(textField)) { MessageBox.Show("Introduce datos validos", "ERROR"); return; } if (variante == null) { variante = new ProductoVariante() { nombre_variante = txtNombre.Text, descripcion = txtDescripcion.Text, disponible = materialToggle1.Checked, id_tipo_producto = tipo.id_tipo_producto, precio_variante = decimal.Parse(txtPrecio.Text) }; if (ControlProductoVariante.Instance.Agregar(variante)) { Changed = true; MessageBox.Show("Bien"); } else { MessageBox.Show("Mal"); } } else { variante.nombre_variante = txtNombre.Text; variante.descripcion = txtDescripcion.Text; variante.disponible = materialToggle1.Checked; variante.id_tipo_producto = tipo.id_tipo_producto; variante.precio_variante = decimal.Parse(txtPrecio.Text); if (ControlProductoVariante.Instance.Editar(variante)) { Changed = true; MessageBox.Show("Bien"); } else { MessageBox.Show("Mal"); } } Close(); }
private void btnEditarVariante_Click(object sender, EventArgs e) { if (materialListView2.SelectedItems.Count < 1) { return; } ProductoVariante variante = materialListView2.SelectedItems[0].Tag as ProductoVariante; using (EditarVarianteFrm agregar = new EditarVarianteFrm(tipo, variante)) { agregar.ShowDialog(this); if (agregar.Changed) { Actualiza(); } } }