Example #1
0
 private void btn_Agregar_Click(object sender, EventArgs e)
 {
     if (string.IsNullOrEmpty(txt_Nombre.Text) || string.IsNullOrEmpty(txt_Email.Text) || string.IsNullOrEmpty(txt_Direccion.Text))
     {
         MessageBox.Show("Ingresa Datos", "Empleados", MessageBoxButtons.OK, MessageBoxIcon.Question);
     }
     else
     {
         if (MessageBox.Show("¿Desea Agregar un Empleado?", "Empleado", MessageBoxButtons.YesNo) == DialogResult.Yes)
         {
             emp = new Empleado
             {
                 Nombre            = txt_Nombre.Text,
                 Telefono          = txt_Telefono.Text,
                 Direccion         = txt_Direccion.Text,
                 Email             = txt_Email.Text,
                 Usuario           = txt_Usuario.Text,
                 Contraseña        = txt_Contra.Text,
                 FechaNacimiento   = dtp_FechaNac.Value,
                 FechaContratacion = dtp_FechaContratacion.Value
             };
             _controller.Agregar(emp);
             _controller.Guardar();
             MessageBox.Show("Empleado Agregado con Exito!");
         }
     }
 }
Example #2
0
 private void btnAgregarP_Click(object sender, EventArgs e)
 {
     if (string.IsNullOrEmpty(txtCat.Text) || string.IsNullOrEmpty(txtNombre.Text))
     {
         MessageBox.Show("Error, Debes Ingresar Datos");
     }
     else
     {
         bool IsGeneric = Convert.ToBoolean(cbxGeneric.Text);
         P = new Producto()
         {
             Nombre       = txtNombre.Text,
             Descripcion  = txtDesc.Text,
             Precio       = Convert.ToInt32(txtPrecio.Text),
             Caducidad    = dtpCaducidad.Value.Date,
             CodigoBarras = txtCodBarras.Text,
             Categoria    = txtCat.Text,
             Stock        = Convert.ToInt32(txtStock.Text),
             Laboratorio  = txtLaboratorio.Text,
             Presentacion = txtPresentacion.Text,
             IsGenerico   = Convert.ToBoolean(cbxGeneric.Text)
         };
         _controller.Agregar(P);
         MessageBox.Show("Dato Agregado");
     }
 }
Example #3
0
 private void btn_Agregar_Click(object sender, EventArgs e)
 {
     if (string.IsNullOrEmpty(txt_Nombre.Text) || string.IsNullOrEmpty(txt_Email.Text) || string.IsNullOrEmpty(txt_Direccion.Text))
     {
         MessageBox.Show("Ingresa Datos", "Clientes", MessageBoxButtons.OK, MessageBoxIcon.Question);
     }
     else
     {
         if (MessageBox.Show("¿Desea Agregar un Cliente?", "Cliente", MessageBoxButtons.YesNo) == DialogResult.Yes)
         {
             c = new Cliente
             {
                 Nombre          = txt_Nombre.Text,
                 Direccion       = txt_Direccion.Text,
                 Telefono        = txt_Telefono.Text,
                 Email           = txt_Email.Text,
                 FechaDeRegistro = dtp_FechaRegistro.Value
             };
             _controller.Agregar(c);
             MessageBox.Show("Cliente Agregado!!");
         }
     }
 }
Example #4
0
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Confirmar Venta", "Confirmar", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                filaSeleccionada = dgvVenta.CurrentRow;
                if (filaSeleccionada != null && dgvVenta.Rows.Count > 0)
                {
                    //Guardar en venta
                    if (venta == null)
                    {
                        //Transacion
                        using (var db = new FARMATICSEntities1())
                        {
                            //Iniciar Transaccion
                            using (var Context = db.Database.BeginTransaction())
                            {
                                try
                                {
                                    //Crear objetos y pasar el contexto
                                    controllerTransac = new FarmaTicsController(db);
                                    //Escribiendo venta
                                    venta = new Venta
                                    {
                                        EmpleadoId   = us.Id,
                                        ClienteId    = cliente.Id,
                                        TotalDeVenta = decimal.Parse(lblTotal.Text),
                                        FechaDeVenta = DateTime.Now,
                                    };
                                    controllerTransac.Agregar(venta);
                                    venta.NumeroDeVenta = venta.Id.ToString();
                                    MessageBox.Show("Venta Guardada");

                                    //Escrinbir detalle Venta

                                    foreach (DataGridViewRow item in dgvVenta.Rows)
                                    {
                                        DetalleVenta detalleVenta = new DetalleVenta
                                        {
                                            VentaId    = venta.Id,
                                            ProductoId = int.Parse(item.Cells[0].Value.ToString()),
                                            Cantidad   = int.Parse(item.Cells[3].Value.ToString())
                                        };
                                        controllerTransac.Agregar(detalleVenta);
                                        MessageBox.Show("Detalle Venta Guardado");

                                        //Actualizar Stock
                                        var p = _controller.ObtenerProductoPorID(detalleVenta.ProductoId);
                                        p.Stock -= detalleVenta.Cantidad;
                                        //throw new Exception();
                                        controllerTransac.Guardar();
                                        MessageBox.Show($"Stock actualizado a: {p.Stock}");
                                    }
                                    Context.Commit();
                                    MessageBox.Show("Transaccion Terminada");
                                }

                                catch (Exception ex)
                                {
                                    Context.Rollback();
                                    MessageBox.Show($"Transaccion Cancelada!!! {ex}");
                                }
                            }
                        }
                    }
                    else
                    {
                    }
                }
                else
                {
                    MessageBox.Show("No hay ningun dato para Guardar");
                }
            }
            else
            {
                MessageBox.Show("Venta Cancelada", "Cancelar", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }