Пример #1
0
        private void btnCrearTienda_Click(object sender, EventArgs e)
        {
            cmbTienda.DroppedDown = true;
            cmbTienda.DroppedDown = false;
            if (validaCampos() == true)
            {
                try
                {
                    int m = 0;
                    for (int f = 0; f < cmbTienda.Items.Count; f++)
                    {
                        if (cmbTienda.CheckBoxItems[f].Checked == true)
                        {
                            m = m + 1;
                        }
                    }
                    if (m == 0)
                    {
                        MessageBox.Show("Debe ingresar al menos una tienda."); cmbTienda.Focus();
                        return;
                    }
                    string[] arreglo = new string[m];

                    string s    = string.Empty;
                    int    cont = 0;
                    for (int x = 0; x < cmbTienda.Items.Count; x++)
                    {
                        if (cmbTienda.CheckBoxItems[x].Checked == true)
                        {
                            s = cmbTienda.CheckBoxItems[x].Text;
                            //s = s.Replace(" [0]", "");
                            arreglo[cont] = s;
                            cont          = cont + 1;
                        }
                    }

                    Int16 h = Int16.Parse(objetoPaso.paso0);                        //id
                    Int16 j;
                    if (chDisponiblidad.Checked == true)
                    {
                        j = 1;
                    }
                    else
                    {
                        j = 0;
                    };                                                               //2X1
                    Int16 i;
                    if (cmbEstado.Text.Equals("Activo"))
                    {
                        i = 1;
                    }
                    else
                    {
                        i = 0;
                    };                                                                       //estado

                    ProductoDAO prodDAO      = new ProductoDAO();
                    Boolean     skuExistente = prodDAO.buscaProductoPorSku(txtSku.Text.ToUpper());

                    prodDAO.EditarProducto(h, txtNombreProducto.Text, txtDescripcion.Text, Int64.Parse(txtPrecio.Text), j, txtSku.Text.ToUpper(), i, DateTime.Now, Int16.Parse(cmbRubro.SelectedValue.ToString()));

                    int idProducto = prodDAO.buscaProductoPorNombre(txtNombreProducto.Text, txtSku.Text.ToUpper());

                    prodDAO.eliminaProductoTienda(idProducto);

                    for (int x = 0; x < arreglo.Length; x++)
                    {
                        TiendaDAO tiDAO    = new TiendaDAO();
                        int       idTienda = tiDAO.buscaIdTiendaPorNombre2(arreglo[x]);
                        prodDAO.guardaProductoTienda(idProducto, idTienda);
                    }

                    MessageBox.Show("Modificación de producto exitosa.");
                    PortadaMantenedorProducto ProductoView = new PortadaMantenedorProducto();
                    ProductoView.cargaProductos();
                    this.Visible = false;
                }
                catch (Exception E)
                {
                    MessageBox.Show("Error al modificar el producto.");
                }
            }
        }
Пример #2
0
        private void btnCrearProducto_Click(object sender, EventArgs e)
        {
            if (validaCampos())
            {
                try
                {
                    int m = 0;
                    for (int f = 0; f < cmbTienda.Items.Count; f++)
                    {
                        if (cmbTienda.CheckBoxItems[f].Checked == true)
                        {
                            m = m + 1;
                        }
                    }
                    if (m == 0)
                    {
                        MessageBox.Show("Debe ingresar al menos una tienda."); cmbTienda.Focus();
                        return;
                    }
                    //m = m - 1;
                    string[] arreglo = new string[m];

                    string s    = string.Empty;
                    int    cont = 0;
                    for (int x = 0; x < cmbTienda.Items.Count; x++)
                    {
                        if (cmbTienda.CheckBoxItems[x].Checked == true)
                        {
                            s = cmbTienda.CheckBoxItems[x].Text;
                            //s = s.Replace(" [0]", "");
                            arreglo[cont] = s;
                            cont          = cont + 1;
                        }
                    }

                    ProductoDAO prodDao = new ProductoDAO();
                    String      sku     = txtSKU.Text.ToUpper();
                    String      nombre  = txtNombre.Text.ToUpper();
                    String      precio  = txtPrecio.Text;
                    sbyte       activo  = 0;
                    if (cmbActivo.Text.Equals("Activo"))
                    {
                        activo = 1;
                    }
                    else
                    {
                        activo = 0;
                    }
                    Int16  rubro       = Int16.Parse(cmbRubro.SelectedValue.ToString());
                    String descripcion = txtDescripcion.Text;
                    String promocion   = cbPermitePromocion.Checked.ToString();
                    if (promocion.Equals("True"))
                    {
                        promocion = "1";
                    }
                    else
                    {
                        promocion = "0";
                    }

                    Boolean skuExistente = prodDao.buscaProductoPorSku(sku);
                    if (!skuExistente)
                    {
                        prodDao.InsertaProducto(nombre, descripcion, precio, promocion, sku, activo, DateTime.Now, rubro);
                    }
                    else
                    {
                        MessageBox.Show("El SKU del producto ya se encuentra ingresado.");
                        return;
                    }

                    int idProducto = prodDao.buscaProductoPorNombre(nombre, sku);

                    for (int x = 0; x < arreglo.Length; x++)
                    {
                        TiendaDAO tiDAO    = new TiendaDAO();
                        int       idTienda = tiDAO.buscaIdTiendaPorNombre2(arreglo[x]);
                        prodDao.guardaProductoTienda(idProducto, idTienda);
                    }

                    MessageBox.Show("Creación de producto exitosa.");
                    limpiarCampos();
                    PortadaMantenedorProducto ProductoView = new PortadaMantenedorProducto();
                    ProductoView.Refresh();
                    this.Visible = false;
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Ocurrió un problema creando el producto. Por favor intenta mas tarde o contacta a soporte.");
                    return;
                }
            }
        }