Пример #1
0
        private void BtnGuardarT_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (txtDescripcion.Text != "" && txtCategoria.Text != "" && TxtCliente.Text != "" && Txtdireccion.Text != "" && txtfechaderecibo.Text != "" && txtFechaEntregado.Text != "" && Txtnoseguimiento.Text != "" && txtPeso.Text != "")
                {
                    Paquete paq = new Paquete();
                    paq.descripcion    = txtDescripcion.Text;
                    paq.idCliente      = Convert.ToInt32(TxtCliente.Text);
                    paq.noSeguimiento  = Txtnoseguimiento.Text;
                    paq.peso           = Convert.ToInt32(txtPeso.Text);
                    paq.fechaRecibido  = txtfechaderecibo.DisplayDate;
                    paq.direccion      = Txtdireccion.Text;
                    paq.fechaEntregado = txtFechaEntregado.DisplayDate;
                    paq.idCategoria    = Convert.ToInt32(txtCategoria.Text);

                    data.Paquete.InsertOnSubmit(paq);
                    data.SubmitChanges();
                    dgPaquete.ItemsSource = data.Paquete;
                    MessageBox.Show("REGISTRO GUARDADO CORRECTAMENTE");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        private void BtnAgregar_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (txtNombre.Text != "" && txtApellido.Text != "" && txtIdentidad.Text != "" && txtNumeroTel.Text != "")
                {
                    Cliente usu = new Cliente();
                    usu.identidad = txtIdentidad.Text;
                    usu.nombre    = txtNombre.Text;
                    usu.apellido  = txtApellido.Text;
                    usu.telefono  = txtNumeroTel.Text;

                    datacontext.Cliente.InsertOnSubmit(usu);
                    datacontext.SubmitChanges();

                    dgcliente.ItemsSource = datacontext.Cliente;
                    MessageBox.Show("Registro Guardado Correctamente");
                }
                else
                {
                    MessageBox.Show("Faltan datos por ingresar");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        private void BtnAgregar_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (txtContrasenia.Text != "" && txtnombre.Text != "" && cbNivel.Text != "")
                {
                    Usuario usu = new Usuario();
                    usu.nombreUsuario = txtnombre.Text;
                    usu.contrasenia   = txtContrasenia.Text;
                    usu.nivel         = cbNivel.Text;
                    usu.idEmpleado    = Convert.ToInt32(txtidempleado.Text);

                    datacontext.Usuario.InsertOnSubmit(usu);
                    datacontext.SubmitChanges();

                    MessageBox.Show("Usuario Creado con exito");

                    dgusu.ItemsSource = datacontext.Usuario;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        private void BtnGuardar_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (txtNombre.Text != "" && txtApellido.Text != "" && txtCargo.Text != "" && txtDireccion.Text != "" && txtIdentidad.Text != "" && txtTelefono.Text != "" && dateFecha.Text != "" && cbSexo.Text != "" && cbEstadoCivil.Text != "")
                {
                    var usuariologead = data.Empleado.FirstOrDefault(usu => usu.identidad.Equals(txtIdentidad.Text));
                    if (usuariologead == null)
                    {
                        Empleado emp = new Empleado();
                        emp.identidad   = txtIdentidad.Text;
                        emp.nombre      = txtNombre.Text;
                        emp.apellido    = txtApellido.Text;
                        emp.direccion   = txtDireccion.Text;
                        emp.telefono    = txtTelefono.Text;
                        emp.fechaNac    = Convert.ToDateTime(dateFecha.Text);
                        emp.sexo        = cbSexo.Text;
                        emp.idCargo     = Convert.ToInt32(txtCargo.Text);
                        emp.estadoCivil = cbEstadoCivil.Text;

                        data.Empleado.InsertOnSubmit(emp);
                        data.SubmitChanges();
                        dgEmpleado1.ItemsSource = data.Empleado;

                        var usuariologeado = data.Empleado.FirstOrDefault(usu => usu.identidad.Equals(txtIdentidad.Text));
                        ClaseGlobal.Idempleadocreado = usuariologeado.idEmpleado;
                    }
                    else
                    {
                        MessageBox.Show("Ya existe un usuario con esa identidad");
                    } txtIdentidad.Focus();
                }
                else
                {
                    MessageBox.Show("falta un dato por completar", MessageBoxImage.Warning.ToString());
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        private void TxtGenerar_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (txtcantidad.Text != "" && txtCliente.Text != "" && txtEmpleado.Text != "" && txtfechaventa1.Text != "" && txtIdenCliente1.Text != "" && txtidPaquete.Text != "" && txtIvs.Text != "" && txtPrecio.Text != "" && txtTotal.Text != "")
                {
                    Venta ven = new Venta();
                    ven.idEmpleado            = Convert.ToInt32(txtEmpleado.Text);
                    ven.identidadCliente      = txtIdenCliente1.Text;
                    ven.idPaquete             = Convert.ToInt32(txtidPaquete.Text);
                    ven.nombreCompletoCliente = txtCliente.Text;
                    ven.fechaVenta            = Convert.ToDateTime(txtfechaventa1.Text);
                    ven.isv = Convert.ToDecimal(txtIvs.Text);

                    data.Venta.InsertOnSubmit(ven);
                    data.SubmitChanges();


                    var venta = data.Venta.FirstOrDefault(usu => usu.nombreCompletoCliente.Equals(txtCliente.Text));
                    if (venta.nombreCompletoCliente != null)
                    {
                        ClaseGlobal.Idventa = venta.idVenta;
                        DetalleVenta dt = new DetalleVenta();
                        dt.idPaquete    = Convert.ToInt32(txtidPaquete.Text);
                        dt.idVenta      = ClaseGlobal.Idventa;
                        dt.precioUnidad = Convert.ToDecimal(txtPrecio.Text);
                        dt.cantidad     = Convert.ToInt32(txtcantidad.Text);
                        dt.total        = Convert.ToDecimal(txtTotal.Text);

                        data.DetalleVenta.InsertOnSubmit(dt);
                        data.SubmitChanges();
                    }
                    dtDetalleVenta.ItemsSource = data.Venta;
                    MessageBox.Show("Venta registrada con exito");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }