コード例 #1
0
 private void CboTipoProducto_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (cboTipoProducto.SelectedIndex != -1)
     {
         cboProducto.Enabled = true;
         if (cboTipoProducto.Text != "")
         {
             LlenarCombo(cboProducto, DBHelper.getDBHelper().ConsultaSQL("SELECT * FROM Productos WHERE idTipoProducto = " + cboTipoProducto.SelectedValue), "idProducto", "nombre");
         }
         if (cboProducto.Items.Count == 0)
         {
             MessageBox.Show("No hay ningun producto de esa categoría...", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
             cboProducto.Enabled           = false;
             cboTipoProducto.SelectedIndex = -1;
             return;
         }
         Entities.TipoProducto p = service.getPrecioCategoria((int)cboTipoProducto.SelectedValue);
         txtPrecio.Text   = p.precioBase.ToString();
         numCantidad.Text = "1";
         float precio;
         if (float.TryParse(txtPrecio.Text, out precio))
         {
             float cantidad;
             if (float.TryParse(numCantidad.Value.ToString(), out cantidad))
             {
                 txtImporte.Text = (precio * cantidad).ToString();
             }
         }
     }
 }
コード例 #2
0
 private void DgvTipoProducto_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     if (!ckBorrados.Checked)
     {
         selected = Int32.Parse(dgvTipoProducto.CurrentRow.Cells[0].Value.ToString());
         Entities.TipoProducto tp = new Entities.TipoProducto();
         tp.id                = Int32.Parse(dgvTipoProducto.CurrentRow.Cells[0].Value.ToString());
         tp.nombre            = dgvTipoProducto.CurrentRow.Cells[1].Value.ToString();
         tp.precioBase        = float.Parse(dgvTipoProducto.CurrentRow.Cells[2].Value.ToString().Replace("$", ""));
         txtNombre.Text       = tp.nombre;
         txtPrecio.Text       = tp.precioBase.ToString();
         btnEliminar.Enabled  = true;
         btnModificar.Enabled = true;
     }
     else
     {
         selected = Int32.Parse(dgvTipoProducto.CurrentRow.Cells[0].Value.ToString());
         Entities.TipoProducto tp = new Entities.TipoProducto();
         tp.id                = Int32.Parse(dgvTipoProducto.CurrentRow.Cells[0].Value.ToString());
         tp.nombre            = dgvTipoProducto.CurrentRow.Cells[1].Value.ToString();
         tp.precioBase        = float.Parse(dgvTipoProducto.CurrentRow.Cells[2].Value.ToString().Replace("$", ""));
         txtNombre.Text       = tp.nombre;
         txtPrecio.Text       = tp.precioBase.ToString();
         btnHabilitar.Enabled = true;
         btnEliminar.Enabled  = false;
         btnModificar.Enabled = false;
     }
 }
コード例 #3
0
        public bool nuevoTipoProducto(Entities.TipoProducto oTipo)
        {
            string sql   = "INSERT INTO TipoProducto (nombre,precioBase,activo) VALUES (@nombre,@precio,1)";
            var    param = new Dictionary <string, Object>();

            param.Add("nombre", oTipo.nombre);
            param.Add("precio", oTipo.precioBase);
            return(DBHelper.getDBHelper().EjecutarSQL(sql, param) >= 1);
        }
コード例 #4
0
        public bool modificarTipoProducto(Entities.TipoProducto oTipo)
        {
            string sql   = "UPDATE TipoProducto SET nombre = '" + oTipo.nombre + "', precioBase = @precio WHERE idTipoProducto = @id";
            var    param = new Dictionary <string, Object>();

            param.Add("precio", oTipo.precioBase);
            param.Add("id", oTipo.id);
            return(DBHelper.getDBHelper().EjecutarSQL(sql, param) == 1);
        }
コード例 #5
0
        private Entities.TipoProducto mapTipoProducto(DataRow row)
        {
            Entities.TipoProducto tp = new Entities.TipoProducto();
            tp.id         = Int32.Parse(row["idTipoProducto"].ToString());
            tp.nombre     = row["nombre"].ToString();
            tp.precioBase = float.Parse(row["precioBase"].ToString());
            tp.activo     = bool.Parse(row["activo"].ToString());

            return(tp);
        }
コード例 #6
0
 public bool update(Entities.TipoProducto tp_edit)
 {
     return(dao.modificarTipoProducto(tp_edit));
 }
コード例 #7
0
 public bool add(Entities.TipoProducto tp)
 {
     return(dao.nuevoTipoProducto(tp));
 }
コード例 #8
0
        private void BtnAplicar_Click(object sender, EventArgs e)
        {
            switch (abm)
            {
            case tipo.add:
                Entities.TipoProducto tp = new Entities.TipoProducto();
                float precio             = 0;
                if (float.TryParse(txtPrecio.Text, out precio))
                {
                    tp.precioBase = precio;

                    if (!(service.isRepeated(txtNombre.Text)))
                    {
                        tp.nombre = txtNombre.Text;
                        if (MessageBox.Show("Está Seguro que desea crear la categoría?", "Aviso", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                        {
                            if (service.add(tp))
                            {
                                MessageBox.Show("Se agregó la categoría exitosamente", "Éxito", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                            else
                            {
                                MessageBox.Show("Hubo un error al agregar la nueva categoría", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("El nombre ya esta asociado a una categoría existente", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                else
                {
                    MessageBox.Show("El precio no tiene los caracteres adecuados...", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                recargardgv();
                break;

            case tipo.edit:
                if (txtNombre.Text != "" && txtPrecio.Text != "" && selected != -1)
                {
                    Entities.TipoProducto tp_edit = new Entities.TipoProducto();
                    float price = 0;
                    if (float.TryParse(txtPrecio.Text, out price))
                    {
                        tp_edit.id         = Int32.Parse(dgvTipoProducto.CurrentRow.Cells[0].Value.ToString());
                        tp_edit.precioBase = price;


                        if (!service.validarEdicion(txtNombre.Text, tp_edit.id))
                        {
                            tp_edit.nombre = txtNombre.Text;
                            if (MessageBox.Show("Está Seguro que desea modificar la categoría?", "Aviso", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                            {
                                if (service.update(tp_edit))
                                {
                                    MessageBox.Show("Se modificó la categoría exitosamente", "Éxito", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                }
                                else
                                {
                                    MessageBox.Show("Hubo un error al modificar la categoría", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                }
                            }
                        }
                        else
                        {
                            MessageBox.Show("El nombre ya esta asociado a una categoría existente", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                    else
                    {
                        MessageBox.Show("El precio no tiene los caracteres adecuados...", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    MessageBox.Show("Uno de los campos no puede estar vacio", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                recargardgv();
                break;
            }
        }