示例#1
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (Editar == false)
     {
         try
         {
             objetoCN.Insertar(txtNombre.Text, txtDescripcion.Text, txtMarca.Text, txtPrecio.Text, txtStock.Text);
             MessageBox.Show("Se inserto correctamente");
             MostrarProductos();
         }
         catch (Exception ex)
         {
             MessageBox.Show("No se pudo insertar los datos por: " + ex);
         }
     }
     if (Editar == true)
     {
         try
         {
             objetoCN.Editar(txtNombre.Text, txtDescripcion.Text, txtMarca.Text, txtPrecio.Text, txtStock.Text, idProducto);
             MessageBox.Show("Se inserto correctamente");
             MostrarProductos();
             limpiarForm();
             Editar = false;
         } catch (Exception ex)
         {
             MessageBox.Show("No se pudo insertar los datos por: " + ex);
         }
     }
 }
示例#2
0
        private void btn_Agregar_NP_Click(object sender, RoutedEventArgs e)
        {
            CN_Productos NPro = new CN_Productos();

            if (string.IsNullOrEmpty(TXT_Nombre_Producto.Text))
            {
                MessageBox.Show("Verifique que el campo Nombre del Producto se encuentre lleno");
                return;
            }
            else if (string.IsNullOrEmpty(TXT_Nombre_Proveedor.Text))
            {
                MessageBox.Show("Verifique que se selecciono un Proveedor");
                return;
            }
            else if (cmb_tipo_producto.SelectedIndex == -1)
            {
                MessageBox.Show("Verifique que se haya escogido un Tipo de Producto");
                return;
            }
            else if (string.IsNullOrEmpty(TXT_Marca.Text))
            {
                MessageBox.Show("Verifique que el campo Marca se encuentre lleno");
                return;
            }
            else if (string.IsNullOrEmpty(TXT_valor_unitario.Text))
            {
                MessageBox.Show("Verifique que se digito un valor unitario del producto");
                return;
            }
            else if (string.IsNullOrEmpty(TXT_STOCK.Text))
            {
                MessageBox.Show("Verifique que se digito la cantidad en stock del producto");
                return;
            }
            else
            {
                char separator = Convert.ToChar(Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator);
                NPro.Insertar(TXT_Nombre_Producto.Text, Convert.ToInt32(cmb_tipo_producto.SelectedValue), Convert.ToInt32(BUSCAR.idProveedor), TXT_Marca.Text, TXT_valor_unitario.Text.Replace(',', separator), Convert.ToInt32(TXT_STOCK.Text));


                MessageBox.Show("Producto Ingresado Correctamente");
                dgvProductos.SetBinding(ItemsControl.ItemsSourceProperty, new Binding {
                    Source = new DataTable()
                });
                limpiarForm();
                return;
            }
        }
        // ==============================================
        //     Boton GUARDAR
        // =============================================
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            try
            {
                string rpta = "";
                if (this.tbProducto.Text == string.Empty)
                {
                    MensajeError("Falta ingresar algunos datos");
                }
                else
                {
                    if (this.esNuevo)
                    {
                        rpta = CN_Productos.Insertar(this.tbProducto.Text.Trim(), this.cbCategorias.Text, this.cbProveedores.Text, this.tbCodigo.Text.Trim(),
                                                     this.tbDescripcion.Text.Trim());
                    }
                    else
                    {
                        // rpta = CN_Productos.Editar(this.tbProducto.Text.Trim(), this.tbCodigo.Text.Trim(), Convert.ToDecimal(this.tbPrecio.Text),
                        //     this.lbDescripcion.Text.Trim(),this.estadoProd);
                    }

                    if (rpta.Equals("OK"))
                    {
                        if (this.esNuevo)
                        {
                            this.MensajeOk("Se Insertó de forma correcta el registro");
                        }
                        else
                        {
                            this.MensajeOk("Se Actualizó de forma correcta el registro");
                        }
                    }
                    else
                    {
                        this.MensajeError(rpta);
                    }
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + ex.StackTrace);
            }
        }
        private void btn_Agregar_NP_Click(object sender, RoutedEventArgs e)
        {
            CN_Productos NPro = new CN_Productos();

            if (string.IsNullOrEmpty(TXT_Nombre_Producto.Text))
            {
                MessageBox.Show("Verifique que el campo Nombre del Producto se encuentre lleno");
                return;
            }
            else if (string.IsNullOrEmpty(TXT_Nombre_Proveedor.Text))
            {
                MessageBox.Show("Verifique que se selecciono un Proveedor");
                return;
            }
            else if (cmb_tipo_producto.SelectedIndex == -1)
            {
                MessageBox.Show("Verifique que se haya escogido un Tipo de Producto");
                return;
            }
            else if (string.IsNullOrEmpty(TXT_Marca.Text))
            {
                MessageBox.Show("Verifique que el campo Marca se encuentre lleno");
                return;
            }
            else if (string.IsNullOrEmpty(TXT_valor_unitario.Text))
            {
                MessageBox.Show("Verifique que se digito un valor unitario del producto");
                return;
            }
            else if (string.IsNullOrEmpty(TXT_STOCK.Text))
            {
                MessageBox.Show("Verifique que se digito la cantidad en stock del producto");
                return;
            }
            else
            {
                NPro.Insertar(TXT_Nombre_Producto.Text, Convert.ToInt32(cmb_tipo_producto.SelectedValue), Convert.ToInt32(BUSCAR.idProveedor), TXT_Marca.Text, TXT_valor_unitario.Text, Convert.ToInt32(TXT_STOCK.Text));


                MessageBox.Show("Producto Ingresado Correctamente");
                MostrarProductos();
                limpiarForm();
                return;
            }
        }