示例#1
0
        /// <summary>
        /// Método para actulizar a un empleado
        /// </summary>
        /// <param name="client"></param>
        public static void Actualizar(Client client)
        {
            OperationsLogs.WriteLogsDebug("EmpleadoDal", "Actualizar", string.Format("{0} Info: {1}", DateTime.Now.ToString(), "Empezando a ejecutar el metodo acceso a datos para eliminar un Persona"));

            SqlCommand command = null;

            // Proporcionar la cadena de consulta
            string queryString = @"UPDATE Cliente
                                    WHERE idPersona=@idPersona";

            try
            {
                command = OperationsSql.CreateBasicCommand(queryString);
                command.Parameters.AddWithValue("@idPersona", client.IdPerson);

                //Actualizo a la persona
                PersonDal.Actualizar(client as Person);

                OperationsSql.ExecuteBasicCommand(command);
            }
            catch (SqlException ex)
            {
                OperationsLogs.WriteLogsRelease("EmpleadoDal", "Actualizar", string.Format("{0} Error: {1}", DateTime.Now.ToString(), ex.Message));
                throw ex;
            }
            catch (Exception ex)
            {
                OperationsLogs.WriteLogsRelease("EmpleadoDal", "Actualizar", string.Format("{0} Error: {1}", DateTime.Now.ToString(), ex.Message));
                throw ex;
            }

            OperationsLogs.WriteLogsDebug("EmpleadoDal", "Actualizar", string.Format("{0}  Info: {1}", DateTime.Now.ToString(), "Termino de ejecutar  el metodo acceso a datos para Eliminar un Cliente"));
        }
示例#2
0
        /// <summary>
        /// Inserta una Cliente a la base de datos
        /// </summary>
        /// <param name="Cliente"></param>
        public static void Insertar(Client client)
        {
            OperationsLogs.WriteLogsDebug("ClienteDal", "Insertar", string.Format("{0} Info: {1}",
                                                                                  DateTime.Now.ToString(), "Empezando a ejecutar el metodo acceso a datos para crear un Cliente"));

            SqlCommand command = null;

            //Consulta para insertar Clientes
            string queryString = @"INSERT INTO Cliente(idPersona) 
                                   VALUES(@idCliente)";
            //Declaro e inicio la conexion
            SqlConnection conexion = OperationsSql.ObtenerConexion();

            //Declaro la transaccion
            SqlTransaction transaccion = null;

            try
            {
                //Abro la conexion a la base de datos
                conexion.Open();

                //Inicio la transaccion
                transaccion = conexion.BeginTransaction();

                //Inserto a la persona
                PersonDal.InsertarConTransaccion(client as Person, transaccion, conexion);

                //Inserto al Cliente
                command = OperationsSql.CreateBasicCommandWithTransaction(queryString, transaccion, conexion);
                command.Parameters.AddWithValue("@idCliente", client.IdPerson);

                OperationsSql.ExecuteBasicCommandWithTransaction(command);

                transaccion.Commit();
            }
            catch (SqlException ex)
            {
                OperationsLogs.WriteLogsRelease("ClienteDal", "Insertar", string.Format("{0} Error: {1} ",
                                                                                        DateTime.Now.ToString(), ex.Message));
                throw ex;
            }
            catch (Exception ex)
            {
                OperationsLogs.WriteLogsRelease("ClienteDal", "Insertar", string.Format("{0} Error: {1}",
                                                                                        DateTime.Now.ToString(), ex.Message));
                throw ex;
            }
            finally
            {
                conexion.Close();
            }
            OperationsLogs.WriteLogsDebug("ClienteDal", "Insertar", string.Format("{0} Info: {1}",
                                                                                  DateTime.Now.ToString(),
                                                                                  "Termino de ejecutar  el metodo acceso a datos para insertar Cliente"));
        }
示例#3
0
        /// <summary>
        /// Método para eliminar a un Cliente
        /// </summary>
        /// <param name="Cliente"></param>
        public static void Eliminar(Guid idCliente)
        {
            OperationsLogs.WriteLogsDebug("ClienteDal", "Eliminar", string.Format("{0} Info: {1}", DateTime.Now.ToString(), "Empezando a ejecutar el metodo acceso a datos para eliminar un Persona"));

            SqlCommand command = null;

            // Proporcionar la cadena de consulta
            string queryString = @"UPDATE Cliente SET idPersona = @id
                                    WHERE idPersona=@id";
            //Declaro e inicio la conexion
            SqlConnection conexion = OperationsSql.ObtenerConexion();

            //Declaro la transaccion
            SqlTransaction transaccion = null;

            try
            {
                //Abro la conexion a la base de datos
                conexion.Open();

                //Inicio la transaccion
                transaccion = conexion.BeginTransaction();

                command = OperationsSql.CreateBasicCommandWithTransaction(queryString, transaccion, conexion);
                command.Parameters.AddWithValue("@id", idCliente);

                //Elimino a la persona
                PersonDal.EliminarConTransaccion(idCliente, transaccion, conexion);

                OperationsSql.ExecuteBasicCommandWithTransaction(command);

                transaccion.Commit();
            }
            catch (SqlException ex)
            {
                OperationsLogs.WriteLogsRelease("ClienteDal", "Eliminar", string.Format("{0} Error: {1}", DateTime.Now.ToString(), ex.Message));
                throw ex;
            }
            catch (Exception ex)
            {
                OperationsLogs.WriteLogsRelease("ClienteDal", "Eliminar", string.Format("{0} Error: {1}", DateTime.Now.ToString(), ex.Message));
                throw ex;
            }
            OperationsLogs.WriteLogsDebug("ClienteDal", "Eliminar", string.Format("{0}  Info: {1}", DateTime.Now.ToString(), "Termino de ejecutar  el metodo acceso a datos para Eliminar un Cliente"));
        }
示例#4
0
        /// <summary>
        /// Metodo para obtener  un Cliente
        /// </summary>
        /// <param name="id">Identificado del Cliente </param>
        /// <returns>Cliente</returns>
        public static Client Obtener(Guid id)
        {
            Client        cliente = null;
            SqlCommand    cmd     = null;
            SqlDataReader dr      = null;
            string        query   = @"SELECT c.idPersona, c.idUbicacion
                             FROM Cliente c
                             INNER JOIN Persona p ON p.idPersona = c.idPersona
                             WHERE c.idPersona = @id and p.eliminado = 1";

            try
            {
                cmd = OperationsSql.CreateBasicCommand(query);
                cmd.Parameters.AddWithValue("@id", id);
                dr      = OperationsSql.ExecuteDataReaderCommand(cmd);
                cliente = PersonDal.ObtenerCliente(id);
                while (dr.Read())
                {
                    cliente.IdPerson = dr.GetGuid(0);
                    cliente.Location = LocationDal.Obtener(dr.GetGuid(1));
                }
            }
            catch (SqlException ex)
            {
                OperationsLogs.WriteLogsRelease("ClienteDal", "Obtenet", string.Format("{0} {1} Error: {1}", DateTime.Now.ToString(), DateTime.Now.ToString(), ex.Message));
                throw ex;
            }
            catch (Exception ex)
            {
                OperationsLogs.WriteLogsRelease("ClienteDal", "Obtenet", string.Format("{0} {1} Error: {1}", DateTime.Now.ToString(), DateTime.Now.ToString(), ex.Message));
                throw ex;
            }
            finally
            {
                cmd.Connection.Close();
            }
            return(cliente);
        }