private void btnAceptar_Click(object sender, EventArgs e)
 {
     if (!ValidarCampos)
     {
         Interface = new InterfaceUsuario(this);
         RegistroProducto temp = ObtenerRegistro;
         temp.Clave = Convert.ToInt32(tbClave.Text);
         if (Interface.RegistrarProducto(temp))
         {
             string Mensaje = "";
             if (!ActualizarProMat(out Mensaje))
             {
                 MessageBox.Show("Producto registrado con éxito", "AVISO", MessageBoxButtons.OK, MessageBoxIcon.Information);
             }
             else
             {
                 Validar.MensajeErrorOK("El producto se registró sin embargo hubo un problema al asociar los materiales, favor de cambiar los parámetros modificando el producto en su opción correspondiente\n\n" + Mensaje);
             }
             Close();
         }
         else
         {
             RegistroProducto[] Productos = Interface.BuscarUnProducto(new RegistroProducto(ObtenerRegistro.Clave, "", -1, -1, -1));
             if (Productos?[0]?.Clave == ObtenerRegistro.Clave)
             {
                 Validar.MensajeErrorOK("El número clave ya ha sido usado anteriormente y no puede repetirse");
             }
             else
             {
                 Productos = Interface.BuscarUnProducto(new RegistroProducto(-1, tbNombre.Text, -1, -1, -1));
                 bool Existe = false;
                 for (int i = 0; i < Productos?.Length && !Existe; i++)
                 {
                     if (Productos?[i]?.Nombre == tbNombre.Text)
                     {
                         Existe = true;
                     }
                 }
                 if (Existe)
                 {
                     Validar.MensajeErrorOK("El nombre ya ha sido usado anteriormente y no puede repetirse");
                 }
                 else
                 {
                     Validar.MensajeErrorBaseDeDatos();
                 }
             }
         }
     }
 }
Esempio n. 2
0
        private void LlenarData(Búsqueda Tipo)
        {
            int Col = 0, Ren = 0;

            if (dgvProductos.SelectedCells.Count > 0)
            {
                DataGridViewCell Cell = dgvProductos.SelectedCells[0];
                Col = Cell.ColumnIndex;
                Ren = Cell.RowIndex;
            }
            dgvProductos.Rows.Clear();
            Interface = new InterfaceUsuario(this);
            RegistroProducto[] temp = null;
            if (Tipo == Búsqueda.Total)
            {
                temp = Interface.BuscarUnProducto(new RegistroProducto(-1, "", -1, -1, 1));
            }
            else
            {
                if (Tipo == Búsqueda.Clave)
                {
                    temp = Interface.BuscarUnProducto(new RegistroProducto(Convert.ToInt32(tbClave.Text), "", -1, -1, 1));
                }
                else
                if (Tipo == Búsqueda.Personalizada)
                {
                    temp = Interface.BuscarUnProducto(new RegistroProducto(-1, tbNombre.Text, Convert.ToInt32(tbDias.Text == "" ? "-1" : tbDias.Text), Convert.ToSingle(tbPrecio.Text == "" ? "-1" : tbPrecio.Text), 1));
                }
            }
            if (temp != null)
            {
                dgvProductos.RowCount = temp.Length;
                for (int i = 0; i < temp.Length; i++)
                {
                    dgvProductos[0, i].Value = temp[i].Clave;
                    dgvProductos[1, i].Value = temp[i].Nombre;
                    dgvProductos[2, i].Value = temp[i].Dias + " Dias";
                    dgvProductos[3, i].Value = "$" + temp[i].Precio.ToString();
                    dgvProductos.Rows[i].DefaultCellStyle.BackColor = temp[i].Activo == 0 ? Color.LightSalmon : Color.LightGreen;
                }
            }
            if (dgvProductos.SelectedCells.Count > 0)
            {
                dgvProductos.CurrentCell = dgvProductos[Col, Ren];
                dgvProductos.Focus();
            }
        }
        public RegistroProducto PedirProducto(out bool Cancelado)
        {
            InterfaceUsuario Interface = new InterfaceUsuario(this);

            Validacion = new Validar(this);
            pbIcono.BackgroundImage = Properties.Resources.IconoProceso;
            tbNumEmpleado.MaxLength = 8;
            lblInfo.Text            = "Ingrese clave del producto a eliminar";
            Text = lblPedir.Text = lblTitulo.Text = "#Producto";
            AlinearCentroHorizontal(lblInfo, lblPedir);
            bool Cerrado = true;

            tbNumEmpleado.KeyPress += delegate(object sender, KeyPressEventArgs e)
            {
                if (e.KeyChar == 13 || e.KeyChar == Convert.ToChar(Keys.Escape))
                {
                    if (!Validacion.ValidarTextBox(tbNumEmpleado))
                    {
                        Close();
                        Cerrado = false;
                    }
                    if (e.KeyChar == Convert.ToChar(Keys.Escape))
                    {
                        Close();
                        Cerrado = true;
                    }
                }
                else
                {
                    if (!char.IsDigit(e.KeyChar) && e.KeyChar != '\b')
                    {
                        e.Handled = true;
                    }
                }
            };
            ShowDialog();
            Cancelado = Cerrado;
            RegistroProducto[] temp = null;
            if (!Cerrado)
            {
                temp = Interface.BuscarUnProducto(new RegistroProducto(Convert.ToInt32(tbNumEmpleado.Text == "" ? "-2" : tbNumEmpleado.Text), "", -1, -1, 1));
            }
            return(temp?[0] ?? null);
        }
Esempio n. 4
0
 private void LlenarProductos(DataGridViewComboBoxCell Celda)
 {
     Celda.Items.Clear();
     Interface = new InterfaceUsuario(this);
     RegistroProMat[] ProMat = Interface.ObtenerProMat(-1, Interface.BuscarUnProducto(new RegistroProducto(-1, dgvProductos[0, (dgvProductos.CurrentCell ?? dgvProductos[0, 0]).RowIndex].FormattedValue.ToString(), -1, -1, -1))?[0].Clave ?? -1);
     for (int i = 0; i < Productos?.Length; i++)
     {
         if (Productos[i].Activo == 1)
         {
             for (int j = 0; j < ProMat.Length; j++)
             {
                 if (ProMat[j].Activo == 1)
                 {
                     (dgvProductos[Celda.ColumnIndex, Celda.RowIndex] as DataGridViewComboBoxCell).Items.Add(Productos[i].Nombre + " $" + Productos[i].Precio);
                     j = ProMat.Length;
                 }
             }
         }
     }
 }