public void GrabarLogMapaBD(DateTime fechaInicio, DateTime FechaFin, double Duracion, Double DuracionSeg, string ip, string nombreUsuario, String TipoLlamada, string url, string tramaInput, string tramaOutput, string TipoEntrada, System.Data.SqlClient.SqlConnection conn = null, string idTrazabilidad = null, string valor1 = null, string IdEvento = null)
        {
            string cadena = "";

            if (ConfigurationManager.ConnectionStrings["TransmisionesDB"] != null)
            {
                cadena = ConfigurationManager.ConnectionStrings["TransmisionesDB"].ConnectionString;

                try
                {
                    using (TransactionScope transactionScope1 = new TransactionScope(TransactionScopeOption.RequiresNew))//(TransactionScopeOption.RequiresNew, option1))
                    {
                        using (SqlConnection conn1 = new SqlConnection(cadena))
                        {
                            try { conn1.Open(); }
                            catch { }

                            System.Data.SqlClient.SqlCommand cm = new System.Data.SqlClient.SqlCommand("USP_INSERT_LOGMAPA", conn1);
                            cm.CommandType = System.Data.CommandType.StoredProcedure;
                            cm.Parameters.Add("@FechaInicio", System.Data.SqlDbType.DateTime).Value = fechaInicio;
                            cm.Parameters.Add("@FechaFin", System.Data.SqlDbType.DateTime).Value    = FechaFin;
                            cm.Parameters.Add("@DuracionMS", System.Data.SqlDbType.Decimal).Value   = Duracion;
                            cm.Parameters.Add("@DuracionSeg", System.Data.SqlDbType.Decimal).Value  = DuracionSeg;


                            if (!string.IsNullOrEmpty(IdEvento))
                            {
                                cm.Parameters.Add("@IdEvento", System.Data.SqlDbType.Char).Value = IdEvento;
                            }
                            else
                            {
                                cm.Parameters.Add("@IdEvento", System.Data.SqlDbType.Char).Value = DBNull.Value;
                            }


                            // INI vj 01/09/2014 - Modificación
                            if (!string.IsNullOrEmpty(idTrazabilidad))
                            {
                                cm.Parameters.Add("@IdTrazabilidad", System.Data.SqlDbType.Char).Value = idTrazabilidad;
                            }
                            else
                            {
                                cm.Parameters.Add("@IdTrazabilidad", System.Data.SqlDbType.Char).Value = DBNull.Value;
                            }
                            if (!string.IsNullOrEmpty(valor1))
                            {
                                cm.Parameters.Add("@Valor1", System.Data.SqlDbType.VarChar).Value = valor1;
                            }
                            else
                            {
                                cm.Parameters.Add("@Valor1", System.Data.SqlDbType.VarChar).Value = DBNull.Value;
                            }
                            // FIN vj 01/09/2014 - Modificación

                            if (!string.IsNullOrEmpty(ip))
                            {
                                cm.Parameters.Add("@IPLocal", System.Data.SqlDbType.VarChar).Value = ip;
                            }
                            else
                            {
                                cm.Parameters.Add("@IPLocal", System.Data.SqlDbType.VarChar).Value = DBNull.Value;
                            }

                            if (!string.IsNullOrEmpty(nombreUsuario))
                            {
                                cm.Parameters.Add("@Usuario", System.Data.SqlDbType.VarChar).Value = nombreUsuario;
                            }
                            else
                            {
                                cm.Parameters.Add("@Usuario", System.Data.SqlDbType.VarChar).Value = DBNull.Value;
                            }

                            if (!string.IsNullOrEmpty(TipoLlamada))
                            {
                                cm.Parameters.Add("@TipoLlamada", System.Data.SqlDbType.VarChar).Value = TipoLlamada;
                            }
                            else
                            {
                                cm.Parameters.Add("@TipoLlamada", System.Data.SqlDbType.VarChar).Value = DBNull.Value;
                            }

                            if (!string.IsNullOrEmpty(url))
                            {
                                cm.Parameters.Add("@URL", System.Data.SqlDbType.VarChar).Value = url;
                            }
                            else
                            {
                                cm.Parameters.Add("@URL", System.Data.SqlDbType.VarChar).Value = DBNull.Value;
                            }

                            if (!string.IsNullOrEmpty(tramaInput))
                            {
                                cm.Parameters.Add("@JsonRequest", System.Data.SqlDbType.Text).Value = tramaInput;
                            }
                            else
                            {
                                cm.Parameters.Add("@JsonRequest", System.Data.SqlDbType.Text).Value = tramaInput;
                            }

                            if (!string.IsNullOrEmpty(tramaOutput))
                            {
                                cm.Parameters.Add("@JsonResponse", System.Data.SqlDbType.Text).Value = tramaOutput;
                            }
                            else
                            {
                                cm.Parameters.Add("@JsonResponse", System.Data.SqlDbType.Text).Value = DBNull.Value;
                            }

                            if (!string.IsNullOrEmpty(TipoEntrada))
                            {
                                cm.Parameters.Add("@TipoEntrada", System.Data.SqlDbType.VarChar).Value = TipoEntrada;
                            }
                            else
                            {
                                cm.Parameters.Add("@TipoEntrada", System.Data.SqlDbType.VarChar).Value = DBNull.Value;
                            }

                            cm.ExecuteNonQuery();

                            try { conn1.Close(); }
                            catch { }
                        }

                        transactionScope1.Complete();
                    }
                }
                catch (Exception ex)
                {
                    var manejadorLogEventos = new ManejadorLogEventos();
                    manejadorLogEventos.GrabarLogMapa(
                        fechaInicio.ToString(),
                        FechaFin.ToString(),
                        Duracion.ToString(),
                        DuracionSeg.ToString(),
                        ip,
                        nombreUsuario,
                        TipoLlamada,
                        url,
                        ex.Message,
                        ex.ToString(),
                        "Error en GrabarLogMapaBD");
                }
            }
            else
            {
                var manejadorLogEventos = new ManejadorLogEventos();
                manejadorLogEventos.GrabarLogMapa(fechaInicio.ToString(), FechaFin.ToString(), Math.Round(Duracion, 2).ToString(), Math.Round(DuracionSeg, 2).ToString(), ip, nombreUsuario, TipoLlamada, url, tramaInput, tramaOutput, IdEvento != null ? IdEvento : "");
            }
        }
        public void GrabarLogMapaBD(DateTime fechaInicio, DateTime FechaFin, double Duracion, Double DuracionSeg, string ip, string nombreUsuario, String TipoLlamada, string url, string tramaInput, string tramaOutput, string TipoEntrada)
        {
            string cadena = "";

            if (ConfigurationManager.ConnectionStrings["AcuerdoComercialAGMADB"] != null)
            {
                cadena = ConfigurationManager.ConnectionStrings["AcuerdoComercialAGMADB"].ConnectionString;
                try
                {
                    using (System.Data.SqlClient.SqlConnection cn = new System.Data.SqlClient.SqlConnection(cadena))
                    {
                        System.Data.SqlClient.SqlCommand cm = new System.Data.SqlClient.SqlCommand("usp_InsertLogMapa", cn);
                        cm.CommandType = System.Data.CommandType.StoredProcedure;
                        cm.Parameters.Add("@FechaInicio", System.Data.SqlDbType.DateTime).Value = fechaInicio;
                        cm.Parameters.Add("@FechaFin", System.Data.SqlDbType.DateTime).Value    = FechaFin;
                        cm.Parameters.Add("@DuracionMS", System.Data.SqlDbType.Decimal).Value   = Duracion;
                        cm.Parameters.Add("@DuracionSeg", System.Data.SqlDbType.Decimal).Value  = DuracionSeg;

                        if (!string.IsNullOrEmpty(ip))
                        {
                            cm.Parameters.Add("@IPLocal", System.Data.SqlDbType.VarChar).Value = ip;
                        }
                        else
                        {
                            cm.Parameters.Add("@IPLocal", System.Data.SqlDbType.VarChar).Value = DBNull.Value;
                        }

                        if (!string.IsNullOrEmpty(nombreUsuario))
                        {
                            cm.Parameters.Add("@Usuario", System.Data.SqlDbType.VarChar).Value = nombreUsuario;
                        }
                        else
                        {
                            cm.Parameters.Add("@Usuario", System.Data.SqlDbType.VarChar).Value = DBNull.Value;
                        }

                        if (!string.IsNullOrEmpty(TipoLlamada))
                        {
                            cm.Parameters.Add("@TipoLlamada", System.Data.SqlDbType.VarChar).Value = TipoLlamada;
                        }
                        else
                        {
                            cm.Parameters.Add("@TipoLlamada", System.Data.SqlDbType.VarChar).Value = DBNull.Value;
                        }

                        if (!string.IsNullOrEmpty(url))
                        {
                            cm.Parameters.Add("@URL", System.Data.SqlDbType.VarChar).Value = url;
                        }
                        else
                        {
                            cm.Parameters.Add("@URL", System.Data.SqlDbType.VarChar).Value = DBNull.Value;
                        }

                        if (!string.IsNullOrEmpty(tramaInput))
                        {
                            cm.Parameters.Add("@JsonRequest", System.Data.SqlDbType.VarChar).Value = tramaInput;
                        }
                        else
                        {
                            cm.Parameters.Add("@JsonRequest", System.Data.SqlDbType.VarChar).Value = tramaInput;
                        }

                        if (!string.IsNullOrEmpty(tramaOutput))
                        {
                            cm.Parameters.Add("@JsonResponse", System.Data.SqlDbType.VarChar).Value = tramaOutput;
                        }
                        else
                        {
                            cm.Parameters.Add("@JsonResponse", System.Data.SqlDbType.VarChar).Value = DBNull.Value;
                        }

                        if (!string.IsNullOrEmpty(TipoEntrada))
                        {
                            cm.Parameters.Add("@TipoEntrada", System.Data.SqlDbType.VarChar).Value = TipoEntrada;
                        }
                        else
                        {
                            cm.Parameters.Add("@TipoEntrada", System.Data.SqlDbType.VarChar).Value = DBNull.Value;
                        }

                        cn.Open();
                        cm.ExecuteNonQuery();
                        cn.Close();
                    }
                }
                catch (Exception)
                {
                    var manejadorLogEventos = new ManejadorLogEventos();
                    manejadorLogEventos.GrabarLogMapa(fechaInicio.ToString(), FechaFin.ToString(), Duracion.ToString(), DuracionSeg.ToString(), ip, nombreUsuario, TipoLlamada, url, tramaInput, tramaOutput, TipoEntrada);
                }
            }
            else
            {
                var manejadorLogEventos = new ManejadorLogEventos();
                manejadorLogEventos.GrabarLogMapa(fechaInicio.ToString(), FechaFin.ToString(), Duracion.ToString(), DuracionSeg.ToString(), ip, nombreUsuario, TipoLlamada, url, tramaInput, tramaOutput, TipoEntrada);
            }
        }