private void BtnGuardar_Click(object sender, EventArgs e)
        {
            try
            {
                ServiceProcess_Validadores.Process_ValidadoresSoapClient auxServiceValidadores = new ServiceProcess_Validadores.Process_ValidadoresSoapClient();
                auxServiceValidadores.ClientCredentials.UserName.UserName = Cuenta.Usuario_iis;
                auxServiceValidadores.ClientCredentials.UserName.Password = Cuenta.Clave_iis;

                ServiceProcess_Cuenta.Process_CuentaSoapClient auxServiceCuenta = new ServiceProcess_Cuenta.Process_CuentaSoapClient();
                auxServiceCuenta.ClientCredentials.UserName.UserName = Cuenta.Usuario_iis;
                auxServiceCuenta.ClientCredentials.UserName.Password = Cuenta.Clave_iis;
                ServiceProcess_Cuenta.Cuenta auxCuenta = new ServiceProcess_Cuenta.Cuenta();

                if (Convert.ToInt32(cbRol.SelectedIndex) == 0 || txtCorreo.Text.Equals(""))
                {
                    if (Convert.ToInt32(cbRol.SelectedIndex) == 0)
                    {
                        MessageBox.Show("Debe Seleccionar Rol antes de Crear Cuenta.", "ATENCION", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else if (txtCorreo.Text.Equals(""))
                    {
                        MessageBox.Show("Correo no puede estar vacio.", "ATENCION", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                else
                {
                    if (txtCorreo.Text.Trim().Length < 6 || txtCorreo.Text.Trim().Length > 60)
                    {
                        MessageBox.Show("Correo debe tener mas de 6 caracteres y menos de 60.", "ATENCION", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        if (!auxServiceValidadores.correoValidacionService(txtCorreo.Text.ToUpper()))
                        {
                            MessageBox.Show("Formato de correo no es  Valido.", "ATENCION", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else
                        {
                            if (MessageBox.Show("Confirmar La Modificacion de la Cuenta", "Confirmar", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                            {
                                //Insertar datos via web service
                                auxServiceCuenta.ActualizarCuentaSinEntidad_Escritorio(_rut_usuario, _rut_empresa, Convert.ToInt32(_estado), Convert.ToInt32(cbRol.SelectedIndex), txtCorreo.Text.Trim().ToUpper());
                                //Metodo Carga de GridView
                                this.DialogResult = DialogResult.OK;
                                this.Close();
                            }
                            else
                            {
                                //se devuelve al Cuadro de datos
                            }
                        }
                    }
                    ;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error en metodo de accion BtnGuardar_Click, Contactese con el Administrador Detalle de Error: " + ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void BtnGuardar_Click(object sender, EventArgs e)
        {
            try
            {
                //Instancia de Web service con credenciales NT
                ServiceProcess_Unidad.Process_UnidadSoapClient auxServiceUnidad = new ServiceProcess_Unidad.Process_UnidadSoapClient();
                auxServiceUnidad.ClientCredentials.UserName.UserName = Cuenta.Usuario_iis;
                auxServiceUnidad.ClientCredentials.UserName.Password = Cuenta.Clave_iis;
                ServiceProcess_Validadores.Process_ValidadoresSoapClient auxServiceValidadores = new ServiceProcess_Validadores.Process_ValidadoresSoapClient();
                auxServiceValidadores.ClientCredentials.UserName.UserName = Cuenta.Usuario_iis;
                auxServiceValidadores.ClientCredentials.UserName.Password = Cuenta.Clave_iis;
                ServiceProcess_Unidad.Unidad auxUnidad = new ServiceProcess_Unidad.Unidad();

                //Validacion espacion en blanco y combobox vacios
                if (txtNombre.Text.Equals("") || txtDescripcion.Text.Equals("") || txtEmpresa.Text.Equals(""))
                {
                    if (txtNombre.Text.Equals(""))
                    {
                        MessageBox.Show("El Nombre de la Unidad no Puede estar Vacia.", "ATENCION", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else if (txtDescripcion.Text.Equals(""))
                    {
                        MessageBox.Show("La Descripcion de la Unidad no Puede estar Vacia.", "ATENCION", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else if (txtEmpresa.Text.Equals(""))
                    {
                        MessageBox.Show("Debe seleccionar una Empresa a la cual pertenece la Unidad, en la Lista de la Izquierda.", "ATENCION", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                else
                {
                    //Validacion de longitud de caracteres
                    if (txtNombre.Text.Trim().Length < 4 || txtNombre.Text.Trim().Length > 99 ||
                        txtDescripcion.Text.Trim().Length < 10 || txtDescripcion.Text.Trim().Length > 250)
                    {
                        if (txtNombre.Text.Trim().Length < 4 || txtNombre.Text.Trim().Length > 99)
                        {
                            MessageBox.Show("El Nombre de la Unidad debe tener Minimo 4 caracteres y Maximo 99 .", "ATENCION", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else if (txtDescripcion.Text.Trim().Length < 10 || txtDescripcion.Text.Trim().Length > 250)
                        {
                            MessageBox.Show("La Descripcion de la Unidad debe tener Minimo 10 caracteres y Maximo 250 .", "ATENCION", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                    else
                    {
                        auxUnidad = auxServiceUnidad.TraerUnidadPorNombrePorEmpresaConEntidad_Escritorio(txtNombre.Text.ToUpper(), rut_empresa);
                        //Validar si Nombre Unidad ya existe en la empresa
                        if (auxUnidad.Nombre == null || auxUnidad.Nombre.ToUpper().Equals(txtNombre.Text.ToUpper()))
                        {
                            if (MessageBox.Show("Confirmar la modificacion de la Unidad", "CONFIRMAR", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                            {
                                //Insertar datos via web service
                                auxServiceUnidad.ActualizarUnidadSinEntidad_Escritorio(id_unidad, txtNombre.Text.ToUpper(), txtDescripcion.Text.ToUpper(), estado, rut_empresa);
                                //Metodo Carga de GridView
                                this.DialogResult = DialogResult.OK;
                                this.Close();
                            }
                            else
                            {
                                //se devuelve al Cuadro de datos
                            }
                        }
                        else
                        {
                            MessageBox.Show("Este Nombre de Unidad ya Existe en la Empresa Seleccionada", "ATENCION", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error en metodo de accion BtnGuardar_Click, Contactese con el Administrador Detalle de Error: " + ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void BtnGuardar_Click(object sender, EventArgs e)
        {
            try
            {
                ServiceProcess_Validadores.Process_ValidadoresSoapClient auxServiceValidadores = new ServiceProcess_Validadores.Process_ValidadoresSoapClient();
                auxServiceValidadores.ClientCredentials.UserName.UserName = Cuenta.Usuario_iis;
                auxServiceValidadores.ClientCredentials.UserName.Password = Cuenta.Clave_iis;

                ServiceProcess_Usuario.Process_UsuarioSoapClient auxServiceUsuario = new ServiceProcess_Usuario.Process_UsuarioSoapClient();
                auxServiceUsuario.ClientCredentials.UserName.UserName = Cuenta.Usuario_iis;
                auxServiceUsuario.ClientCredentials.UserName.Password = Cuenta.Clave_iis;

                ServiceProcess_CargosUsuarios.Process_CargosUsuariosSoapClient auxServiceCargosUsuarios = new ServiceProcess_CargosUsuarios.Process_CargosUsuariosSoapClient();
                auxServiceCargosUsuarios.ClientCredentials.UserName.UserName = Cuenta.Usuario_iis;
                auxServiceCargosUsuarios.ClientCredentials.UserName.Password = Cuenta.Clave_iis;

                //Validacion espacio en blanco y seleccion de combobox
                if (txtRutUsuario.Text.Trim().Equals("") || txtPrimerNombre.Text.Trim().Equals("") || txtSegundoNombre.Text.Trim().Equals("") ||
                    txtPrimerApellido.Text.Equals("") || txtSegundoApellido.Text.Equals("") || txtDireccion.Text.Equals("") ||
                    txtTelefonoFijo.Text.Equals("") || txtTelefonoMovil.Text.Equals("") || txtCargo.Text.Equals("") ||
                    Convert.ToInt32(cbRegion.SelectedIndex) == 0 || Convert.ToInt32(cbProvincia.SelectedIndex) == 0 ||
                    Convert.ToInt32(cbComuna.SelectedIndex) == 0 || Convert.ToInt32(cbEmpresa.SelectedIndex) == 0)
                {
                    if (txtRutUsuario.Text.Trim().Equals(""))//Mensaje Para Rut Vacio
                    {
                        MessageBox.Show("El campo Rut No puede estar Vacio.", "ATENCION", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else if (txtPrimerNombre.Text.Trim().Equals(""))//Mensaje Para Primer Nombre Vacio
                    {
                        MessageBox.Show("El campo Primer Nombre No puede estar Vacio.", "ATENCION", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else if (txtSegundoNombre.Text.Trim().Equals(""))//Mensaje Para Segundo Nombre Vacio
                    {
                        MessageBox.Show("El campo Segundo Nombre No puede estar Vacio.", "ATENCION", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else if (txtPrimerApellido.Text.Equals(""))//Mensaje Para Primer Apellido Vacio
                    {
                        MessageBox.Show("El campo Primer Apellido No puede estar Vacio.", "ATENCION", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else if (txtSegundoApellido.Text.Equals(""))//Mensaje Para Segundo Apellido Vacio
                    {
                        MessageBox.Show("El campo Segundo Apellido No puede estar Vacio.", "ATENCION", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else if (txtDireccion.Text.Equals(""))//Mensaje Para Direccion Vacio
                    {
                        MessageBox.Show("El campo Direccion No puede estar Vacio.", "ATENCION", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else if (txtTelefonoFijo.Text.Equals(""))//Mensaje Para Telefono fijo Vacio
                    {
                        MessageBox.Show("El campo Telefono Fijo No puede estar Vacio.", "ATENCION", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else if (txtTelefonoMovil.Text.Equals(""))//Mensaje Para Telefono Movil Vacio
                    {
                        MessageBox.Show("El campo Telefono Movil No puede estar Vacio.", "ATENCION", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else if (txtCargo.Text.Equals(""))//Mensaje Para cargo Vacio
                    {
                        MessageBox.Show("Debe seleccionar un Cargo para el usuario.", "ATENCION", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else if (Convert.ToInt32(cbRegion.SelectedIndex) == 0)//Mensaje Para Combo region Sin seleccionar
                    {
                        MessageBox.Show("Debe seleccionar una Region .", "ATENCION", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else if (Convert.ToInt32(cbProvincia.SelectedIndex) == 0)//Mensaje Para Combo provincia Sin seleccionar
                    {
                        MessageBox.Show("Debe seleccionar una Provincia .", "ATENCION", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else if (Convert.ToInt32(cbComuna.SelectedIndex) == 0)//Mensaje Para Combo Comuna Sin seleccionar
                    {
                        MessageBox.Show("Debe seleccionar una Comuna .", "ATENCION", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else if (Convert.ToInt32(cbEmpresa.SelectedIndex) == 0)//Mensaje Para Combo Empresa Sin seleccionar
                    {
                        MessageBox.Show("Debe seleccionar una Empresa .", "ATENCION", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
                else
                {
                    //Validar longitud de caracteres
                    if (txtRutUsuario.Text.Trim().Length < 10 || txtRutUsuario.Text.Trim().Length > 12 ||
                        txtPrimerNombre.Text.Trim().Length < 2 || txtPrimerNombre.Text.Trim().Length > 70 ||
                        txtSegundoNombre.Text.Trim().Length < 2 || txtSegundoNombre.Text.Trim().Length > 70 ||
                        txtPrimerApellido.Text.Trim().Length < 2 || txtPrimerApellido.Text.Trim().Length > 70 ||
                        txtSegundoApellido.Text.Trim().Length < 2 || txtSegundoApellido.Text.Trim().Length > 70 ||
                        txtDireccion.Text.Trim().Length < 5 || txtDireccion.Text.Trim().Length > 70 ||
                        txtTelefonoFijo.Text.Trim().Length < 9 || txtTelefonoFijo.Text.Trim().Length > 12 ||
                        txtTelefonoMovil.Text.Trim().Length < 8 || txtTelefonoMovil.Text.Trim().Length > 12)
                    {
                        if (txtRutUsuario.Text.Trim().Length < 10 || txtRutUsuario.Text.Trim().Length > 12)//Mensaje longitud fuera de rango rut usuario
                        {
                            MessageBox.Show("El Rut, debe tener un minimo de 10 Caracteres.", "ATENCION", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                        else if (txtPrimerNombre.Text.Trim().Length < 2 || txtPrimerNombre.Text.Trim().Length > 70)//Mensaje longitud fuera de rango primer nombre
                        {
                            MessageBox.Show("El Primer Nombre, debe tener un minimo de 2 Caracteres.", "ATENCION", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                        else if (txtSegundoNombre.Text.Trim().Length < 2 || txtSegundoNombre.Text.Trim().Length > 70)//Mensaje longitud fuera de rango segundo nombre
                        {
                            MessageBox.Show("El Segundo Nombre, debe tener un minimo de 2 Caracteres.", "ATENCION", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                        else if (txtPrimerApellido.Text.Trim().Length < 2 || txtPrimerApellido.Text.Trim().Length > 70)//Mensaje longitud fuera de rango primer apellido
                        {
                            MessageBox.Show("El Primer Apellido, debe tener un minimo de 2 Caracteres.", "ATENCION", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                        else if (txtSegundoApellido.Text.Trim().Length < 2 || txtSegundoApellido.Text.Trim().Length > 70)//Mensaje longitud fuera de rango segundo apellido
                        {
                            MessageBox.Show("El Segundo Apellido, debe tener un minimo de 2 Caracteres.", "ATENCION", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                        else if (txtDireccion.Text.Trim().Length < 5 || txtDireccion.Text.Trim().Length > 70)//Mensaje longitud fuera de rango direccion
                        {
                            MessageBox.Show("La Direccion, debe tener un minimo de 5 Caracteres.", "ATENCION", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                        else if (txtTelefonoFijo.Text.Trim().Length < 9 || txtTelefonoFijo.Text.Trim().Length > 12) //Mensaje longitud fuera de rango telefono fijo
                        {
                            MessageBox.Show("El Telefono Fijo, debe tener un minimo de 9 Caracteres.", "ATENCION", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                        else if (txtTelefonoMovil.Text.Trim().Length < 8 || txtTelefonoMovil.Text.Trim().Length > 12) //Mensaje longitud fuera de rango telefono movil
                        {
                            MessageBox.Show("El Telefono Movil, debe tener un minimo de 8 Caracteres.", "ATENCION", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                    }
                    else
                    {
                        //Validacion de formato de correo, validacion numero de telefono, validacion rut correcto
                        if (!auxServiceValidadores.numeroValidacionService(txtTelefonoFijo.Text) ||
                            !auxServiceValidadores.numeroValidacionService(txtTelefonoMovil.Text) ||
                            !auxServiceValidadores.rutValidacionService(txtRutUsuario.Text))
                        {
                            if (!auxServiceValidadores.numeroValidacionService(txtTelefonoFijo.Text))//Mensaje de ingreso de caracteres en telefono fijo
                            {
                                MessageBox.Show("El Telefono Fijo debe contener solo Numeros.", "ATENCION", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            }
                            else if (!auxServiceValidadores.numeroValidacionService(txtTelefonoMovil.Text))//Mensaje de ingreso de caracteres en telefono movil
                            {
                                MessageBox.Show("El Telefono Movil debe contener solo Numeros.", "ATENCION", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            }
                            else if (!auxServiceValidadores.rutValidacionService(txtRutUsuario.Text))//Mensaje de rut no valido
                            {
                                MessageBox.Show("Rut Ingresado No Valido.", "ATENCION", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            }
                        }
                        else
                        {
                            DataSet ds = auxServiceUsuario.TraerUsuarioPorRutPorEmpresaSinEntidad_Escritorio(txtRutUsuario.Text.ToUpper(), cbEmpresa.SelectedValue.ToString().ToUpper());
                            //Validacion si existe Usuario
                            if (ds.Tables.Count == 0)
                            {
                                //confirmacion de crear nuevo usuario
                                if (MessageBox.Show("Confirmar La Creacion del Usuario.", "CONFIRMAR", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                                {
                                    //Insertar datos via web service tabla usuario
                                    auxServiceUsuario.InsertarUsuarioSinEntidad_Escritorio(txtRutUsuario.Text.ToUpper(), txtPrimerNombre.Text.ToUpper(), txtSegundoNombre.Text.ToUpper(),
                                                                                           txtPrimerApellido.Text.ToUpper(), txtSegundoApellido.Text.ToUpper(), txtDireccion.Text.ToUpper(),
                                                                                           Convert.ToInt32(txtTelefonoFijo.Text.ToUpper()), Convert.ToInt32(txtTelefonoMovil.Text.ToString()),
                                                                                           Convert.ToInt32(cbComuna.SelectedValue.ToString()));
                                    //Insertar datos via web service tabla cargo_usuario
                                    auxServiceCargosUsuarios.InsertarCargosUsuarioSinEntidad_Escritorio(txtRutUsuario.Text, Convert.ToInt32(_id_cargo), 1);

                                    this.DialogResult = DialogResult.OK;
                                    this.Close();
                                }
                                else
                                {
                                    //se devuelve al Cuadro de datos
                                    MessageBox.Show("Se cancelo la creacion del Usuario.", "CREACION DE USUARIO", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                }
                            }
                            else
                            {
                                string nombreEmpresa = Convert.ToString(cbEmpresa.GetItemText(cbEmpresa.SelectedItem));
                                MessageBox.Show("El Usuario Ya existe En la Empresa " + nombreEmpresa + ".", "ATENCION", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error en metodo BtnGuardar_Click, Contactese con el Administrador Detalle de Error: " + ex.Message, "Mensaje de sistema");
            }
        }
        private void BtnGuardar_Click(object sender, EventArgs e)
        {
            try
            {
                //Instancia de Web service con credenciales NT
                ServiceProcess_Empresa.Process_EmpresaSoapClient auxServiceEmpresa = new ServiceProcess_Empresa.Process_EmpresaSoapClient();
                auxServiceEmpresa.ClientCredentials.UserName.UserName = Cuenta.Usuario_iis;
                auxServiceEmpresa.ClientCredentials.UserName.Password = Cuenta.Clave_iis;
                ServiceProcess_Validadores.Process_ValidadoresSoapClient auxServiceValidadores = new ServiceProcess_Validadores.Process_ValidadoresSoapClient();
                auxServiceValidadores.ClientCredentials.UserName.UserName = Cuenta.Usuario_iis;
                auxServiceValidadores.ClientCredentials.UserName.Password = Cuenta.Clave_iis;
                if (_guardar == 1)//Modificar empresa
                {
                    //Validacion espacion en blanco y combobox vacios
                    if (txtRutEmpresa.Text.Equals("") || txtNombreEmpresa.Text.Equals("") || txtGiro.Text.Equals("") ||
                        txtDireccion.Text.Equals("") || txtEstado.Text.Equals("") || Convert.ToInt32(cbRegion.SelectedIndex) == 0 ||
                        cbProvincia.SelectedValue == null || cbComuna.SelectedValue == null)
                    {
                        if (txtRutEmpresa.Text.Equals(""))
                        {
                            MessageBox.Show("El Rut de la Empresa no Puede estar Vacio.", "ATENCION", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else if (txtNombreEmpresa.Text.Equals(""))
                        {
                            MessageBox.Show("El Nombre de la Empresa no Puede estar Vacio.", "ATENCION", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else if (txtGiro.Text.Equals(""))
                        {
                            MessageBox.Show("El Giro de la Empresa no Puede estar Vacio.", "ATENCION", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else if (txtEstado.Text.Equals(""))
                        {
                            MessageBox.Show("El Estado de la Empresa no Puede estar Vacio.", "ATENCION", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else if (Convert.ToInt32(cbRegion.SelectedIndex) == 0)
                        {
                            MessageBox.Show("Debe seleccionar una Region.", "ATENCION", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else if (cbProvincia.SelectedValue == null)
                        {
                            MessageBox.Show("Debe seleccionar una Provincia.", "ATENCION", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else if (cbComuna.SelectedValue == null)
                        {
                            MessageBox.Show("Debe seleccionar una Comuna.", "ATENCION", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                    else
                    {
                        //Validacion de longitud de caracteres
                        if (txtRutEmpresa.Text.Trim().Length < 9 || txtRutEmpresa.Text.Trim().Length > 12 ||
                            txtNombreEmpresa.Text.Trim().Length < 4 || txtNombreEmpresa.Text.Trim().Length > 50 ||
                            txtGiro.Text.Trim().Length < 4 || txtGiro.Text.Trim().Length > 50 ||
                            txtDireccion.Text.Trim().Length < 4 || txtDireccion.Text.Trim().Length > 50)
                        {
                            if (txtRutEmpresa.Text.Trim().Length < 9 || txtRutEmpresa.Text.Trim().Length > 12)
                            {
                                MessageBox.Show("El Rut de la empresa debe tener Minimo 9 caracteres y Maximo 12 .", "ATENCION", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                            else if (txtNombreEmpresa.Text.Trim().Length < 4 || txtNombreEmpresa.Text.Trim().Length > 50)
                            {
                                MessageBox.Show("El Nombre de la empresa debe tener Minimo 4 caracteres y Maximo 50 .", "ATENCION", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                            else if (txtGiro.Text.Trim().Length < 4 || txtGiro.Text.Trim().Length > 50)
                            {
                                MessageBox.Show("El Giro de la empresa debe tener Minimo 4 caracteres y Maximo 50 .", "ATENCION", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                            else if (txtDireccion.Text.Trim().Length < 4 || txtDireccion.Text.Trim().Length > 50)
                            {
                                MessageBox.Show("La Direccion de la empresa debe tener Minimo 4 caracteres y Maximo 50 .", "ATENCION", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                        }
                        else
                        {
                            //confirmacion de crear nueva empresa
                            if (MessageBox.Show("Confirmar La Modificacion de la Empresa Seleccionada", "CONFIRMAR", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                            {
                                //ESTADO
                                int _estado;
                                if (txtEstado.Equals("ACTIVO"))
                                {
                                    _estado = 1;
                                }
                                else
                                {
                                    _estado = 0;
                                }
                                //Insertar datos via web service
                                auxServiceEmpresa.ActualizarEmpresaSinEntidad_Escritorio(txtRutEmpresa.Text.ToUpper(), txtNombreEmpresa.Text.ToUpper(), txtGiro.Text.ToUpper(), txtDireccion.Text.ToUpper(), _estado, Convert.ToInt32(cbComuna.SelectedValue));
                                //Metodo Carga de GridView

                                this.DialogResult = DialogResult.OK;
                                this.Close();
                            }
                            else
                            {
                                //se devuelve al Cuadro de datos
                            }
                        }
                    }
                }
                else//Nueva empresa
                {
                    //Validacion espacion en blanco y combobox vacios
                    if (txtRutEmpresa.Text.Equals("") || txtNombreEmpresa.Text.Equals("") || txtGiro.Text.Equals("") ||
                        txtDireccion.Text.Equals("") || Convert.ToInt32(cbRegion.SelectedIndex) == 0 ||
                        cbProvincia.SelectedValue == null || cbComuna.SelectedValue == null ||
                        Convert.ToInt32(cbProvincia.SelectedIndex) == 0 || Convert.ToInt32(cbComuna.SelectedIndex) == 0)
                    {
                        if (txtRutEmpresa.Text.Equals(""))
                        {
                            MessageBox.Show("El Rut de la Empresa no Puede estar Vacio.", "ATENCION", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else if (txtNombreEmpresa.Text.Equals(""))
                        {
                            MessageBox.Show("El Nombre de la Empresa no Puede estar Vacio.", "ATENCION", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else if (txtGiro.Text.Equals(""))
                        {
                            MessageBox.Show("El Giro de la Empresa no Puede estar Vacio.", "ATENCION", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else if (Convert.ToInt32(cbRegion.SelectedIndex) == 0)
                        {
                            MessageBox.Show("Debe seleccionar una Region.", "ATENCION", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else if (cbProvincia.SelectedValue == null)
                        {
                            MessageBox.Show("Debe seleccionar una Provincia.", "ATENCION", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else if (cbComuna.SelectedValue == null)
                        {
                            MessageBox.Show("Debe seleccionar una Comuna.", "ATENCION", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else if (Convert.ToInt32(cbProvincia.SelectedIndex) == 0)
                        {
                            MessageBox.Show("Debe seleccionar una Provincia.", "ATENCION", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else if (Convert.ToInt32(cbComuna.SelectedIndex) == 0)
                        {
                            MessageBox.Show("Debe seleccionar una Comuna.", "ATENCION", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                    else
                    {
                        //Validacion de longitud de caracteres
                        if (txtRutEmpresa.Text.Trim().Length < 9 || txtRutEmpresa.Text.Trim().Length > 12 ||
                            txtNombreEmpresa.Text.Trim().Length < 4 || txtNombreEmpresa.Text.Trim().Length > 50 ||
                            txtGiro.Text.Trim().Length < 4 || txtGiro.Text.Trim().Length > 50 ||
                            txtDireccion.Text.Trim().Length < 4 || txtDireccion.Text.Trim().Length > 50)
                        {
                            if (txtRutEmpresa.Text.Trim().Length < 9 || txtRutEmpresa.Text.Trim().Length > 12)
                            {
                                MessageBox.Show("El Rut de la empresa debe tener Minimo 9 caracteres y Maximo 12 .", "ATENCION", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                            else if (txtNombreEmpresa.Text.Trim().Length < 4 || txtNombreEmpresa.Text.Trim().Length > 50)
                            {
                                MessageBox.Show("El Nombre de la empresa debe tener Minimo 4 caracteres y Maximo 50 .", "ATENCION", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                            else if (txtGiro.Text.Trim().Length < 4 || txtGiro.Text.Trim().Length > 50)
                            {
                                MessageBox.Show("El Giro de la empresa debe tener Minimo 4 caracteres y Maximo 50 .", "ATENCION", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                            else if (txtDireccion.Text.Trim().Length < 4 || txtDireccion.Text.Trim().Length > 50)
                            {
                                MessageBox.Show("La Direccion de la empresa debe tener Minimo 4 caracteres y Maximo 50 .", "ATENCION", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                        }
                        else
                        {
                            //Validacion de rut
                            if (!auxServiceValidadores.rutValidacionService(txtRutEmpresa.Text.ToUpper()))
                            {
                                MessageBox.Show("El RUT de la Empresa ingresado no es Valido.", "ATENCION", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                            else
                            {
                                //carga clase empresa
                                ServiceProcess_Empresa.Empresa auxEmpresa = new ServiceProcess_Empresa.Empresa();
                                auxEmpresa = auxServiceEmpresa.TraerEmpresaConEntidad_Escritorio(txtRutEmpresa.Text);
                                //Validar si empresa nueva ya esta registrada en sistema
                                if (auxEmpresa.Rut_empresa == null)
                                {
                                    //confirmacion de crear nueva empresa
                                    if (MessageBox.Show("Confirmar La Creacion de la Empresa.", "CONFIRMAR", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                                    {
                                        //ESTADO
                                        int _estado;
                                        _estado = 1;
                                        //Insertar datos via web service
                                        auxServiceEmpresa.InsertarEmpresaSinEntidad_Escritorio(txtRutEmpresa.Text.ToUpper(), txtNombreEmpresa.Text.ToUpper(), txtGiro.Text.ToUpper(), txtDireccion.Text.ToUpper(), _estado, Convert.ToInt32(cbComuna.SelectedValue));
                                        //Metodo Carga de GridView
                                        this.DialogResult = DialogResult.OK;
                                        this.Close();
                                    }
                                    else
                                    {
                                        //se devuelve al Cuadro de datos
                                    }
                                }
                                else
                                {
                                    MessageBox.Show("La Empresa que intenta registrar ya esta en el Sistema.", "ATENCION", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                }
                            }
                        }
                    }
                }//fin if principal
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error en Metodo de Accion BtnGuardar_Click, Contactese con el Administrador Detalle de Error: " + ex.Message, "Mensaje de sistema");
            }//fin try catch
        }