Ejemplo n.º 1
0
        public void InsertComputerConnectionEdit(ComputerConnectionEditDto dto)
        {
            if (dto == null)
                throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, Resources.NullArguementException, "dto"));

            const string Sql =
                @"
INSERT INTO [dbo].[MultiplexorComputerConnections]
(
     [GuidId]
    ,[LastModifiedOn]
    ,[ConnectionId]
    ,[ComputerConnection]
    ,[ConnectionType]
    ,[PortName]    
)
VALUES
(
     @guid
    ,GETDATE()
    ,@connectionId
    ,@computerConnection
    ,@connectionType
    ,@portName  
);

SELECT [Id]
FROM   [dbo].[MultiplexorComputerConnections]
WHERE  [Id] = SCOPE_IDENTITY()
";

            try
            {
                using (var ctx = ConnectionManager<SqlConnection>.GetManager(Database.VeyronMeta, false))
                {
                    var cn = ctx.Connection;

                    using (var cmd = new SqlCommand(Sql, cn))
                    {
                        cmd.Parameters.AddWithValue("@guid", dto.Guid);
                        cmd.Parameters.AddWithValue("@connectionId", dto.ConnectionId);
                        cmd.Parameters.AddWithValue("@computerConnection", dto.ComputerConnection);
                        cmd.Parameters.AddWithValue("@connectionType", dto.ConnectionType.ToString());
                        cmd.Parameters.AddWithValue("@portName", dto.PortName);

                        dto.Id = (int)cmd.ExecuteScalar();
                    }
                }
            }

            catch (Exception ex)
            {
                throw new DBConcurrencyException(ex.Data.ToString());
            }

        }
Ejemplo n.º 2
0
        public void UpdateComputerConnectionEdit(ComputerConnectionEditDto dto)
        {
            if (dto == null) throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, Resources.NullArguementException, "dto"));

            const string Sql =
                @"
UPDATE [dbo].[MultiplexorComputerConnections]
SET
     [GuidId] = @guid
    ,[LastModifiedOn] = GETDATE()
    ,[ConnectionId] = @connectionId 
    ,[ComputerConnection] = @computerConnection
    ,[ConnectionType] = @connectionType
    ,[PortName] = @portName   
WHERE [Id] = @id;
";

            using (var ctx = ConnectionManager<SqlConnection>.GetManager(Database.VeyronMeta, false))
            {
                var cn = ctx.Connection;

                using (var cmd = new SqlCommand(Sql, cn))
                {
                    cmd.Parameters.AddWithValue("@id", dto.Id);

                    cmd.Parameters.AddWithValue("@guid", dto.Guid);
                    cmd.Parameters.AddWithValue("@connectionId", dto.ConnectionId);
                    cmd.Parameters.AddWithValue("@computerConnection", dto.ComputerConnection);
                    cmd.Parameters.AddWithValue("@connectionType", dto.ConnectionType.ToString());
                    cmd.Parameters.AddWithValue("@portName", dto.PortName);

                    var rowsAffetcted = cmd.ExecuteNonQuery();
                    if (rowsAffetcted == 0)
                        throw new DBConcurrencyException(
                            "The entity is out of date on the client. Please update the entity and try again. This could also be thrown if the sql statement failed to execute.");
                }
            }
        }
Ejemplo n.º 3
0
        private static void FetchComputerConnectionList(SqlConnection connection, ConnectionSettingsDto dto)
        {
            const string Sql =
              @"
SELECT
     [Id]
    ,[GuidId]   
    ,[ConnectionId]
    ,[ComputerConnection]
    ,[ConnectionType]
    ,[PortName]   
FROM
    [dbo].[MultiplexorComputerConnections]
WHERE [ConnectionId] = @connectionId;
";
            using (var cmd = new SqlCommand(Sql, connection))
            {
                cmd.Parameters.AddWithValue("@connectionId", dto.ConnectionSetupId);

                try
                {
                    using (var reader = new SafeDataReader(cmd.ExecuteReader()))
                    {
                        while (reader.Read())
                        {
                            var connectionSettingsDto = new ComputerConnectionEditDto
                            {
                                Id = reader.GetInt(0),
                                Guid = reader.GetGuid(1),
                                ConnectionId = reader.GetInt32(2),
                                ComputerConnection = reader.GetString(3),
                                ConnectionType = !string.IsNullOrEmpty(reader.GetString(4))
                                                ? (ConnectionType)Enum.Parse(typeof(ConnectionType), reader.GetString(4))
                                                : ConnectionType.SerialPort,
                                PortName = reader.GetString(5)
                            };
                            dto.ComputerConectionList.Add(connectionSettingsDto);
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw new DBConcurrencyException(ex.Data.ToString());
                }
            }
        }