Exemple #1
0
        /// <summary>
        /// Verificar si el NumeroIdentificacion ya Existe
        /// </summary>
        /// <param name="cliente">Mandamos la clase con los datos dentro</param>
        /// <param name="servicio">Conexion del CRM</param>
        /// <returns></returns>
        public string BuscarPlantillaCotizacion(string nombrePlantilla, IOrganizationService servicio)
        {
            try
            {
                string   guidPlantilla = "";
                zthFetch busquedaFetch = new zthFetch("documenttemplate", ref servicio);
                busquedaFetch.AgregarCampoRetorno("documenttemplate", "documenttemplateid", (zthFetch.TipoRetorno.Key));//devuelvo el vendedor
                busquedaFetch.AgregarFiltroPlano("documenttemplate", (zthFetch.TipoFiltro.and), "name", (zthFetch.TipoComparacionFiltro.Igual), nombrePlantilla);

                DataTable dataTable2 = busquedaFetch.GeneraTblconFetchResult();
                if (dataTable2.Rows.Count > 0)
                {
                    guidPlantilla = Cls_Generales.validaDBnullValue(RuntimeHelpers.GetObjectValue(dataTable2.Rows[0]["documenttemplateid"]));
                    return(guidPlantilla);
                }
                else
                {
                    return(string.Empty);
                }
            }
            catch (Exception ex)
            {
                return(string.Empty);
            }
        }
        /// <summary>
        /// Validamos si Existe el Contacto Mediante su DNI
        /// </summary>
        /// <param name="DNI">DNI a Validar</param>
        /// <returns>Validamos si Existe el Contacto Mediante su DNI</returns>
        public DataTable ValidaExisteContacto(string TipoDeDocumento, string NumeroDocumento)
        {
            try

            {
                // Resumen:
                //         Cadena de conexión  ----> CrmServiceClient ( Set up de las Credenciales) ---->  IOrganizationServices (Web Service Intermedio) ----> CRM online 2016

                IOrganizationService servicio;              // Instancia de IOrgnizationService
                servicio = ConexionCRMDA.ObtenerConexion(); // Obtenemos la Conexión de CRM

                /**
                 *
                 * FetchXML, se utiliza para una busqueda avanzada
                 *
                 * **/

                // Ocupamos el Espacio de Nombre "ZthFetchXml365"
                // Instancia de fetch, se ocupa para manipular los datos del CRM :
                //Le Entregamos el nombre de la entidad principal a buscar(Contacto, y la referencia al servicio web de CRM)
                zthFetch fetch = new zthFetch("contact", ref servicio);


                // Fetch contiene métodos parámetrizados, cuando me meta mas al CRM lo voy a entender mejor


                fetch.AgregarCampoRetorno("contact", "contactid", ZthFetchXml365.zthFetch.TipoRetorno.Key);
                //    public void AgregarCampoRetorno(string NombreEntidad, string NombreCampo, TipoRetorno Tipo);
                fetch.AgregarFiltroPlano("contact", ZthFetchXml365.zthFetch.TipoFiltro.and, "sole_tipodocumento", ZthFetchXml365.zthFetch.TipoComparacionFiltro.Igual, TipoDeDocumento);
                //     public void AgregarFiltroPlano(string NombreEntidad, TipoFiltro TipoFiltro, string NombreAtributo, TipoComparacionFiltro TipoComparacion, string ValorAtributo);
                //     Tipo Documento
                fetch.AgregarFiltroPlano("contact", ZthFetchXml365.zthFetch.TipoFiltro.and, "sole_numerodocumento", ZthFetchXml365.zthFetch.TipoComparacionFiltro.Igual, NumeroDocumento);
                //     Numero Documento
                fetch.AgregarCantidadRegistrosDevolver_puedesermenorque5000(1);

                //  Crea un objeto de tipo  datatable
                DataTable Dato = new DataTable();

                // Genera la tabla con el resultado del Fetch y lo llena en la tabla de datos en memoria

                Dato = fetch.GeneraTblconFetchResult(false); // ¿Por que false?

                return(Dato);
            }
            catch (Exception ex)

            {
                // Mensaje de la excepción
                string Mensaje = "Se ha producido el siguiente error: " + ex.Message;
                // DLL guarda el mensaje de excepción en un registro
                ZthMetodosVarios.Metodos.GuardarLog(Ruta, Mensaje);
                // Lo mandan a un correo compartido en outlook, correo soporte
                ZthEnvioCorreos_CRM365.Metodos.EnviarCorreoError(CorreoSoporte, CorreoCliente, Aplicativo, Ruta, Mensaje, CorreoClave, Port, Host);

                throw ex;
            }
        }