public static List <OperationRegister> GetLastOperations()
        {
            var operationRegisters = new List <OperationRegister>();

            try
            {
                using (var connection = SqlServer.OpenConnection())
                {
                    const string strSql = "SELECT TOP 10 Id, OperationInId, OperationOutId, PalletId, MoldId, PartId, InitDateTime, EndDateTime FROM OperationRegisters WHERE EndDateTime IS NOT NULL  ORDER BY EndDateTime DESC";

                    using (var command = new SqlCommand(strSql, connection))
                    {
                        using (var reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                var operationRegister = new OperationRegister
                                {
                                    Id          = int.Parse(reader["Id"].ToString()),
                                    OperationIn =
                                        OperationRepository.GetById(int.Parse(reader["OperationInId"].ToString())),
                                    OperationOut =
                                        OperationRepository.GetById(int.Parse(reader["OperationOutId"].ToString())),
                                    Mold   = MoldRepository.GetById(int.Parse(reader["MoldId"].ToString())),
                                    Pallet = PalletRepository.GetById(int.Parse(reader["PalletId"].ToString()))
                                };

                                if (reader["PartId"] != DBNull.Value)
                                {
                                    operationRegister.Part = PartRepository.GetById(int.Parse(reader["PartId"].ToString()));
                                }

                                operationRegister.InitDateTime = (DateTime)reader["InitDateTime"];
                                operationRegister.EndDateTime  = (DateTime)reader["EndDateTime"];

                                operationRegisters.Add(operationRegister);
                            }
                        }
                    }
                }

                return(operationRegisters);
            }
            catch (Exception ex)
            {
                // ReSharper disable once PossibleIntendedRethrow
                throw ex;
            }
        }
        public static OperationRegister GetActiveByPallet(Pallet pallet)
        {
            var operationRegister = new OperationRegister();

            try
            {
                using (var connection = SqlServer.OpenConnection())
                {
                    var strSql = "SELECT Id, OperationInId, PalletId, MoldId, PartId, InitDateTime  FROM OperationRegisters WHERE PalletId=@PalletId AND EndDateTime IS NULL";

                    using (var command = new SqlCommand(strSql, connection))
                    {
                        command.Parameters.AddWithValue("@PalletId", pallet.Id);

                        using (var reader = command.ExecuteReader())
                        {
                            if (reader.Read())
                            {
                                operationRegister.Id          = int.Parse(reader["Id"].ToString());
                                operationRegister.OperationIn = OperationRepository.GetById(int.Parse(reader["OperationInId"].ToString()));
                                operationRegister.Mold        = MoldRepository.GetById(int.Parse(reader["MoldId"].ToString()));
                                operationRegister.Pallet      = PalletRepository.GetById(int.Parse(reader["PalletId"].ToString()));

                                if (reader["PartId"] != DBNull.Value)
                                {
                                    operationRegister.Part = PartRepository.GetById(int.Parse(reader["PartId"].ToString()));
                                }

                                operationRegister.InitDateTime = (DateTime)reader["InitDateTime"];
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                //Introducir en el futuro codigo para NLog.
            }

            return(operationRegister);
        }